Browse Source

Add support for the new output formats

doc-issue-template
MrS0m30n3 8 years ago
parent
commit
a8c8436cdc
4 changed files with 29 additions and 26 deletions
  1. 11
      youtube_dl_gui/formats.py
  2. 17
      youtube_dl_gui/optionsframe.py
  3. 13
      youtube_dl_gui/optionsmanager.py
  4. 14
      youtube_dl_gui/parsers.py

11
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")
])

17
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

13
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

14
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.

Loading…
Cancel
Save