2019-09-12 20:03:56 +03:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
A set of utilities for tracking text-based game releases
|
|
|
|
Copyright (C) 2017-2018 Alexander Yakovlev
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2020-10-21 07:48:00 +03:00
|
|
|
*/
|
2019-09-12 20:03:56 +03:00
|
|
|
namespace App\Sources;
|
|
|
|
|
|
|
|
use \App\Models\Game;
|
2020-10-21 07:48:00 +03:00
|
|
|
use \App\Models\Author;
|
|
|
|
use \App\Models\Tag;
|
|
|
|
use \App\Models\Language;
|
2019-09-12 20:03:56 +03:00
|
|
|
use \App\Source;
|
|
|
|
|
|
|
|
class Gamejolt extends Source {
|
|
|
|
public $title = "GameJolt";
|
2020-10-21 07:48:00 +03:00
|
|
|
public $keyword = 'gamejolt';
|
2019-09-12 22:30:03 +03:00
|
|
|
public function parse_tag($url) {
|
2019-09-12 20:03:56 +03:00
|
|
|
$data = json_decode($this->get_text($url));
|
|
|
|
if (empty($data) or !isset($data->payload)) {
|
|
|
|
echo 'GameJolt data empty';
|
|
|
|
return;
|
|
|
|
}
|
2020-10-21 07:48:00 +03:00
|
|
|
$language = Language::findByCode('en');
|
2019-09-12 20:03:56 +03:00
|
|
|
$games = $data->payload->games;
|
|
|
|
if (count($games) > 0) {
|
|
|
|
foreach ($games as $gameData) {
|
2020-10-21 07:48:00 +03:00
|
|
|
$descUrl = 'https://gamejolt.com/site-api/web/discover/games/'.$gameData->id;
|
2019-09-12 20:03:56 +03:00
|
|
|
$descData = json_decode($this->get_text($descUrl));
|
|
|
|
$game = new Game;
|
2020-10-21 09:22:02 +03:00
|
|
|
$game->source_id = $gameData->id;
|
2019-09-12 20:03:56 +03:00
|
|
|
$game->title = $gameData->title;
|
2020-10-21 09:22:02 +03:00
|
|
|
$game = $this->findGame($game);
|
2020-10-21 07:48:00 +03:00
|
|
|
$author_name = $gameData->developer->display_name;
|
|
|
|
$author_model = Author::findByName($author_name);
|
|
|
|
if (empty($author_model)) {
|
|
|
|
$author_model = new Author();
|
|
|
|
$author_model->name = $author_name;
|
|
|
|
$author_model->url = $gameData->developer->web_site;
|
|
|
|
$author_model->save();
|
|
|
|
}
|
|
|
|
$timestamp = floor($gameData->published_on / 1000);
|
|
|
|
$game->release_date = new \DateTime('@'.$timestamp);
|
|
|
|
$content = $descData->payload->game->description_content;
|
|
|
|
$content = json_decode($content);
|
|
|
|
if (isset($descData->payload->metaDescription)) {
|
|
|
|
$game->short_description = $descData->payload->metaDescription;
|
|
|
|
}
|
|
|
|
$tags = [];
|
|
|
|
foreach ($content->content as $bit) {
|
|
|
|
if ($bit->type === 'text') {
|
|
|
|
$game->description = $bit->content;
|
|
|
|
}
|
|
|
|
elseif($bit->type === 'paragraph') {
|
|
|
|
$game->description = '';
|
|
|
|
foreach ($bit->content as $paragraph) {
|
|
|
|
if (isset($paragraph->text)) {
|
|
|
|
$game->description .= $paragraph->text;
|
|
|
|
}
|
|
|
|
if (isset($paragraph->marks)) {
|
|
|
|
foreach ($paragraph->marks as $mark) {
|
|
|
|
if (isset($mark->attrs) && isset($mark->attrs->tag)) {
|
|
|
|
$tag_model = Tag::findByName($mark->attrs->tag, $language);
|
|
|
|
if (!$tag_model) {
|
|
|
|
$tag_model = new Tag;
|
|
|
|
$tag_model->title = $mark->attrs->tag;
|
|
|
|
$tag_model->language_id = $language->id;
|
|
|
|
$tag_model->save();
|
|
|
|
}
|
|
|
|
$tags[] = $tag_model;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elseif ($bit->type === 'tag') {
|
|
|
|
$tag = $bit->attrs->tag;
|
|
|
|
$tag_model = Tag::findByName($tag, $language);
|
|
|
|
$tags[] = $tag_model;
|
|
|
|
}
|
|
|
|
}
|
2019-09-12 20:03:56 +03:00
|
|
|
$game->url = 'https://gamejolt.com/games/'.$gameData->slug.'/'.$gameData->id;
|
2020-10-21 07:48:00 +03:00
|
|
|
$game->save();
|
2020-10-23 11:15:12 +03:00
|
|
|
$game->authors()->sync([$author_model->id]);
|
2020-10-21 07:48:00 +03:00
|
|
|
foreach ($tags as $t) {
|
2020-10-23 11:15:12 +03:00
|
|
|
$game->tags()->syncWithoutDetaching([$t->id]);
|
2020-10-21 07:48:00 +03:00
|
|
|
}
|
2020-10-21 09:45:37 +03:00
|
|
|
$game->guessPlatform();
|
2019-09-12 20:03:56 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-09-12 22:30:03 +03:00
|
|
|
public function parse() {
|
2020-10-21 07:48:00 +03:00
|
|
|
$this->parse_tag("https://gamejolt.com/site-api/web/search/games/?q=twine");
|
|
|
|
$this->parse_tag("https://gamejolt.com/site-api/web/search/games/?q=#twine");
|
|
|
|
$this->parse_tag("https://gamejolt.com/site-api/web/search/games/?q=renpy");
|
|
|
|
$this->parse_tag("https://gamejolt.com/site-api/web/search/games/?q=#renpy");
|
|
|
|
$this->parse_tag("https://gamejolt.com/site-api/web/search/games/?q=#text");
|
|
|
|
$this->parse_tag("https://gamejolt.com/site-api/web/search/games/?q=#ascii");
|
2019-09-12 20:03:56 +03:00
|
|
|
}
|
|
|
|
}
|