limit filename length, disable yt-dlp updating, resolve config paths
This commit is contained in:
parent
8b0fbf4bf0
commit
b84710b222
|
@ -115,11 +115,15 @@ def load_input_file():
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
del input_file # release file object
|
del input_file # release file object
|
||||||
# Verify each line in the file is a valid URL.
|
# Verify each line in the file is a valid URL.
|
||||||
|
# Also resolve the paths
|
||||||
|
resolved_paths = {}
|
||||||
for directory, urls in url_list.items():
|
for directory, urls in url_list.items():
|
||||||
for item in urls:
|
for item in urls:
|
||||||
if not re.match(url_regex, str(item)):
|
if not re.match(url_regex, str(item)):
|
||||||
print(f'Not a url:', item)
|
print(f'Not a url:', item)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
resolved_paths[resolve_path(directory)] = urls
|
||||||
|
url_list = resolved_paths
|
||||||
else:
|
else:
|
||||||
if not args.output:
|
if not args.output:
|
||||||
args.output = resolve_path(Path(os.getcwd(), 'automated-youtube-dl_output'))
|
args.output = resolve_path(Path(os.getcwd(), 'automated-youtube-dl_output'))
|
||||||
|
@ -137,7 +141,7 @@ create_directories(*url_list.keys(), args.download_cache_file_directory)
|
||||||
|
|
||||||
def do_update():
|
def do_update():
|
||||||
if not args.no_update:
|
if not args.no_update:
|
||||||
print('Checking if yt-dlp needs to be updated...')
|
print('Updating yt-dlp...')
|
||||||
updated = update_ytdlp()
|
updated = update_ytdlp()
|
||||||
if updated:
|
if updated:
|
||||||
print('Restarting program...')
|
print('Restarting program...')
|
||||||
|
@ -321,7 +325,7 @@ if not args.daemon:
|
||||||
already_erased_downloaded_tracker = False
|
already_erased_downloaded_tracker = False
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
do_update()
|
# do_update() # this doesn't work very well. freezes
|
||||||
progress_bar = tqdm(total=url_count, position=0, desc='Inputs', disable=args.daemon, bar_format='{l_bar}{bar}| {n_fmt}/{total_fmt}')
|
progress_bar = tqdm(total=url_count, position=0, desc='Inputs', disable=args.daemon, bar_format='{l_bar}{bar}| {n_fmt}/{total_fmt}')
|
||||||
for output_path, urls in url_list.items():
|
for output_path, urls in url_list.items():
|
||||||
for target_url in urls:
|
for target_url in urls:
|
||||||
|
|
|
@ -22,6 +22,9 @@ class ytdl_logger(object):
|
||||||
|
|
||||||
def __init__(self, logger=None):
|
def __init__(self, logger=None):
|
||||||
self.logger = logger
|
self.logger = logger
|
||||||
|
# logging.basicConfig(level=logging.DEBUG)
|
||||||
|
# self.logger = logging
|
||||||
|
# self.logger.info('testlog')
|
||||||
|
|
||||||
def debug(self, msg):
|
def debug(self, msg):
|
||||||
if self.logger:
|
if self.logger:
|
||||||
|
@ -53,7 +56,7 @@ def is_manager_lock_locked(lock) -> bool:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
name_max = subprocess.check_output("getconf NAME_MAX /", shell=True)
|
name_max = int(subprocess.check_output("getconf NAME_MAX /", shell=True).decode()) - 30
|
||||||
|
|
||||||
|
|
||||||
def download_video(args) -> dict:
|
def download_video(args) -> dict:
|
||||||
|
@ -76,6 +79,11 @@ def download_video(args) -> dict:
|
||||||
|
|
||||||
video = args[0]
|
video = args[0]
|
||||||
kwargs = args[1]
|
kwargs = args[1]
|
||||||
|
|
||||||
|
# Clean the strings of forign languages
|
||||||
|
video['title'] = unidecode(video['title'])
|
||||||
|
video['uploader'] = unidecode(video['uploader'])
|
||||||
|
|
||||||
output_dict = {'downloaded_video_id': None, 'video_id': video['id'], 'video_critical_err_msg': [], 'video_critical_err_msg_short': [], 'status_msg': [], 'logger_msg': []} # empty object
|
output_dict = {'downloaded_video_id': None, 'video_id': video['id'], 'video_critical_err_msg': [], 'video_critical_err_msg_short': [], 'status_msg': [], 'logger_msg': []} # empty object
|
||||||
|
|
||||||
if not kwargs['ignore_downloaded'] and not video['channel_id'] or not video['channel'] or not video['channel_url']:
|
if not kwargs['ignore_downloaded'] and not video['channel_id'] or not video['channel'] or not video['channel_url']:
|
||||||
|
@ -113,15 +121,23 @@ def download_video(args) -> dict:
|
||||||
video = video_n
|
video = video_n
|
||||||
del video_n
|
del video_n
|
||||||
|
|
||||||
# Clean the strings of forign languages
|
# We created a new dict
|
||||||
video['title'] = unidecode(video['title'])
|
video['title'] = unidecode(video['title'])
|
||||||
video['uploader'] = unidecode(video['uploader'])
|
video['uploader'] = unidecode(video['uploader'])
|
||||||
|
|
||||||
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=['/'])
|
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
|
# Make sure the video title isn't too long
|
||||||
while len(video_filename) > name_max:
|
while len(video_filename) >= name_max - 3: # -3 so that I can add ...
|
||||||
x = Path(video_filename)
|
video['title'] = video['title'][:-1]
|
||||||
video_filename = f'{str(x.stem)[:-1]}{x.suffix}'
|
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 = str(Path(kwargs['output_dir'], video_filename))
|
base_path = str(Path(kwargs['output_dir'], video_filename))
|
||||||
|
|
||||||
|
|
|
@ -99,23 +99,24 @@ class YDL:
|
||||||
|
|
||||||
def update_ytdlp():
|
def update_ytdlp():
|
||||||
package_name = 'yt-dlp'
|
package_name = 'yt-dlp'
|
||||||
# Get the current version of the package
|
try:
|
||||||
before_version = subprocess.check_output(['pip', 'show', package_name]).decode('utf-8')
|
result = subprocess.run(
|
||||||
before_version = before_version.split('\n')[1].split(': ')[1]
|
["pip", "install", "--disable-pip-version-check", "--upgrade", package_name],
|
||||||
|
capture_output=True,
|
||||||
|
text=True,
|
||||||
|
check=True
|
||||||
|
)
|
||||||
|
|
||||||
# Update the package
|
if f"Successfully installed {package_name}" in result.stdout:
|
||||||
subprocess.call(['pip', 'install', '--upgrade', package_name])
|
# print(f"{package_name} was updated.")
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
# print(f"{package_name} was not updated.")
|
||||||
|
return False
|
||||||
|
|
||||||
# Get the new version of the package
|
except subprocess.CalledProcessError as e:
|
||||||
after_version = subprocess.check_output(['pip', 'show', package_name]).decode('utf-8')
|
print(f"An error occurred while updating {package_name}:")
|
||||||
after_version = after_version.split('\n')[1].split(': ')[1]
|
print(e.output)
|
||||||
|
|
||||||
# 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
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
|
Reference in New Issue