83 lines
2.8 KiB
PHP
83 lines
2.8 KiB
PHP
<?php
|
|
namespace Source;
|
|
|
|
use \Game;
|
|
use \Symfony\Component\DomCrawler\Crawler;
|
|
|
|
class Steam extends Source {
|
|
public $title = "Steam";
|
|
protected $months = [
|
|
'янв.' => 'January',
|
|
'фев.' => 'February',
|
|
'мар.' => 'March',
|
|
'апр.' => 'April',
|
|
'мая.' => 'May',
|
|
'июн.' => 'June',
|
|
'июл.' => 'July',
|
|
'авг.' => 'August',
|
|
'сен.' => 'September',
|
|
'окт.' => 'October',
|
|
'ноя.' => 'November',
|
|
'дек.' => 'December',
|
|
];
|
|
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
|
|
]);
|
|
$text = $this->get_text($url);
|
|
$this->loadStr($text);
|
|
unset($text);
|
|
$this->dom->filter('#search_result_container a.search_result_row')->each(function($gameLink){
|
|
$url = $gameLink->attr('href');
|
|
$url = substr($url,0,strpos($url, '?')); // remove query string
|
|
$game = $this->page($url);
|
|
$date = $game->date->format('U');
|
|
if ($date < $this->period) return;
|
|
$this->output .= $game->print();
|
|
});
|
|
}
|
|
protected function parse() {
|
|
$this->parse_tag("text-based");
|
|
}
|
|
public function checkPage($url) {
|
|
return (strpos($url,'http://store.steampowered.com/') !== FALSE);
|
|
}
|
|
public function page($url) {
|
|
$this->cookies = 'mature_content=1; Steam_Language=russian';
|
|
$text = $this->get_text($url);
|
|
$game_page = new Crawler($text);
|
|
unset($text);
|
|
|
|
$game = new Game;
|
|
$game->url = $url;
|
|
$game->title = trim($game_page->filter('div.apphub_AppName')->first()->text());
|
|
$game->description = trim($game_page->filter('div.game_description_snippet')->first()->text());
|
|
$game->author = trim($game_page->filter('div#developers_list')->first()->text());
|
|
if (strpos($game->author, ',') !== FALSE) {
|
|
$game->author = explode(',', $game->author);
|
|
$game->author = array_map('trim', $game->author);
|
|
}
|
|
$game->image = $game_page->filter('img.game_header_image_full')->first()->attr('src');
|
|
$game->categories = 'Коммерческая ИЛ';
|
|
$languages = $game_page->filter('.game_language_options tr td:first-child');
|
|
$game->language = [];
|
|
foreach ($languages as $language) {
|
|
$game->language[] = trim($language->nodeValue);
|
|
}
|
|
$game->language = implode(', ', $game->language);
|
|
$date = $game_page->filter('div.date')->first()->text();
|
|
$game->date = \DateTime::createFromFormat('d M, Y', $date);
|
|
if ($game->date === FALSE) { // если Steam отдал страницу на русском
|
|
foreach ($this->months as $ruM => $enM) {
|
|
$date = str_replace($ruM, $enM, $date);
|
|
}
|
|
$game->date = \DateTime::createFromFormat('d F Y', $date);
|
|
}
|
|
return $game;
|
|
}
|
|
}
|