Skip to content

Commit

Permalink
Revert "Sync Update: Simplified Removal Process (#438)"
Browse files Browse the repository at this point in the history
This reverts commit a95b8d6.
  • Loading branch information
7x11x13 committed Apr 30, 2024
1 parent a95b8d6 commit e1d0a25
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 19 deletions.
2 changes: 1 addition & 1 deletion scdl/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# -*- encoding: utf-8 -*-
"""Python Soundcloud Music Downloader."""
__version__ = "v2.7.6"
__version__ = "v2.7.5"
30 changes: 12 additions & 18 deletions scdl/scdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand All @@ -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:
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e1d0a25

Please sign in to comment.