mirror of
https://github.com/KevinMidboe/spotify-downloader.git
synced 2025-12-08 20:39:08 +00:00
[WIP] Refactor spotdl.py; introduced classes (#410)
* Refactor spotdl.py; introduced classes * introduce CheckExists class * Move these classes to download.py * Fix refresh_token * Add a changelog entry
This commit is contained in:
18
spotdl/internals.py
Executable file → Normal file
18
spotdl/internals.py
Executable file → Normal file
@@ -48,11 +48,12 @@ def input_link(links):
|
||||
log.warning("Choose a valid number!")
|
||||
|
||||
|
||||
def trim_song(text_file):
|
||||
def trim_song(tracks_file):
|
||||
""" Remove the first song from file. """
|
||||
with open(text_file, "r") as file_in:
|
||||
log.debug("Removing downloaded song from tracks file")
|
||||
with open(tracks_file, "r") as file_in:
|
||||
data = file_in.read().splitlines(True)
|
||||
with open(text_file, "w") as file_out:
|
||||
with open(tracks_file, "w") as file_out:
|
||||
file_out.writelines(data[1:])
|
||||
return data[0]
|
||||
|
||||
@@ -181,20 +182,23 @@ def extract_spotify_id(raw_string):
|
||||
return spotify_id
|
||||
|
||||
|
||||
def get_unique_tracks(text_file):
|
||||
def get_unique_tracks(tracks_file):
|
||||
"""
|
||||
Returns a list of unique tracks given a path to a
|
||||
file containing tracks.
|
||||
"""
|
||||
|
||||
with open(text_file, "r") as listed:
|
||||
log.info(
|
||||
"Checking and removing any duplicate tracks "
|
||||
"in reading {}".format(tracks_file)
|
||||
)
|
||||
with open(tracks_file, "r") as tracks_in:
|
||||
# Read tracks into a list and remove any duplicates
|
||||
lines = listed.read().splitlines()
|
||||
lines = tracks_in.read().splitlines()
|
||||
|
||||
# Remove blank and strip whitespaces from lines (if any)
|
||||
lines = [line.strip() for line in lines if line.strip()]
|
||||
lines = remove_duplicates(lines)
|
||||
|
||||
return lines
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user