From 6ca58e4b96c46b45d99c7fdde1500cfe0d68131a Mon Sep 17 00:00:00 2001 From: Euiseo Cha Date: Mon, 21 Jun 2021 15:21:16 +0900 Subject: [PATCH] feat: add show URLs support --- spotify_uri/__init__.py | 10 +--------- spotify_uri/parse.py | 8 ++++++-- spotify_uri/show.py | 24 ++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 11 deletions(-) create mode 100644 spotify_uri/show.py diff --git a/spotify_uri/__init__.py b/spotify_uri/__init__.py index c01d0af..911b134 100644 --- a/spotify_uri/__init__.py +++ b/spotify_uri/__init__.py @@ -1,14 +1,6 @@ - -__version__ = "1.0.2" +__version__ = "1.0.3" from spotify_uri.parse import parse as _parse -from spotify_uri.search import Search as _Search -from spotify_uri.local import Local as _Local -from spotify_uri.playlist import Playlist as _Playlist -from spotify_uri.artist import Artist as _Artist -from spotify_uri.album import Album as _Album -from spotify_uri.track import Track as _Track -from spotify_uri.user import User as _User from spotify_uri.spotify import SpotifyUri diff --git a/spotify_uri/parse.py b/spotify_uri/parse.py index adca783..4e18739 100644 --- a/spotify_uri/parse.py +++ b/spotify_uri/parse.py @@ -1,5 +1,7 @@ from typing import List from urllib.parse import urlparse, parse_qs +from spotify_uri.spotify import SpotifyUri +from spotify_uri.util import decode from spotify_uri.local import Local from spotify_uri.search import Search from spotify_uri.playlist import Playlist @@ -7,9 +9,9 @@ from spotify_uri.album import Album from spotify_uri.track import Track from spotify_uri.episode import Episode +from spotify_uri.show import Show from spotify_uri.user import User -from spotify_uri.util import decode -from spotify_uri.spotify import SpotifyUri + def parse(_input: str): @@ -85,5 +87,7 @@ def parseParts(uri: str, parts: List[str]): return Track(uri, parts[2]) if parts[1] == "episode": return Episode(uri, parts[2]) + if parts[1] == "show": + return Show(uri, parts[2]) raise TypeError(f"Could not determine type for: {uri}") diff --git a/spotify_uri/show.py b/spotify_uri/show.py new file mode 100644 index 0000000..c97a5f4 --- /dev/null +++ b/spotify_uri/show.py @@ -0,0 +1,24 @@ +from typing import Any +from spotify_uri.spotify import SpotifyUri +from spotify_uri.util import encode + + +class Show(SpotifyUri): + def __init__(self, uri: str, _id: str) -> None: + self.type = "show" + self.id = _id + super(Show, self).__init__(uri) + + @staticmethod + def is_(v: Any) -> bool: + x = v is Show + if x: + return v.type == "show" + else: + return False + + def toURI(self) -> str: + return f"spotify:{self.type}:{encode(self.id)}" + + def toURL(self) -> str: + return f"/{self.type}/{encode(self.id)}" \ No newline at end of file