Compare commits
2 Commits
c38cfd293f
...
071a6aa4a6
Author | SHA1 | Date | |
---|---|---|---|
071a6aa4a6 | |||
4319b53cdb |
13
nmv.py
13
nmv.py
@ -28,7 +28,18 @@ def main() -> None:
|
|||||||
|
|
||||||
current_song = current_song_response[0]
|
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:
|
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)?')
|
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'):
|
if interaction.lower() in ('', 'y', 'yes'):
|
||||||
|
13
shared.py
13
shared.py
@ -6,12 +6,12 @@ from pathlib import Path
|
|||||||
@dataclass(frozen=True)
|
@dataclass(frozen=True)
|
||||||
class Song:
|
class Song:
|
||||||
id: str
|
id: str
|
||||||
artist: str
|
|
||||||
track_name: str
|
track_name: str
|
||||||
|
artist: str
|
||||||
path: Path
|
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(
|
r = conn.execute(
|
||||||
'select id, title, artist, path from media_file where lower(title) = lower(?) and lower(artist) = lower(?);',
|
'select id, title, artist, path from media_file where lower(title) = lower(?) and lower(artist) = lower(?);',
|
||||||
(track_name, artist)).fetchall()
|
(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:
|
for res in r:
|
||||||
results.append(Song(*res))
|
results.append(Song(*res))
|
||||||
|
|
||||||
if len(results) == 0:
|
return results
|
||||||
return None
|
|
||||||
|
|
||||||
elif len(results) == 1:
|
|
||||||
return results[0]
|
|
||||||
|
|
||||||
else:
|
|
||||||
raise RuntimeError("Found multiple matches for search criteria" + str(results))
|
|
||||||
|
|
||||||
|
|
||||||
def path_clause(path: str):
|
def path_clause(path: str):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user