From 8272c71811ba48dc076f4de7412b24c226d31c9f Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Sat, 21 Mar 2020 20:24:23 +0100 Subject: [PATCH] Handle query and anchors in Spotify URI's (#33084) * Handle query and anchors in Spotify URI's * Use yarl for cleaning up the URL --- homeassistant/components/spotify/media_player.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/homeassistant/components/spotify/media_player.py b/homeassistant/components/spotify/media_player.py index 9588f428a66..7a00fb02146 100644 --- a/homeassistant/components/spotify/media_player.py +++ b/homeassistant/components/spotify/media_player.py @@ -7,6 +7,7 @@ from typing import Any, Callable, Dict, List, Optional from aiohttp import ClientError from spotipy import Spotify, SpotifyException +from yarl import URL from homeassistant.components.media_player import MediaPlayerDevice from homeassistant.components.media_player.const import ( @@ -295,6 +296,10 @@ class SpotifyMediaPlayer(MediaPlayerDevice): """Play media.""" kwargs = {} + # Spotify can't handle URI's with query strings or anchors + # Yet, they do generate those types of URI in their official clients. + media_id = str(URL(media_id).with_query(None).with_fragment(None)) + if media_type == MEDIA_TYPE_MUSIC: kwargs["uris"] = [media_id] elif media_type == MEDIA_TYPE_PLAYLIST: