Archived
1
0
Fork 0

game sources

This commit is contained in:
Alexander Yakovlev 2019-09-13 02:30:03 +07:00
parent f73d5bb412
commit d6afa0e6fa
Signed by: oreolek
GPG key ID: 1CDC4B7820C93BD3
19 changed files with 68 additions and 41 deletions

View file

@ -40,7 +40,7 @@ abstract class Source {
$this->dom = new Crawler($html); $this->dom = new Crawler($html);
} }
abstract protected function parse(); abstract public function parse();
/** /**
* System function to download page HTML. * System function to download page HTML.

View file

@ -37,7 +37,7 @@ class Anivisual extends Source {
'Ноября' => 'November', 'Ноября' => 'November',
'Декабря' => 'December', 'Декабря' => 'December',
]; ];
protected function parse() { public function parse() {
$text = $this->get_text('http://anivisual.net/stuff/1'); $text = $this->get_text('http://anivisual.net/stuff/1');
$this->loadStr($text); $this->loadStr($text);
unset($text); unset($text);

View file

@ -27,7 +27,7 @@ use \App\Source;
*/ */
class Apero extends Source { class Apero extends Source {
public $title = "Apero"; public $title = "Apero";
protected function parse() { public function parse() {
$text = $this->get_text('http://apero.ru/Текстовые-игры/Песочница', [ $text = $this->get_text('http://apero.ru/Текстовые-игры/Песочница', [
'order_by' => 'by_public', 'order_by' => 'by_public',
]); ]);
@ -41,7 +41,7 @@ class Apero extends Source {
$this->loadStr($text); $this->loadStr($text);
$this->parseIndex(); $this->parseIndex();
} }
protected function parseIndex() public function parseIndex()
{ {
$this->dom->filter('.tabled-game-block')->each(function($gameBlock){ $this->dom->filter('.tabled-game-block')->each(function($gameBlock){
$formatter = new \IntlDateFormatter( 'ru', \IntlDateFormatter::LONG, \IntlDateFormatter::NONE ); $formatter = new \IntlDateFormatter( 'ru', \IntlDateFormatter::LONG, \IntlDateFormatter::NONE );

View file

@ -25,7 +25,7 @@ class Axma extends Source {
public $title = "Библиотека AXMA (самая новая)"; public $title = "Библиотека AXMA (самая новая)";
protected $games = array(); protected $games = array();
protected $rootUrl = 'https://axma.info/library/'; protected $rootUrl = 'https://axma.info/library/';
protected function parse() { public function parse() {
$i = 0; $i = 0;
$text = $this->get_text('https://axma.info/library/?sort=last&from='.$i); $text = $this->get_text('https://axma.info/library/?sort=last&from='.$i);
$this->loadStr($text); $this->loadStr($text);

View file

@ -26,7 +26,7 @@ use \App\Source;
*/ */
class Dashingdon extends Source { class Dashingdon extends Source {
public $title = "DashingDon"; public $title = "DashingDon";
protected function parse() { public function parse() {
$text = $this->get_text("https://dashingdon.com/screenreader/"); $text = $this->get_text("https://dashingdon.com/screenreader/");
$this->loadStr($text); $this->loadStr($text);
unset($text); unset($text);

View file

@ -23,7 +23,7 @@ use \App\Source;
class Gamejolt extends Source { class Gamejolt extends Source {
public $title = "GameJolt"; public $title = "GameJolt";
protected function parse_tag($url) { public function parse_tag($url) {
$data = json_decode($this->get_text($url)); $data = json_decode($this->get_text($url));
if (empty($data) or !isset($data->payload)) { if (empty($data) or !isset($data->payload)) {
echo 'GameJolt data empty'; echo 'GameJolt data empty';
@ -44,7 +44,7 @@ class Gamejolt extends Source {
} }
} }
} }
protected function parse() { public function parse() {
try { try {
$this->parse_tag("https://gamejolt.com/site-api/web/library/games/tag/twine"); $this->parse_tag("https://gamejolt.com/site-api/web/library/games/tag/twine");
$this->parse_tag("https://gamejolt.com/site-api/web/library/games/tag/renpy"); $this->parse_tag("https://gamejolt.com/site-api/web/library/games/tag/renpy");

View file

@ -25,7 +25,7 @@ class Hyperbook extends Source {
public $title = "Гиперкнига"; public $title = "Гиперкнига";
protected $games = array(); protected $games = array();
protected $rootUrl = 'http://hyperbook.ru'; protected $rootUrl = 'http://hyperbook.ru';
protected function parse() { public function parse() {
$text = $this->get_text($this->rootUrl.'/lib.php?sort=time'); $text = $this->get_text($this->rootUrl.'/lib.php?sort=time');
$this->loadStr($text); $this->loadStr($text);
unset($text); unset($text);

View file

@ -23,7 +23,7 @@ use \App\Source;
class IFDB extends Source { class IFDB extends Source {
public $title = "IFDB"; public $title = "IFDB";
protected function parse() { public function parse() {
$service = new \Sabre\Xml\Service(); $service = new \Sabre\Xml\Service();
$xml = $this->get_text("http://ifdb.tads.org/allnew-rss"); $xml = $this->get_text("http://ifdb.tads.org/allnew-rss");
$xml = tidy_repair_string($xml, [ $xml = tidy_repair_string($xml, [

View file

@ -37,13 +37,8 @@ class Instead extends Source {
$this->saveGame($game); $this->saveGame($game);
}); });
} }
protected function parse() { public function parse() {
$this->insteadfeed("http://instead-games.ru/"); $this->insteadfeed("http://instead-games.ru/");
if (FORMAT === 'HTML') {
$this->output .= "<h5>Песочница</h5>\n";
} elseif (FORMAT === 'MARKDOWN') {
$this->output .= "##### Песочница\n";
}
$this->insteadfeed("http://instead-games.ru/index.php?approved=0"); $this->insteadfeed("http://instead-games.ru/index.php?approved=0");
} }
public function checkPage($url) { public function checkPage($url) {

View file

@ -23,10 +23,10 @@ use \App\Source;
class Instory extends Source { class Instory extends Source {
public $title = "Instory"; public $title = "Instory";
protected function parse() { public function parse() {
$this->parseFeed('http://instory.su/feed/'); $this->parseFeed('http://instory.su/feed/');
} }
protected function parseFeed($feedUrl) { public function parseFeed($feedUrl) {
$string = $this->get_text($feedUrl); $string = $this->get_text($feedUrl);
$string = mb_convert_encoding($string, 'UTF-8', 'auto'); $string = mb_convert_encoding($string, 'UTF-8', 'auto');
$service = new \Sabre\Xml\Service(); $service = new \Sabre\Xml\Service();
@ -48,13 +48,13 @@ class Instory extends Source {
unset($string); unset($string);
foreach ($games as $gameBlock) { foreach ($games as $gameBlock) {
$date = strtotime($gameBlock['pubDate']); $date = strtotime($gameBlock['pubDate']);
if ($date < $this->period) continue; // TODO abort if pubdate equals to last parsed game
$game = new Game; $game = new Game;
$game->title = trim($gameBlock['title']); $game->title = trim($gameBlock['title']);
$game->url = trim($gameBlock['link']); $game->url = trim($gameBlock['link']);
$game->description = trim($gameBlock['description']); $game->description = trim($gameBlock['description']);
$game->author = trim($gameBlock['{http://purl.org/dc/elements/1.1/}creator']); $game->author = trim($gameBlock['{http://purl.org/dc/elements/1.1/}creator']);
$this->output .= $game->print(); $this->saveGame($game);
} }
} }
public function checkPage($url) { public function checkPage($url) {

View file

@ -27,7 +27,7 @@ class Itch extends Source {
public $queue = []; public $queue = [];
public $games = []; public $games = [];
public $print_description = FALSE; public $print_description = FALSE;
protected function parse_tag($url) { public function parse_tag($url) {
$max_pages = 4; // load 30*4 = 120 latest games $max_pages = 4; // load 30*4 = 120 latest games
for ($i = 1; $i <= $max_pages; $i++) { for ($i = 1; $i <= $max_pages; $i++) {
$cururl = $url.'?format=json&page='.$i; $cururl = $url.'?format=json&page='.$i;
@ -47,12 +47,12 @@ class Itch extends Source {
} }
} }
} }
protected function parse() { public function parse() {
global $argv; global $argv;
if (isset($argv[2])) { if (isset($argv[2])) {
$game_page = $this->get_text($argv[2]); $game_page = $this->get_text($argv[2]);
$this->loadStr($game_page, []); $this->loadStr($game_page);
$this->output .= $this->page($argv[2])->print(); $this->saveGame($this->page($argv[2]));
} else { } else {
$this->parse_tag("https://itch.io/games/newest/tag-text-based"); $this->parse_tag("https://itch.io/games/newest/tag-text-based");
$this->parse_tag("https://itch.io/games/newest/tag-twine"); $this->parse_tag("https://itch.io/games/newest/tag-twine");
@ -60,11 +60,9 @@ class Itch extends Source {
$this->queue = array_unique($this->queue); $this->queue = array_unique($this->queue);
foreach ($this->queue as $game) { foreach ($this->queue as $game) {
$game_page = $this->get_text($game->url); $game_page = $this->get_text($game->url);
$this->loadStr($game_page, []); $this->loadStr($game_page);
$game = $this->page($game->url); $game = $this->page($game->url);
if ($game->date < $this->period) { // if ($game->date < $this->period) {
continue;
}
$this->games[] = $game->print(); $this->games[] = $game->print();
} }
$this->games = array_unique($this->games); $this->games = array_unique($this->games);

View file

@ -24,7 +24,7 @@ use \App\Source;
class Kvester extends Source { class Kvester extends Source {
public $title = "Квестер"; public $title = "Квестер";
protected $baseUrl = 'http://kvester.ru'; protected $baseUrl = 'http://kvester.ru';
protected function parse() { public function parse() {
$text = $this->get_text($this->baseUrl."/catalog?sort=date"); $text = $this->get_text($this->baseUrl."/catalog?sort=date");
$this->loadStr($text); $this->loadStr($text);
unset($text); unset($text);

View file

@ -23,7 +23,7 @@ use \App\Source;
class Qsp extends Source { class Qsp extends Source {
public $title = "Библиотека QSP"; public $title = "Библиотека QSP";
protected function parse() { public function parse() {
$text = $this->get_text("http://qsp.su/index.php?option=com_sobi2&sobi2Task=rss&no_html=1&catid=1&Itemid=55"); $text = $this->get_text("http://qsp.su/index.php?option=com_sobi2&sobi2Task=rss&no_html=1&catid=1&Itemid=55");
$this->loadStr($text); $this->loadStr($text);
unset($text); unset($text);

View file

@ -24,7 +24,7 @@ use \App\Source;
class Questbook extends Source { class Questbook extends Source {
public $title = "Сторигеймы"; public $title = "Сторигеймы";
protected function parse() { public function parse() {
global $argv; global $argv;
if (isset($argv[2])) { if (isset($argv[2])) {
$game_page = $this->get_text($argv[2]); $game_page = $this->get_text($argv[2]);
@ -36,7 +36,7 @@ class Questbook extends Source {
} }
} }
protected function parseFeed($feedUrl) { public function parseFeed($feedUrl) {
$string = $this->get_text($feedUrl); $string = $this->get_text($feedUrl);
$string = mb_convert_encoding($string, 'UTF-8', 'auto'); $string = mb_convert_encoding($string, 'UTF-8', 'auto');
$service = new \Sabre\Xml\Service(); $service = new \Sabre\Xml\Service();

View file

@ -42,7 +42,7 @@ class Steam extends Source {
'ноя.' => 'November', 'ноя.' => 'November',
'дек.' => 'December', 'дек.' => 'December',
]; ];
protected function parse_tag($tag) { public function parse_tag($tag) {
$url = 'https://store.steampowered.com/search/'; $url = 'https://store.steampowered.com/search/';
$url .= '?'.http_build_query([ $url .= '?'.http_build_query([
'sort_by' => 'Released_DESC', 'sort_by' => 'Released_DESC',
@ -66,7 +66,7 @@ class Steam extends Source {
} }
}); });
} }
protected function parse() { public function parse() {
global $argv; global $argv;
if (isset($argv[2])) { if (isset($argv[2])) {
$game = $this->page($argv[2]); $game = $this->page($argv[2]);

View file

@ -24,7 +24,7 @@ use \Symfony\Component\DomCrawler\Crawler;
class Textadventures extends Source { class Textadventures extends Source {
public $title = "Textadventures.co.uk"; public $title = "Textadventures.co.uk";
protected function parse() { public function parse() {
$text = $this->get_text('http://textadventures.co.uk/games/latest'); $text = $this->get_text('http://textadventures.co.uk/games/latest');
$this->loadStr($text); $this->loadStr($text);
unset($text); unset($text);

View file

@ -23,7 +23,7 @@ use \App\Source;
class Urq extends Source { class Urq extends Source {
public $title = "Библиотека URQ"; public $title = "Библиотека URQ";
protected function parse() { public function parse() {
$text = $this->get_text('http://urq.plut.info/node/209'); $text = $this->get_text('http://urq.plut.info/node/209');
$this->loadStr($text); $this->loadStr($text);
unset($text); unset($text);
@ -32,7 +32,7 @@ class Urq extends Source {
$game->author = trim($gameBlock->filter('.views-field-taxonomy-vocabulary-2')->first()->text()); $game->author = trim($gameBlock->filter('.views-field-taxonomy-vocabulary-2')->first()->text());
$game->title = trim($gameBlock->filter('.views-field-title')->text()); $game->title = trim($gameBlock->filter('.views-field-title')->text());
$game->url = 'http://urq.plut.info'.trim($gameBlock->filter('.views-field-title a')->attr('href')); $game->url = 'http://urq.plut.info'.trim($gameBlock->filter('.views-field-title a')->attr('href'));
$this->output .= $game->print(); $this->saveGame($game);
}); });
} }
public function checkPage($url) { public function checkPage($url) {

View file

@ -23,7 +23,7 @@ use \App\Source;
class VNDB extends Source { class VNDB extends Source {
public $title = "VNDB"; public $title = "VNDB";
protected function parse() { public function parse() {
global $config; global $config;
$client = new Client(); $client = new Client();
$client->connect(); $client->connect();

View file

@ -0,0 +1,34 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class Sources extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('games', function (Blueprint $table) {
$table->string('source')->nullable();
$table->string('source_id')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('games', function (Blueprint $table) {
$table->dropColumn('source');
$table->dropColumn('source_id');
});
}
}