56 lines
1.3 KiB
PHP
56 lines
1.3 KiB
PHP
|
<?php
|
||
|
|
||
|
declare(strict_types=1);
|
||
|
|
||
|
namespace OCA\RePod\Controller;
|
||
|
|
||
|
use Exception;
|
||
|
use OCA\RePod\AppInfo\Application;
|
||
|
use OCP\AppFramework\Controller;
|
||
|
use OCP\AppFramework\Http\JSONResponse;
|
||
|
use OCP\Http\Client\IClientService;
|
||
|
use OCP\IRequest;
|
||
|
|
||
|
class SearchController extends Controller
|
||
|
{
|
||
|
public function __construct(
|
||
|
IRequest $request,
|
||
|
private IClientService $clientService
|
||
|
) {
|
||
|
parent::__construct(Application::APP_ID, $request);
|
||
|
}
|
||
|
|
||
|
public function index(string $value): JSONResponse {
|
||
|
$podcasts = [];
|
||
|
|
||
|
try {
|
||
|
$fyydClient = $this->clientService->newClient();
|
||
|
$fyydReponse = $fyydClient->get("https://api.fyyd.de/0.2/search/podcast", [
|
||
|
'query' => [
|
||
|
'title' => $value,
|
||
|
'term' => $value
|
||
|
]
|
||
|
]);
|
||
|
$fyydJson = (array) json_decode((string) $fyydReponse->getBody(), true, flags: JSON_THROW_ON_ERROR);
|
||
|
|
||
|
if (array_key_exists('data', $fyydJson) && is_array($fyydJson['data'])) {
|
||
|
/** @var string[] $fyydFeed */
|
||
|
foreach ($fyydJson['data'] as $fyydFeed) {
|
||
|
$podcasts[] = [
|
||
|
'id' => $fyydFeed['id'],
|
||
|
'title' => $fyydFeed['title'],
|
||
|
'description' => $fyydFeed['description'],
|
||
|
'image' => $fyydFeed['imgURL'],
|
||
|
'url' => $fyydFeed['xmlURL'],
|
||
|
'lang' => $fyydFeed['language'],
|
||
|
'lastpub' => $fyydFeed['lastpub']
|
||
|
];
|
||
|
}
|
||
|
}
|
||
|
} catch (Exception $e) {
|
||
|
}
|
||
|
|
||
|
return new JSONResponse($podcasts);
|
||
|
}
|
||
|
}
|