Archived
1
0
Fork 0
This repository has been archived on 2020-07-31. You can view files and clone it, but cannot push or open issues or pull requests.
news-script/Source/Steam.php

58 lines
1.6 KiB
PHP

<?php
namespace Source;
use \Game;
use \PHPHtmlParser\Dom;
class Steam extends Source {
public $title = "Steam";
protected function parse_tag($tag) {
$url = 'http://store.steampowered.com/search/';
$url .= '?'.http_build_query([
'sort_by' => 'Released_DESC',
'term' => $tag,
'displayterm' => $tag,
'category1' => 998, // only games
]);
try {
$text = $this->get_text($url);
$this->dom->loadStr($text, []);
} catch (\Exception $e) {
echo $e->getMessage();
echo $e->getTraceAsString();
return "";
}
unset($text);
$games = $this->dom->find('#search_result_container a.search_result_row');
foreach ($games as $gameLink) {
$url = $gameLink->getAttribute('href');
$url = substr($url,0,strpos($url, '?')); // remove query string
game = new Game;
$game->url = $url;
try {
$text = $this->get_text($url);
$this->dom = new Dom;
$this->dom->loadStr($text, []);
var_dump($text);
unset($text);
$name = $this->dom->find('div.apphub_AppName');
$description = $this->dom->find('meta[property=og:description]');
try {
$game->title = $name->innerHtml;
$game->description = $description->innerHtml;
} catch (\Exception $e) {
echo 'No title or description found for '.$url.PHP_EOL;
}
} catch (\Exception $e) {
echo $e->getMessage();
echo $e->getTraceAsString();
}
$this->output .= $game->print();
die();
}
}
protected function parse() {
$this->parse_tag("text-based");
}
}