From 6c126bc20fce92c78acfefaa6672c1ed41becfe2 Mon Sep 17 00:00:00 2001 From: floppydiskette Date: Wed, 25 Dec 2024 22:41:17 +0000 Subject: Update last/current track display --- app/Http/Controllers/MusicController.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'app') diff --git a/app/Http/Controllers/MusicController.php b/app/Http/Controllers/MusicController.php index 08a01f6..71ab1cc 100644 --- a/app/Http/Controllers/MusicController.php +++ b/app/Http/Controllers/MusicController.php @@ -25,12 +25,18 @@ class MusicController extends Controller $data = $response->json(); error_log($response->body()); $track_data = $data["recenttracks"]["track"][0]; - $image = array_column($track_data["image"], null, 'size')['large'] ?? false; + // $image = array_column($track_data["image"], null, 'size')['large'] ?? false; + $image = $track_data["image"][(array_key_last($track_data["image"]))] ?? false; + $now_playing = false; + if (array_key_exists("@attr", $track_data)) { + $now_playing = $track_data["@attr"]["nowplaying"] == "true" ?? ["url"=>null]; + } $current_track = [ 'title' => $track_data["name"], 'artist' => $track_data["artist"]["#text"], 'url' => $track_data["url"], 'image' => $image["#text"], + 'header' => $now_playing ? "Now Playing" : "Last Track", ]; Cache::put('current_track', $current_track, now()->addSeconds(15)); return $current_track; -- cgit v1.2.3-54-g00ecf