fix filename too long

This commit is contained in:
Cyberes 2023-05-06 15:30:34 -06:00
parent caed0646b5
commit 8b0fbf4bf0
2 changed files with 32 additions and 7 deletions

View File

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

View File

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