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

View file

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

View file

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