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/src/Source/Apero.php

98 lines
3.4 KiB
PHP
Raw Normal View History

2017-01-23 09:00:42 +02:00
<?php
/*
A set of utilities for tracking text-based game releases
Copyright (C) 2017-2018 Alexander Yakovlev
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
2019-07-29 09:35:32 +03:00
namespace Oreolek\Source;
2017-01-23 09:15:26 +02:00
2019-07-29 09:35:32 +03:00
use \Oreolek\Game;
use \Oreolek\Source;
2017-01-23 09:15:26 +02:00
/**
* Парсер для Apero.ru
* Проблема парсера в том, что на Аперо часто поломана кодировка UTF-8.
*/
2017-01-23 09:00:42 +02:00
class Apero extends Source {
public $title = "Apero";
protected function parse() {
2018-07-20 08:38:23 +03:00
$text = $this->get_text('http://apero.ru/Текстовые-игры/Песочница', [
'order_by' => 'by_public',
]);
$text = mb_convert_encoding($text, 'UTF-8', 'auto');
2018-03-24 21:22:00 +02:00
$this->loadStr($text);
$this->parseIndex();
2018-07-20 08:38:23 +03:00
$text = $this->get_text('http://apero.ru/Текстовые-игры', [
'order_by' => 'by_public',
]);
$text = mb_convert_encoding($text, 'UTF-8', 'auto');
2018-03-24 21:22:00 +02:00
$this->loadStr($text);
$this->parseIndex();
}
2018-03-24 21:22:00 +02:00
protected function parseIndex()
{
2018-03-24 21:22:00 +02:00
$this->dom->filter('.tabled-game-block')->each(function($gameBlock){
$formatter = new \IntlDateFormatter( 'ru', \IntlDateFormatter::LONG, \IntlDateFormatter::NONE );
$date = trim($gameBlock->filter('.game-updated-block')->text(), "() \t\n\r\0\x0B");
2018-06-08 09:22:41 +03:00
$date = str_replace('вчера', date('d.m.Y', strtotime('-1 day')), $date);
2017-01-23 09:00:42 +02:00
$date = $formatter->parse($date);
2018-03-24 21:22:00 +02:00
if ($date < $this->period) return;
2017-01-23 09:00:42 +02:00
$game = new Game;
2018-03-24 21:22:00 +02:00
$game->author = trim($gameBlock->filter('.game-author-block:first-child a')->text());
$game->title = trim($gameBlock->filter('h2 a')->first()->text());
$game->url = trim($gameBlock->filter('h2 a')->first()->attr('href'));
$game->description = trim($gameBlock->filter('.game-desc-block')->first()->text());
2017-01-23 09:00:42 +02:00
$this->output .= $game->print();
2018-03-24 21:22:00 +02:00
});
2017-01-23 09:00:42 +02:00
}
public function checkPage($url) {
return (strpos($url,'http://apero.ru/') !== FALSE);
}
public function page($url) {
$game = new Game;
$game->url = $url;
$game->platform = 'Аперо';
$game->title = $this->dom->filter('dd')->reduce(function($block) {
if ($block->attr('itemprop') === 'name') {
return true;
}
return false;
})->text();
$game->author = [];
$this->dom->filter('dd a')->reduce(function($block){
if ($block->attr('itemprop') === 'author') {
return true;
}
return false;
})->each(function($block) use($game){
$game->author[] = $block->text();
});
$date = $this->dom->filter('meta')->reduce(function($block){
if ($block->attr('itemprop') === 'datePublished') {
return true;
}
return false;
})->first();
if ($date->count() > 0) {
$date = $date->attr('content');
} else {
$date = NULL;
}
$game->date = \DateTime::createFromFormat('Y-M-d', $date);
// TODO description
return $game;
}
2017-01-23 09:00:42 +02:00
}