Archived
1
0
Fork 0

Парсер INSTEAD

This commit is contained in:
Alexander Yakovlev 2018-04-07 17:41:19 +07:00
parent aa2bab8399
commit 408622afea
2 changed files with 18 additions and 7 deletions

View file

@ -5,6 +5,7 @@ use \Game;
class Instead extends Source {
public $title = "INSTEAD репозиторий";
protected $baseUrl = 'http://instead-games.ru/';
protected function insteadfeed($url) {
$text = $this->get_text($url);
$this->loadStr($text);
@ -17,7 +18,7 @@ class Instead extends Source {
$game = new Game;
$game->author = str_replace(trim($gameBlock->filter('span.author')->first()->text()), 'Автор: ', '');
$game->title = trim($gameBlock->filter('h2:first-child a:first-child')->first()->text());
$game->url = 'http://instead-games.ru/'.trim($gameBlock->filter('h2:first-child a:first-child')->first()->attr('href'));
$game->url = $this->baseUrl.trim($gameBlock->filter('h2:first-child a:first-child')->first()->attr('href'));
$this->output .= $game->print();
});
}
@ -39,10 +40,20 @@ class Instead extends Source {
unset($text);
$game = new Game;
$game->url = $url;
preg_match('/\s([0-9]{4}\.[01][0-9]\.[0-3][0-9])\s/', $this->dom->filter('#panel')->text(), $matches);
$date = \DateTime::createFromFormat('Y.m.d', $matches[0]);
$text = trim($this->dom->filter('#panel')->text());
preg_match('/Дата: ([0-9]{4}\.[01][0-9]\.[0-3][0-9])Размер/', $text, $matches);
$date = \DateTime::createFromFormat('Y.m.d', $matches[1]);
$date = $date->format('U');
$game->author = str_replace(trim($gameBlock->filter('span.author')->first()->text()), 'Автор: ', '');
$game->title = trim($gameBlock->filter('h2')->first()->text());
preg_match('/Автор: (.+)Дата/', $text, $matches);
$game->author = trim($matches[1]);
$game->title = trim($this->dom->filter('h2')->first()->text());
$game->description = trim($this->dom->filter('.gamedsc')->first()->html());
if($this->dom->filter('#instead-em')->first()) {
$game->url_online = $this->baseUrl.$this->dom->filter('#instead-em')->attr('href');
$game->url_online_description = 'Играть онлайн';
}
$game->url_download = $this->baseUrl.ltrim($this->dom->selectLink('Скачать')->first()->attr('href'), '/');
$game->url_discussion = $this->dom->selectLink('Обсудить')->first()->attr('href');
return $game;
}
}

View file

@ -116,12 +116,12 @@ class Wikipage {
if (!empty($this->game->url_download) || !empty($this->game->url_online)) {
$this->content .= "\n== Версии ==";
}
$this->txtadd('url_online', "\n* [#{@game.url_online} #{@game.url_online_description}]");
$this->txtadd('url_online', PHP_EOL.'* ['.$this->game->url_online.' '.$this->game->url_online_description.']');
if (!empty($this->game->url_download)) {
if (!empty($this->game->url_download_description)) {
$this->content .= PHP_EOL.'* ['.$this->game->url_download.' '.$this->game->url_download_description.']';
} else {
$this->content .= "\n* [#{$this->game->url_download} Скачать игру]";
$this->content .= PHP_EOL.'* ['.$this->game->url_download.' Скачать игру]';
}
}
if (!empty($this->game->url_discussion) || !empty($this->game->url)) {