Skip to content
This repository has been archived by the owner on Feb 9, 2024. It is now read-only.

Commit

Permalink
Do not resolve playlists if no tracks are missing. Less crashy.
Browse files Browse the repository at this point in the history
  • Loading branch information
mayhem committed Dec 31, 2023
1 parent 1c594ac commit c8e8241
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lb_content_resolver/content_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,21 @@ def resolve_playlist(self, match_threshold, recordings=None, jspf_playlist=None)

print("\nResolve recordings to local files or subsonic ids")

self.db.open_db()
self.build_index()

artist_recording_data = []
if jspf_playlist is not None:
if len(jspf_playlist["playlist"]["track"]) == 0:
return []
for i, track in enumerate(jspf_playlist["playlist"]["track"]):
artist_recording_data.append({"artist_name": track["creator"], "recording_name": track["title"]})
else:
if not recordings:
return []
for rec in recordings:
artist_recording_data.append({"artist_name": rec.artist.name, "recording_name": rec.name})

self.db.open_db()
self.build_index()

hits = self.resolve_recordings(artist_recording_data, match_threshold)
hit_index = {hit["index"]: hit for hit in hits}

Expand Down Expand Up @@ -135,7 +139,7 @@ def resolve_playlist(self, match_threshold, recordings=None, jspf_playlist=None)

if len(results) == 0:
print("Sorry, but no tracks could be resolved, no playlist generated.")
return
return []

print(f'\n{len(recordings)} recordings resolved, {len(artist_recording_data) - len(recordings)} not resolved.')

Expand Down
3 changes: 3 additions & 0 deletions lb_content_resolver/lb_radio.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ def resolve_recordings(self, playlist):

recordings.append(recording)

if not recordings:
return

cr = ContentResolver(self.db)
resolved = cr.resolve_playlist(self.MATCH_THRESHOLD, recordings)

Expand Down

0 comments on commit c8e8241

Please sign in to comment.