2023-10-12 22:09:04 +00:00
|
|
|
<?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 {
|
2023-10-13 18:01:07 +00:00
|
|
|
return $this->templating->render('dev/np', [
|
2023-10-12 22:09:04 +00:00
|
|
|
'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],
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|