diff --git a/nmv.py b/nmv.py index f0ee90a..28250bf 100755 --- a/nmv.py +++ b/nmv.py @@ -28,7 +28,18 @@ def main() -> None: current_song = current_song_response[0] - search_result = shared.get_media_by_metadata(current_song.artist, current_song.track_name, conn) + search_results = shared.get_media_by_metadata(current_song.artist, current_song.track_name, conn) + search_results.remove(current_song) + if len(search_results) == 1: + search_result = search_results[0] + + elif len(search_results) > 1: + print(f"Found more than one match for {current_song}. Skipping") + continue + + else: + continue + if search_result is not None: interaction = input(f'Do you want to move these files {str(search_result.path)!r} --> {str(file_path)!r} (Y/n)?') if interaction.lower() in ('', 'y', 'yes'): diff --git a/shared.py b/shared.py index aca4d7c..a9ef26f 100755 --- a/shared.py +++ b/shared.py @@ -11,7 +11,7 @@ class Song: path: Path -def get_media_by_metadata(artist: str, track_name: str, conn: sqlite3.Connection) -> Song | None: +def get_media_by_metadata(artist: str, track_name: str, conn: sqlite3.Connection) -> list[Song]: r = conn.execute( 'select id, title, artist, path from media_file where lower(title) = lower(?) and lower(artist) = lower(?);', (track_name, artist)).fetchall() @@ -19,14 +19,7 @@ def get_media_by_metadata(artist: str, track_name: str, conn: sqlite3.Connection for res in r: results.append(Song(*res)) - if len(results) == 0: - return None - - elif len(results) == 1: - return results[0] - - else: - raise RuntimeError("Found multiple matches for search criteria" + str(results)) + return results def path_clause(path: str):