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/>.
|
2020-10-21 10:01:46 +03:00
|
|
|
*/
|
2019-09-12 20:03:56 +03:00
|
|
|
namespace App\Sources;
|
|
|
|
|
|
|
|
use \App\Models\Game;
|
|
|
|
use \App\Source;
|
|
|
|
|
|
|
|
class VNDB extends Source {
|
|
|
|
public $title = "VNDB";
|
2020-10-21 10:01:46 +03:00
|
|
|
public $keyword = 'vndb';
|
|
|
|
protected $fp;
|
2019-09-12 22:30:03 +03:00
|
|
|
public function parse() {
|
2020-10-21 10:01:46 +03:00
|
|
|
$this->fp = fsockopen("api.vndb.org", 19534, $errno, $errstr, 10);
|
|
|
|
$data = array(
|
|
|
|
'protocol' => 1,
|
|
|
|
'client' => 'ifnews',
|
|
|
|
'clientver' => 1.0,
|
|
|
|
'username' => env('VNDB_USER'),
|
|
|
|
'password' => env('VNDB_PASSWORD'),
|
|
|
|
);
|
|
|
|
$response = $this->sendCommand('login', $data);
|
|
|
|
if (empty($response)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$date = (new \DateTime("1 week ago"))->format('Y-m-d');
|
|
|
|
$list = $this->sendCommand('get vn basic (released > "'.$date.'")');
|
|
|
|
// var_dump($list['items'][0]);
|
|
|
|
// die();
|
|
|
|
|
|
|
|
/*
|
|
|
|
foreach ($list['items'] as $gameData) {
|
2019-09-12 20:03:56 +03:00
|
|
|
$game = new Game;
|
|
|
|
$game->title = $gameData->title;
|
2020-10-21 10:01:46 +03:00
|
|
|
$game = $this->findGame($game);
|
|
|
|
// $res = $client->getVisualNovelDataById(5);
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function sendCommand($command, $data = null)
|
|
|
|
{
|
|
|
|
$packet = $command;
|
|
|
|
if ($data) {
|
|
|
|
$packet .= ' ' . json_encode($data);
|
|
|
|
}
|
|
|
|
//echo "SENDING: [$packet]";
|
|
|
|
fwrite($this->fp, $packet . chr(0x04));
|
|
|
|
|
|
|
|
$res = $this->getResponse();
|
|
|
|
|
|
|
|
if ($res === 'ok') {
|
|
|
|
return 'ok';
|
|
|
|
} else {
|
|
|
|
$p = strpos($res, '{');
|
|
|
|
if ($p>0) {
|
|
|
|
// $type = substr($res, 0, $p - 1);
|
|
|
|
|
|
|
|
$json = substr($res, $p);
|
|
|
|
$data = json_decode($json, true);
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getResponse()
|
|
|
|
{
|
|
|
|
$buffer = '';
|
|
|
|
while (!feof($this->fp)) {
|
|
|
|
$c = fgets($this->fp, 2);
|
|
|
|
if (ord($c)==0x04) {
|
|
|
|
return $buffer;
|
|
|
|
} else {
|
|
|
|
$buffer .= $c;
|
|
|
|
}
|
2019-09-12 20:03:56 +03:00
|
|
|
}
|
2020-10-21 10:01:46 +03:00
|
|
|
return null;
|
2019-09-12 20:03:56 +03:00
|
|
|
}
|
|
|
|
}
|