mirror of
https://git.crystalyx.net/Xefir/repod.git
synced 2024-12-28 01:32:49 +01:00
80 lines
2.1 KiB
PHP
80 lines
2.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace OCA\RePod\Service;
|
|
|
|
use OCP\Http\Client\IClientService;
|
|
use OCP\Http\Client\IResponse;
|
|
use OCP\IUserSession;
|
|
use OCP\L10N\IFactory;
|
|
|
|
class FyydService implements IProvider
|
|
{
|
|
public function __construct(
|
|
private IClientService $clientService,
|
|
private IFactory $l10n,
|
|
private IUserSession $userSession
|
|
) {
|
|
}
|
|
|
|
public function search(string $value): array
|
|
{
|
|
$podcasts = [];
|
|
|
|
$client = $this->clientService->newClient();
|
|
$response = $client->get('https://api.fyyd.de/0.2/search/podcast', [
|
|
'query' => [
|
|
'title' => $value,
|
|
'term' => $value,
|
|
],
|
|
]);
|
|
$json = (array) json_decode((string) $response->getBody(), true, flags: JSON_THROW_ON_ERROR);
|
|
|
|
if (array_key_exists('data', $json) && is_array($json['data'])) {
|
|
/** @var string[] $feed */
|
|
foreach ($json['data'] as $feed) {
|
|
$podcasts[] = [
|
|
'provider' => 'fyyd',
|
|
'id' => $feed['id'],
|
|
'title' => $feed['title'],
|
|
'author' => $feed['author'],
|
|
'image' => $feed['imgURL'],
|
|
'provider_url' => $feed['htmlURL'],
|
|
'feed_url' => $feed['xmlURL'],
|
|
'last_pub' => $feed['lastpub'],
|
|
'nb_episodes' => $feed['episode_count'],
|
|
];
|
|
}
|
|
}
|
|
|
|
return $podcasts;
|
|
}
|
|
|
|
public function hot(): IResponse
|
|
{
|
|
$language = 'en';
|
|
|
|
try {
|
|
$langClient = $this->clientService->newClient();
|
|
$langResponse = $langClient->get('https://api.fyyd.de/0.2/feature/podcast/hot/languages');
|
|
$langJson = (array) json_decode((string) $langResponse->getBody(), true, flags: JSON_THROW_ON_ERROR);
|
|
if (array_key_exists('data', $langJson) && is_array($langJson['data'])) {
|
|
$language = $this->l10n->getUserLanguage($this->userSession->getUser());
|
|
$language = explode('_', $language);
|
|
$language = count($language) > 1 ? $language[1] : $language[0];
|
|
$language = in_array($language, $langJson['data']) ? $language : 'en';
|
|
}
|
|
} catch (\Exception $e) {
|
|
}
|
|
|
|
$podcastClient = $this->clientService->newClient();
|
|
|
|
return $podcastClient->get('https://api.fyyd.de/0.2/feature/podcast/hot', [
|
|
'query' => [
|
|
'language' => $language,
|
|
],
|
|
]);
|
|
}
|
|
}
|