fix log file not being chreated with special characters
This commit is contained in:
parent
ee56dd71ac
commit
69fe86b1f0
|
@ -1,5 +1,6 @@
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import ffmpeg
|
import ffmpeg
|
||||||
|
@ -76,3 +77,11 @@ def remove_duplicates_from_playlist(entries):
|
||||||
videos.append(video)
|
videos.append(video)
|
||||||
s.add(video['id'])
|
s.add(video['id'])
|
||||||
return videos
|
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
|
||||||
|
|
|
@ -13,7 +13,7 @@ from tqdm.auto import tqdm
|
||||||
from unidecode import unidecode
|
from unidecode import unidecode
|
||||||
|
|
||||||
import ydl.yt_dlp as ydl
|
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):
|
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.
|
# # 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']
|
# 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
|
kwargs['ydl_opts']['logger'] = ylogger
|
||||||
yt_dlp = ydl.YDL(kwargs['ydl_opts']) # recreate the object with the correct logging path
|
yt_dlp = ydl.YDL(kwargs['ydl_opts']) # recreate the object with the correct logging path
|
||||||
error_code = yt_dlp(video['url']) # Do the download
|
error_code = yt_dlp(video['url']) # Do the download
|
||||||
|
|
Reference in New Issue