IFDB
This commit is contained in:
parent
8794061ae5
commit
905edf9f6d
|
@ -33,17 +33,17 @@ class Collect extends Command
|
|||
//'HyperbookEn',
|
||||
//'Apero',
|
||||
//'Questbook',
|
||||
'Axma',
|
||||
/*
|
||||
'Textadventures',
|
||||
//'Axma',
|
||||
'IFDB',
|
||||
/*
|
||||
'instead',
|
||||
'Itch',
|
||||
'Steam',
|
||||
'Urq',
|
||||
'Kvester',
|
||||
'vndb',
|
||||
'Instory',
|
||||
'instead',
|
||||
'Textadventures',
|
||||
'vndb',
|
||||
'Dashingdon',
|
||||
'Gamejolt',
|
||||
*/
|
||||
|
|
|
@ -19,10 +19,18 @@
|
|||
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 IFDB extends Source {
|
||||
public $title = "IFDB";
|
||||
public $keyword = 'ifdb';
|
||||
protected $urls = [];
|
||||
|
||||
public function parse() {
|
||||
$service = new \Sabre\Xml\Service();
|
||||
$xml = $this->get_text("http://ifdb.tads.org/allnew-rss");
|
||||
|
@ -33,6 +41,7 @@ class IFDB extends Source {
|
|||
$service->elementMap = [
|
||||
'{}item' => function(\Sabre\Xml\Reader $reader) {
|
||||
$game = new Game;
|
||||
$author = '';
|
||||
$keyValue = \Sabre\Xml\Deserializer\keyValue($reader, '{}item');
|
||||
if (isset($keyValue['{}title'])) {
|
||||
$title = $keyValue['{}title'];
|
||||
|
@ -42,19 +51,33 @@ class IFDB extends Source {
|
|||
$title = explode(' by ', $title);
|
||||
$game->title = $title[0];
|
||||
if (isset($title[1])) {
|
||||
$game->author = $title[1];
|
||||
$author = $title[1];
|
||||
}
|
||||
}
|
||||
if (isset($keyValue['{}link'])) {
|
||||
$game->url = $keyValue['{}link'];
|
||||
$game->url = trim($keyValue['{}link']);
|
||||
$id = str_replace('http:', 'https:', $game->url);
|
||||
$id = str_replace('https://ifdb.tads.org/viewgame?id=', '', $id);
|
||||
$game->source_id = $id;
|
||||
}
|
||||
$game = $this->findGame($game);
|
||||
if (isset($keyValue['{}description'])) {
|
||||
$game->description = $keyValue['{}description'];
|
||||
}
|
||||
if (isset($keyValue['{}pubDate'])) {
|
||||
$game->date = strtotime($keyValue['{}pubDate']);
|
||||
$game->release_date = new \DateTime($keyValue['{}pubDate']);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
$this->saveGame($game);
|
||||
return $game;
|
||||
},
|
||||
];
|
||||
|
|
Reference in a new issue