Skip to content

Commit ae2c2ee

Browse files
committed
check that the flag to delete has been explicitly set and not "truthy" set
fixes "not in the playlist anymore, we delete it" #344
1 parent 8cc6043 commit ae2c2ee

File tree

3 files changed

+33
-33
lines changed

3 files changed

+33
-33
lines changed

spotify_dl/constants.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
__all__ = ["VERSION"]
55

6-
VERSION = "8.8.0"
6+
VERSION = "8.8.1"
77

88
if os.getenv("XDG_CACHE_HOME") is not None:
99
SAVE_PATH = os.getenv("XDG_CACHE_HOME") + "/spotifydl"

spotify_dl/spotify_dl.py

+15-20
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@
1818
get_item_name,
1919
)
2020

21-
from spotify_dl.youtube import download_songs, default_filename, playlist_num_filename, dump_json
21+
from spotify_dl.youtube import (
22+
download_songs,
23+
default_filename,
24+
playlist_num_filename,
25+
dump_json,
26+
)
2227

2328

2429
def spotify_dl():
@@ -54,7 +59,7 @@ def spotify_dl():
5459
"--dump-json",
5560
action="store_true",
5661
help="Dump info-json using youtube-dl",
57-
default=False
62+
default=False,
5863
)
5964
parser.add_argument(
6065
"-f",
@@ -95,8 +100,8 @@ def spotify_dl():
95100
"-r",
96101
"--remove-trailing-tracks",
97102
default="no",
98-
action="store_true",
99-
help="Whether we should delete tracks that were previously downloaded but are not longer in the playlist"
103+
action="store",
104+
help="Whether we should delete tracks that were previously downloaded but are not longer in the playlist",
100105
)
101106
parser.add_argument(
102107
"-V",
@@ -143,7 +148,7 @@ def spotify_dl():
143148
"Requested cores %d exceeds available %d, using %d cores.",
144149
args.multi_core,
145150
num_cores,
146-
num_cores - 1
151+
num_cores - 1,
147152
)
148153
args.multi_core = num_cores - 1
149154
if args.version:
@@ -177,16 +182,13 @@ def spotify_dl():
177182
)
178183
)
179184
log.debug("Arguments: %s ", args)
180-
log.info(
181-
"Sponsorblock enabled?: %s",
182-
args.use_sponsorblock
183-
)
185+
log.info("Sponsorblock enabled?: %s", args.use_sponsorblock)
184186
valid_urls = validate_spotify_urls(args.url)
185187
if not valid_urls:
186188
sys.exit(1)
187189

188190
url_data = {"urls": []}
189-
191+
start_time = time.time()
190192
for url in valid_urls:
191193
url_dict = {}
192194
item_type, item_id = parse_spotify_url(url)
@@ -195,10 +197,7 @@ def spotify_dl():
195197
PurePath.joinpath(Path(args.output), Path(directory_name))
196198
)
197199
url_dict["save_path"].mkdir(parents=True, exist_ok=True)
198-
log.info(
199-
"Saving songs to %s directory",
200-
directory_name
201-
)
200+
log.info("Saving songs to %s directory", directory_name)
202201
url_dict["songs"] = fetch_tracks(sp, item_type, url)
203202
url_data["urls"].append(url_dict.copy())
204203
if args.dump_json is True:
@@ -215,18 +214,14 @@ def spotify_dl():
215214
skip_mp3=args.skip_mp3,
216215
keep_playlist_order=args.keep_playlist_order,
217216
no_overwrites=args.no_overwrites,
218-
remove_trailing_tracks=args.remove_trailing_tracks,
217+
remove_trailing_tracks=(args.remove_trailing_tracks[0].lower()),
219218
use_sponsorblock=args.use_sponsorblock,
220219
file_name_f=file_name_f,
221220
multi_core=args.multi_core,
222221
proxy=args.proxy,
223222
)
223+
log.info("Download completed in %.2f seconds.", time.time() - start_time)
224224

225225

226226
if __name__ == "__main__":
227-
start_time = time.time()
228227
spotify_dl()
229-
log.info(
230-
"Download completed in %f seconds.",
231-
time.time() - start_time
232-
)

spotify_dl/youtube.py

+17-12
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,21 @@ def dump_json(songs):
3333
:param songs: the songs for which the JSON should be output
3434
"""
3535
for song in songs:
36-
query = f"{song.get('artist')} - {song.get('name')} Lyrics".replace(":", "").replace("\"", "")
36+
query = f"{song.get('artist')} - {song.get('name')} Lyrics".replace(
37+
":", ""
38+
).replace('"', "")
3739

38-
ydl_opts = {
39-
'quiet': True
40-
}
40+
ydl_opts = {"quiet": True}
4141

4242
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
4343
try:
44-
ytJson = ydl.extract_info('ytsearch:' + query, False)
45-
print(json.dumps(ytJson.get('entries')))
44+
ytJson = ydl.extract_info("ytsearch:" + query, False)
45+
print(json.dumps(ytJson.get("entries")))
4646
except Exception as e: # skipcq: PYL-W0703
4747
log.debug(e)
48-
print(f"Failed to download {song.get('name')}, make sure yt_dlp is up to date")
48+
print(
49+
f"Failed to download {song.get('name')}, make sure yt_dlp is up to date"
50+
)
4951
continue
5052

5153

@@ -163,7 +165,6 @@ def find_and_download_songs(kwargs):
163165
)
164166

165167
if kwargs["use_sponsorblock"][0].lower() == "y":
166-
167168
sponsorblock_postprocessor = [
168169
{
169170
"key": "SponsorBlock",
@@ -188,13 +189,17 @@ def find_and_download_songs(kwargs):
188189

189190
path_files.add(f"{file_name}.mp3")
190191

191-
if kwargs["no_overwrites"] and not kwargs["skip_mp3"] and path.exists(mp3file_path):
192-
print(f'File {mp3file_path} already exists, we do not overwrite it ')
192+
if (
193+
kwargs["no_overwrites"]
194+
and not kwargs["skip_mp3"]
195+
and path.exists(mp3file_path)
196+
):
197+
print(f"File {mp3file_path} already exists, we do not overwrite it ")
193198
continue
194199

195200
outtmpl = f"{file_path}.%(ext)s"
196201
ydl_opts = {
197-
"proxy": kwargs.get('proxy'),
202+
"proxy": kwargs.get("proxy"),
198203
"default_search": "ytsearch",
199204
"format": "bestaudio/best",
200205
"outtmpl": outtmpl,
@@ -225,7 +230,7 @@ def find_and_download_songs(kwargs):
225230
print(f"Failed to download {name}, make sure yt_dlp is up to date")
226231
if not kwargs["skip_mp3"]:
227232
set_tags(temp, mp3file_path, kwargs)
228-
if kwargs["remove_trailing_tracks"]:
233+
if kwargs["remove_trailing_tracks"] == "y":
229234
for save_path in files:
230235
for f in os.listdir(save_path):
231236
if f not in files[save_path]:

0 commit comments

Comments
 (0)