1
0
Fork 0
forked from blallo/rss-bridge

[bridges] one bridge for technically different imageboard solutions

Danbooru serves HTML content while Moebooru send content in JSON format

Signed-off-by: Pierre Mazière <pierre.maziere@gmx.com>
This commit is contained in:
Pierre Mazière 2016-09-04 01:18:06 +02:00
parent c365f35e47
commit 97926b839e
2 changed files with 94 additions and 30 deletions

View file

@ -1,39 +1,54 @@
<?php <?php
class DanbooruBridge extends BridgeAbstract{ class DanbooruBridge extends BridgeAbstract{
const MAINTAINER = "mitsukarenai"; const MAINTAINER = "mitsukarenai";
const NAME = "Danbooru"; const NAME = "Danbooru";
const URI = "http://donmai.us/"; const URI = "http://donmai.us/";
const DESCRIPTION = "Returns images from given page"; const DESCRIPTION = "Returns images from given page";
const PARAMETERS = array( array( const PARAMETERS = array(
'p'=>array( 'global'=>array(
'name'=>'page', 'p'=>array(
'type'=>'number' 'name'=>'page',
), 'defaultValue'=>1,
't'=>array('name'=>'tags') 'type'=>'number'
)); ),
't'=>array('name'=>'tags')
),
0=>array()
);
public function collectData(){ const PATHTODATA='article';
$page = $this->getInput('p')?$this->getInput('p'):1; const IDATTRIBUTE='data-id';
$tags = urlencode($this->getInput('t'));
$html = $this->getSimpleHTMLDOM(self::URI."posts?&page=$page&tags=$tags") protected function getFullURI(){
or $this->returnServerError('Could not request Danbooru.'); return $this->getURI().'posts?'
foreach($html->find('div[id=posts] article') as $element) { .'&page='.$this->getInput('p')
$item = array(); .'&tags='.urlencode($this->getInput('t'));
$item['uri'] = self::URI.$element->find('a', 0)->href; }
$item['postid'] = (int)preg_replace("/[^0-9]/",'', $element->getAttribute('data-id'));
$item['timestamp'] = time(); protected function getItemFromElement($element){
$thumbnailUri = self::URI.$element->find('img', 0)->src; $item = array();
$item['tags'] = $element->find('img', 0)->getAttribute('alt'); $item['uri'] = $this->getURI().$element->find('a', 0)->href;
$item['title'] = 'Danbooru | '.$item['postid']; $item['postid'] = (int)preg_replace("/[^0-9]/",'', $element->getAttribute(static::IDATTRIBUTE));
$item['content'] = '<a href="' . $item['uri'] . '"><img src="' . $thumbnailUri . '" /></a><br>Tags: '.$item['tags']; $item['timestamp'] = time();
$this->items[] = $item; $thumbnailUri = $this->getURI().$element->find('img', 0)->src;
} $item['tags'] = $element->find('img', 0)->getAttribute('alt');
$item['title'] = $this->getName().' | '.$item['postid'];
$item['content'] = '<a href="' . $item['uri'] . '"><img src="' . $thumbnailUri . '" /></a><br>Tags: '.$item['tags'];
return $item;
}
public function collectData(){
$html = $this->getSimpleHTMLDOM($this->getFullURI())
or $this->returnServerError('Could not request '.$this->getName());
foreach($html->find(static::PATHTODATA) as $element) {
$this->items[] = $this->getItemFromElement($element);
} }
}
public function getCacheDuration(){ public function getCacheDuration(){
return 1800; // 30 minutes return 1800; // 30 minutes
} }
} }

View file

@ -0,0 +1,49 @@
<?php
class MoebooruBridge extends BridgeAbstract{
const NAME = "Moebooru";
const URI = "https://moe.dev.myconan.net/";
const DESCRIPTION = "Returns images from given page";
const PARAMETERS = array( array(
'p'=>array(
'name'=>'page',
'defaultValue'=>1,
'type'=>'number'
),
't'=>array('name'=>'tags')
));
protected function getFullURI(){
return $this->getURI().'post?'
.'page='.$this->getInput('p')
.'&tags='.urlencode($this->getInput('t'));
}
public function collectData(){
$html = $this->getSimpleHTMLDOM($this->getFullURI())
or $this->returnServerError('Could not request '.$this->getName());
$input_json = explode('Post.register(', $html);
foreach($input_json as $element)
$data[] = preg_replace('/}\)(.*)/', '}', $element);
unset($data[0]);
foreach($data as $datai) {
$json = json_decode($datai, TRUE);
$item = array();
$item['uri'] = $this->getURI().'/post/show/'.$json['id'];
$item['postid'] = $json['id'];
$item['timestamp'] = $json['created_at'];
$item['imageUri'] = $json['file_url'];
$item['title'] = $this->getName().' | '.$json['id'];
$item['content'] = '<a href="' . $item['imageUri'] . '"><img src="' . $json['preview_url'] . '" /></a><br>Tags: '.$json['tags'];
$this->items[] = $item;
}
}
public function getCacheDuration(){
return 1800; // 30 minutes
}
}