Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check that the flag to delete has been explicitly set #345

Merged
merged 1 commit into from
May 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion spotify_dl/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

__all__ = ["VERSION"]

VERSION = "8.8.0"
VERSION = "8.8.1"

if os.getenv("XDG_CACHE_HOME") is not None:
SAVE_PATH = os.getenv("XDG_CACHE_HOME") + "/spotifydl"
Expand Down
35 changes: 15 additions & 20 deletions spotify_dl/spotify_dl.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@
get_item_name,
)

from spotify_dl.youtube import download_songs, default_filename, playlist_num_filename, dump_json
from spotify_dl.youtube import (
download_songs,
default_filename,
playlist_num_filename,
dump_json,
)


def spotify_dl():
Expand Down Expand Up @@ -54,7 +59,7 @@ def spotify_dl():
"--dump-json",
action="store_true",
help="Dump info-json using youtube-dl",
default=False
default=False,
)
parser.add_argument(
"-f",
Expand Down Expand Up @@ -95,8 +100,8 @@ def spotify_dl():
"-r",
"--remove-trailing-tracks",
default="no",
action="store_true",
help="Whether we should delete tracks that were previously downloaded but are not longer in the playlist"
action="store",
help="Whether we should delete tracks that were previously downloaded but are not longer in the playlist",
)
parser.add_argument(
"-V",
Expand Down Expand Up @@ -143,7 +148,7 @@ def spotify_dl():
"Requested cores %d exceeds available %d, using %d cores.",
args.multi_core,
num_cores,
num_cores - 1
num_cores - 1,
)
args.multi_core = num_cores - 1
if args.version:
Expand Down Expand Up @@ -177,16 +182,13 @@ def spotify_dl():
)
)
log.debug("Arguments: %s ", args)
log.info(
"Sponsorblock enabled?: %s",
args.use_sponsorblock
)
log.info("Sponsorblock enabled?: %s", args.use_sponsorblock)
valid_urls = validate_spotify_urls(args.url)
if not valid_urls:
sys.exit(1)

url_data = {"urls": []}

start_time = time.time()
for url in valid_urls:
url_dict = {}
item_type, item_id = parse_spotify_url(url)
Expand All @@ -195,10 +197,7 @@ def spotify_dl():
PurePath.joinpath(Path(args.output), Path(directory_name))
)
url_dict["save_path"].mkdir(parents=True, exist_ok=True)
log.info(
"Saving songs to %s directory",
directory_name
)
log.info("Saving songs to %s directory", directory_name)
url_dict["songs"] = fetch_tracks(sp, item_type, url)
url_data["urls"].append(url_dict.copy())
if args.dump_json is True:
Expand All @@ -215,18 +214,14 @@ def spotify_dl():
skip_mp3=args.skip_mp3,
keep_playlist_order=args.keep_playlist_order,
no_overwrites=args.no_overwrites,
remove_trailing_tracks=args.remove_trailing_tracks,
remove_trailing_tracks=(args.remove_trailing_tracks[0].lower()),
use_sponsorblock=args.use_sponsorblock,
file_name_f=file_name_f,
multi_core=args.multi_core,
proxy=args.proxy,
)
log.info("Download completed in %.2f seconds.", time.time() - start_time)


if __name__ == "__main__":
start_time = time.time()
spotify_dl()
log.info(
"Download completed in %f seconds.",
time.time() - start_time
)
29 changes: 17 additions & 12 deletions spotify_dl/youtube.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,21 @@ def dump_json(songs):
:param songs: the songs for which the JSON should be output
"""
for song in songs:
query = f"{song.get('artist')} - {song.get('name')} Lyrics".replace(":", "").replace("\"", "")
query = f"{song.get('artist')} - {song.get('name')} Lyrics".replace(
":", ""
).replace('"', "")

ydl_opts = {
'quiet': True
}
ydl_opts = {"quiet": True}

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


Expand Down Expand Up @@ -163,7 +165,6 @@ def find_and_download_songs(kwargs):
)

if kwargs["use_sponsorblock"][0].lower() == "y":

sponsorblock_postprocessor = [
{
"key": "SponsorBlock",
Expand All @@ -188,13 +189,17 @@ def find_and_download_songs(kwargs):

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

if kwargs["no_overwrites"] and not kwargs["skip_mp3"] and path.exists(mp3file_path):
print(f'File {mp3file_path} already exists, we do not overwrite it ')
if (
kwargs["no_overwrites"]
and not kwargs["skip_mp3"]
and path.exists(mp3file_path)
):
print(f"File {mp3file_path} already exists, we do not overwrite it ")
continue

outtmpl = f"{file_path}.%(ext)s"
ydl_opts = {
"proxy": kwargs.get('proxy'),
"proxy": kwargs.get("proxy"),
"default_search": "ytsearch",
"format": "bestaudio/best",
"outtmpl": outtmpl,
Expand Down Expand Up @@ -225,7 +230,7 @@ def find_and_download_songs(kwargs):
print(f"Failed to download {name}, make sure yt_dlp is up to date")
if not kwargs["skip_mp3"]:
set_tags(temp, mp3file_path, kwargs)
if kwargs["remove_trailing_tracks"]:
if kwargs["remove_trailing_tracks"] == "y":
for save_path in files:
for f in os.listdir(save_path):
if f not in files[save_path]:
Expand Down