From 84221f92ae864e9ed09eab38633bf7663ec7c1e3 Mon Sep 17 00:00:00 2001 From: "billy@pom" Date: Fri, 1 May 2026 20:02:47 -0400 Subject: [PATCH] auto --- components/MusicTable.py | 7 ++++--- main.py | 2 +- utils/add_files_to_database.py | 4 +++- utils/export_playlist_by_id.py | 20 ++++++++++---------- utils/get_tags.py | 4 +++- utils/scan_for_music.py | 4 +++- 6 files changed, 24 insertions(+), 17 deletions(-) diff --git a/components/MusicTable.py b/components/MusicTable.py index 085df9c..3428b73 100644 --- a/components/MusicTable.py +++ b/components/MusicTable.py @@ -441,12 +441,13 @@ class MusicTable(QTableView): Args: - args: ((return_data),) - - data returned from the original worker process function are returned here - as the first item in a tuple + data returned from the original worker process function are returned here + as the first item in a tuple """ try: + _, details = args[0][:2] - details = dict(tuple(details)[0]) + # details =(tuple(details)[0],) if details: window = DebugWindow(details) window.exec_() diff --git a/main.py b/main.py index 1586d0d..efbc747 100644 --- a/main.py +++ b/main.py @@ -259,7 +259,7 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow): for id in ids: worker = Worker(export_playlist_by_id, id) # worker.signals.signal_finished.connect(None) - # worker.signals.signal_progress.connect() + worker.signals.signal_progress.connect(self.handle_progress) threadpool.start(worker) # export_playlist_by_id(id) except Exception: diff --git a/utils/add_files_to_database.py b/utils/add_files_to_database.py index 058153d..323d8c5 100644 --- a/utils/add_files_to_database.py +++ b/utils/add_files_to_database.py @@ -32,7 +32,7 @@ def add_files_to_database(files: list[str], playlist_id: int | None = None, prog if not files: debug('add_files_to_database() - no files to add') if progress_callback: - progress_callback('failed') + progress_callback.emit('failed') return False, {"Failure": "All operations failed in add_files_to_database()"} failed_dict: dict[str, str] = {} insert_data: list[tuple[ @@ -49,6 +49,8 @@ def add_files_to_database(files: list[str], playlist_id: int | None = None, prog for filepath in files: if progress_callback: progress_callback.emit(filepath) + # FIXME: can this be improved? + # filename.basename or something like that filename = filepath.split("/")[-1] tags, fail_reason = get_tags(filepath) if fail_reason: diff --git a/utils/export_playlist_by_id.py b/utils/export_playlist_by_id.py index 74e6f12..fba2f14 100644 --- a/utils/export_playlist_by_id.py +++ b/utils/export_playlist_by_id.py @@ -8,12 +8,13 @@ from pathlib import Path from time import time -def export_playlist_by_id(playlist_db_id: int) -> bool: +def export_playlist_by_id(playlist_db_id: int, progress_callback=None) -> bool: """ Exports a playlist to its defined auto_export_path, by database ID """ logging.debug(f"Exporting playlist id: {playlist_db_id}") - threadpool = QThreadPool() + if progress_callback: + progress_callback.emit(f"Exporting playlist id: {playlist_db_id}") try: with DBA.DBAccess() as db: result = db.query( @@ -56,22 +57,21 @@ def export_playlist_by_id(playlist_db_id: int) -> bool: write_paths = [] # Relative paths logging.debug("Creating relative paths...") + threadpool = QThreadPool() for song in db_paths: artist, album = parse_artist_album(song) write_path = Path(path_prefix) / artist / album / song.name write_paths.append(str(write_path) + "\n") - write_to_playlist_file(write_paths, auto_export_path) + # write_to_playlist_file(write_paths, auto_export_path) - # worker = Worker(write_to_playlist_file, write_paths, auto_export_path) - # worker.signals.signal_finished.connect(None) - # worker.signals.signal_progress.connect() - # threadpool.start(worker) + worker = Worker(write_to_playlist_file, write_paths, auto_export_path) + # worker.signals.signal_finished.connect(None) + # worker.signals.signal_progress.connect() + threadpool.start(worker) return True -def write_to_playlist_file( - paths: list[str], outfile: str, progress_callback=None -) -> None: +def write_to_playlist_file(paths: list[str], outfile: str, progress_callback=None) -> None: """ Writes a list of strings to a m3u file """ diff --git a/utils/get_tags.py b/utils/get_tags.py index e6cc3df..3ecf2e6 100644 --- a/utils/get_tags.py +++ b/utils/get_tags.py @@ -39,6 +39,7 @@ def id3_remap(audio: MP3 | ID3 | FLAC) -> dict[str, str | int | None]: Turns the ID3 dict of an audio file into a normal dict that I, the human, can use. Add extra fields too :D yahooo """ + # FIXME: implement other filetypes here too remap = {} if isinstance(audio, MP3): # so ugly @@ -85,7 +86,8 @@ def get_tags(filename: str) -> tuple[MP3 | ID3 | FLAC, str]: ... } """ - if filename.endswith(".mp3"): + # FIXME: this is where i implement other filetypes + if filename.lower().endswith(".mp3"): tags, details = get_mp3_tags(filename) else: tags, details = ID3(), "non mp3 file" diff --git a/utils/scan_for_music.py b/utils/scan_for_music.py index 69dac17..3d3d581 100644 --- a/utils/scan_for_music.py +++ b/utils/scan_for_music.py @@ -28,4 +28,6 @@ def scan_for_music(progress_callback=None): filename = os.path.join(dirpath, file) if any(filename.lower().endswith(ext) for ext in extensions): files_to_add.append(filename) - add_files_to_database(files_to_add, progress_callback) + if progress_callback: + progress_callback.emit(f'Scanning {filename}') + add_files_to_database(files=files_to_add, playlist_id=None, progress_callback=progress_callback)