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-04 15:53:51 +03:00
|
|
|
use \App\Models\Platform;
|
|
|
|
use \App\Models\Language;
|
|
|
|
use \App\Models\Author;
|
2019-09-12 20:03:56 +03:00
|
|
|
use \App\Source;
|
2020-04-04 15:53:51 +03:00
|
|
|
use Log;
|
2019-09-12 20:03:56 +03:00
|
|
|
|
|
|
|
class Axma extends Source {
|
|
|
|
public $title = "Библиотека AXMA (самая новая)";
|
2020-04-05 09:13:35 +03:00
|
|
|
protected $platform = 'AXMA Story Maker';
|
2020-04-04 15:53:51 +03:00
|
|
|
public $keyword = 'axma';
|
2019-09-12 20:03:56 +03:00
|
|
|
protected $rootUrl = 'https://axma.info/library/';
|
2020-04-04 15:53:51 +03:00
|
|
|
protected $games = array();
|
|
|
|
protected $urls = [];
|
|
|
|
|
2019-09-12 22:30:03 +03:00
|
|
|
public function parse() {
|
2019-09-12 20:03:56 +03:00
|
|
|
$i = 0;
|
|
|
|
$text = $this->get_text('https://axma.info/library/?sort=last&from='.$i);
|
|
|
|
$this->loadStr($text);
|
|
|
|
unset($text);
|
2020-04-04 15:53:51 +03:00
|
|
|
$this->dom->filter(".entry.page .entry-content a")->each(function($link) {
|
|
|
|
if ($link->filter('h5')->count() === 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$url = $link->attr('href');
|
|
|
|
$game = new Game();
|
|
|
|
$game->url = $url;
|
|
|
|
$text = $link->filter('h5')->text();
|
|
|
|
$version = $link->filter('h5 span.version')->text();
|
|
|
|
$author = $link->filter('h5 span.author')->text();
|
|
|
|
$text = str_replace($version, '', $text);
|
|
|
|
$text = str_replace($author, '', $text);
|
|
|
|
$game->title = trim($text);
|
|
|
|
|
|
|
|
$game = $this->findGame($game);
|
|
|
|
|
|
|
|
if ($link->nextAll()->filter('div a .coverlib')->count() > 0) {
|
|
|
|
$cover = $link->nextAll('div a .coverlib')->first();
|
|
|
|
$cover = $cover->attr('src');
|
|
|
|
if (!empty($cover)) {
|
|
|
|
$game->image_url = 'https://axma.info'.$cover;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$link->nextAll()->filter('div.small')->each(function($div) use(&$game) {
|
|
|
|
$style = $div->attr('style');
|
|
|
|
if ($style !== 'float:right;') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!empty($game->release_date)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$time = \DateTime::createFromFormat('d.m.y', $div->text());
|
|
|
|
if ($time) {
|
|
|
|
$game->release_date = $time;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
$game->description = $link->nextAll()->filter('a div.subtitle')->text();
|
|
|
|
if ($game->save() && !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()) {
|
2020-10-23 11:15:12 +03:00
|
|
|
$game->authors()->sync([$author_model->id]);
|
2020-04-04 15:53:51 +03:00
|
|
|
}
|
|
|
|
}
|
2020-04-05 09:13:35 +03:00
|
|
|
|
|
|
|
$language = Language::findByCode('ru');
|
2020-10-23 11:15:12 +03:00
|
|
|
$game->languages()->sync([$language->id]);
|
2020-04-05 09:13:35 +03:00
|
|
|
|
|
|
|
$model = Platform::where('title', $this->platform)->first();
|
|
|
|
if (!$model) {
|
|
|
|
$model = new Platform();
|
|
|
|
$model->title = $this->platform;
|
|
|
|
$model->save();
|
|
|
|
}
|
2020-10-23 11:15:12 +03:00
|
|
|
$game->platforms()->sync([$model->id]);
|
2020-04-04 15:53:51 +03:00
|
|
|
});
|
|
|
|
$i += 5;
|
|
|
|
}
|
|
|
|
public function checkPage($url) {
|
|
|
|
return (strpos($url,$this->rootUrl) !== FALSE);
|
|
|
|
}
|
2019-09-12 20:03:56 +03:00
|
|
|
}
|