Update last/current track display
This commit is contained in:
parent
80f4601670
commit
6c126bc20f
4 changed files with 13 additions and 4 deletions
|
@ -25,12 +25,18 @@ public function getCurrentTrack() {
|
|||
$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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue