Compare commits

...

2 Commits

2 changed files with 15 additions and 11 deletions

13
nmv.py
View File

@ -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'):

View File

@ -6,12 +6,12 @@ from pathlib import Path
@dataclass(frozen=True)
class Song:
id: str
artist: str
track_name: str
artist: str
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):