def format_fallback_replacement_summary(self, video_index: int): replacement_summaries = [] for replaced_format in self.store.formats_replaced_by_fallback[ video_index]: base_format = replaced_format["base"]["format"] base_definition = replaced_format["base"]["definition"] fallback_format = replaced_format["fallback"]["format"] fallback_definition = replaced_format["fallback"]["definition"] formatted_base = self.format_replaced_format( base_format, base_definition) formatted_fallback = self.format_replaced_format( fallback_format, fallback_definition) replacement_summaries.append( "Format " + colored(formatted_base, fore=Colors.fore.YELLOW, style=Colors.style.BRIGHT) + " is not available for this video. Falling back to " + colored(formatted_fallback, fore=Colors.fore.BLUE, style=Colors.style.BRIGHT) + "\n") formatted_replacement_summaries = [ Content.format_inner_text(summary_text, ContentCategories.WARNING) for summary_text in replacement_summaries ] return "\n".join(formatted_replacement_summaries)
def format_download_progress_bar(self, video_index: int): media_resource = self.store.downloading_media_resources[video_index] status_color = self.get_status_color(media_resource.download_status) bytes_downloaded = (media_resource.total_size - media_resource.get_total_bytes_remaining()) progress_percentage = bytes_downloaded / media_resource.total_size available_width = min(screen.get_console_width(), self.store.MAX_SCREEN_WIDTH) formatted_bytes_downloaded = self.format_data_size(bytes_downloaded) formatted_total_size = self.format_data_size(media_resource.total_size) progress_bar_right = colored( f" {progress_percentage * 100:.1f}% ", fore=status_color, style=Colors.style.BRIGHT, ) + colored( f"({formatted_bytes_downloaded} / " + f"{formatted_total_size})", style=Colors.style.DIM, ) max_progress_bar_right_width = len( f" 100.0% ({formatted_total_size} / {formatted_total_size})") available_space_for_loading_bar = (available_width - max_progress_bar_right_width - 2) loaded_section_length = floor(available_space_for_loading_bar * progress_percentage) not_loaded_section_length = (available_space_for_loading_bar - loaded_section_length) if global_config.ui_colors_disabled: loaded_section_character = "#" not_loaded_section_character = "-" wrapper_characters = { "left": "[", "right": "]", } else: loaded_section_character = "█" not_loaded_section_character = "█" wrapper_characters = { "left": "", "right": "", } progress_bar_left = (" " + wrapper_characters["left"] + colored( loaded_section_character * loaded_section_length, fore=status_color) + colored( not_loaded_section_character * not_loaded_section_length, style=Colors.style.DIM, ) + wrapper_characters["right"]) progress_bar = progress_bar_left + progress_bar_right return progress_bar
def _show_success_message(self): screen.append_content( colored("\nSuccess! ", fore=Colors.fore.GREEN) + "Files saved at " + colored( f"{self.store.output_path}/\n\n", fore=Colors.fore.CYAN, ) )
def format_batch_file_info_body(self, valid_video_urls_in_batch_file): number_of_valid_urls = len(valid_video_urls_in_batch_file) return ("Found " + colored( f"{number_of_valid_urls} ", fore=Colors.fore.CYAN, style=Colors.style.BRIGHT, ) + (colored("video URLs", fore=Colors.fore.CYAN) if number_of_valid_urls > 1 else colored("video URL", fore=Colors.fore.CYAN)) + ". Preparing to download...\n")
def __init__(self, batch_file): message = ("\nCould not find any valid video URLs in " + colored(batch_file, fore=Colors.fore.MAGENTA) + "\nPlease check your entries and try again.\n\n") category = ContentCategories.ERROR super().__init__(message, category)
def format_skipped_formats_warning(self, video_index: int): skipped_formats = self.store.skipped_formats[video_index] if len(skipped_formats) == 0: return "" formatted_skipped_formats = [ f'[{" ".join(skipped_format)}]' for skipped_format in self.store.skipped_formats[video_index] ] skipped_formats_message = ( ("Formats " if len(self.store.skipped_formats[video_index]) > 1 else "Format ") + colored( " ".join(formatted_skipped_formats), fore=Colors.fore.MAGENTA, style=Colors.style.BRIGHT, ) + (" were " if len(self.store.skipped_formats[video_index]) > 1 else " was ") + "not found. Skipping " + ("them" if len(self.store.skipped_formats[video_index]) > 1 else "it") + "...\n") skipped_formats_warning = Content.format_inner_text( skipped_formats_message, ContentCategories.WARNING, ) return skipped_formats_warning
def format_download_confirmation_prompt_message(self): download_confirmation_prompt = "\nConfirm download? " + colored( "(Y/n) ", fore=Colors.fore.CYAN, ) return download_confirmation_prompt
def __init__(self, available_formats): message = ("None of the specified formats were found.\n" + "Please, verify your entries and try again.\n\n" + "The formats available for this video are:\n" + colored(" (video) ", style=Colors.style.DIM + Colors.style.BRIGHT) + colored( " ".join(available_formats["video"]), fore=Colors.fore.BLUE, style=Colors.style.BRIGHT, ) + colored("\n (audio) ", style=Colors.style.DIM + Colors.style.BRIGHT) + colored( " ".join(available_formats["audio"]), fore=Colors.fore.BLUE, style=Colors.style.BRIGHT, ) + "\n\n") category = ContentCategories.ERROR super().__init__(message, category)
def format_download_progress_heading(self, video_index: int): media_resource = self.store.downloading_media_resources[video_index] status_character = self.get_next_status_character( video_index, media_resource.download_status) status_color = self.get_status_color(media_resource.download_status) label = media_resource.download_status.title() heading = ("\n" + colored( f"{status_character} {label} ", fore=status_color ) + colored( f"{self.format_video_title(video_index)} ", style=Colors.style.BRIGHT, ) + colored( f"{self.store.downloading_media_resources[video_index].formatted_definition}", fore=Colors.fore.BLUE, style=Colors.style.BRIGHT, )) return heading
def format_video_heading(self, video_index: int): formatted_video_length = self.format_video_length(video_index) remaining_number_of_characters = ( min(screen.get_console_width(), self.store.MAX_SCREEN_WIDTH) - len(formatted_video_length) - 4) formatted_video_title = self.format_video_title( video_index, remaining_number_of_characters) spaces_between_heading_components = " " * ( min(screen.get_console_width(), self.store.MAX_SCREEN_WIDTH) - len(formatted_video_title) - len(formatted_video_length) - 3) video_heading = ("\n" + colored(formatted_video_title, fore=Colors.fore.CYAN, style=Colors.style.BRIGHT) + spaces_between_heading_components + colored(f"({formatted_video_length})\n", style=Colors.style.BRIGHT)) return video_heading
def format_ready_to_download_label(self, video_index: int): formatted_title = limit_text_length( self.store.videos[video_index].title, 26) formatted_download_formats = self.format_download_formats() is_preceded_by_format_warnings = ( len(self.store.skipped_formats[video_index]) > 0 or len(self.store.formats_replaced_by_fallback[video_index]) > 0) prefix = "\n" if is_preceded_by_format_warnings else "" colored_formatted_title = colored( f"{formatted_title} ", fore=Colors.fore.CYAN, style=Colors.style.BRIGHT, ) colored_formatted_download_formats = colored( f"{formatted_download_formats}\n", fore=Colors.fore.BLUE, style=Colors.style.BRIGHT, ) return (prefix + "Ready to download " + colored_formatted_title + colored_formatted_download_formats)
def __init__(self, args=sys.argv, parse_and_update_global_config=True): self.arguments = args[1:] self.unique_arguments = set(self.arguments) self.parsed_arguments = None self.parser = Parser(formatter_class=RawDescriptionHelpFormatter, add_help=False) self.parser.add_global_arguments() self.global_arguments = self.parser.parse_known_args()[0] if parse_and_update_global_config: update_global_config_based_on_arguments(self.global_arguments) self.parser.description = (colored(f"{name.lower()} v{version}\n", style=Colors.style.BRIGHT) + description)
def format_total_download_size_label(self, video_index: int): media_resource = self.store.media_resources_to_download[video_index] if media_resource is None: return "" total_download_size = media_resource.total_size formatted_download_size = self.format_data_size(total_download_size) total_download_size_label = Content.format_inner_text( "Total download size: " + colored(f"{formatted_download_size}\n", fore=Colors.fore.YELLOW), ContentCategories.INFO, ) return total_download_size_label
def __init__(self, supposed_file): message = ("\nNo such file: " + colored(supposed_file, fore=Colors.fore.MAGENTA) + "\n\n") category = ContentCategories.ERROR super().__init__(message, category)
def format_batch_file_info_header(self, batch_filename: str): return ("\nReading URLs from " + colored( batch_filename, fore=Colors.fore.CYAN, style=Colors.style.BRIGHT) + "...\n")
def format_header(self): header = colored(f"{name.lower()} v{version}\n", style=Colors.style.BRIGHT) return header