Restyled by black
This commit is contained in:
@@ -47,9 +47,11 @@ class PlayableId:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def is_supported(uri: str):
|
def is_supported(uri: str):
|
||||||
return not uri.startswith("spotify:local:") and \
|
return (
|
||||||
not uri == "spotify:delimiter" and \
|
not uri.startswith("spotify:local:")
|
||||||
not uri == "spotify:meta:delimiter"
|
and not uri == "spotify:delimiter"
|
||||||
|
and not uri == "spotify:meta:delimiter"
|
||||||
|
)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def should_play(track: ContextTrack):
|
def should_play(track: ContextTrack):
|
||||||
@@ -94,8 +96,7 @@ class AlbumId(SpotifyId):
|
|||||||
matcher = AlbumId._PATTERN.search(uri)
|
matcher = AlbumId._PATTERN.search(uri)
|
||||||
if matcher is not None:
|
if matcher is not None:
|
||||||
album_id = matcher.group(1)
|
album_id = matcher.group(1)
|
||||||
return AlbumId(
|
return AlbumId(Utils.bytes_to_hex(AlbumId._BASE62.decode(album_id, 16)))
|
||||||
Utils.bytes_to_hex(AlbumId._BASE62.decode(album_id, 16)))
|
|
||||||
raise TypeError("Not a Spotify album ID: {}.f".format(uri))
|
raise TypeError("Not a Spotify album ID: {}.f".format(uri))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@@ -108,7 +109,8 @@ class AlbumId(SpotifyId):
|
|||||||
|
|
||||||
def to_mercury_uri(self) -> str:
|
def to_mercury_uri(self) -> str:
|
||||||
return "spotify:album:{}".format(
|
return "spotify:album:{}".format(
|
||||||
AlbumId._BASE62.encode(Utils.hex_to_bytes(self._hexId)))
|
AlbumId._BASE62.encode(Utils.hex_to_bytes(self._hexId))
|
||||||
|
)
|
||||||
|
|
||||||
def hex_id(self) -> str:
|
def hex_id(self) -> str:
|
||||||
return self._hexId
|
return self._hexId
|
||||||
@@ -127,14 +129,12 @@ class ArtistId(SpotifyId):
|
|||||||
matcher = ArtistId._PATTERN.search(uri)
|
matcher = ArtistId._PATTERN.search(uri)
|
||||||
if matcher is not None:
|
if matcher is not None:
|
||||||
artist_id = matcher.group(1)
|
artist_id = matcher.group(1)
|
||||||
return ArtistId(
|
return ArtistId(Utils.bytes_to_hex(ArtistId._BASE62.decode(artist_id, 16)))
|
||||||
Utils.bytes_to_hex(ArtistId._BASE62.decode(artist_id, 16)))
|
|
||||||
raise TypeError("Not a Spotify artist ID: {}".format(uri))
|
raise TypeError("Not a Spotify artist ID: {}".format(uri))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_base62(base62: str) -> ArtistId:
|
def from_base62(base62: str) -> ArtistId:
|
||||||
return ArtistId(Utils.bytes_to_hex(ArtistId._BASE62.decode(base62,
|
return ArtistId(Utils.bytes_to_hex(ArtistId._BASE62.decode(base62, 16)))
|
||||||
16)))
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_hex(hex_str: str) -> ArtistId:
|
def from_hex(hex_str: str) -> ArtistId:
|
||||||
@@ -145,7 +145,8 @@ class ArtistId(SpotifyId):
|
|||||||
|
|
||||||
def to_spotify_uri(self) -> str:
|
def to_spotify_uri(self) -> str:
|
||||||
return "spotify:artist:{}".format(
|
return "spotify:artist:{}".format(
|
||||||
ArtistId._BASE62.encode(Utils.hex_to_bytes(self._hexId)))
|
ArtistId._BASE62.encode(Utils.hex_to_bytes(self._hexId))
|
||||||
|
)
|
||||||
|
|
||||||
def hex_id(self) -> str:
|
def hex_id(self) -> str:
|
||||||
return self._hexId
|
return self._hexId
|
||||||
@@ -164,14 +165,13 @@ class EpisodeId(SpotifyId, PlayableId):
|
|||||||
if matcher is not None:
|
if matcher is not None:
|
||||||
episode_id = matcher.group(1)
|
episode_id = matcher.group(1)
|
||||||
return EpisodeId(
|
return EpisodeId(
|
||||||
Utils.Utils.bytes_to_hex(
|
Utils.Utils.bytes_to_hex(PlayableId.BASE62.decode(episode_id, 16))
|
||||||
PlayableId.BASE62.decode(episode_id, 16)))
|
)
|
||||||
TypeError("Not a Spotify episode ID: {}".format(uri))
|
TypeError("Not a Spotify episode ID: {}".format(uri))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_base62(base62: str) -> EpisodeId:
|
def from_base62(base62: str) -> EpisodeId:
|
||||||
return EpisodeId(
|
return EpisodeId(Utils.Utils.bytes_to_hex(PlayableId.BASE62.decode(base62, 16)))
|
||||||
Utils.Utils.bytes_to_hex(PlayableId.BASE62.decode(base62, 16)))
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_hex(hex_str: str) -> EpisodeId:
|
def from_hex(hex_str: str) -> EpisodeId:
|
||||||
@@ -182,7 +182,8 @@ class EpisodeId(SpotifyId, PlayableId):
|
|||||||
|
|
||||||
def to_spotify_uri(self) -> str:
|
def to_spotify_uri(self) -> str:
|
||||||
return "Spotify:episode:{}".format(
|
return "Spotify:episode:{}".format(
|
||||||
PlayableId.BASE62.encode(Utils.Utils.hex_to_bytes(self._hexId)))
|
PlayableId.BASE62.encode(Utils.Utils.hex_to_bytes(self._hexId))
|
||||||
|
)
|
||||||
|
|
||||||
def hex_id(self) -> str:
|
def hex_id(self) -> str:
|
||||||
return self._hexId
|
return self._hexId
|
||||||
@@ -204,8 +205,7 @@ class ShowId(SpotifyId):
|
|||||||
matcher = ShowId._PATTERN.search(uri)
|
matcher = ShowId._PATTERN.search(uri)
|
||||||
if matcher is not None:
|
if matcher is not None:
|
||||||
show_id = matcher.group(1)
|
show_id = matcher.group(1)
|
||||||
return ShowId(
|
return ShowId(Utils.bytes_to_hex(ShowId._BASE62.decode(show_id, 16)))
|
||||||
Utils.bytes_to_hex(ShowId._BASE62.decode(show_id, 16)))
|
|
||||||
raise TypeError("Not a Spotify show ID: {}".format(uri))
|
raise TypeError("Not a Spotify show ID: {}".format(uri))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@@ -221,7 +221,8 @@ class ShowId(SpotifyId):
|
|||||||
|
|
||||||
def to_spotify_uri(self) -> str:
|
def to_spotify_uri(self) -> str:
|
||||||
return "spotify:show:{}".format(
|
return "spotify:show:{}".format(
|
||||||
ShowId._BASE62.encode(Utils.hex_to_bytes(self._hexId)))
|
ShowId._BASE62.encode(Utils.hex_to_bytes(self._hexId))
|
||||||
|
)
|
||||||
|
|
||||||
def hex_id(self) -> str:
|
def hex_id(self) -> str:
|
||||||
return self._hexId
|
return self._hexId
|
||||||
@@ -239,14 +240,12 @@ class TrackId(PlayableId, SpotifyId):
|
|||||||
search = TrackId.PATTERN.search(uri)
|
search = TrackId.PATTERN.search(uri)
|
||||||
if search is not None:
|
if search is not None:
|
||||||
track_id = search.group(1)
|
track_id = search.group(1)
|
||||||
return TrackId(
|
return TrackId(Utils.bytes_to_hex(PlayableId.BASE62.decode(track_id, 16)))
|
||||||
Utils.bytes_to_hex(PlayableId.BASE62.decode(track_id, 16)))
|
|
||||||
raise RuntimeError("Not a Spotify track ID: {}".format(uri))
|
raise RuntimeError("Not a Spotify track ID: {}".format(uri))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_base62(base62: str) -> TrackId:
|
def from_base62(base62: str) -> TrackId:
|
||||||
return TrackId(Utils.bytes_to_hex(PlayableId.BASE62.decode(base62,
|
return TrackId(Utils.bytes_to_hex(PlayableId.BASE62.decode(base62, 16)))
|
||||||
16)))
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_hex(hex_str: str) -> TrackId:
|
def from_hex(hex_str: str) -> TrackId:
|
||||||
|
|||||||
Reference in New Issue
Block a user