diff --git a/process/funcs.py b/process/funcs.py index 9d92170..10d8ede 100644 --- a/process/funcs.py +++ b/process/funcs.py @@ -1,5 +1,6 @@ import logging import os +import re import sys import ffmpeg @@ -76,3 +77,11 @@ def remove_duplicates_from_playlist(entries): videos.append(video) s.add(video['id']) return videos + + +def remove_special_chars_linux(string, special_chars: list = None): + if special_chars is None: + special_chars = ['\\', '`', '*', '_', '{', '}', '[', ']', '(', ')', '>', '#', '+', '-', '.', '!', '$', '\''] + for char in special_chars: + string = re.sub(re.escape(char), '', string) + return string diff --git a/process/threads.py b/process/threads.py index bd7e7b7..d6ce2d4 100644 --- a/process/threads.py +++ b/process/threads.py @@ -13,7 +13,7 @@ from tqdm.auto import tqdm from unidecode import unidecode import ydl.yt_dlp as ydl -from process.funcs import setup_file_logger +from process.funcs import remove_special_chars_linux, setup_file_logger class ytdl_logger(object): @@ -122,7 +122,7 @@ def download_video(args) -> dict: # # Sometimes we won't be able to pull the video info so just use the video's ID. # base_path = kwargs['output_dir'] / video['id'] - ylogger = ytdl_logger(setup_file_logger(video['id'], base_path + '.log')) + ylogger = ytdl_logger(setup_file_logger(video['id'], remove_special_chars_linux(base_path, special_chars=['/']) + '.log')) kwargs['ydl_opts']['logger'] = ylogger yt_dlp = ydl.YDL(kwargs['ydl_opts']) # recreate the object with the correct logging path error_code = yt_dlp(video['url']) # Do the download