From 8b0fbf4bf078e7c4fbde55f50f472ac8301864bb Mon Sep 17 00:00:00 2001 From: Cyberes Date: Sat, 6 May 2023 15:30:34 -0600 Subject: [PATCH] fix filename too long --- process/threads.py | 16 +++++++++++++--- ydl/yt_dlp.py | 23 +++++++++++++++++++---- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/process/threads.py b/process/threads.py index 56ad0e6..a835318 100644 --- a/process/threads.py +++ b/process/threads.py @@ -1,6 +1,7 @@ import math import multiprocessing import os +import subprocess import sys import time import traceback @@ -52,6 +53,9 @@ def is_manager_lock_locked(lock) -> bool: return False +name_max = subprocess.check_output("getconf NAME_MAX /", shell=True) + + def download_video(args) -> dict: # Sleep for a little bit to space out the rush of workers flooding the bar locks. # time.sleep(random.randint(1, 20) / 1000) @@ -112,8 +116,15 @@ def download_video(args) -> dict: # Clean the strings of forign languages video['title'] = unidecode(video['title']) video['uploader'] = unidecode(video['uploader']) - video_filename = ydl.get_output_templ(video_id=video['id'], title=video['title'], uploader=video['uploader'], uploader_id=video['uploader_id'], include_ext=False) - base_path = remove_special_chars_linux(str(Path(kwargs['output_dir'], video_filename)), special_chars=['/']) + video_filename = remove_special_chars_linux(ydl.get_output_templ(video_id=video['id'], title=video['title'], uploader=video['uploader'], uploader_id=video['uploader_id'], include_ext=False), special_chars=['/']) + + # Make sure the filename isn't too long + while len(video_filename) > name_max: + x = Path(video_filename) + video_filename = f'{str(x.stem)[:-1]}{x.suffix}' + + base_path = str(Path(kwargs['output_dir'], video_filename)) + kwargs['ydl_opts']['outtmpl'] = f"{base_path}.%(ext)s" # try: @@ -121,7 +132,6 @@ def download_video(args) -> dict: # 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'] - ylogger = ytdl_logger(setup_file_logger(video['id'], base_path + '.log')) kwargs['ydl_opts']['logger'] = ylogger yt_dlp = ydl.YDL(kwargs['ydl_opts']) # recreate the object with the correct logging path diff --git a/ydl/yt_dlp.py b/ydl/yt_dlp.py index 58f528e..877d135 100644 --- a/ydl/yt_dlp.py +++ b/ydl/yt_dlp.py @@ -98,10 +98,25 @@ class YDL: def update_ytdlp(): - old = subprocess.check_output('pip freeze | grep yt-dlp', shell=True).decode().strip('\n') - subprocess.run('if pip list --outdated | grep -q yt-dlp; then pip install --upgrade yt-dlp; fi', shell=True) - new = subprocess.check_output('pip freeze | grep yt-dlp', shell=True).decode().strip('\n') - return old != new + package_name = 'yt-dlp' + # Get the current version of the package + before_version = subprocess.check_output(['pip', 'show', package_name]).decode('utf-8') + before_version = before_version.split('\n')[1].split(': ')[1] + + # Update the package + subprocess.call(['pip', 'install', '--upgrade', package_name]) + + # Get the new version of the package + after_version = subprocess.check_output(['pip', 'show', package_name]).decode('utf-8') + after_version = after_version.split('\n')[1].split(': ')[1] + + # Check if the package was updated + if before_version != after_version: + # print(f'{package_name} was updated from version {before_version} to {after_version}') + return True + else: + # print(f'{package_name} is already up to date') + return False class ytdl_no_logger(object):