From 7ab21cccb263c588c714ed9ca2f3c505a88bbd2f Mon Sep 17 00:00:00 2001 From: Andrea Rogers Date: Mon, 22 Aug 2022 18:17:27 -0500 Subject: [PATCH] used the proper filename sanitizer As reported by KajeArch on GitHub on issue #3 (https://github.com/swolegoal/squid-dl/issues/3), I was not correctly handling playlists named with characters invalid for a file path. As it turns out, I was using the wrong helper function from yt_dlp.utils. I changed all the calls from sanitize_path(), a function made to clean up Windows paths to the more fully-featured sanitize_filename(). If any Windows users notice any bad behavior after this change, please feel free to make a ticket at: https://github.com/swolegoal/squid-dl/issues/new/choose --- scripts/squidson | 4 ++-- squid_dl/downloader.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/squidson b/scripts/squidson index 0641302..72c7a84 100755 --- a/scripts/squidson +++ b/scripts/squidson @@ -2,7 +2,7 @@ import argparse import json as j from yt_dlp import YoutubeDL -from yt_dlp.utils import encodeFilename, sanitize_path +from yt_dlp.utils import encodeFilename, sanitize_filename """ Dump yt_dlp's entire info_dict for a whole playlist in JSON format. @@ -43,7 +43,7 @@ if __name__ == "__main__": y.extract_info(opts.playlist_url, download=False) ) - dump_path = encodeFilename(sanitize_path(info_dict["title"] + ".json")) + dump_path = encodeFilename(sanitize_filename(info_dict["title"] + ".json")) print( '[INFO]: Writing JSON-ified playlist info_dict to "{}"'.format( dump_path diff --git a/squid_dl/downloader.py b/squid_dl/downloader.py index 7ab2cae..4af1693 100644 --- a/squid_dl/downloader.py +++ b/squid_dl/downloader.py @@ -38,7 +38,7 @@ from random import randint from time import sleep import typing from yt_dlp import YoutubeDL -from yt_dlp.utils import encodeFilename, sanitize_path +from yt_dlp.utils import encodeFilename, sanitize_filename from yt_dlp.extractor.common import InfoExtractor as IE from .linode import LinodeProxy @@ -233,7 +233,7 @@ def check_dl(in_q: Queue, out_q: Queue): y = YoutubeDL({"ignoreerrors": True}) basename = os.path.splitext( - sanitize_path(encodeFilename(y.prepare_filename(entry))) + sanitize_filename(encodeFilename(y.prepare_filename(entry))) )[0] try: if check_subs_done(entry, basename): @@ -458,7 +458,7 @@ def main(args: [str], name: str) -> int: print("[INFO]: Starting squid-dl...") - dirname = info_dict["title"] + dirname = sanitize_filename(info_dict["title"]) print('[INFO]: saving videos to "{}" directory'.format(dirname)) if not (os.path.exists(dirname) and os.path.isdir(dirname)): os.mkdir(dirname)