Archived
1
0
Fork 0

Hyperbook + HyperbookEn

This commit is contained in:
Alexander Yakovlev 2020-01-05 15:10:04 +07:00
parent 3e8185ca99
commit a18fa48339
Signed by: oreolek
GPG key ID: 1CDC4B7820C93BD3
3 changed files with 27 additions and 9 deletions

View file

@ -30,6 +30,7 @@ class Collect extends Command
protected $parsers = [
//'Anivisual',
'Hyperbook',
'HyperbookEn',
/*
'Apero',
'Questbook',
@ -42,7 +43,6 @@ class Collect extends Command
'vndb',
'Instory',
'instead',
'HyperbookEn',
'Dashingdon',
'Gamejolt',
*/

View file

@ -32,6 +32,9 @@ class Hyperbook extends Source {
protected $platform_model;
protected $language_model;
protected $rootUrl = 'http://hyperbook.ru';
protected function set_language(): void {
$this->language_model = Language::findByCode('ru');
}
public function parse() {
$text = $this->get_text($this->rootUrl.'/lib.php?sort=time');
$this->loadStr($text);
@ -43,15 +46,18 @@ class Hyperbook extends Source {
$model->save();
}
$this->platform_model = $model;
$this->set_language();
$this->language_model = Language::findByCode('ru');
$this->dom->filter("#listPubs h3 a")->each(function($link) {
$urls = [];
$this->dom->filter("#listPubs h3 a")->each(function($link) use (&$urls) {
$id = $link->attr('href');
$id = (int) str_replace('file', '', $id);
$url = $this->rootUrl.'/comments.php?id='.$id;
$this->page($url, $id);
$urls[$id] = $url;
});
foreach ($urls as $id => $url) {
$this->page($url, $id);
}
}
public function checkPage($url) {
return (strpos($url,$this->rootUrl.'/comments.php') !== FALSE);
@ -60,14 +66,22 @@ class Hyperbook extends Source {
$game = new Game;
$game->url = $url;
$game->source_id = $id;
if (empty($game->source_id)) {
throw new \Exception('no id');
return;
}
$game = $this->findGame($game);
if ($game->isClean()) {
return;
}
$game->title = $this->dom->filter(".content h1")->first()->text();
$game->title = trim(str_replace($this->dom->filter("h1 span")->first()->text(), '', $game->title));
$this->loadStr($this->get_text($url));
$title = $this->dom->filter(".content h1")->first()->text();
$this->dom->filter(".content h1 span")->each(function($span) use(&$title) {
$title = trim(str_replace($span->text(), '', $title));
});
$game->title = $title;
$date = $this->dom->filter(".content div.small")->reduce(function($node) {
if ($node->attr('style') === 'float: left; width: 20%; text-align:right;')
@ -77,7 +91,7 @@ class Hyperbook extends Source {
if ($date->count() > 0){
$date = $date->first()->text();
if (!empty($date)) {
$game->date = \DateTime::createFromFormat('d.m.y', $date);
$game->release_date = \DateTime::createFromFormat('d.m.y', $date);
}
}
@ -116,7 +130,7 @@ class Hyperbook extends Source {
}
$game->platforms()->attach($this->platform_model);
if (!$game->languages()->where('code', 'ru')->exists()) {
if (!$game->languages()->where('code', $this->language_model->code)->exists()) {
$game->languages()->attach($this->language_model);
}

View file

@ -19,10 +19,14 @@
namespace App\Sources;
use \App\Models\Game;
use \App\Models\Language;
use \App\Sources\Hyperbook;
use \App\Source;
class HyperbookEn extends Hyperbook {
public $title = "Гиперкнига";
protected $rootUrl = 'http://ifiction.net';
protected function set_language(): void {
$this->language_model = Language::findByCode('en');
}
}