From 41379efd1ba4af8f07c67b3113946d8bca1b9864 Mon Sep 17 00:00:00 2001 From: Keith Edmunds Date: Fri, 11 Nov 2022 21:12:12 +0000 Subject: [PATCH] Limit number of matching tracks on import --- app/config.py | 1 + app/musicmuster.py | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/app/config.py b/app/config.py index 0f78d4a..68c5600 100644 --- a/app/config.py +++ b/app/config.py @@ -65,6 +65,7 @@ class Config(object): MAIL_SERVER = os.environ.get('MAIL_SERVER') or "woodlands.midnighthax.com" MAIL_USERNAME = os.environ.get('MAIL_USERNAME') MAIL_USE_TLS = os.environ.get('MAIL_USE_TLS') is not None + MAX_IMPORT_MATCHES = 5 MAX_INFO_TABS = 5 MAX_MISSING_FILES_TO_REPORT = 10 MILLISECOND_SIGFIGS = 0 diff --git a/app/musicmuster.py b/app/musicmuster.py index 19729ba..be9c659 100755 --- a/app/musicmuster.py +++ b/app/musicmuster.py @@ -668,17 +668,18 @@ class Window(QMainWindow, Ui_MainWindow): new_tracks.append((fname, tags)) title = tags['title'] artist = tags['artist'] + count = 0 possible_matches = Tracks.search_titles(session, title) if possible_matches: - if len(possible_matches) > 5: - txt = "More than five tracks look similar to " - txt += f'"{title}" by "{artist} ({fname})":\n\n' - else: - txt += 'Similar to new track ' - txt += f'"{title}" by "{artist} ({fname})":\n\n' - for track in possible_matches: - txt += f' "{track.title}" by {track.artist}' - txt += f' ({track.path})\n\n' + txt += 'Similar to new track ' + txt += f'"{title}" by "{artist} ({fname})":\n\n' + for track in possible_matches: + txt += f' "{track.title}" by {track.artist}' + txt += f' ({track.path})\n\n' + count += 1 + if count >= Config.MAX_IMPORT_MATCHES: + txt += "\nThere are more similar-looking tracks" + break txt += "\n" # Check whether to proceed if there were potential matches txt += "Proceed with import?"