WIP Questbook
This commit is contained in:
parent
2c331e9122
commit
2eec38191f
|
@ -31,9 +31,9 @@ class Collect extends Command
|
||||||
//'Anivisual',
|
//'Anivisual',
|
||||||
//'Hyperbook',
|
//'Hyperbook',
|
||||||
//'HyperbookEn',
|
//'HyperbookEn',
|
||||||
'Apero',
|
//'Apero',
|
||||||
/*
|
|
||||||
'Questbook',
|
'Questbook',
|
||||||
|
/*
|
||||||
'Textadventures',
|
'Textadventures',
|
||||||
'IFDB',
|
'IFDB',
|
||||||
'Itch',
|
'Itch',
|
||||||
|
|
|
@ -11,5 +11,15 @@ class Platform extends Model
|
||||||
|
|
||||||
public function games() {
|
public function games() {
|
||||||
return $this->belongsToMany(Game::class, 'games_platforms', 'platform_id');
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,21 +19,25 @@
|
||||||
namespace App\Sources;
|
namespace App\Sources;
|
||||||
|
|
||||||
use \App\Models\Game;
|
use \App\Models\Game;
|
||||||
|
use \App\Models\Platform;
|
||||||
|
use \App\Models\Language;
|
||||||
|
use \App\Models\Author;
|
||||||
|
use \App\Models\Tag;
|
||||||
use \App\Source;
|
use \App\Source;
|
||||||
|
use Log;
|
||||||
|
|
||||||
class Questbook extends Source {
|
class Questbook extends Source {
|
||||||
public $title = "Сторигеймы";
|
public $title = "Сторигеймы";
|
||||||
|
protected $platform_atril;
|
||||||
|
protected $platform_pdf;
|
||||||
|
protected $language_model;
|
||||||
|
|
||||||
public function parse() {
|
public function parse() {
|
||||||
global $argv;
|
$this->language_model = Language::findByCode('ru');
|
||||||
if (isset($argv[2])) {
|
$this->platform_atril = Platform::findByName('Атрил');
|
||||||
$game_page = $this->get_text($argv[2]);
|
$this->platform_pdf = Platform::findByName('PDF');
|
||||||
$this->loadStr($game_page, []);
|
$this->parseFeed('https://quest-book.ru/directory/rss/');
|
||||||
$this->output .= $this->page($argv[2])->print();
|
$this->parseFeed('https://quest-book.ru/online/rss.xml');
|
||||||
} else {
|
|
||||||
$this->parseFeed('https://quest-book.ru/directory/rss/');
|
|
||||||
$this->parseFeed('https://quest-book.ru/online/rss.xml');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function parseFeed($feedUrl) {
|
public function parseFeed($feedUrl) {
|
||||||
|
@ -57,15 +61,32 @@ class Questbook extends Source {
|
||||||
}
|
}
|
||||||
unset($string);
|
unset($string);
|
||||||
foreach ($games as $gameBlock) {
|
foreach ($games as $gameBlock) {
|
||||||
$date = strtotime($gameBlock['pubDate']);
|
$game = new Game();
|
||||||
if ($date < $this->period) continue;
|
|
||||||
$game = new Game;
|
|
||||||
$game->title = trim($gameBlock['title'] ?? '');
|
$game->title = trim($gameBlock['title'] ?? '');
|
||||||
|
$game->release_date = strtotime($gameBlock['pubDate']);
|
||||||
$game->url = trim($gameBlock['link'] ?? '');
|
$game->url = trim($gameBlock['link'] ?? '');
|
||||||
$game->url = str_replace('http://', 'https://', $game->url);
|
$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->description = trim($gameBlock['description'] ?? '');
|
||||||
$game->author = trim($gameBlock['author'] ?? '');
|
$game->author = trim($gameBlock['author'] ?? '');
|
||||||
$this->output .= $game->print();
|
|
||||||
|
$game = $this->findGame($game);
|
||||||
|
if (!$game->isClean()) {
|
||||||
|
$game->save();
|
||||||
|
$this->page($game->url);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue