-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[KemonoBridge] Add KemonoBridge (#4192)
* [KemonoBridge] Add KemonoBridge * refactor * [KemonoBridge] fix categories in cases where it's a proper json array --------- Co-authored-by: Dag <[email protected]>
- Loading branch information
Showing
1 changed file
with
93 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?php | ||
|
||
class KemonoBridge extends BridgeAbstract | ||
{ | ||
const NAME = 'Kemono'; | ||
const MAINTAINER = 'phantop'; | ||
const URI = 'https://kemono.su/'; | ||
const DESCRIPTION = 'Returns posts from Kemono.'; | ||
const PARAMETERS = [[ | ||
'service' => [ | ||
'name' => 'Content service', | ||
'type' => 'list', | ||
'defaultValue' => 'patreon', | ||
'values' => [ | ||
'Patreon' => 'patreon', | ||
'Pixiv Fanbox' => 'fanbox', | ||
'Fantia' => 'fantia', | ||
'Boosty' => 'boosty', | ||
'Gumroad' => 'gumroad', | ||
'SubscribeStar' => 'subscribestar', | ||
] | ||
], | ||
'user' => [ | ||
'name' => 'User ID/Name', | ||
'exampleValue' => '9069743', # Thomas Joy | ||
'required' => true, | ||
] | ||
]]; | ||
|
||
private $title; | ||
|
||
public function collectData() | ||
{ | ||
$api = parent::getURI() . 'api/v1/'; | ||
$url = $api . $this->getInput('service') . '/user/' . $this->getInput('user'); | ||
$api_response = getContents($url); | ||
$json = Json::decode($api_response); | ||
|
||
$url .= '/profile'; | ||
$api_response = getContents($url); | ||
$profile = Json::decode($api_response); | ||
$this->title = ucfirst($profile['name']); | ||
|
||
foreach ($json as $element) { | ||
$item = []; | ||
$item['author'] = $this->title; | ||
$item['content'] = $element['content']; | ||
$item['timestamp'] = strtotime($element['published']); | ||
$item['title'] = $element['title']; | ||
$item['uid'] = $element['id']; | ||
$item['uri'] = $this->getURI() . '/post/' . $item['uid']; | ||
|
||
if ($element['tags']) { | ||
$tags = $element['tags']; | ||
if (is_array($tags)) { | ||
$item['categories'] = $tags; | ||
} else { | ||
$tags = preg_replace('/^{"?/', '["', $tags); | ||
$tags = preg_replace('/"?}$/', '"]', $tags); | ||
$item['categories'] = Json::decode($tags); | ||
} | ||
} | ||
|
||
$item['enclosures'] = []; | ||
if (array_key_exists('url', $element['embed'])) { | ||
$item['enclosures'][] = $element['embed']['url']; | ||
} | ||
if (array_key_exists('path', $element['file'])) { | ||
$element['attachments'][] = $element['file']; | ||
} | ||
foreach ($element['attachments'] as $file) { | ||
$item['enclosures'][] = parent::getURI() . $file['path']; | ||
} | ||
|
||
$this->items[] = $item; | ||
} | ||
} | ||
|
||
public function getName() | ||
{ | ||
$name = parent::getName(); | ||
if (isset($this->title)) { | ||
$name .= ' - ' . $this->title; | ||
} | ||
return $name; | ||
} | ||
|
||
public function getURI() | ||
{ | ||
$uri = parent::getURI() . $this->getInput('service') . '/user/' . $this->getInput('user'); | ||
return $uri; | ||
} | ||
} |