2018-12-26 23:14:04 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class DerpibooruBridge extends BridgeAbstract
|
2022-07-01 16:10:30 +03:00
|
|
|
{
|
2018-12-26 23:14:04 +03:00
|
|
|
const NAME = 'Derpibooru Bridge';
|
|
|
|
const URI = 'https://derpibooru.org/';
|
|
|
|
const DESCRIPTION = 'Returns newest images from a Derpibooru search';
|
|
|
|
const CACHE_TIMEOUT = 300; // 5min
|
|
|
|
const MAINTAINER = 'Roliga';
|
|
|
|
|
|
|
|
const PARAMETERS = [
|
2022-07-01 16:10:30 +03:00
|
|
|
[
|
2018-12-26 23:14:04 +03:00
|
|
|
'f' => [
|
|
|
|
'name' => 'Filter',
|
2022-03-24 13:59:34 +03:00
|
|
|
'type' => 'list',
|
|
|
|
'values' => [
|
|
|
|
'Everything' => 56027,
|
2018-12-26 23:14:04 +03:00
|
|
|
'18+ R34' => 37432,
|
2022-03-24 13:59:34 +03:00
|
|
|
'Legacy Default' => 37431,
|
2018-12-26 23:14:04 +03:00
|
|
|
'18+ Dark' => 37429,
|
|
|
|
'Maximum Spoilers' => 37430,
|
|
|
|
'Default' => 100073
|
2022-07-01 16:10:30 +03:00
|
|
|
],
|
2022-03-24 13:59:34 +03:00
|
|
|
'defaultValue' => 56027
|
2018-12-26 23:14:04 +03:00
|
|
|
|
2022-07-01 16:10:30 +03:00
|
|
|
],
|
|
|
|
'q' => [
|
2018-12-26 23:14:04 +03:00
|
|
|
'name' => 'Query',
|
2022-03-24 13:59:34 +03:00
|
|
|
'required' => true,
|
2018-12-26 23:14:04 +03:00
|
|
|
'exampleValue' => 'dog',
|
2022-07-01 16:10:30 +03:00
|
|
|
]
|
|
|
|
]
|
2018-12-26 23:14:04 +03:00
|
|
|
];
|
|
|
|
|
|
|
|
public function detectParameters($url)
|
|
|
|
{
|
|
|
|
$params = [];
|
|
|
|
|
|
|
|
// Search page e.g. https://derpibooru.org/search?q=cute
|
|
|
|
$regex = '/^(https?:\/\/)?(www\.)?derpibooru.org\/search.+q=([^\/&?\n]+)/';
|
|
|
|
if (preg_match($regex, $url, $matches) > 0) {
|
|
|
|
$params['q'] = urldecode($matches[3]);
|
|
|
|
return $params;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tag page, e.g. https://derpibooru.org/tags/artist-colon-devinian
|
|
|
|
$regex = '/^(https?:\/\/)?(www\.)?derpibooru.org\/tags\/([^\/&?\n]+)/';
|
|
|
|
if (preg_match($regex, $url, $matches) > 0) {
|
|
|
|
$params['q'] = str_replace('-colon-', ':', urldecode($matches[3]));
|
|
|
|
return $params;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getName()
|
|
|
|
{
|
|
|
|
if (!is_null($this->getInput('q'))) {
|
|
|
|
return 'Derpibooru search for: '
|
|
|
|
. $this->getInput('q');
|
|
|
|
} else {
|
|
|
|
return parent::getName();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getURI()
|
|
|
|
{
|
|
|
|
if (!is_null($this->getInput('f')) && !is_null($this->getInput('q'))) {
|
|
|
|
return self::URI
|
2021-04-26 21:07:42 +03:00
|
|
|
. 'search?filter_id='
|
2018-12-26 23:14:04 +03:00
|
|
|
. urlencode($this->getInput('f'))
|
|
|
|
. '&q='
|
|
|
|
. urlencode($this->getInput('q'));
|
2022-07-01 16:10:30 +03:00
|
|
|
} else {
|
2022-01-02 12:36:09 +03:00
|
|
|
return parent::getURI();
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
|
|
|
}
|
2018-12-26 23:14:04 +03:00
|
|
|
|
2021-04-26 21:07:42 +03:00
|
|
|
public function collectData()
|
|
|
|
{
|
2024-07-31 18:30:06 +03:00
|
|
|
$url = self::URI . 'api/v1/json/search/images?filter_id=' . urlencode($this->getInput('f')) . '&q=' . urlencode($this->getInput('q'));
|
|
|
|
|
|
|
|
$queryJson = json_decode(getContents($url));
|
2018-12-26 23:14:04 +03:00
|
|
|
|
|
|
|
foreach ($queryJson->images as $post) {
|
|
|
|
$item = [];
|
|
|
|
|
|
|
|
$postUri = self::URI . $post->id;
|
|
|
|
|
2021-04-26 21:07:42 +03:00
|
|
|
$item['uri'] = $postUri;
|
2021-12-08 19:17:28 +03:00
|
|
|
$item['title'] = $post->name;
|
2018-12-26 23:14:04 +03:00
|
|
|
$item['timestamp'] = strtotime($post->created_at);
|
|
|
|
$item['author'] = $post->uploader;
|
2021-04-26 21:07:42 +03:00
|
|
|
$item['enclosures'] = [$post->view_url];
|
|
|
|
$item['categories'] = $post->tags;
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2018-12-26 23:14:04 +03:00
|
|
|
$item['content'] = '<p><a href="' // image preview
|
|
|
|
. $postUri
|
2021-04-26 21:07:42 +03:00
|
|
|
. '"><img src="'
|
2018-12-26 23:14:04 +03:00
|
|
|
. $post->representations->medium
|
|
|
|
. '"></a></p><p>' // description
|
|
|
|
. $post->description
|
|
|
|
. '</p><p><b>Size:</b> ' // image size
|
|
|
|
. $post->width
|
|
|
|
. 'x'
|
2021-04-26 21:07:42 +03:00
|
|
|
. $post->height;
|
|
|
|
// source link
|
|
|
|
if ($post->source_url != null) {
|
|
|
|
$item['content'] .= '<br><b>Source:</b> <a href="'
|
2018-12-26 23:14:04 +03:00
|
|
|
. $post->source_url
|
2022-07-01 16:10:30 +03:00
|
|
|
. '">'
|
2018-12-26 23:14:04 +03:00
|
|
|
. $post->source_url
|
|
|
|
. '</a></p>';
|
2021-04-26 21:07:42 +03:00
|
|
|
};
|
2018-12-26 23:14:04 +03:00
|
|
|
$this->items[] = $item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|