40 lines
1.1 KiB
PHP
40 lines
1.1 KiB
PHP
|
<?php
|
||
|
namespace Makai;
|
||
|
|
||
|
use Index\Routing\Route;
|
||
|
use Index\Routing\RouteHandler;
|
||
|
use Sasae\SasaeEnvironment;
|
||
|
|
||
|
class NowListeningRoutes extends RouteHandler {
|
||
|
public function __construct(
|
||
|
private SasaeEnvironment $templating
|
||
|
) {}
|
||
|
|
||
|
#[Route('GET', '/now-listening')]
|
||
|
public function getIndex($response, $request): string {
|
||
|
return $this->templating->render('np', [
|
||
|
'header_offset' => (int)$request->getParam('offset', FILTER_SANITIZE_NUMBER_INT),
|
||
|
]);
|
||
|
}
|
||
|
|
||
|
#[Route('GET', '/now-listening.json')]
|
||
|
public function getJson(): array {
|
||
|
$info = json_decode(file_get_contents('https://now.flash.moe/get.php?u=flashwave_'));
|
||
|
if(empty($info[0]?->name))
|
||
|
return [];
|
||
|
|
||
|
$info = $info[0];
|
||
|
|
||
|
return [
|
||
|
'name' => $info->name,
|
||
|
'now_playing' => !empty($info->nowplaying),
|
||
|
'url' => $info->url,
|
||
|
'cover' => $info->images?->large ?? '',
|
||
|
'artist' => [
|
||
|
'name' => $info->artist?->name ?? '',
|
||
|
'url' => explode('/_/', $info->url)[0],
|
||
|
],
|
||
|
];
|
||
|
}
|
||
|
}
|