From 7b2bbca784fc5686538cb57393d745b7d2c7d7e7 Mon Sep 17 00:00:00 2001 From: Kartik Ohri Date: Tue, 28 May 2024 19:40:35 +0530 Subject: [PATCH] revert changes to identifier and minor fixes --- troi/patches/lb_radio_classes/playlist.py | 2 +- troi/playlist.py | 21 +++++++++++---------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/troi/patches/lb_radio_classes/playlist.py b/troi/patches/lb_radio_classes/playlist.py index 59f5e5b..56e350b 100755 --- a/troi/patches/lb_radio_classes/playlist.py +++ b/troi/patches/lb_radio_classes/playlist.py @@ -40,7 +40,7 @@ def read(self, entities): self.local_storage["data_cache"]["element-descriptions"].append(f"playlist {self.mbid}") # Fetch the recordings, then shuffle - mbid_list = [r["identifier"][0][34:] for r in r.json()["playlist"]["track"]] + mbid_list = [r["identifier"][34:] for r in r.json()["playlist"]["track"]] shuffle(mbid_list) # Select and convert the first n MBIDs into Recordings diff --git a/troi/playlist.py b/troi/playlist.py index e707e1f..b8d385d 100755 --- a/troi/playlist.py +++ b/troi/playlist.py @@ -63,7 +63,7 @@ def _serialize_to_jspf(playlist, created_for=None, track_count=None): track["creator"] = e.artist_credit.name if e.artist_credit else "" track["title"] = e.name - track["identifier"] = ["https://musicbrainz.org/recording/" + str(e.mbid)] + track["identifier"] = "https://musicbrainz.org/recording/" + str(e.mbid) loc = e.musicbrainz.get("filename", None) if loc is not None: @@ -109,20 +109,21 @@ def _deserialize_from_jspf(data) -> Playlist: for track in data["track"]: identifier = track["identifier"] - if isinstance(track["identifier"], str): - identifier = [identifier] - mbid = None - for id in identifier: - if id.startswith("https://musicbrainz.org/recording/") or id.startswith("http://musicbrainz.org/recording/"): - mbid = id.split("/")[-1] - break + + if identifier.startswith("https://musicbrainz.org/recording/") or \ + identifier.startswith("http://musicbrainz.org/recording/"): + mbid = identifier.split("/")[-1] + else: + mbid = None recording = Recording(name=track["title"], mbid=mbid) if track.get("creator"): extension = track["extension"][PLAYLIST_TRACK_EXTENSION_URI] if extension.get("artist_identifiers"): artist_mbids = [url.split("/")[-1] for url in extension.get("artist_identifiers")] - artists = [ Artist(mbid) for mbid in artist_mbids ] + artists = [Artist(mbid) for mbid in artist_mbids] + else: + artists = None recording.artist_credit = ArtistCredit(name=track["creator"], artists=artists) if track.get("album"): @@ -429,7 +430,7 @@ class PlaylistMakerElement(Element): :param desc: The description of the playlist :param patch-slug: The patch slug (URL-safe short name) of the patch that created the playlist. Optional. :param max_num_recordings: The maximum number of recordings to have in the playlist. Extras are discarded. Optional argument, and the default is to keep all recordings - :param max_artist_occurence: The number of times and artist is allowed to appear in the playlist. Any recordings that exceed this count ared discarded. Optional, default is to keep all recordings. + :param max_artist_occurrence: The number of times and artist is allowed to appear in the playlist. Any recordings that exceed this count ared discarded. Optional, default is to keep all recordings. :param shuffle: If True, the playlist will be shuffled before being truncated. Optional. Default: False :param is_april_first: If True, do something very sneaky. Default: False. '''