2019-01-15 16:36:42 +01:00
|
|
|
<?php
|
|
|
|
class BakaUpdatesMangaReleasesBridge extends BridgeAbstract {
|
|
|
|
const NAME = 'Baka Updates Manga Releases';
|
|
|
|
const URI = 'https://www.mangaupdates.com/';
|
|
|
|
const DESCRIPTION = 'Get the latest series releases';
|
|
|
|
const MAINTAINER = 'fulmeek';
|
|
|
|
const PARAMETERS = array(array(
|
|
|
|
'series_id' => array(
|
|
|
|
'name' => 'Series ID',
|
|
|
|
'type' => 'number',
|
|
|
|
'required' => true,
|
|
|
|
'exampleValue' => '12345'
|
|
|
|
)
|
|
|
|
));
|
2019-03-02 19:09:16 +01:00
|
|
|
const LIMIT_COLS = 5;
|
2019-01-15 16:36:42 +01:00
|
|
|
const LIMIT_ITEMS = 10;
|
|
|
|
|
|
|
|
private $feedName = '';
|
|
|
|
|
|
|
|
public function collectData() {
|
|
|
|
$html = getSimpleHTMLDOM($this->getURI())
|
|
|
|
or returnServerError('Series not found');
|
|
|
|
|
2019-03-02 19:09:16 +01: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 16:36:42 +01:00
|
|
|
returnServerError('No releases');
|
|
|
|
|
2019-03-02 19:09:16 +01:00
|
|
|
$rows = array_slice(
|
|
|
|
array_chunk($cols, self::LIMIT_COLS), 0, self::LIMIT_ITEMS
|
|
|
|
);
|
|
|
|
|
|
|
|
if (isset($rows[0][1])) {
|
2019-03-14 19:43:00 +01:00
|
|
|
$this->feedName = $this->filterHTML($rows[0][1]->plaintext);
|
2019-03-02 19:09:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
foreach($rows as $cols) {
|
|
|
|
if (count($cols) < self::LIMIT_COLS) continue;
|
2019-01-15 16:36:42 +01:00
|
|
|
|
|
|
|
$item = array();
|
|
|
|
$title = array();
|
|
|
|
|
|
|
|
$item['content'] = '';
|
|
|
|
|
|
|
|
$objDate = $cols[0];
|
|
|
|
if ($objDate)
|
|
|
|
$item['timestamp'] = strtotime($objDate->plaintext);
|
|
|
|
|
|
|
|
$objTitle = $cols[1];
|
|
|
|
if ($objTitle) {
|
2019-03-14 19:43:00 +01:00
|
|
|
$title[] = $this->filterHTML($objTitle->plaintext);
|
|
|
|
$item['content'] .= '<p>Series: ' . $this->filterText($objTitle->innertext) . '</p>';
|
2019-01-15 16:36:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$objVolume = $cols[2];
|
|
|
|
if ($objVolume && !empty($objVolume->plaintext))
|
|
|
|
$title[] = 'Vol.' . $objVolume->plaintext;
|
|
|
|
|
|
|
|
$objChapter = $cols[3];
|
|
|
|
if ($objChapter && !empty($objChapter->plaintext))
|
|
|
|
$title[] = 'Chp.' . $objChapter->plaintext;
|
|
|
|
|
|
|
|
$objAuthor = $cols[4];
|
|
|
|
if ($objAuthor && !empty($objAuthor->plaintext)) {
|
2019-03-14 19:43:00 +01:00
|
|
|
$item['author'] = $this->filterHTML($objAuthor->plaintext);
|
|
|
|
$item['content'] .= '<p>Groups: ' . $this->filterText($objAuthor->innertext) . '</p>';
|
2019-01-15 16:36:42 +01:00
|
|
|
}
|
|
|
|
|
2019-03-02 19:09:16 +01:00
|
|
|
$item['title'] = implode(' ', $title);
|
|
|
|
$item['uri'] = $this->getURI();
|
2019-04-30 21:01:48 +02:00
|
|
|
$item['uid'] = $this->getSanitizedHash($item['title']);
|
2019-01-15 16:36:42 +01:00
|
|
|
|
|
|
|
$this->items[] = $item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getURI(){
|
|
|
|
$series_id = $this->getInput('series_id');
|
|
|
|
if (!empty($series_id)) {
|
|
|
|
return self::URI . 'releases.html?search=' . $series_id . '&stype=series';
|
|
|
|
}
|
|
|
|
return self::URI;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getName(){
|
|
|
|
if(!empty($this->feedName)) {
|
|
|
|
return $this->feedName . ' - ' . self::NAME;
|
|
|
|
}
|
|
|
|
return parent::getName();
|
|
|
|
}
|
2019-03-14 19:43:00 +01:00
|
|
|
|
2019-04-30 21:01:48 +02:00
|
|
|
private function getSanitizedHash($string) {
|
|
|
|
return hash('sha1', preg_replace('/[^a-zA-Z0-9\-\.]/', '', ucwords(strtolower($string))));
|
|
|
|
}
|
|
|
|
|
2019-03-14 19:43:00 +01:00
|
|
|
private function filterText($text) {
|
2019-04-30 21:01:48 +02:00
|
|
|
return rtrim($text, '* ');
|
2019-03-14 19:43:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private function filterHTML($text) {
|
|
|
|
return $this->filterText(html_entity_decode($text));
|
|
|
|
}
|
2019-01-15 16:36:42 +01:00
|
|
|
}
|