diff --git a/youtube_dl_gui/optionsframe.py b/youtube_dl_gui/optionsframe.py index 6686c66..9a062cb 100644 --- a/youtube_dl_gui/optionsframe.py +++ b/youtube_dl_gui/optionsframe.py @@ -24,7 +24,8 @@ from .utils import ( TwoWayOrderedDict as twodict, os_path_exists, get_icon_file, - read_formats + read_formats, + os_sep ) from .formats import ( @@ -369,11 +370,22 @@ class GeneralTab(TabPanel): def _on_template(self, event): """Event handler for the wx.EVT_MENU of the custom_format_menu menu items.""" label = self.custom_format_menu.GetLabelText(event.GetId()) - template = "-%({0})s".format(label.lower().replace(' ', '_')) + label = label.lower().replace(' ', '_') custom_format = self.filename_custom_format.GetValue() - custom_format += template - self.filename_custom_format.SetValue(custom_format) + + if label == "ext": + prefix = '.' + else: + prefix = '-' + + if not custom_format or custom_format[-1] == os_sep: + # If the custom format is empty or ends with path separator + # remove the prefix + prefix = '' + + template = "{0}%({1})s".format(prefix, label) + self.filename_custom_format.SetValue(custom_format + template) def _on_format(self, event): """Event handler for the wx.EVT_BUTTON of the filename_custom_format_button.""" diff --git a/youtube_dl_gui/utils.py b/youtube_dl_gui/utils.py index 5884ec3..2a92e61 100644 --- a/youtube_dl_gui/utils.py +++ b/youtube_dl_gui/utils.py @@ -99,6 +99,7 @@ def convert_on_bounds(func): # See: https://github.com/MrS0m30n3/youtube-dl-gui/issues/57 # Patch os functions to convert between 'str' and 'unicode' on app bounds +os_sep = unicode(os.sep) os_getenv = convert_on_bounds(os.getenv) os_makedirs = convert_on_bounds(os.makedirs) os_path_isdir = convert_on_bounds(os.path.isdir)