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/Anivisual.php

82 lines
2.8 KiB
PHP

<?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/>.
*/
namespace Source;
use \Game;
class Anivisual extends Source {
public $title = "Anivisual";
protected $months = [
'Января' => 'January',
'Февраля' => 'February',
'Марта' => 'March',
'Апреля' => 'April',
'Мая' => 'May',
'Июня' => 'June',
'Июля' => 'July',
'Августа' => 'August',
'Сентября' => 'September',
'Октября' => 'October',
'Ноября' => 'November',
'Декабря' => 'December',
];
protected function parse() {
$text = $this->get_text('http://anivisual.net/stuff/1');
$this->loadStr($text);
unset($text);
$this->dom->filter('.entryBlock')->each(function($gameBlock) {
$date = trim($gameBlock->filter('.icon-calendar')->text());
foreach ($this->months as $ruM => $enM) {
$date = str_replace($ruM, $enM, $date);
}
$date = \DateTime::createFromFormat('d F Y', $date);
$date = $date->format('U');
if ($date < $this->period) return;
$game = new Game;
$link = $gameBlock->filter('.novel-ttl a')->first();
$game->title = htmlspecialchars_decode($link->html());
$game->url = 'http://anivisual.net'.$link->attr('href');
$game->description = $gameBlock->filter('span')->first()->text();
$games[] = $game;
$this->output .= $game->print();
});
}
public function checkPage($url) {
return (strpos($url,'http://anivisual.net/stuff/') !== FALSE);
}
public function page($url) {
$game = new Game;
$game->url = $url;
$gameBlock = $this->dom->filter('#casing-box');
$date = trim($gameBlock->filter('.icon-calendar')->first()->text());
if (!empty($date)) {
foreach ($this->months as $ruM => $enM) {
$date = str_replace($ruM, $enM, $date);
}
$game->date = \DateTime::createFromFormat('d F Y', $date);
unset($date);
}
$game->title = htmlspecialchars_decode($gameBlock->filter('h1.logo')->text());
$game->description = $this->dom->filter('#content > section > span')->text();
return $game;
}
}