#173 Implement PlaylistId

This commit is contained in:
kokarare1212
2023-01-03 10:16:51 +09:00
parent 29ff02882b
commit e65f7fc691
2 changed files with 37 additions and 2 deletions

View File

@@ -62,6 +62,29 @@ class PlayableId:
raise NotImplementedError
class PlaylistId(SpotifyId):
base62 = Base62.create_instance_with_inverted_character_set()
pattern = re.compile(r"spotify:playlist:(.{22})")
__id: str
def __init__(self, _id: str):
self.__id = _id
@staticmethod
def from_uri(uri: str) -> PlaylistId:
matcher = PlaylistId.pattern.search(uri)
if matcher is not None:
playlist_id = matcher.group(1)
return PlaylistId(playlist_id)
raise TypeError("Not a Spotify playlist ID: {}.".format(uri))
def id(self) -> str:
return self.__id
def to_spotify_uri(self) -> str:
return "spotify:playlist:" + self.__id
class UnsupportedId(PlayableId):
uri: str