mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-01-29 11:58:23 +01:00
[GelbooruBridge] + inheriting Bridges. Switch to using Gelbooru API (#2472)
This commit is contained in:
parent
c6675ddeee
commit
907d09f116
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
require_once('GelbooruBridge.php');
|
||||
require_once('DanbooruBridge.php');
|
||||
|
||||
class BooruprojectBridge extends GelbooruBridge {
|
||||
class BooruprojectBridge extends DanbooruBridge {
|
||||
|
||||
const MAINTAINER = 'mitsukarenai';
|
||||
const NAME = 'Booruproject';
|
||||
@ -11,6 +11,7 @@ class BooruprojectBridge extends GelbooruBridge {
|
||||
'global' => array(
|
||||
'p' => array(
|
||||
'name' => 'page',
|
||||
'defaultValue' => 0,
|
||||
'type' => 'number'
|
||||
),
|
||||
't' => array(
|
||||
@ -29,8 +30,30 @@ class BooruprojectBridge extends GelbooruBridge {
|
||||
)
|
||||
);
|
||||
|
||||
const PATHTODATA = '.thumb';
|
||||
const IDATTRIBUTE = 'id';
|
||||
const TAGATTRIBUTE = 'title';
|
||||
const PIDBYPAGE = 20;
|
||||
|
||||
protected function getFullURI(){
|
||||
return $this->getURI()
|
||||
. 'index.php?page=post&s=list&pid='
|
||||
. ($this->getInput('p') ? ($this->getInput('p') - 1) * static::PIDBYPAGE : '')
|
||||
. '&tags=' . urlencode($this->getInput('t'));
|
||||
}
|
||||
|
||||
protected function getTags($element){
|
||||
$tags = parent::getTags($element);
|
||||
$tags = explode(' ', $tags);
|
||||
|
||||
// Remove statistics from the tags list (identified by colon)
|
||||
foreach($tags as $key => $tag) {
|
||||
if(strpos($tag, ':') !== false) unset($tags[$key]);
|
||||
}
|
||||
|
||||
return implode(' ', $tags);
|
||||
}
|
||||
|
||||
public function getURI(){
|
||||
if(!is_null($this->getInput('i'))) {
|
||||
return 'https://' . $this->getInput('i') . '.booru.org/';
|
||||
|
@ -1,35 +1,87 @@
|
||||
<?php
|
||||
require_once('DanbooruBridge.php');
|
||||
|
||||
class GelbooruBridge extends DanbooruBridge {
|
||||
class GelbooruBridge extends BridgeAbstract {
|
||||
|
||||
const MAINTAINER = 'mitsukarenai';
|
||||
const NAME = 'Gelbooru';
|
||||
const URI = 'http://gelbooru.com/';
|
||||
const URI = 'https://gelbooru.com/';
|
||||
const DESCRIPTION = 'Returns images from given page';
|
||||
|
||||
const PATHTODATA = '.thumb';
|
||||
const IDATTRIBUTE = 'id';
|
||||
const TAGATTRIBUTE = 'title';
|
||||
|
||||
const PIDBYPAGE = 63;
|
||||
const PARAMETERS = array(
|
||||
'global' => array(
|
||||
'p' => array(
|
||||
'name' => 'page',
|
||||
'defaultValue' => 0,
|
||||
'type' => 'number'
|
||||
),
|
||||
't' => array(
|
||||
'name' => 'tags',
|
||||
'exampleValue' => 'pinup',
|
||||
'title' => 'Tags to search for'
|
||||
),
|
||||
'l' => array(
|
||||
'name' => 'limit',
|
||||
'exampleValue' => 100,
|
||||
'title' => 'How many posts to retrieve (hard limit of 1000)'
|
||||
)
|
||||
),
|
||||
0 => array()
|
||||
);
|
||||
|
||||
protected function getFullURI(){
|
||||
return $this->getURI()
|
||||
. 'index.php?page=post&s=list&pid='
|
||||
. ($this->getInput('p') ? ($this->getInput('p') - 1) * static::PIDBYPAGE : '')
|
||||
. 'index.php?&page=dapi&s=post&q=index&json=1&pid=' . $this->getInput('p')
|
||||
. '&limit=' . $this->getInput('l')
|
||||
. '&tags=' . urlencode($this->getInput('t'));
|
||||
}
|
||||
|
||||
protected function getTags($element){
|
||||
$tags = parent::getTags($element);
|
||||
$tags = explode(' ', $tags);
|
||||
/*
|
||||
This function is superfluous for GelbooruBridge, but useful
|
||||
for Bridges that inherit from it
|
||||
*/
|
||||
protected function buildThumbnailURI($element){
|
||||
return $this->getURI() . 'thumbnails/' . $element->directory
|
||||
. '/thumbnail_' . $element->md5 . '.jpg';
|
||||
}
|
||||
|
||||
// Remove statistics from the tags list (identified by colon)
|
||||
foreach($tags as $key => $tag) {
|
||||
if(strpos($tag, ':') !== false) unset($tags[$key]);
|
||||
protected function getItemFromElement($element){
|
||||
$item = array();
|
||||
$item['uri'] = $this->getURI() . 'index.php?page=post&s=view&id='
|
||||
. $element->id;
|
||||
$item['postid'] = $element->id;
|
||||
$item['author'] = $element->owner;
|
||||
$item['timestamp'] = date('d F Y H:i:s', $element->change);
|
||||
$item['tags'] = $element->tags;
|
||||
$item['title'] = $this->getName() . ' | ' . $item['postid'];
|
||||
|
||||
if (isset($element->preview_url)) {
|
||||
$thumbnailUri = $element->preview_url;
|
||||
} else{
|
||||
$thumbnailUri = $this->buildThumbnailURI($element);
|
||||
}
|
||||
|
||||
return implode(' ', $tags);
|
||||
$item['content'] = '<a href="' . $item['uri'] . '"><img src="'
|
||||
. $thumbnailUri . '" /></a><br><br><b>Tags:</b> '
|
||||
. $item['tags'] . '<br><br>' . $item['timestamp'];
|
||||
|
||||
return $item;
|
||||
}
|
||||
|
||||
public function collectData(){
|
||||
$content = getContents($this->getFullURI());
|
||||
|
||||
// Most other Gelbooru-based boorus put their content in the root of
|
||||
// the JSON. This check is here for Bridges that inherit from this one
|
||||
$posts = json_decode($content);
|
||||
if (isset($posts->post)) {
|
||||
$posts = $posts->post;
|
||||
}
|
||||
|
||||
if (is_null($posts)) {
|
||||
returnServerError('No posts found.');
|
||||
}
|
||||
|
||||
foreach($posts as $post) {
|
||||
$this->items[] = $this->getItemFromElement($post);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,8 +5,11 @@ class MspabooruBridge extends GelbooruBridge {
|
||||
|
||||
const MAINTAINER = 'mitsukarenai';
|
||||
const NAME = 'Mspabooru';
|
||||
const URI = 'http://mspabooru.com/';
|
||||
const URI = 'https://mspabooru.com/';
|
||||
const DESCRIPTION = 'Returns images from given page';
|
||||
const PIDBYPAGE = 50;
|
||||
|
||||
protected function buildThumbnailURI($element){
|
||||
return $this->getURI() . 'thumbnails/' . $element->directory
|
||||
. '/thumbnail_' . $element->image;
|
||||
}
|
||||
}
|
||||
|
@ -8,5 +8,4 @@ class Rule34Bridge extends GelbooruBridge {
|
||||
const URI = 'https://rule34.xxx/';
|
||||
const DESCRIPTION = 'Returns images from given page';
|
||||
|
||||
const PIDBYPAGE = 50;
|
||||
}
|
||||
|
@ -8,5 +8,9 @@ class SafebooruBridge extends GelbooruBridge {
|
||||
const URI = 'https://safebooru.org/';
|
||||
const DESCRIPTION = 'Returns images from given page';
|
||||
|
||||
const PIDBYPAGE = 40;
|
||||
protected function buildThumbnailURI($element){
|
||||
$regex = '/\.\w+$/';
|
||||
return $this->getURI() . 'thumbnails/' . $element->directory
|
||||
. '/thumbnail_' . preg_replace($regex, '.jpg', $element->image);
|
||||
}
|
||||
}
|
||||
|
@ -8,5 +8,9 @@ class TbibBridge extends GelbooruBridge {
|
||||
const URI = 'https://tbib.org/';
|
||||
const DESCRIPTION = 'Returns images from given page';
|
||||
|
||||
const PIDBYPAGE = 50;
|
||||
protected function buildThumbnailURI($element){
|
||||
$regex = '/\.\w+$/';
|
||||
return $this->getURI() . 'thumbnails/' . $element->directory
|
||||
. '/thumbnail_' . preg_replace($regex, '.jpg', $element->image);
|
||||
}
|
||||
}
|
||||
|
@ -8,5 +8,8 @@ class XbooruBridge extends GelbooruBridge {
|
||||
const URI = 'https://xbooru.com/';
|
||||
const DESCRIPTION = 'Returns images from given page';
|
||||
|
||||
const PIDBYPAGE = 50;
|
||||
protected function buildThumbnailURI($element){
|
||||
return $this->getURI() . 'thumbnails/' . $element->directory
|
||||
. '/thumbnail_' . $element->hash . '.jpg';
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user