From cdd013b09ed8028408498182057cf6c4b2e7982b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Fri, 19 Nov 2021 17:46:32 +0100 Subject: [PATCH] Also save ext data in .song_ids file (filename, date, etc) --- zspotify/track.py | 4 ++-- zspotify/utils.py | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/zspotify/track.py b/zspotify/track.py index ae5e54b3..4863ca21 100644 --- a/zspotify/track.py +++ b/zspotify/track.py @@ -158,10 +158,10 @@ def download_track(mode: str, track_id: str, extra_keys={}, disable_progressbar= # add song id to archive file if ZSpotify.CONFIG.get_skip_previously_downloaded(): - add_to_archive(scraped_song_id, artists[0], name) + add_to_archive(scraped_song_id, filename, artists[0], name) # add song id to download directory's .song_ids file if not check_id: - add_to_directory_song_ids(filedir, scraped_song_id) + add_to_directory_song_ids(filedir, scraped_song_id, filename, artists[0], name) if not ZSpotify.CONFIG.get_anti_ban_wait_time(): time.sleep(ZSpotify.CONFIG.get_anti_ban_wait_time()) diff --git a/zspotify/utils.py b/zspotify/utils.py index d7627d95..bb233c76 100644 --- a/zspotify/utils.py +++ b/zspotify/utils.py @@ -42,17 +42,17 @@ def get_previously_downloaded() -> List[str]: return ids -def add_to_archive(song_id: str, author_name: str, song_name: str) -> None: +def add_to_archive(song_id: str, filename: str, author_name: str, song_name: str) -> None: """ Adds song id to all time installed songs archive """ archive_path = os.path.join(os.path.dirname(__file__), ZSpotify.CONFIG.get_root_path(), ZSpotify.CONFIG.get_song_archive()) if os.path.exists(archive_path): - with open(archive_path, 'a', encoding='utf-8') as f: - f.write(f'{song_id}\t{datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")}\t{author_name}\t{song_name}\n') + with open(archive_path, 'a', encoding='utf-8') as file: + file.write(f'{song_id}\t{datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")}\t{author_name}\t{song_name}\t{filename}\n') else: - with open(archive_path, 'w', encoding='utf-8') as f: - f.write(f'{song_id}\t{datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")}\t{author_name}\t{song_name}\n') + with open(archive_path, 'w', encoding='utf-8') as file: + file.write(f'{song_id}\t{datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")}\t{author_name}\t{song_name}\t{filename}\n') def get_directory_song_ids(download_path: str) -> List[str]: """ Gets song ids of songs in directory """ @@ -62,18 +62,18 @@ def get_directory_song_ids(download_path: str) -> List[str]: hidden_file_path = os.path.join(download_path, '.song_ids') if os.path.isfile(hidden_file_path): with open(hidden_file_path, 'r', encoding='utf-8') as file: - song_ids.extend([line.strip() for line in file.readlines()]) + song_ids.extend([line.strip().split('\t')[0] for line in file.readlines()]) return song_ids -def add_to_directory_song_ids(download_path: str, song_id: str) -> None: +def add_to_directory_song_ids(download_path: str, song_id: str, filename: str, author_name: str, song_name: str) -> None: """ Appends song_id to .song_ids file in directory """ hidden_file_path = os.path.join(download_path, '.song_ids') # not checking if file exists because we need an exception # to be raised if something is wrong with open(hidden_file_path, 'a', encoding='utf-8') as file: - file.write(f'{song_id}\n') + file.write(f'{song_id}\t{datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")}\t{author_name}\t{song_name}\t{filename}\n') def get_downloaded_song_duration(filename: str) -> float: """ Returns the downloaded file's duration in seconds """