From e1d0a25069b1b9a6919d32774d5364ca6b9d1026 Mon Sep 17 00:00:00 2001 From: 7x11x13 Date: Tue, 30 Apr 2024 13:03:57 -0400 Subject: [PATCH] Revert "Sync Update: Simplified Removal Process (#438)" This reverts commit a95b8d61ae3455d591193b58cd78b1a03aaa8512. --- scdl/__init__.py | 2 +- scdl/scdl.py | 30 ++++++++++++------------------ 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/scdl/__init__.py b/scdl/__init__.py index 1369cdd7..117edc8b 100644 --- a/scdl/__init__.py +++ b/scdl/__init__.py @@ -1,3 +1,3 @@ # -*- encoding: utf-8 -*- """Python Soundcloud Music Downloader.""" -__version__ = "v2.7.6" \ No newline at end of file +__version__ = "v2.7.5" diff --git a/scdl/scdl.py b/scdl/scdl.py index d4fbeed0..8eac798e 100755 --- a/scdl/scdl.py +++ b/scdl/scdl.py @@ -389,12 +389,11 @@ def remove_files(): """ Removes any pre-existing tracks that were not just downloaded """ - logger.info("Removing local track files...") + logger.info("Removing local track files that were not downloaded...") files = [f for f in os.listdir(".") if os.path.isfile(f)] for f in files: if f not in fileToKeep: os.remove(f) - logger.info(f'Removed {f}') def sync(client: SoundCloud, playlist: BasicAlbumPlaylist, playlist_info, **kwargs): """ @@ -417,22 +416,19 @@ def sync(client: SoundCloud, playlist: BasicAlbumPlaylist, playlist_info, **kwar new = [track.id for track in playlist.tracks] add = set(new).difference(old) # find tracks to download rem = set(old).difference(new) # find tracks to remove - for track_id in new: - if ( - client.get_track(track_id).downloadable - and not kwargs["onlymp3"] - and not kwargs.get("no_original") - ): - fileToKeep.append(get_original_filename(client, client.get_track(track_id), playlist_info, **kwargs)) - else: - fileToKeep.append(get_filename(client.get_track(track_id), playlist_info=playlist_info, **kwargs)) if not (add or rem): logger.info("No changes found. Exiting...") sys.exit(0) if rem: - remove_files() + for track_id in rem: + filename = get_filename(client.get_track(track_id),playlist_info=playlist_info,**kwargs) + if filename in os.listdir('.'): + os.remove(filename) + logger.info(f'Removed {filename}') + else: + logger.info(f'Could not find {filename} to remove') with open(archive,'w') as f: for track_id in old: if track_id not in rem: @@ -531,7 +527,10 @@ def get_filename(track: BasicTrack, original_filename=None, aac=False, playlist_ filename = sanitize_filename(filename) return filename -def get_original_filename(client: SoundCloud, track: BasicTrack, playlist_info=None, **kwargs): + +def download_original_file(client: SoundCloud, track: BasicTrack, title: str, playlist_info=None, **kwargs): + logger.info("Downloading the original file.") + # Get the requests stream url = client.get_track_original_download(track.id, track.secret_token) @@ -568,12 +567,7 @@ def get_original_filename(client: SoundCloud, track: BasicTrack, playlist_info=N filename += ext filename = get_filename(track, filename, playlist_info=playlist_info, **kwargs) - return filename - -def download_original_file(client: SoundCloud, track: BasicTrack, title: str, playlist_info=None, **kwargs): - logger.info("Downloading the original file.") - filename = get_original_filename(client, track, playlist_info, **kwargs) logger.debug(f"filename : {filename}") # Skip if file ID or filename already exists