Archived
1
0
Fork 0

WIP Questbook

This commit is contained in:
Alexander Yakovlev 2020-01-05 16:19:04 +07:00
parent 2c331e9122
commit 2eec38191f
Signed by: oreolek
GPG key ID: 1CDC4B7820C93BD3
3 changed files with 47 additions and 16 deletions

View file

@ -31,9 +31,9 @@ class Collect extends Command
//'Anivisual',
//'Hyperbook',
//'HyperbookEn',
'Apero',
/*
//'Apero',
'Questbook',
/*
'Textadventures',
'IFDB',
'Itch',

View file

@ -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;
}
}

View file

@ -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);
}
}
}