better file handling
This commit is contained in:
parent
50924c5552
commit
9912683db4
|
@ -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.funcs import get_silent_logger, remove_duplicates_from_playlist, restart_program, setup_file_logger
|
||||||
from process.threads import bar_eraser, download_video
|
from process.threads import bar_eraser, download_video
|
||||||
from ydl.files import create_directories, resolve_path
|
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):
|
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
|
# 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
|
# 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 = {
|
ydl_opts = {
|
||||||
# TODO: https://github.com/TheFrenchGhosty/TheFrenchGhostys-Ultimate-YouTube-DL-Scripts-Collection/blob/master/docs/Details.md
|
# 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/
|
# 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_bar.update(len(downloaded_videos))
|
||||||
|
|
||||||
playlist_ydl_opts = ydl_opts.copy()
|
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
|
if len(download_queue): # Don't mess with multiprocessing if all videos are already downloaded
|
||||||
with Pool(processes=args.threads) as pool:
|
with Pool(processes=args.threads) as pool:
|
||||||
|
|
|
@ -9,6 +9,7 @@ from threading import Thread
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from tqdm.auto import tqdm
|
from tqdm.auto import tqdm
|
||||||
|
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 setup_file_logger
|
||||||
|
@ -108,7 +109,8 @@ def download_video(args) -> dict:
|
||||||
del video_n
|
del video_n
|
||||||
|
|
||||||
try:
|
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:
|
except AttributeError:
|
||||||
# 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']
|
||||||
|
|
|
@ -5,4 +5,5 @@ mergedeep
|
||||||
numpy
|
numpy
|
||||||
pyyaml
|
pyyaml
|
||||||
appdirs
|
appdirs
|
||||||
phantomjs
|
phantomjs
|
||||||
|
unidecode
|
|
@ -116,3 +116,7 @@ class ytdl_no_logger(object):
|
||||||
|
|
||||||
def error(self, msg):
|
def error(self, msg):
|
||||||
return
|
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
|
||||||
|
|
Reference in New Issue