From a8c8436cdc07e0d322e5c78ac6f6e187a516ce05 Mon Sep 17 00:00:00 2001 From: MrS0m30n3 Date: Sat, 15 Oct 2016 12:38:13 +0300 Subject: [PATCH] Add support for the new output formats --- youtube_dl_gui/formats.py | 11 +++++++++++ youtube_dl_gui/optionsframe.py | 17 +++++------------ youtube_dl_gui/optionsmanager.py | 13 +++++-------- youtube_dl_gui/parsers.py | 14 ++++++++------ 4 files changed, 29 insertions(+), 26 deletions(-) create mode 100644 youtube_dl_gui/formats.py diff --git a/youtube_dl_gui/formats.py b/youtube_dl_gui/formats.py new file mode 100644 index 0000000..9cb4ba9 --- /dev/null +++ b/youtube_dl_gui/formats.py @@ -0,0 +1,11 @@ +# -*- coding: UTF-8 -*- + +from .utils import TwoWayOrderedDict as tdict + + +OUTPUT_FORMATS = tdict([ + (0, "ID"), + (1, "Title"), + (2, "Title + ID"), + (3, "Custom") +]) diff --git a/youtube_dl_gui/optionsframe.py b/youtube_dl_gui/optionsframe.py index 287638e..6422e7a 100644 --- a/youtube_dl_gui/optionsframe.py +++ b/youtube_dl_gui/optionsframe.py @@ -26,6 +26,8 @@ from .utils import ( get_icon_file, read_formats ) + +from .formats import OUTPUT_FORMATS #TODO Bind events #TODO Adjust layout #TODO Set frame's min size @@ -251,15 +253,6 @@ class GeneralTab(TabPanel): ('tr_TR', 'Turkish') ]) - # TODO Add support on parsers.py - OUTPUT_FORMATS = [ - "Title", - "Title + Quality", - "Title + ID", - "Title + ID + Quality", - "Custom" - ] - def __init__(self, *args, **kwargs): super(GeneralTab, self).__init__(*args, **kwargs) @@ -267,7 +260,7 @@ class GeneralTab(TabPanel): self.language_combobox = self.crt_combobox(self.LOCALE_NAMES.values()) self.filename_format_label = self.crt_statictext("Filename format") - self.filename_format_combobox = self.crt_combobox(self.OUTPUT_FORMATS) + self.filename_format_combobox = self.crt_combobox(OUTPUT_FORMATS.values()) self.filename_custom_format = self.crt_textctrl() self.filename_opts_label = self.crt_statictext("Filename options") @@ -310,7 +303,7 @@ class GeneralTab(TabPanel): def load_options(self): self.language_combobox.SetValue(self.LOCALE_NAMES[self.opt_manager.options["locale_name"]]) - #TODO Add filename_format_combobox + self.filename_format_combobox.SetValue(OUTPUT_FORMATS[self.opt_manager.options["output_format"]]) self.filename_custom_format.SetValue(self.opt_manager.options["output_template"]) self.filename_ascii_checkbox.SetValue(self.opt_manager.options["restrict_filenames"]) #TODO Add confirm_exit_checkbox @@ -319,7 +312,7 @@ class GeneralTab(TabPanel): def save_options(self): self.opt_manager.options["locale_name"] = self.LOCALE_NAMES[self.language_combobox.GetValue()] - #TODO Add filename_format_combobox + self.opt_manager.options["output_format"] = OUTPUT_FORMATS[self.filename_format_combobox.GetValue()] self.opt_manager.options["output_template"] = self.filename_custom_format.GetValue() self.opt_manager.options["restrict_filenames"] = self.filename_ascii_checkbox.GetValue() #TODO Add confirm_exit_checkbox diff --git a/youtube_dl_gui/optionsmanager.py b/youtube_dl_gui/optionsmanager.py index 4fe410d..87a49a2 100644 --- a/youtube_dl_gui/optionsmanager.py +++ b/youtube_dl_gui/optionsmanager.py @@ -88,11 +88,7 @@ class OptionsManager(object): the downloaded file filename to ASCII characters only. output_format (string): This option sets the downloaded file - output template. Available values are 'id', 'title', 'custom' - - 'id' -> '%(id)s.%(ext)s' - 'title' -> '%(title)s.%(ext)s' - 'custom' -> Use 'output_template' as output template. + output template. See formats.OUTPUT_FORMATS for more info. output_template (string): Can be any output template supported by youtube-dl. @@ -201,6 +197,7 @@ class OptionsManager(object): save_path_dirs (list): List that contains temporary save paths. """ + #TODO Remove old options self.options = { 'save_path': os_path_expanduser('~'), 'save_path_dirs': [], @@ -211,8 +208,8 @@ class OptionsManager(object): 'audio_format': 'mp3', 'audio_quality': '5', 'restrict_filenames': False, - 'output_format': 'title', - 'output_template': '%(uploader)s/%(title)s.%(ext)s', + 'output_format': 1, + 'output_template': '%(uploader)s/%(title)s.%(ext)s', #TODO Fix path on Windows 'playlist_start': 1, 'playlist_end': 0, 'max_downloads': 0, @@ -319,7 +316,7 @@ class OptionsManager(object): 'second_video_format': VALID_VIDEO_FORMAT, 'audio_format': VALID_AUDIO_FORMAT, 'audio_quality': VALID_AUDIO_QUALITY, - 'output_format': VALID_OUTPUT_FORMAT, + #'output_format': VALID_OUTPUT_FORMAT, #TODO validate 'min_filesize_unit': VALID_FILESIZE_UNIT, 'max_filesize_unit': VALID_FILESIZE_UNIT, 'subs_lang': VALID_SUB_LANGUAGE diff --git a/youtube_dl_gui/parsers.py b/youtube_dl_gui/parsers.py index d22fc7c..84a1589 100644 --- a/youtube_dl_gui/parsers.py +++ b/youtube_dl_gui/parsers.py @@ -155,14 +155,16 @@ class OptionsParser(object): """ save_path = remove_shortcuts(options_dict['save_path']) - if options_dict['output_format'] == 'id': - save_path = os.path.join(save_path, '%(id)s.%(ext)s') - elif options_dict['output_format'] == 'title': - save_path = os.path.join(save_path, '%(title)s.%(ext)s') + if options_dict["output_format"] == 0: + template = "%(id)s.%(ext)s" + elif options_dict["output_format"] == 1: + template = "%(title)s.%(ext)s" + elif options_dict["output_format"] == 2: + template = "%(title)s-%(id)s.%(ext)s" else: - save_path = os.path.join(save_path, options_dict['output_template']) + template = options_dict["output_template"] - options_dict['save_path'] = save_path + options_dict["save_path"] = os.path.join(save_path, template) def _build_videoformat(self, options_dict): """Build the video format.