diff --git a/downloader.py b/downloader.py index f97d291..3cb785b 100755 --- a/downloader.py +++ b/downloader.py @@ -115,11 +115,15 @@ def load_input_file(): sys.exit(1) del input_file # release file object # Verify each line in the file is a valid URL. + # Also resolve the paths + resolved_paths = {} for directory, urls in url_list.items(): for item in urls: if not re.match(url_regex, str(item)): print(f'Not a url:', item) sys.exit(1) + resolved_paths[resolve_path(directory)] = urls + url_list = resolved_paths else: if not args.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(): if not args.no_update: - print('Checking if yt-dlp needs to be updated...') + print('Updating yt-dlp...') updated = update_ytdlp() if updated: print('Restarting program...') @@ -321,7 +325,7 @@ if not args.daemon: already_erased_downloaded_tracker = False 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}') for output_path, urls in url_list.items(): for target_url in urls: diff --git a/process/threads.py b/process/threads.py index a835318..151c70b 100644 --- a/process/threads.py +++ b/process/threads.py @@ -22,6 +22,9 @@ class ytdl_logger(object): def __init__(self, logger=None): self.logger = logger + # logging.basicConfig(level=logging.DEBUG) + # self.logger = logging + # self.logger.info('testlog') def debug(self, msg): if self.logger: @@ -53,7 +56,7 @@ def is_manager_lock_locked(lock) -> bool: 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: @@ -76,6 +79,11 @@ def download_video(args) -> dict: video = args[0] 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 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 del video_n - # Clean the strings of forign languages + # We created a new dict video['title'] = unidecode(video['title']) 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=['/']) - # 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}' + # Make sure the video title isn't too long + while len(video_filename) >= name_max - 3: # -3 so that I can add ... + video['title'] = video['title'][:-1] + 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)) diff --git a/ydl/yt_dlp.py b/ydl/yt_dlp.py index 877d135..28e7546 100644 --- a/ydl/yt_dlp.py +++ b/ydl/yt_dlp.py @@ -99,23 +99,24 @@ class YDL: def update_ytdlp(): 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] + try: + result = subprocess.run( + ["pip", "install", "--disable-pip-version-check", "--upgrade", package_name], + capture_output=True, + text=True, + check=True + ) - # Update the package - subprocess.call(['pip', 'install', '--upgrade', package_name]) + if f"Successfully installed {package_name}" in result.stdout: + # 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 - 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') + except subprocess.CalledProcessError as e: + print(f"An error occurred while updating {package_name}:") + print(e.output) return False