better file handling

This commit is contained in:
Cyberes 2023-02-07 19:45:11 -07:00
parent 50924c5552
commit 9912683db4
4 changed files with 11 additions and 5 deletions

View File

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

View File

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

View File

@ -5,4 +5,5 @@ mergedeep
numpy
pyyaml
appdirs
phantomjs
phantomjs
unidecode

View File

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