fix log file not being chreated with special characters

This commit is contained in:
Cyberes 2023-05-06 14:23:20 -06:00
parent ee56dd71ac
commit 69fe86b1f0
2 changed files with 11 additions and 2 deletions

View File

@ -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

View File

@ -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