Archived
1
0
Fork 0
This repository has been archived on 2021-07-30. You can view files and clone it, but cannot push or open issues or pull requests.
ifnews/app/Sources/Kvester.php

100 lines
3.8 KiB
PHP
Raw Normal View History

2019-09-12 20:03:56 +03: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/>.
*/
namespace App\Sources;
use \App\Models\Game;
use \App\Source;
2020-04-19 08:58:31 +03:00
use \App\Models\Language;
2020-04-19 09:05:55 +03:00
use \App\Models\Author;
2019-09-12 20:03:56 +03:00
class Kvester extends Source {
public $title = "Квестер";
2020-04-19 08:58:31 +03:00
public $keyword = 'kvester';
2019-09-12 20:03:56 +03:00
protected $baseUrl = 'http://kvester.ru';
2019-09-12 22:30:03 +03:00
public function parse() {
2019-09-12 20:03:56 +03:00
$text = $this->get_text($this->baseUrl."/catalog?sort=date");
2020-04-19 08:58:31 +03:00
if (empty($text)) {
// Квестер опять упал
return;
}
2019-09-12 20:03:56 +03:00
$this->loadStr($text);
unset($text);
$this->dom->filter('.catalog-item')->each(function($gameBlock){
$date = trim($gameBlock->filter('.cell-2 .date')->text(), "() \t\n\r\0\x0B");
$date = \DateTime::createFromFormat("d.m.y", $date);
if ($date === false) return;
$game = new Game;
2020-04-19 09:05:55 +03:00
$game->release_date = $date;
$author = trim(strip_tags($gameBlock->filter('.cell-2 .author')->text()));
2019-09-12 20:03:56 +03:00
$game->title = trim($gameBlock->filter('.cell-2 h3 a')->text());
$game->url = $this->baseUrl.trim($gameBlock->filter('.cell-2 h3 a')->attr('href'));
$game->description = "";
$this->loadStr($this->get_text($game->url));
$game->description = $this->dom->filter('.description')->first()->text();
2020-04-19 08:58:31 +03:00
$game = $this->findGame($game);
$game->save();
2019-09-12 20:03:56 +03:00
2020-04-19 08:58:31 +03:00
$language = Language::findByCode('ru');
if (!$game->languages()->where('code', 'ru')->exists()) {
$game->languages()->attach($language);
}
2020-04-19 09:05:55 +03:00
if (!empty($author)) {
$author_model = Author::findByName($author);
if (empty($author_model)) {
$author_model = new Author();
$author_model->name = $author;
$author_model->save();
}
if (!$game->authors()->where('name', $author)->exists()) {
$game->authors()->attach($author_model);
}
}
2019-09-12 20:03:56 +03:00
});
}
public function checkPage($url) {
return (strpos($url, $this->baseUrl.'/game/') !== FALSE);
}
public function page($url) {
$game = new Game;
$game->url = $url;
$game_id = (int) str_replace($this->baseUrl.'/game/', '', $url);
$game->platform = 'Квестер';
$game->title = trim($this->dom->filter(".qt-in-1 h2")->first()->text());
$game->author = trim($this->dom->filter('.quest-info .author a')->text());
$game->date = \DateTime::createFromFormat(
'd.m.y',
trim($this->dom->filter('.quest-info .date')->first()->text())
);
$game->url_online = $this->baseUrl.trim($this->dom->filter(".play a")->first()->attr('href'));
$game->url_online_description = 'Играть онлайн на Квестер.ру';
$game->description = trim($this->dom->filter('.quest-profile .description')->first()->text());
$game->image = $this->baseUrl.trim($this->dom->filter('.quest-profile .cell-1 img')->first()->attr('src'));
if ($game->author === 'Совместный') {
$this->loadStr($this->get_text($this->baseUrl.'/game/quest/team/'.$game_id.'?ts_mode=public'));
$game->author = [];
$this->dom->filter('.team-item a .txt')->each(function($author) use($game){
$game->author[] = $author->text();
});
}
return $game;
}
}