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

85 lines
2.5 KiB
PHP
Raw Normal View History

2017-10-07 11:53:14 +03:00
<?php
namespace Source;
use \Game;
2017-10-26 14:53:48 +03:00
use \PHPHtmlParser\Dom;
2017-10-07 11:53:14 +03:00
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 {
2017-10-26 14:44:32 +03:00
$text = $this->get_text($url);
2017-10-07 11:53:14 +03:00
$this->dom->loadStr($text, []);
2017-10-26 14:44:32 +03:00
} catch (\Exception $e) {
2017-10-07 11:53:14 +03:00
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');
2017-10-26 14:53:48 +03:00
$url = substr($url,0,strpos($url, '?')); // remove query string
2017-12-15 08:05:23 +02:00
$game = new Game;
2017-10-26 14:44:32 +03:00
$game->url = $url;
2017-10-07 15:08:42 +03:00
try {
2017-10-26 14:44:32 +03:00
$text = $this->get_text($url);
2017-10-26 14:53:48 +03:00
$this->dom = new Dom;
2017-10-07 15:08:42 +03:00
$this->dom->loadStr($text, []);
2017-10-26 14:44:32 +03:00
unset($text);
2017-10-26 14:53:48 +03:00
$name = $this->dom->find('div.apphub_AppName');
$description = $this->dom->find('meta[property=og:description]');
2017-10-26 14:44:32 +03:00
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();
2017-10-07 11:53:14 +03:00
}
$this->output .= $game->print();
}
}
protected function parse() {
$this->parse_tag("text-based");
}
2018-03-24 07:45:54 +02:00
public function checkPage($url) {
return (strpos($url,'http://store.steampowered.com/') !== FALSE);
}
public function page($url) {
$text = $this->get_text($url);
try {
$this->dom->loadStr($text, []);
} catch (\Exception $e) {
echo $e->getMessage();
echo $e->getTraceAsString();
return "";
}
unset($text);
$game = new Game;
$game->url = $url;
$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;
}
$date = trim($gameBlock->find('.icon-calendar')->first()->text);
$date = \DateTime::createFromFormat('d F Y', $date);
$date = $date->format('U');
$game->date = $date;
return $game;
}
2017-10-07 11:53:14 +03:00
}