diff --git a/app/Commands/Collect.php b/app/Commands/Collect.php index d17153b..cbe9373 100644 --- a/app/Commands/Collect.php +++ b/app/Commands/Collect.php @@ -31,9 +31,9 @@ class Collect extends Command //'Anivisual', //'Hyperbook', //'HyperbookEn', - 'Apero', - /* + //'Apero', 'Questbook', + /* 'Textadventures', 'IFDB', 'Itch', diff --git a/app/Models/Platform.php b/app/Models/Platform.php index 2df40e2..528b290 100644 --- a/app/Models/Platform.php +++ b/app/Models/Platform.php @@ -11,5 +11,15 @@ class Platform extends Model public function games() { return $this->belongsToMany(Game::class, 'games_platforms', 'platform_id'); - } + } + + public static function findByName($name) { + $model = self::where('name', $name)->first(); + if (empty($model)) { + $model = new self; + $model->name = $name; + $model->save(); + } + return $model; + } } diff --git a/app/Sources/Questbook.php b/app/Sources/Questbook.php index c1447f0..b7589f9 100644 --- a/app/Sources/Questbook.php +++ b/app/Sources/Questbook.php @@ -19,21 +19,25 @@ namespace App\Sources; use \App\Models\Game; +use \App\Models\Platform; +use \App\Models\Language; +use \App\Models\Author; +use \App\Models\Tag; use \App\Source; +use Log; class Questbook extends Source { public $title = "Сторигеймы"; + protected $platform_atril; + protected $platform_pdf; + protected $language_model; public function parse() { - global $argv; - if (isset($argv[2])) { - $game_page = $this->get_text($argv[2]); - $this->loadStr($game_page, []); - $this->output .= $this->page($argv[2])->print(); - } else { - $this->parseFeed('https://quest-book.ru/directory/rss/'); - $this->parseFeed('https://quest-book.ru/online/rss.xml'); - } + $this->language_model = Language::findByCode('ru'); + $this->platform_atril = Platform::findByName('Атрил'); + $this->platform_pdf = Platform::findByName('PDF'); + $this->parseFeed('https://quest-book.ru/directory/rss/'); + $this->parseFeed('https://quest-book.ru/online/rss.xml'); } public function parseFeed($feedUrl) { @@ -57,15 +61,32 @@ class Questbook extends Source { } unset($string); foreach ($games as $gameBlock) { - $date = strtotime($gameBlock['pubDate']); - if ($date < $this->period) continue; - $game = new Game; + $game = new Game(); $game->title = trim($gameBlock['title'] ?? ''); + $game->release_date = strtotime($gameBlock['pubDate']); $game->url = trim($gameBlock['link'] ?? ''); $game->url = str_replace('http://', 'https://', $game->url); + $source_id = NULL; + if (strpos('online/game', $game->url) !== false) { + $source_id = (int) str_replace('https://quest-book.ru/online/game', '', $game->url); + } + if (strpos('/directory/', $game->url) !== false) { + $url = str_replace('https://quest-book.ru/directory/', '', $game->url); + $url = explode('/', $url); + $url = array_filter($url); + $source_id = reset($url); + } + if (!empty($source_id)) { + $game->source_id = $source_id; + } $game->description = trim($gameBlock['description'] ?? ''); $game->author = trim($gameBlock['author'] ?? ''); - $this->output .= $game->print(); + + $game = $this->findGame($game); + if (!$game->isClean()) { + $game->save(); + $this->page($game->url); + } } }