fix filename too long
This commit is contained in:
parent
caed0646b5
commit
8b0fbf4bf0
|
@ -1,6 +1,7 @@
|
||||||
import math
|
import math
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
import os
|
import os
|
||||||
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
import traceback
|
import traceback
|
||||||
|
@ -52,6 +53,9 @@ def is_manager_lock_locked(lock) -> bool:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
name_max = subprocess.check_output("getconf NAME_MAX /", shell=True)
|
||||||
|
|
||||||
|
|
||||||
def download_video(args) -> dict:
|
def download_video(args) -> dict:
|
||||||
# Sleep for a little bit to space out the rush of workers flooding the bar locks.
|
# Sleep for a little bit to space out the rush of workers flooding the bar locks.
|
||||||
# time.sleep(random.randint(1, 20) / 1000)
|
# time.sleep(random.randint(1, 20) / 1000)
|
||||||
|
@ -112,8 +116,15 @@ def download_video(args) -> dict:
|
||||||
# Clean the strings of forign languages
|
# Clean the strings of forign languages
|
||||||
video['title'] = unidecode(video['title'])
|
video['title'] = unidecode(video['title'])
|
||||||
video['uploader'] = unidecode(video['uploader'])
|
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)
|
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=['/'])
|
||||||
base_path = remove_special_chars_linux(str(Path(kwargs['output_dir'], video_filename)), 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"
|
kwargs['ydl_opts']['outtmpl'] = f"{base_path}.%(ext)s"
|
||||||
|
|
||||||
# try:
|
# try:
|
||||||
|
@ -121,7 +132,6 @@ def download_video(args) -> dict:
|
||||||
# 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']
|
||||||
|
|
||||||
ylogger = ytdl_logger(setup_file_logger(video['id'], base_path + '.log'))
|
ylogger = ytdl_logger(setup_file_logger(video['id'], base_path + '.log'))
|
||||||
kwargs['ydl_opts']['logger'] = ylogger
|
kwargs['ydl_opts']['logger'] = ylogger
|
||||||
yt_dlp = ydl.YDL(kwargs['ydl_opts']) # recreate the object with the correct logging path
|
yt_dlp = ydl.YDL(kwargs['ydl_opts']) # recreate the object with the correct logging path
|
||||||
|
|
|
@ -98,10 +98,25 @@ class YDL:
|
||||||
|
|
||||||
|
|
||||||
def update_ytdlp():
|
def update_ytdlp():
|
||||||
old = subprocess.check_output('pip freeze | grep yt-dlp', shell=True).decode().strip('\n')
|
package_name = 'yt-dlp'
|
||||||
subprocess.run('if pip list --outdated | grep -q yt-dlp; then pip install --upgrade yt-dlp; fi', shell=True)
|
# Get the current version of the package
|
||||||
new = subprocess.check_output('pip freeze | grep yt-dlp', shell=True).decode().strip('\n')
|
before_version = subprocess.check_output(['pip', 'show', package_name]).decode('utf-8')
|
||||||
return old != new
|
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):
|
class ytdl_no_logger(object):
|
||||||
|
|
Reference in New Issue