Archived
1
0
Fork 0

Textadventures

This commit is contained in:
Alexander Yakovlev 2018-03-25 03:41:44 +07:00
parent 0f15e8bcef
commit 89ae1da15f

View file

@ -2,36 +2,37 @@
namespace Source; namespace Source;
use \Game; use \Game;
use \Symfony\Component\DomCrawler\Crawler;
class Textadventures extends Source { class Textadventures extends Source {
public $title = "Textadventures.co.uk"; public $title = "Textadventures.co.uk";
protected function parse() { protected function parse() {
$text = $this->get_text('http://textadventures.co.uk/games/latest'); $text = $this->get_text('http://textadventures.co.uk/games/latest');
$this->dom->loadStr($text, []); $this->loadStr($text);
unset($text); unset($text);
$games = $this->dom->find('.games-item'); $this->dom->filter('.games-item')->each(function($gameBlock){
foreach ($games as $gameBlock) {
$game = new Game; $game = new Game;
$game->url = 'http://textadventures.co.uk'.$gameBlock->find('.games-title a')->getAttribute('href'); $game->url = 'http://textadventures.co.uk'.$gameBlock->filter('.games-title a')->attr('href');
$lines = $this->dom->find('.game_info_panel_widget tr'); $game->title = $gameBlock->filter('.games-title a')->text();
$game->title = $gameBlock->find('.games-title a')->innerHtml; $date = strtotime($gameBlock->filter('.games-date')->text());
$date = strtotime($gameBlock->find('.games-date')->innerHtml); if ($date < $this->period) return;
if ($date < $this->period) continue;
$game_page = new \PHPHtmlParser\Dom;
$text = $this->get_text($game->url); $text = $this->get_text($game->url);
$game_page->loadStr($text, []); $game_page = new Crawler($text);
unset($text); unset($text);
try { $game->author = str_replace('by ', '', $game_page->filter('h1 small')->text());
$game->author = str_replace('by ', '', $game_page->find('h1 small')->innerHtml); $image = $game_page->filter('img.cover-image')->first();
$desc = $game_page->find('.col-md-12 .col-md-9 .col-md-7')[0]; if ($image->count()) {
if ($desc) { $game->image = $image->attr('src');
$play = $desc->find('.play-buttons'); }
$desc = strip_tags($desc->innerHtml); $game_page = $game_page->filter('.col-md-12 .col-md-9 > .col-md-12')->first();
$game->description = trim(str_replace(strip_tags($play->innerHtml), '', $desc)); if (!$game_page->count()) {
} $game_page = $game_page->filter('.col-md-12 .col-md-9 > .col-md-7')->first();
} catch (\Exception $e) {} // probably a 18+ game, no info on game page }
if ($game_page->count()) {
$game->desc = trim($game_page->children()->first()->text());
}
$this->output .= $game->print(); $this->output .= $game->print();
} });
} }
} }