From 9791aea0f2b0df801a75b1ce1bbd1275aab088eb Mon Sep 17 00:00:00 2001 From: Justin Donofrio Date: Sun, 17 Nov 2024 14:41:52 -0500 Subject: [PATCH] Add playlist number and service to track path --- src/onthespot/api/deezer.py | 1 - src/onthespot/cli.py | 1 + src/onthespot/downloader.py | 3 +-- src/onthespot/gui/mainui.py | 1 + src/onthespot/parse_item.py | 13 +++++++++---- src/onthespot/utils.py | 14 ++++++++------ 6 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/onthespot/api/deezer.py b/src/onthespot/api/deezer.py index ed3b2ce..8ad2901 100644 --- a/src/onthespot/api/deezer.py +++ b/src/onthespot/api/deezer.py @@ -320,6 +320,5 @@ def deezer_get_search_results(token, search_term, content_types): 'item_thumbnail_url': track["album"]["cover"] }) - logger.info(search_results) return search_results diff --git a/src/onthespot/cli.py b/src/onthespot/cli.py index e94bcff..5bb748b 100644 --- a/src/onthespot/cli.py +++ b/src/onthespot/cli.py @@ -50,6 +50,7 @@ def run(self): 'is_playlist_item': item['is_playlist_item'], 'playlist_name': playlist_name, 'playlist_by': playlist_by, + 'playlist_number': item['playlist_number'] } time.sleep(1) continue diff --git a/src/onthespot/downloader.py b/src/onthespot/downloader.py index 38c1007..0cd1ce4 100644 --- a/src/onthespot/downloader.py +++ b/src/onthespot/downloader.py @@ -73,8 +73,7 @@ def run(self): try: item_metadata = globals()[f"{item_service}_get_{item_type}_metadata"](token, item_id) - - item_path = format_track_path(item_metadata, item_service, item_type, item['parent_category'], item['playlist_name'], item['playlist_by']) + item_path = format_track_path(item, item_metadata) except (Exception, KeyError): item['item_status'] = "Failed" diff --git a/src/onthespot/gui/mainui.py b/src/onthespot/gui/mainui.py index 5de6205..4a59b75 100644 --- a/src/onthespot/gui/mainui.py +++ b/src/onthespot/gui/mainui.py @@ -415,6 +415,7 @@ def add_item_to_download_list(self, item, item_metadata): 'parent_category': item['parent_category'], 'playlist_name': playlist_name, 'playlist_by': playlist_by, + 'playlist_number': item.get('playlist_number', ''), "gui": { "status_label": status_label, "progress_bar": pbar, diff --git a/src/onthespot/parse_item.py b/src/onthespot/parse_item.py index e26e258..52dbf1c 100755 --- a/src/onthespot/parse_item.py +++ b/src/onthespot/parse_item.py @@ -105,8 +105,10 @@ def parsingworker(): 'item_id': item_id, 'parent_category': 'playlist', 'playlist_name': playlist_name, - 'playlist_by': playlist_by + 'playlist_by': playlist_by, + 'playlist_number': str(index + 1) } + print(pending) except TypeError: logger.error(f'TypeError for {item}') continue @@ -147,7 +149,8 @@ def parsingworker(): 'item_id': item_id, 'parent_category': 'playlist', 'playlist_name': 'Liked Songs', - 'playlist_by': 'me' + 'playlist_by': 'me', + 'playlist_number': str(index + 1) } continue @@ -161,7 +164,8 @@ def parsingworker(): 'item_id': item_id, 'parent_category': 'playlist', 'playlist_name': 'Your Episodes', - 'playlist_by': 'me' + 'playlist_by': 'me', + 'playlist_number': str(index + 1) } continue @@ -212,7 +216,8 @@ def parsingworker(): 'item_id': item_id, 'parent_category': 'playlist', 'playlist_name': playlist_name, - 'playlist_by': playlist_by + 'playlist_by': playlist_by, + 'playlist_number': str(index + 1) } continue elif current_type == "artist": diff --git a/src/onthespot/utils.py b/src/onthespot/utils.py index d354d6a..4a58c2c 100644 --- a/src/onthespot/utils.py +++ b/src/onthespot/utils.py @@ -94,7 +94,7 @@ def conv_list_format(items): return (config.get('metadata_seperator')).join(items) -def format_track_path(item_metadata, item_service, item_type, parent_category, playlist_name, playlist_by): +def format_track_path(item, item_metadata): if config.get("translate_file_path"): name = translate(item_metadata.get('title', '')) album = translate(item_metadata.get('album_name', '')) @@ -102,14 +102,15 @@ def format_track_path(item_metadata, item_service, item_type, parent_category, p name = item_metadata.get('title', '') album = item_metadata.get('album_name', '') - if parent_category == 'playlist' and config.get("use_playlist_path"): + if item['parent_category'] == 'playlist' and config.get("use_playlist_path"): path = config.get("playlist_path_formatter") - elif item_type == 'track': + elif item['item_type'] == 'track': path = config.get("track_path_formatter") - elif item_type == 'episode': + elif item['item_type'] == 'episode': path = config.get("podcast_path_formatter") item_path = path.format( + service=sanitize_data(item.get('item_service', '')).title(), artist=sanitize_data(item_metadata.get('artists', '')), album=sanitize_data(album), album_artist=sanitize_data(item_metadata.get('album_artists', '')), @@ -122,8 +123,9 @@ def format_track_path(item_metadata, item_service, item_type, parent_category, p explicit=sanitize_data(str(config.get('explicit_label')) if item_metadata.get('explicit') else ''), trackcount=item_metadata.get('total_tracks', ''), disccount=item_metadata.get('total_discs', ''), - playlist_name=sanitize_data(playlist_name), - playlist_owner=sanitize_data(playlist_by), + playlist_name=sanitize_data(item.get('playlist_name', '')), + playlist_owner=sanitize_data(item.get('playlist_by', '')), + playlist_number=sanitize_data(item.get('playlist_number', '')), ) return item_path