2019-01-15 18:36:42 +03:00
|
|
|
<?php
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2019-01-15 18:36:42 +03:00
|
|
|
class BakaUpdatesMangaReleasesBridge extends BridgeAbstract
|
|
|
|
{
|
|
|
|
const NAME = 'Baka Updates Manga Releases';
|
|
|
|
const URI = 'https://www.mangaupdates.com/';
|
|
|
|
const DESCRIPTION = 'Get the latest series releases';
|
2021-10-03 23:35:31 +03:00
|
|
|
const MAINTAINER = 'fulmeek, KamaleiZestri';
|
|
|
|
const PARAMETERS = [
|
|
|
|
'By series' => [
|
|
|
|
'series_id' => [
|
|
|
|
'name' => 'Series ID',
|
|
|
|
'type' => 'number',
|
|
|
|
'required' => true,
|
2022-03-24 13:59:34 +03:00
|
|
|
'exampleValue' => '188066'
|
2022-07-01 16:10:30 +03:00
|
|
|
]
|
2021-10-03 23:35:31 +03:00
|
|
|
],
|
|
|
|
'By list' => [
|
|
|
|
'list_id' => [
|
|
|
|
'name' => 'List ID and Type',
|
|
|
|
'type' => 'text',
|
|
|
|
'required' => true,
|
2022-03-24 13:59:34 +03:00
|
|
|
'exampleValue' => '4395&list=read'
|
2022-07-01 16:10:30 +03:00
|
|
|
]
|
|
|
|
]
|
2021-10-03 23:35:31 +03:00
|
|
|
];
|
2019-03-02 21:09:16 +03:00
|
|
|
const LIMIT_COLS = 5;
|
2019-01-15 18:36:42 +03:00
|
|
|
const LIMIT_ITEMS = 10;
|
2021-10-03 23:35:31 +03:00
|
|
|
const RELEASES_URL = 'https://www.mangaupdates.com/releases.html';
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2019-01-15 18:36:42 +03:00
|
|
|
private $feedName = '';
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2019-01-15 18:36:42 +03:00
|
|
|
public function collectData()
|
|
|
|
{
|
2021-10-03 23:35:31 +03:00
|
|
|
if ($this -> queriedContext == 'By series') {
|
|
|
|
$this -> collectDataBySeries();
|
|
|
|
} else { //queriedContext == 'By list'
|
|
|
|
$this -> collectDataByList();
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
|
|
|
|
2021-10-03 23:35:31 +03:00
|
|
|
public function getURI()
|
|
|
|
{
|
|
|
|
if ($this -> queriedContext == 'By series') {
|
|
|
|
$series_id = $this->getInput('series_id');
|
|
|
|
if (!empty($series_id)) {
|
|
|
|
return self::URI . 'releases.html?search=' . $series_id . '&stype=series';
|
|
|
|
}
|
|
|
|
} else { //queriedContext == 'By list'
|
|
|
|
return self::RELEASES_URL;
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
|
|
|
|
2021-10-03 23:35:31 +03:00
|
|
|
return self::URI;
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2021-10-03 23:35:31 +03:00
|
|
|
public function getName()
|
|
|
|
{
|
|
|
|
if (!empty($this->feedName)) {
|
|
|
|
return $this->feedName . ' - ' . self::NAME;
|
|
|
|
}
|
|
|
|
return parent::getName();
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2021-10-03 23:35:31 +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
|
|
|
|
2021-10-03 23:35:31 +03:00
|
|
|
private function filterText($text)
|
|
|
|
{
|
|
|
|
return rtrim($text, '* ');
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2021-10-03 23:35:31 +03:00
|
|
|
private function filterHTML($text)
|
|
|
|
{
|
|
|
|
return $this->filterText(html_entity_decode($text));
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2021-10-03 23:35:31 +03:00
|
|
|
private function findID($manga)
|
|
|
|
{
|
|
|
|
// sometimes new series are on the release list that have no ID. just drop them.
|
|
|
|
if (@$this -> filterHTML($manga -> find('a', 0) -> href) != null) {
|
|
|
|
preg_match('/id=([0-9]*)/', $this -> filterHTML($manga -> find('a', 0) -> href), $match);
|
|
|
|
return $match[1];
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
|
|
|
|
2021-10-03 23:35:31 +03:00
|
|
|
private function collectDataBySeries()
|
|
|
|
{
|
|
|
|
$html = getSimpleHTMLDOM($this->getURI());
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2019-03-02 21:09:16 +03:00
|
|
|
// content is an unstructured pile of divs, ugly to parse
|
|
|
|
$cols = $html->find('div#main_content div.row > div.text');
|
|
|
|
if (!$cols) {
|
2019-01-15 18:36:42 +03:00
|
|
|
returnServerError('No releases');
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
|
|
|
|
2019-03-02 21:09:16 +03:00
|
|
|
$rows = array_slice(
|
|
|
|
array_chunk($cols, self::LIMIT_COLS),
|
|
|
|
0,
|
|
|
|
self::LIMIT_ITEMS
|
|
|
|
);
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2019-03-02 21:09:16 +03:00
|
|
|
if (isset($rows[0][1])) {
|
2019-03-14 21:43:00 +03:00
|
|
|
$this->feedName = $this->filterHTML($rows[0][1]->plaintext);
|
2019-03-02 21:09:16 +03:00
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2019-03-02 21:09:16 +03:00
|
|
|
foreach ($rows as $cols) {
|
|
|
|
if (count($cols) < self::LIMIT_COLS) {
|
|
|
|
continue;
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
|
|
|
|
2019-01-15 18:36:42 +03:00
|
|
|
$item = [];
|
|
|
|
$title = [];
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2019-01-15 18:36:42 +03:00
|
|
|
$item['content'] = '';
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2019-01-15 18:36:42 +03:00
|
|
|
$objDate = $cols[0];
|
|
|
|
if ($objDate) {
|
|
|
|
$item['timestamp'] = strtotime($objDate->plaintext);
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
|
|
|
|
2019-01-15 18:36:42 +03:00
|
|
|
$objTitle = $cols[1];
|
|
|
|
if ($objTitle) {
|
2019-03-14 21:43:00 +03:00
|
|
|
$title[] = $this->filterHTML($objTitle->plaintext);
|
|
|
|
$item['content'] .= '<p>Series: ' . $this->filterText($objTitle->innertext) . '</p>';
|
2019-01-15 18:36:42 +03:00
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2019-01-15 18:36:42 +03:00
|
|
|
$objVolume = $cols[2];
|
|
|
|
if ($objVolume && !empty($objVolume->plaintext)) {
|
|
|
|
$title[] = 'Vol.' . $objVolume->plaintext;
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
|
|
|
|
2019-01-15 18:36:42 +03:00
|
|
|
$objChapter = $cols[3];
|
|
|
|
if ($objChapter && !empty($objChapter->plaintext)) {
|
|
|
|
$title[] = 'Chp.' . $objChapter->plaintext;
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
|
|
|
|
2019-01-15 18:36:42 +03:00
|
|
|
$objAuthor = $cols[4];
|
|
|
|
if ($objAuthor && !empty($objAuthor->plaintext)) {
|
2019-03-14 21:43:00 +03:00
|
|
|
$item['author'] = $this->filterHTML($objAuthor->plaintext);
|
|
|
|
$item['content'] .= '<p>Groups: ' . $this->filterText($objAuthor->innertext) . '</p>';
|
2019-01-15 18:36:42 +03:00
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2019-03-02 21:09:16 +03:00
|
|
|
$item['title'] = implode(' ', $title);
|
|
|
|
$item['uri'] = $this->getURI();
|
2021-10-03 23:35:31 +03:00
|
|
|
$item['uid'] = $this->getSanitizedHash($item['title'] . $item['author']);
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2019-01-15 18:36:42 +03:00
|
|
|
$this->items[] = $item;
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
|
|
|
|
2021-10-03 23:35:31 +03:00
|
|
|
private function collectDataByList()
|
|
|
|
{
|
|
|
|
$this -> feedName = 'Releases';
|
|
|
|
$list = [];
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2021-10-03 23:35:31 +03:00
|
|
|
$releasesHTML = getSimpleHTMLDOM(self::RELEASES_URL);
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2021-10-03 23:35:31 +03:00
|
|
|
$list_id = $this -> getInput('list_id');
|
|
|
|
$listHTML = getSimpleHTMLDOM('https://www.mangaupdates.com/mylist.html?id=' . $list_id);
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2021-10-03 23:35:31 +03:00
|
|
|
//get ids of the manga that the user follows,
|
|
|
|
$parts = $listHTML -> find('table#ptable tr > td.pl');
|
|
|
|
foreach ($parts as $part) {
|
|
|
|
$list[] = $this -> findID($part);
|
2019-01-15 18:36:42 +03:00
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2021-10-03 23:35:31 +03:00
|
|
|
//similar to above, but the divs are in groups of 3.
|
|
|
|
$cols = $releasesHTML -> find('div#main_content div.row > div.pbreak');
|
|
|
|
$rows = array_slice(array_chunk($cols, 3), 0);
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2021-10-03 23:35:31 +03:00
|
|
|
foreach ($rows as $cols) {
|
|
|
|
//check if current manga is in user's list.
|
|
|
|
$id = $this -> findId($cols[0]);
|
|
|
|
if (!array_search($id, $list)) {
|
|
|
|
continue;
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
|
|
|
|
2021-10-03 23:35:31 +03:00
|
|
|
$item = [];
|
|
|
|
$title = [];
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2021-10-03 23:35:31 +03:00
|
|
|
$item['content'] = '';
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2021-10-03 23:35:31 +03:00
|
|
|
$objTitle = $cols[0];
|
|
|
|
if ($objTitle) {
|
|
|
|
$title[] = $this->filterHTML($objTitle->plaintext);
|
|
|
|
$item['content'] .= '<p>Series: ' . $this->filterHTML($objTitle -> innertext) . '</p>';
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2021-10-03 23:35:31 +03:00
|
|
|
$objVolChap = $cols[1];
|
|
|
|
if ($objVolChap && !empty($objVolChap->plaintext)) {
|
|
|
|
$title[] = $this -> filterHTML($objVolChap -> innertext);
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
|
|
|
|
2021-10-03 23:35:31 +03:00
|
|
|
$objAuthor = $cols[2];
|
|
|
|
if ($objAuthor && !empty($objAuthor->plaintext)) {
|
|
|
|
$item['author'] = $this->filterHTML($objAuthor -> plaintext);
|
|
|
|
$item['content'] .= '<p>Groups: ' . $this->filterHTML($objAuthor -> innertext) . '</p>';
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2021-10-03 23:35:31 +03:00
|
|
|
$item['title'] = implode(' ', $title);
|
|
|
|
$item['uri'] = self::URI . 'releases.html?search=' . $id . '&stype=series';
|
|
|
|
$item['uid'] = $this->getSanitizedHash($item['title'] . $item['author']);
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2021-10-03 23:35:31 +03:00
|
|
|
$this->items[] = $item;
|
|
|
|
}
|
2019-03-14 21:43:00 +03:00
|
|
|
}
|
2019-01-15 18:36:42 +03:00
|
|
|
}
|