Skip to content

Commit

Permalink
revert changes to identifier and minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
amCap1712 committed May 28, 2024
1 parent 0faa42d commit 7b2bbca
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion troi/patches/lb_radio_classes/playlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 11 additions & 10 deletions troi/playlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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"):
Expand Down Expand Up @@ -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.
'''
Expand Down

0 comments on commit 7b2bbca

Please sign in to comment.