. */ 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 Axma extends Source { public $title = "Библиотека AXMA (самая новая)"; protected $platform = 'AXMA Story Maker'; public $keyword = 'axma'; protected $rootUrl = 'https://axma.info/library/'; protected $games = array(); protected $urls = []; public function parse() { $i = 0; $text = $this->get_text('https://axma.info/library/?sort=last&from='.$i); $this->loadStr($text); unset($text); $this->dom->filter(".entry.page .entry-content a")->each(function($link) { if ($link->filter('h5')->count() === 0) { return; } $url = $link->attr('href'); $game = new Game(); $game->url = $url; $text = $link->filter('h5')->text(); $version = $link->filter('h5 span.version')->text(); $author = $link->filter('h5 span.author')->text(); $text = str_replace($version, '', $text); $text = str_replace($author, '', $text); $game->title = trim($text); $game = $this->findGame($game); if ($link->nextAll()->filter('div a .coverlib')->count() > 0) { $cover = $link->nextAll('div a .coverlib')->first(); $cover = $cover->attr('src'); if (!empty($cover)) { $game->image_url = 'https://axma.info'.$cover; } } $link->nextAll()->filter('div.small')->each(function($div) use(&$game) { $style = $div->attr('style'); if ($style !== 'float:right;') { return; } if (!empty($game->release_date)) { return; } $time = \DateTime::createFromFormat('d.m.y', $div->text()); if ($time) { $game->release_date = $time; } }); $game->description = $link->nextAll()->filter('a div.subtitle')->text(); if ($game->save() && !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); } } $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; } public function checkPage($url) { return (strpos($url,$this->rootUrl) !== FALSE); } }