2022-05-24 14:34:40 +03:00
|
|
|
|
<?php
|
2022-07-01 16:10:30 +03:00
|
|
|
|
|
2022-05-24 14:34:40 +03:00
|
|
|
|
class CubariBridge extends BridgeAbstract
|
|
|
|
|
{
|
|
|
|
|
const NAME = 'Cubari';
|
|
|
|
|
const URI = 'https://cubari.moe';
|
|
|
|
|
const DESCRIPTION = 'Parses given cubari-formatted JSON file for updates.';
|
|
|
|
|
const MAINTAINER = 'KamaleiZestri';
|
|
|
|
|
const PARAMETERS = [[
|
|
|
|
|
'gist' => [
|
|
|
|
|
'name' => 'Gist/Raw Url',
|
|
|
|
|
'type' => 'text',
|
|
|
|
|
'required' => true,
|
|
|
|
|
'exampleValue' => 'https://raw.githubusercontent.com/kurisumx/baka/main/ikedan'
|
2022-07-01 16:10:30 +03:00
|
|
|
|
]
|
2022-05-24 14:34:40 +03:00
|
|
|
|
]];
|
2022-07-01 16:10:30 +03:00
|
|
|
|
|
2022-05-24 14:34:40 +03:00
|
|
|
|
private $mangaTitle = '';
|
2022-07-01 16:10:30 +03:00
|
|
|
|
|
2022-05-24 14:34:40 +03:00
|
|
|
|
public function getName()
|
|
|
|
|
{
|
|
|
|
|
if (!empty($this->mangaTitle)) {
|
|
|
|
|
return $this->mangaTitle . ' - ' . self::NAME;
|
|
|
|
|
} else {
|
|
|
|
|
return self::NAME;
|
2022-07-01 16:10:30 +03:00
|
|
|
|
}
|
2022-05-24 14:34:40 +03:00
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
|
2022-05-24 14:34:40 +03:00
|
|
|
|
public function getURI()
|
|
|
|
|
{
|
|
|
|
|
if ($this->getInput('gist') != '') {
|
|
|
|
|
return self::URI . '/read/gist/' . $this->getEncodedGist();
|
|
|
|
|
} else {
|
|
|
|
|
return self::URI;
|
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-24 14:34:40 +03:00
|
|
|
|
/**
|
|
|
|
|
* The Cubari bridge.
|
|
|
|
|
*
|
|
|
|
|
* Cubari urls are base64 encodes of a given github raw or gist link described as below:
|
|
|
|
|
* https://cubari.moe/read/gist/${bаse64.url_encode(raw/<rest of the url...>)}/
|
|
|
|
|
* https://cubari.moe/read/gist/${bаse64.url_encode(gist/<rest of the url...>)}/
|
|
|
|
|
* https://cubari.moe/read/gist/${gitio shortcode}
|
|
|
|
|
*
|
|
|
|
|
* This bridge uses just the raw/gist and generates matching cubari urls.
|
|
|
|
|
*/
|
|
|
|
|
public function collectData()
|
|
|
|
|
{
|
|
|
|
|
$jsonSite = getContents($this->getInput('gist'));
|
|
|
|
|
$jsonFile = json_decode($jsonSite, true);
|
2022-07-01 16:10:30 +03:00
|
|
|
|
|
2022-05-24 14:34:40 +03:00
|
|
|
|
$this->mangaTitle = $jsonFile['title'];
|
2022-07-01 16:10:30 +03:00
|
|
|
|
|
2022-05-24 14:34:40 +03:00
|
|
|
|
$chapters = $jsonFile['chapters'];
|
2022-07-01 16:10:30 +03:00
|
|
|
|
|
2022-05-24 14:34:40 +03:00
|
|
|
|
foreach ($chapters as $chapnum => $chapter) {
|
|
|
|
|
$item = $this->getItemFromChapter($chapnum, $chapter);
|
|
|
|
|
$this->items[] = $item;
|
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
|
2022-05-24 14:34:40 +03:00
|
|
|
|
array_multisort(array_column($this->items, 'timestamp'), SORT_DESC, $this->items);
|
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
|
2022-05-24 14:34:40 +03:00
|
|
|
|
protected function getEncodedGist()
|
|
|
|
|
{
|
|
|
|
|
$url = $this->getInput('gist');
|
2022-07-01 16:10:30 +03:00
|
|
|
|
|
2022-05-24 14:34:40 +03:00
|
|
|
|
preg_match('/\/([a-z]*)\.githubusercontent.com(.*)/', $url, $matches);
|
2022-07-01 16:10:30 +03:00
|
|
|
|
|
2022-05-24 14:34:40 +03:00
|
|
|
|
// raw or gist is first match.
|
|
|
|
|
$unencoded = $matches[1] . $matches[2];
|
2022-07-01 16:10:30 +03:00
|
|
|
|
|
2022-05-24 14:34:40 +03:00
|
|
|
|
return base64_encode($unencoded);
|
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
|
2022-05-24 14:34:40 +03:00
|
|
|
|
private function getSanitizedHash($string)
|
|
|
|
|
{
|
|
|
|
|
return hash('sha1', preg_replace('/[^a-zA-Z0-9\-\.]/', '', ucwords(strtolower($string))));
|
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
|
2022-05-24 14:34:40 +03:00
|
|
|
|
protected function getItemFromChapter($chapnum, $chapter)
|
|
|
|
|
{
|
|
|
|
|
$item = [];
|
2022-07-01 16:10:30 +03:00
|
|
|
|
|
2022-05-24 14:34:40 +03:00
|
|
|
|
$item['uri'] = $this->getURI() . '/' . $chapnum;
|
|
|
|
|
$item['title'] = 'Chapter ' . $chapnum . ' - ' . $chapter['title'] . ' - ' . $this->mangaTitle;
|
|
|
|
|
foreach ($chapter['groups'] as $key => $value) {
|
|
|
|
|
$item['author'] = $key;
|
2022-07-01 16:10:30 +03:00
|
|
|
|
}
|
2022-05-24 14:34:40 +03:00
|
|
|
|
$item['timestamp'] = $chapter['last_updated'];
|
2022-07-01 16:10:30 +03:00
|
|
|
|
|
2022-05-24 14:34:40 +03:00
|
|
|
|
$item['content'] = '<p>Manga: <a href=' . $this->getURI() . '>' . $this->mangaTitle . '</a> </p>
|
|
|
|
|
<p>Chapter Number: ' . $chapnum . '</p>
|
|
|
|
|
<p>Chapter Title: <a href=' . $item['uri'] . '>' . $chapter['title'] . '</a></p>
|
|
|
|
|
<p>Group: ' . $item['author'] . '</p>';
|
|
|
|
|
|
|
|
|
|
$item['uid'] = $this->getSanitizedHash($item['title'] . $item['author']);
|
|
|
|
|
|
|
|
|
|
return $item;
|
|
|
|
|
}
|
|
|
|
|
}
|