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

110 lines
3.5 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 App\Sources;
use \App\Models\Game;
use \App\Models\Platform;
use \App\Models\Language;
use \App\Models\Author;
use \App\Models\Tag;
use \App\Source;
use Log;
class Axma extends Source {
public $title = "Библиотека AXMA (самая новая)";
protected $platform = 'AXMA Story Maker';
public $keyword = 'axma';
protected $rootUrl = 'https://axma.info/library/';
protected $games = array();
protected $urls = [];
public function parse() {
$i = 0;
$text = $this->get_text('https://axma.info/library/?sort=last&from='.$i);
$this->loadStr($text);
unset($text);
$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()) {
$game->authors()->attach($author_model);
}
}
$language = Language::findByCode('ru');
if (!$game->languages()->where('code', 'ru')->exists()) {
$game->languages()->attach($language);
}
$model = Platform::where('title', $this->platform)->first();
if (!$model) {
$model = new Platform();
$model->title = $this->platform;
$model->save();
}
$game->platforms()->attach($model);
});
$i += 5;
}
public function checkPage($url) {
return (strpos($url,$this->rootUrl) !== FALSE);
}
}