forked from blallo/rss-bridge
Add new option to receive chapter updates for one specific manga
This commit is contained in:
parent
ff9c60f53c
commit
e6f388d6e4
1 changed files with 98 additions and 39 deletions
|
@ -1,5 +1,5 @@
|
|||
<?php
|
||||
|
||||
define('MANGAREADER_LIMIT', 10); // The default limit
|
||||
class MangareaderBridge extends BridgeAbstract{
|
||||
|
||||
public function loadMetadatas() {
|
||||
|
@ -7,53 +7,112 @@ class MangareaderBridge extends BridgeAbstract{
|
|||
$this->maintainer = "logmanoriginal";
|
||||
$this->name = "Mangareader Bridge";
|
||||
$this->uri = "http://www.mangareader.net";
|
||||
$this->description = "Returns the latest Manga updates";
|
||||
$this->update = "2016-01-10";
|
||||
|
||||
$this->parameters["Get latest updates"] = '[]';
|
||||
$this->description = "Returns the latest updates. Set limits to -1 to disable the limit.";
|
||||
$this->update = "2016-01-16";
|
||||
|
||||
$this->parameters["Get site updates"] = '[]';
|
||||
$this->parameters["Get manga updates"] = '
|
||||
[
|
||||
{
|
||||
"name" : "Manga path",
|
||||
"identifier" : "path",
|
||||
"type" : "text",
|
||||
"required" : "true",
|
||||
"pattern" : "[a-zA-Z0-9-_]*",
|
||||
"exampleValue" : "bleach, umi-no-kishidan"
|
||||
},
|
||||
{
|
||||
"name" : "Limit",
|
||||
"identifier" : "limit",
|
||||
"type" : "number",
|
||||
"exampleValue" : "10"
|
||||
}
|
||||
]';
|
||||
}
|
||||
|
||||
public function collectData(array $param){
|
||||
|
||||
/* We'll use the DOM parser for this as it makes navigation easier */
|
||||
$html = file_get_contents("http://www.mangareader.net/latest");
|
||||
$doc = new DomDocument;
|
||||
$this->request = '';
|
||||
|
||||
$path = "latest";
|
||||
$limit = MANGAREADER_LIMIT;
|
||||
|
||||
if(isset($param['path'])){
|
||||
$path = $param['path'];
|
||||
}
|
||||
|
||||
if(isset($param['limit']) && $param['limit'] !== ""){
|
||||
$limit = $param['limit'];
|
||||
}
|
||||
|
||||
// We'll use the DOM parser for this as it makes navigation easier
|
||||
$html = file_get_contents("http://www.mangareader.net/" . $path);
|
||||
if(!$html){
|
||||
$this->returnError('Could not receive data for ' . $path . '!', 400);
|
||||
}
|
||||
$doc = new DomDocument;
|
||||
@$doc->loadHTML($html);
|
||||
|
||||
/* The latest updates are on the frontpage, navigate via XPath */
|
||||
// Navigate via XPath
|
||||
$xpath = new DomXPath($doc);
|
||||
|
||||
/* Query each item (consists of Manga + chapters) */
|
||||
$nodes = $xpath->query("//*[@id='latestchapters']/table//td");
|
||||
// Build feed based on the context (site updates or manga updates)
|
||||
if($path === "latest"){
|
||||
|
||||
foreach ($nodes as $node){
|
||||
/* Query the manga */
|
||||
$manga = $xpath->query("a[@class='chapter']", $node)->item(0);
|
||||
$this->request = 'Latest';
|
||||
|
||||
/* Collect the chapters for each Manga */
|
||||
$chapters = $xpath->query("a[@class='chaptersrec']", $node);
|
||||
// Query each item (consists of Manga + chapters)
|
||||
$nodes = $xpath->query("//*[@id='latestchapters']/table//td");
|
||||
|
||||
if (isset($manga) && $chapters->length >= 1){
|
||||
$item = new \Item();
|
||||
$item->uri = 'http://www.mangareader.net' . htmlspecialchars($manga->getAttribute('href'));
|
||||
$item->title = htmlspecialchars($manga->nodeValue);
|
||||
foreach ($nodes as $node){
|
||||
// Query the manga
|
||||
$manga = $xpath->query("a[@class='chapter']", $node)->item(0);
|
||||
|
||||
/* Add each chapter to the feed */
|
||||
$item->content = "";
|
||||
// Collect the chapters for each Manga
|
||||
$chapters = $xpath->query("a[@class='chaptersrec']", $node);
|
||||
|
||||
foreach ($chapters as $chapter){
|
||||
if($item->content <> ""){
|
||||
$item->content .= "<br>";
|
||||
}
|
||||
$item->content .= "<a href='http://www.mangareader.net" . htmlspecialchars($chapter->getAttribute('href')) . "'>" . htmlspecialchars($chapter->nodeValue) . "</a>";
|
||||
}
|
||||
if (isset($manga) && $chapters->length >= 1){
|
||||
$item = new \Item();
|
||||
$item->uri = 'http://www.mangareader.net' . htmlspecialchars($manga->getAttribute('href'));
|
||||
$item->title = htmlspecialchars($manga->nodeValue);
|
||||
|
||||
$this->items[] = $item;
|
||||
}
|
||||
}
|
||||
// Add each chapter to the feed
|
||||
$item->content = "";
|
||||
|
||||
/* Return some dummy-data if no content available */
|
||||
foreach ($chapters as $chapter){
|
||||
if($item->content <> ""){
|
||||
$item->content .= "<br>";
|
||||
}
|
||||
$item->content .= "<a href='http://www.mangareader.net" . htmlspecialchars($chapter->getAttribute('href')) . "'>" . htmlspecialchars($chapter->nodeValue) . "</a>";
|
||||
}
|
||||
|
||||
$this->items[] = $item;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
$this->request = $xpath->query(".//*[@id='mangaproperties']//*[@class='aname']")->item(0)->nodeValue;
|
||||
|
||||
$query = "(.//*[@id='listing']//tr)[position() > 1]";
|
||||
|
||||
if($limit !== -1){
|
||||
$query = "(.//*[@id='listing']//tr)[position() > 1][position() <= " . $limit . "]";
|
||||
}
|
||||
|
||||
$chapters = $xpath->query($query);
|
||||
|
||||
foreach ($chapters as $chapter){
|
||||
$item = new \Item();
|
||||
$item->title = $xpath->query("td[1]/a", $chapter)->item(0)->nodeValue; // first column contains anchor with the name
|
||||
$item->uri = 'http://www.mangareader.net' . $xpath->query("td[1]/a", $chapter)->item(0)->getAttribute('href'); // anchor includes path (with leading '/')
|
||||
$item->description = substr($xpath->query("td[1]", $chapter)->item(0)->nodeValue, strlen($item->title) + 4); // first column provides "<name> : <desccription>", we only want the description
|
||||
$item->date = $xpath->query("td[2]", $chapter)->item(0)->nodeValue; // second column provides the release date
|
||||
$item->content = $item->description . "<br/>" . $item->date;
|
||||
$this->items[] = $item;
|
||||
}
|
||||
}
|
||||
|
||||
// Return some dummy-data if no content available
|
||||
if(count($this->items) == 0){
|
||||
$item = new \Item();
|
||||
$item->content = "<p>No updates available</p>";
|
||||
|
@ -63,7 +122,7 @@ class MangareaderBridge extends BridgeAbstract{
|
|||
}
|
||||
|
||||
public function getName(){
|
||||
return 'Mangareader Bridge';
|
||||
return (!empty($this->request) ? $this->request . ' - ' : '') . 'Mangareader Bridge';
|
||||
}
|
||||
|
||||
public function getURI(){
|
||||
|
|
Loading…
Reference in a new issue