diff --git a/app/Commands/Collect.php b/app/Commands/Collect.php index abc2a19..48f78ec 100644 --- a/app/Commands/Collect.php +++ b/app/Commands/Collect.php @@ -35,9 +35,9 @@ class Collect extends Command //'Questbook', //'Axma', //'IFDB', - 'Itch', + //'Itch', + 'Instead', /* - 'instead', 'Steam', 'Urq', 'Kvester', diff --git a/app/Sources/Axma.php b/app/Sources/Axma.php index 4e87240..b3b79f1 100644 --- a/app/Sources/Axma.php +++ b/app/Sources/Axma.php @@ -28,6 +28,7 @@ use Log; class Axma extends Source { public $title = "Библиотека AXMA (самая новая)"; + protected $platform = 'AXMA Story Maker'; public $keyword = 'axma'; protected $rootUrl = 'https://axma.info/library/'; protected $games = array(); @@ -86,6 +87,19 @@ class Axma extends Source { $game->authors()->attach($author_model); } } + + $language = Language::findByCode('ru'); + if (!$game->languages()->where('code', 'ru')->exists()) { + $game->languages()->attach($language); + } + + $model = Platform::where('title', $this->platform)->first(); + if (!$model) { + $model = new Platform(); + $model->title = $this->platform; + $model->save(); + } + $game->platforms()->attach($model); }); $i += 5; } diff --git a/app/Sources/Instead.php b/app/Sources/Instead.php index daeb15d..ff18582 100644 --- a/app/Sources/Instead.php +++ b/app/Sources/Instead.php @@ -19,11 +19,27 @@ 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 Instead extends Source { public $title = "INSTEAD репозиторий"; + public $keyword = 'instead'; protected $baseUrl = 'http://instead-games.ru/'; + protected $platform; + protected $language_model; + + public function parse() { + $this->language_model = Language::findByCode('ru'); + $this->platform = Platform::findByName('INSTEAD'); + $this->insteadfeed("http://instead-games.ru/"); + $this->insteadfeed("http://instead-games.ru/index.php?approved=0"); + } + protected function insteadfeed($url) { $text = $this->get_text($url); $this->loadStr($text); @@ -33,14 +49,9 @@ class Instead extends Source { $date = \DateTime::createFromFormat('Y.m.d', $date); $date = $date->format('U'); $url = $this->baseUrl.trim($gameBlock->filter('h2:first-child a:first-child')->first()->attr('href')); - $game = $this->page($url); - $this->saveGame($game); + $this->page($url); }); } - public function parse() { - $this->insteadfeed("http://instead-games.ru/"); - $this->insteadfeed("http://instead-games.ru/index.php?approved=0"); - } public function checkPage($url) { return (strpos($url,'http://instead-games.ru/game.php') !== FALSE); } @@ -50,16 +61,16 @@ class Instead extends Source { unset($text); $game = new Game; $game->url = $url; - $game->platform = 'INSTEAD'; $text = trim($this->dom->filter('#panel')->text()); - preg_match('/Дата: ([0-9]{4}\.[01][0-9]\.[0-3][0-9])Размер/', $text, $matches); - $game->date = \DateTime::createFromFormat('Y.m.d', $matches[1]); - preg_match('/Автор: (.+)Дата/', $text, $matches); - $game->author = trim($matches[1]); + preg_match('/Дата: ([0-9]{4}\.[01][0-9]\.[0-3][0-9])/', $text, $matches); + $game->release_date = \DateTime::createFromFormat('Y.m.d', $matches[1]); + preg_match('/Автор: (.+)/', $text, $matches); + $author = trim($matches[1]); $game->title = trim($this->dom->filter('h2')->first()->text()); + $game = $this->findGame($game); $game->description = trim($this->dom->filter('.gamedsc')->first()->html()); if($this->dom->filter('#instead-em')->first()) { - $game->url_online = $this->baseUrl.$this->dom->filter('#instead-em')->attr('href'); + $game->url_play_online = $this->baseUrl.$this->dom->filter('#instead-em')->attr('href'); $game->url_online_description = 'Играть онлайн'; } $game->url_download = $this->baseUrl.ltrim($this->dom->selectLink('Скачать')->first()->attr('href'), '/'); @@ -69,8 +80,22 @@ class Instead extends Source { } $image = $this->dom->filter('#screenshots a')->first(); if ($image->count() > 0) { - $game->image = $this->baseUrl.$image->attr('href'); + $game->image_url = $this->baseUrl.$image->attr('href'); } - return $game; + $game->save(); + if (!empty($author)) { + $author_model = Author::findByName($author); + if (empty($author_model)) { + $author_model = new Author(); + $author_model->name = $author; + $author_model->save(); + } + if (!$game->authors()->where('name', $author)->exists()) { + $game->authors()->attach($author_model); + } + } + + $game->languages()->attach($this->language_model); + $game->platforms()->attach($this->platform); } }