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;
|
2020-04-05 09:13:35 +03:00
|
|
|
use \App\Models\Platform;
|
|
|
|
use \App\Models\Language;
|
|
|
|
use \App\Models\Author;
|
|
|
|
use \App\Models\Tag;
|
2019-09-12 20:03:56 +03:00
|
|
|
use \App\Source;
|
2020-04-05 09:13:35 +03:00
|
|
|
use Log;
|
2019-09-12 20:03:56 +03:00
|
|
|
|
|
|
|
class Instead extends Source {
|
|
|
|
public $title = "INSTEAD репозиторий";
|
2020-04-05 09:13:35 +03:00
|
|
|
public $keyword = 'instead';
|
2019-09-12 20:03:56 +03:00
|
|
|
protected $baseUrl = 'http://instead-games.ru/';
|
2020-04-05 09:13:35 +03:00
|
|
|
protected $platform;
|
|
|
|
protected $language_model;
|
|
|
|
|
|
|
|
public function parse() {
|
|
|
|
$this->language_model = Language::findByCode('ru');
|
|
|
|
$this->platform = Platform::findByName('INSTEAD');
|
|
|
|
$this->insteadfeed("http://instead-games.ru/");
|
|
|
|
$this->insteadfeed("http://instead-games.ru/index.php?approved=0");
|
|
|
|
}
|
|
|
|
|
2019-09-12 20:03:56 +03:00
|
|
|
protected function insteadfeed($url) {
|
|
|
|
$text = $this->get_text($url);
|
|
|
|
$this->loadStr($text);
|
|
|
|
unset($text);
|
|
|
|
$this->dom->filter('.game')->each(function($gameBlock) {
|
|
|
|
$date = trim($gameBlock->filter('.b .date b')->text());
|
|
|
|
$date = \DateTime::createFromFormat('Y.m.d', $date);
|
|
|
|
$date = $date->format('U');
|
|
|
|
$url = $this->baseUrl.trim($gameBlock->filter('h2:first-child a:first-child')->first()->attr('href'));
|
2020-04-05 09:13:35 +03:00
|
|
|
$this->page($url);
|
2019-09-12 20:03:56 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
public function checkPage($url) {
|
|
|
|
return (strpos($url,'http://instead-games.ru/game.php') !== FALSE);
|
|
|
|
}
|
|
|
|
public function page($url) {
|
|
|
|
$text = $this->get_text($url);
|
|
|
|
$this->loadStr($text);
|
|
|
|
unset($text);
|
|
|
|
$game = new Game;
|
|
|
|
$game->url = $url;
|
|
|
|
$text = trim($this->dom->filter('#panel')->text());
|
2020-04-05 09:13:35 +03:00
|
|
|
preg_match('/Дата: ([0-9]{4}\.[01][0-9]\.[0-3][0-9])/', $text, $matches);
|
|
|
|
$game->release_date = \DateTime::createFromFormat('Y.m.d', $matches[1]);
|
|
|
|
preg_match('/Автор: (.+)/', $text, $matches);
|
|
|
|
$author = trim($matches[1]);
|
2019-09-12 20:03:56 +03:00
|
|
|
$game->title = trim($this->dom->filter('h2')->first()->text());
|
2020-04-05 09:13:35 +03:00
|
|
|
$game = $this->findGame($game);
|
2019-09-12 20:03:56 +03:00
|
|
|
$game->description = trim($this->dom->filter('.gamedsc')->first()->html());
|
|
|
|
if($this->dom->filter('#instead-em')->first()) {
|
2020-04-05 09:13:35 +03:00
|
|
|
$game->url_play_online = $this->baseUrl.$this->dom->filter('#instead-em')->attr('href');
|
2019-09-12 20:03:56 +03:00
|
|
|
$game->url_online_description = 'Играть онлайн';
|
|
|
|
}
|
|
|
|
$game->url_download = $this->baseUrl.ltrim($this->dom->selectLink('Скачать')->first()->attr('href'), '/');
|
|
|
|
$link = $this->dom->selectLink('Обсудить')->first();
|
|
|
|
if ($link->count() > 0) {
|
|
|
|
$game->url_discussion = $link->attr('href');
|
|
|
|
}
|
|
|
|
$image = $this->dom->filter('#screenshots a')->first();
|
|
|
|
if ($image->count() > 0) {
|
2020-04-05 09:13:35 +03:00
|
|
|
$game->image_url = $this->baseUrl.$image->attr('href');
|
|
|
|
}
|
|
|
|
$game->save();
|
|
|
|
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
|
|
|
}
|
2020-04-05 09:13:35 +03:00
|
|
|
|
|
|
|
$game->languages()->attach($this->language_model);
|
|
|
|
$game->platforms()->attach($this->platform);
|
2019-09-12 20:03:56 +03:00
|
|
|
}
|
|
|
|
}
|