Parse dates, tags and platforms on Itch
This commit is contained in:
parent
e259c5b2b5
commit
478c26ad0e
|
@ -170,6 +170,9 @@ class Anivisual extends Source {
|
|||
$tags = array_map('trim', $tags);
|
||||
$tags = array_filter($tags);
|
||||
$language_ru = Language::findByCode('ru');
|
||||
if (!$game->languages()->where('code', 'ru')->exists()) {
|
||||
$game->languages()->attach($language);
|
||||
}
|
||||
foreach ($tags as $tag) {
|
||||
$model = Tag::where('language_id', $language_ru->id)
|
||||
->where('title', $tag)
|
||||
|
|
|
@ -22,7 +22,6 @@ 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;
|
||||
|
||||
|
|
|
@ -81,7 +81,9 @@ class Itch extends Source {
|
|||
$game_page = $this->get_text($url);
|
||||
$this->loadStr($game_page);
|
||||
$game = $this->page($url);
|
||||
$game->save();
|
||||
if (!empty($game)) {
|
||||
$game->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
public function checkPage($url) {
|
||||
|
@ -93,6 +95,7 @@ class Itch extends Source {
|
|||
$game = $this->findGame($game);
|
||||
$title = trim($this->dom->filter("title")->first()->text());
|
||||
[$game->title, $author_name] = explode(' by ', $title);
|
||||
unset($author_name);
|
||||
unset($title);
|
||||
$this->dom->filter('script[type="application/ld+json"]')->each(function($script) use(&$game) {
|
||||
$data = json_decode($script->html());
|
||||
|
@ -114,11 +117,56 @@ class Itch extends Source {
|
|||
}
|
||||
});
|
||||
$game->title = html_entity_decode($game->title);
|
||||
$date = $this->dom->filter('td abbr');
|
||||
if ($date->count() > 0) {
|
||||
$date = $date->first()->attr('title');
|
||||
$this->dom->filter('.game_info_panel_widget td abbr')->each(function($date) use(&$game) {
|
||||
$label = $date->closest('td')->siblings()->first()->text();
|
||||
$date = $date->attr('title');
|
||||
$date = str_replace('@', '', $date);
|
||||
$game->release_date = new \DateTime($date);
|
||||
switch ($label) {
|
||||
case 'Updated':
|
||||
$game->updated_at = (new \DateTime($date))->format('c');
|
||||
break;
|
||||
case 'Published':
|
||||
case 'Release date':
|
||||
$game->release_date = new \DateTime($date);
|
||||
break;
|
||||
}
|
||||
});
|
||||
$tags = [];
|
||||
$platforms = [];
|
||||
$this->dom->filter('.game_info_panel_widget tr > td > a')->each(function($link) use(&$tags, &$platforms) {
|
||||
if (preg_match('/^https:\/\/itch.io\/games\/tag-/', $link->attr('href'))) {
|
||||
$tags[] = $link->text();
|
||||
}
|
||||
if (preg_match('/^https:\/\/itch.io\/games\/platform-/', $link->attr('href'))) {
|
||||
$platforms[] = $link->text();
|
||||
}
|
||||
});
|
||||
$language_en = Language::findByCode('en');
|
||||
if (!$game->languages()->where('code', 'en')->exists()) {
|
||||
$game->languages()->attach($language_en);
|
||||
}
|
||||
if (array_intersect(['Bitsy', 'VR'], $tags) !== []) {
|
||||
Log::info('Skipping '.$game->title.' for undesirable tags.');
|
||||
// Skip Bitsy and VR games.
|
||||
return;
|
||||
}
|
||||
foreach ($tags as $tag) {
|
||||
$model = Tag::where('language_id', $language_en->id)
|
||||
->where('title', $tag)
|
||||
->first();
|
||||
if (!$model) {
|
||||
$model = new Tag();
|
||||
$model->language_id = $language_en->id;
|
||||
$model->title = $tag;
|
||||
$model->save();
|
||||
}
|
||||
$game->tags()->attach($model);
|
||||
}
|
||||
foreach ($platforms as $platform) {
|
||||
$model = Platform::findByName($platform);
|
||||
if (!$game->platforms()->where('title', $platform)->exists()) {
|
||||
$game->platforms()->attach($model);
|
||||
}
|
||||
}
|
||||
if ($this->print_description) {
|
||||
$desc = $this->dom->filter('.formatted_description');
|
||||
|
|
Reference in a new issue