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