From c8e82410f84427950ef8da141c751c15a404d706 Mon Sep 17 00:00:00 2001 From: Robert Kaye Date: Sun, 31 Dec 2023 21:15:00 +0100 Subject: [PATCH] Do not resolve playlists if no tracks are missing. Less crashy. --- lb_content_resolver/content_resolver.py | 12 ++++++++---- lb_content_resolver/lb_radio.py | 3 +++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lb_content_resolver/content_resolver.py b/lb_content_resolver/content_resolver.py index cf23e46..f137f0f 100755 --- a/lb_content_resolver/content_resolver.py +++ b/lb_content_resolver/content_resolver.py @@ -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} @@ -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.') diff --git a/lb_content_resolver/lb_radio.py b/lb_content_resolver/lb_radio.py index ca897d1..277b431 100755 --- a/lb_content_resolver/lb_radio.py +++ b/lb_content_resolver/lb_radio.py @@ -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)