-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[GelbooruBridge] + inheriting Bridges. Switch to using Gelbooru API #2472
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a1ef0a0
Use Rule34.xxx API JSON response instead of parsing HTML
quickwick 9e4cd24
Change bridge name back to original
quickwick 5969d6e
Merge branch 'RSS-Bridge:master' into Rule34Bridge
quickwick 10af43d
Change GelbooruBridge to use Gelbooru API, plus all inheriting Bridges
quickwick cef82fe
Merge branch 'Rule34Bridge' of https://github.com/quickwick/rss-bridg…
quickwick 8fb0a81
Error handling for no search results, better file extension search/re…
quickwick File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'; | ||
} | ||
|
||
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']; | ||
|
||
// Remove statistics from the tags list (identified by colon) | ||
foreach($tags as $key => $tag) { | ||
if(strpos($tag, ':') !== false) unset($tags[$key]); | ||
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want this? It generates
HTTP 500 Internal Server Error
from us. Maybe better to give user an empty feed?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Due to how the API works, this should only ever occur when someone is testing/creating a new feed via the web interface. Once they have a working feed URL, it should never generate this error. It may generate the exact same result every single time it's queried, if it's an unpopular tag, but the results should never shrink/disappear. Unless somehow all items with the queried tag are subsequently deleted from the site. If the the site itself goes down or the API changes/stops working, that should fail at a different point in the code.