Skip to content

Commit

Permalink
feat: add show URLs support
Browse files Browse the repository at this point in the history
  • Loading branch information
zeroday0619 committed Jun 21, 2021
1 parent 30a8d73 commit 6ca58e4
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
10 changes: 1 addition & 9 deletions spotify_uri/__init__.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down
8 changes: 6 additions & 2 deletions spotify_uri/parse.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
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
from spotify_uri.artist import Artist
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):
Expand Down Expand Up @@ -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}")
24 changes: 24 additions & 0 deletions spotify_uri/show.py
Original file line number Diff line number Diff line change
@@ -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)}"

0 comments on commit 6ca58e4

Please sign in to comment.