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

80 lines
2.7 KiB
PHP
Raw Normal View History

2017-10-07 11:53:14 +03:00
<?php
namespace Source;
use \Game;
2018-03-24 23:11:27 +02:00
use \Symfony\Component\DomCrawler\Crawler;
2017-10-07 11:53:14 +03:00
class Steam extends Source {
public $title = "Steam";
2018-03-24 23:11:27 +02:00
protected $months = [
'янв.' => 'January',
'фев.' => 'February',
'мар.' => 'March',
'апр.' => 'April',
'мая.' => 'May',
'июн.' => 'June',
'июл.' => 'July',
'авг.' => 'August',
'сен.' => 'September',
'окт.' => 'October',
'ноя.' => 'November',
'дек.' => 'December',
];
2017-10-07 11:53:14 +03:00
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
]);
2018-03-24 23:11:27 +02:00
$text = $this->get_text($url);
$this->loadStr($text);
2017-10-07 11:53:14 +03:00
unset($text);
2018-03-24 23:11:27 +02:00
$this->dom->filter('#search_result_container a.search_result_row')->each(function($gameLink){
$url = $gameLink->attr('href');
2017-10-26 14:53:48 +03:00
$url = substr($url,0,strpos($url, '?')); // remove query string
2018-03-24 23:11:27 +02:00
$game = $this->page($url);
$date = $game->date->format('U');
if ($date < $this->period) return;
2017-10-07 11:53:14 +03:00
$this->output .= $game->print();
2018-03-24 23:11:27 +02:00
});
2017-10-07 11:53:14 +03:00
}
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) {
2018-03-24 23:11:27 +02:00
$this->cookies = 'mature_content=1; Steam_Language=russian';
2018-03-24 07:45:54 +02:00
$game = new Game;
$game->url = $url;
2018-03-29 10:42:44 +03:00
$game->title = trim($this->dom->filter('div.apphub_AppName')->first()->text());
$game->description = trim($this->dom->filter('div.game_description_snippet')->first()->text());
$game->author = trim($this->dom->filter('div#developers_list')->first()->text());
if (strpos($game->author, ',') !== FALSE) {
$game->author = explode(',', $game->author);
$game->author = array_map('trim', $game->author);
}
2018-03-29 10:42:44 +03:00
$game->image = $this->dom->filter('img.game_header_image_full')->first()->attr('src');
2018-03-28 17:43:01 +03:00
$game->categories = 'Коммерческая ИЛ';
2018-03-29 10:42:44 +03:00
$languages = $this->dom->filter('.game_language_options tr td:first-child');
2018-03-28 17:43:01 +03:00
$game->language = [];
foreach ($languages as $language) {
$game->language[] = trim($language->nodeValue);
}
$game->language = implode(', ', $game->language);
2018-03-29 10:42:44 +03:00
$date = $this->dom->filter('div.date')->first()->text();
2018-03-24 23:11:27 +02:00
$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);
2018-03-24 07:45:54 +02:00
}
return $game;
}
2017-10-07 11:53:14 +03:00
}