1
0
mirror of https://github.com/RSS-Bridge/rss-bridge.git synced 2025-10-17 01:26:08 +02:00
Files
php-rss-bridge/bridges/KemonoBridge.php
July 2bbd31a085 [KemonoBridge] Update to new API and add more services (#4699)
Bridge update does the following:
- Switches to new kemono.cr domain
- Adds support for DLSite and, from coomer.st, OnlyFans, Fansly, CandFans (Fixes #4518)
- Follows API changes, including needing to request a CSS type and
  separately obtain post contents (limit option added in correspondence
  with this) (Fixes #4671)
2025-09-12 20:25:53 +02:00

119 lines
3.5 KiB
PHP

<?php
class KemonoBridge extends BridgeAbstract
{
const NAME = 'Kemono';
const MAINTAINER = 'phantop';
const URI = 'https://kemono.cr/';
const DESCRIPTION = 'Returns posts from Kemono and Coomer.';
const PARAMETERS = [[
'service' => [
'name' => 'Content service',
'type' => 'list',
'defaultValue' => 'patreon',
'values' => [
'Patreon' => 'patreon',
'Pixiv Fanbox' => 'fanbox',
'Fantia' => 'fantia',
'Boosty' => 'boosty',
'Gumroad' => 'gumroad',
'SubscribeStar' => 'subscribestar',
'DLSite' => 'dlsite',
'OnlyFans' => 'onlyfans',
'Fansly' => 'fansly',
'CandFans' => 'candfans',
]
],
'user' => [
'name' => 'User ID/Name',
'exampleValue' => '9069743', # Thomas Joy
'required' => true,
],
'q' => [
'name' => 'Search query',
'exampleValue' => 'classic',
'required' => false,
],
'limit' => self::LIMIT,
]];
private $author;
private function isCoomer()
{
return str_contains($this->getInput('service'), 'fans');
}
private function baseURI()
{
if ($this->isCoomer()) {
return 'https://coomer.st/';
}
return parent::getURI();
}
private function getJson(string $endpoint)
{
$api = $this->baseURI() . 'api/v1/' . $this->getInput('service');
$url = $api . $this->getInput('service') . '/user/' . $this->getInput('user');
$header = [ 'Accept: text/css' ]; // Required by API
$api_response = getContents("$api$endpoint", $header);
return Json::decode($api_response);
}
public function collectData()
{
$user = '/user/' . $this->getInput('user');
$profile = $this->getJson("$user/profile");
$this->author = ucfirst($profile['name']);
$json = $this->getJson("$user/posts?q=" . urlencode($this->getInput('q')));
$elements = array_slice($json, 0, $this->getInput('limit'));
foreach ($elements as $element) {
$element = $this->getJson($user . '/post/' . $element['id']);
$post = $element['post'];
$item = [
'author' => $this->author,
'categories' => $post['tags'],
'content' => $post['content'],
'timestamp' => strtotime($post['published']),
'title' => $post['title'],
'uid' => $post['id'],
'uri' => $this->getURI() . '/post/' . $post['id'],
];
$item['enclosures'] = [];
if (array_key_exists('url', $post['embed'])) {
$item['enclosures'][] = $post['embed']['url'];
}
if (array_key_exists('path', $post['file'])) {
$element['attachments'][] = $post['file'];
}
foreach ($element['attachments'] as $file) {
$item['enclosures'][] = $this->baseURI() . $file['path'];
}
$this->items[] = $item;
}
}
public function getName()
{
$name = parent::getName();
if (isset($this->author)) {
$name .= ' - ' . $this->author;
}
return $name;
}
public function getURI()
{
$uri = $this->baseURI() . $this->getInput('service') . '/user/' . $this->getInput('user');
return $uri;
}
}