Skip to content

Commit

Permalink
Fix type for missing cases and fallback to queue by default
Browse files Browse the repository at this point in the history
  • Loading branch information
DrNiels committed Mar 8, 2024
1 parent af04eba commit 3049929
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions Spotify/module.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ public function RequestAction($Ident, $Value)
break;
}
switch ($this->GetBuffer('CurrentType')) {
case 'artist':
case 'queue':
$this->SkipTracks($list['current']);
break;

Expand Down Expand Up @@ -613,7 +613,8 @@ public function UpdateVariables()
if (!isset($contextInfo['error'])) {
$playlistEntries = [];
$currentIndex = -1;
switch ($contextInfo['type']) {
$type = isset($contextInfo['type']) ? $contextInfo['type'] : 'queue';
switch ($type) {
case 'playlist':
case 'album':
case 'show':
Expand All @@ -636,9 +637,11 @@ public function UpdateVariables()
}
break;

default:
case 'artist':
// An artist provides no playlist, so we get the queue instead
$queueInfo = $this->MakeRequest('GET', 'https://api.spotify.com/v1/me/player/queue', '', true);
$type = 'queue';
if (is_string($queueInfo)) {
$queueInfo = json_decode($queueInfo, true);
if (!isset($queueInfo['error'])) {
Expand All @@ -660,8 +663,9 @@ public function UpdateVariables()

}
if (count($playlistEntries) > 0) {
$this->SetBuffer('CurrentType', $contextInfo['type']);
$this->SetBuffer('CurrentURI', $contextInfo['uri']);
$this->SetBuffer('CurrentType', $type);
// If no URI is available, we won't need it, as we only use it for specific cases (playlist, album, show)
$this->SetBuffer('CurrentURI', isset($contextInfo['uri']) ? $contextInfo['uri'] : 'No-URI');
$this->SetValue('CurrentPlaylist', json_encode([
'current' => $currentIndex,
'entries' => $playlistEntries
Expand Down

0 comments on commit 3049929

Please sign in to comment.