Handle query and anchors in Spotify URI's (#33084)

* Handle query and anchors in Spotify URI's

* Use yarl for cleaning up the URL
This commit is contained in:
Franck Nijhof 2020-03-21 20:24:23 +01:00 committed by GitHub
parent 699ca44260
commit 8272c71811
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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: