From 207702b227cb41dc57a73f2b26c6408b912d55be Mon Sep 17 00:00:00 2001 From: neumann <> Date: Tue, 30 May 2017 19:33:18 +0000 Subject: [PATCH] 37_Spotify: target device playlist by name git-svn-id: https://svn.fhem.de/fhem/trunk@14429 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/37_Spotify.pm | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/fhem/FHEM/37_Spotify.pm b/fhem/FHEM/37_Spotify.pm index 83a46c2af..d14be7150 100644 --- a/fhem/FHEM/37_Spotify.pm +++ b/fhem/FHEM/37_Spotify.pm @@ -502,13 +502,17 @@ sub Spotify_playArtistByName($$) { # play an artist by its name using search sub Spotify_playPlaylistByName($$) { # play a playlist by its name my ($hash, $playlistname) = @_; my $name = $hash->{NAME}; - return 'wrong syntax: set playPlaylistByName ' if(!defined $playlistname); + return 'wrong syntax: set playPlaylistByName ' if(!defined $playlistname); + + my @parts = split(" ", $playlistname); + my $device_id = Spotify_getTargetDeviceID($hash, $parts[-1], 0) if(@parts > 1); # resolve device id (may be last part of the command) + $playlistname = substr($playlistname, 0, -length($parts[-1])-1) if(@parts > 1 && defined $device_id); # if last part was indeed the device id, remove it from the track name Spotify_apiRequest($hash, 'search?limit=1&type=playlist&q='. urlEncode($playlistname), undef, 'GET', 1); my $result = $hash->{helper}{dispatch}{json}{playlists}{items}[0]; return 'could not find playlist' if(!defined $result); - Spotify_playContextByURI($hash, $result->{uri}, undef, undef); + Spotify_playContextByURI($hash, $result->{uri}, undef, $device_id); Log3 $name, 4, "$name: $result->{uri} ($result->{name})"; return undef; } @@ -820,7 +824,7 @@ sub Spotify_dispatch($$$) { Spotify_saveDevice($hash, $device, "device_active", 0); } else { delete $hash->{helper}{device_active}; - Spotify_saveDevice($hash, {id => "none", "name" => "none", "volume_percent" => -1, "type" => "none"}, 'device_active', 0) if(!defined $hash->{helper}{device_active}); + Spotify_saveDevice($hash, {id => "none", "name" => "none", "volume_percent" => -1, "type" => "none"}, 'device_active', 0); $hash->{STATE} = 'connected' if(!defined $json->{device}); } @@ -983,7 +987,7 @@ sub Spotify_isDisabled($) { plays a context (playlist, album or artist) using a Spotify URI
  • - playPlaylistByName <playlist_name>
    + playPlaylistByName <playlist_name> [ <device_id> ]
    plays any playlist by providing a name (uses search)
  • @@ -1138,7 +1142,7 @@ sub Spotify_isDisabled($) { spielt einen Context (Playlist, Album oder Künstler) durch Angabe der URI ab
  • - playPlaylistByName <playlist_name>
    + playPlaylistByName <playlist_name> [ <device_id> ]
    sucht eine Playlist und spielt diese ab