diff --git a/downloader.py b/downloader.py index 75593c5..1303494 100755 --- a/downloader.py +++ b/downloader.py @@ -21,7 +21,7 @@ from tqdm.auto import tqdm from process.funcs import get_silent_logger, remove_duplicates_from_playlist, restart_program, setup_file_logger from process.threads import bar_eraser, download_video from ydl.files import create_directories, resolve_path -from ydl.yt_dlp import YDL, update_ytdlp +from ydl.yt_dlp import YDL, get_output_templ, update_ytdlp def signal_handler(sig, frame): @@ -257,7 +257,6 @@ class ytdl_logger(object): # TODO: https://github.com/TheFrenchGhosty/TheFrenchGhostys-Ultimate-YouTube-DL-Scripts-Collection/blob/master/docs/Scripts-Type.md#archivist-scripts # https://github.com/yt-dlp/yt-dlp#embedding-examples -base_outtempl = '[%(id)s] [%(title)s] [%(uploader)s] [%(uploader_id)s].%(ext)s' # leading dash can cause issues due to bash args so we surround the variables in brackets ydl_opts = { # TODO: https://github.com/TheFrenchGhosty/TheFrenchGhostys-Ultimate-YouTube-DL-Scripts-Collection/blob/master/docs/Details.md # https://old.reddit.com/r/DataHoarder/comments/c6fh4x/after_hoarding_over_50k_youtube_videos_here_is/ @@ -361,7 +360,7 @@ while True: playlist_bar.update(len(downloaded_videos)) playlist_ydl_opts = ydl_opts.copy() - playlist_ydl_opts['outtmpl'] = f'{output_path}/{base_outtempl}' + # playlist_ydl_opts['outtmpl'] = f'{output_path}/{get_output_templ()}' if len(download_queue): # Don't mess with multiprocessing if all videos are already downloaded with Pool(processes=args.threads) as pool: diff --git a/process/threads.py b/process/threads.py index 9aaea37..fd59fbb 100644 --- a/process/threads.py +++ b/process/threads.py @@ -9,6 +9,7 @@ from threading import Thread import numpy as np from tqdm.auto import tqdm +from unidecode import unidecode import ydl.yt_dlp as ydl from process.funcs import setup_file_logger @@ -108,7 +109,8 @@ def download_video(args) -> dict: del video_n try: - base_path = os.path.splitext(yt_dlp.prepare_filename(video))[0] + base_path = os.path.splitext(unidecode(yt_dlp.prepare_filename(video)))[0] + video['outtmpl'] = f"{kwargs['output_path']}/{ydl.get_output_templ(title=unidecode(video['title']), uploader=unidecode(video['uploader']))}" # clean the filename except AttributeError: # 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'] diff --git a/requirements.txt b/requirements.txt index 3775d92..27449ed 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,4 +5,5 @@ mergedeep numpy pyyaml appdirs -phantomjs \ No newline at end of file +phantomjs +unidecode \ No newline at end of file diff --git a/ydl/yt_dlp.py b/ydl/yt_dlp.py index fef17a3..30b7c67 100644 --- a/ydl/yt_dlp.py +++ b/ydl/yt_dlp.py @@ -116,3 +116,7 @@ class ytdl_no_logger(object): def error(self, msg): return + + +def get_output_templ(title: str = None, uploader: str = None): + return f'[%(id)s] [{title if title else "%(title)s"}] [{uploader if uploader else "%(uploader)s"}] [%(uploader_id)s].%(ext)s' # leading dash can cause issues due to bash args so we surround the variables in brackets