Browse Source

Change options

Store options in dictionary
  Write options to .json file
doc-issue-template
MrS0m30n3 10 years ago
parent
commit
0cb59fc217
3 changed files with 242 additions and 340 deletions
  1. 206
      youtube_dl_gui/OptionsHandler.py
  2. 266
      youtube_dl_gui/YoutubeDLGUI.py
  3. 110
      youtube_dl_gui/YoutubeDLInterpreter.py

206
youtube_dl_gui/OptionsHandler.py

@ -1,16 +1,16 @@
#! /usr/bin/env python #! /usr/bin/env python
from .version import __version__
import json
from .Utils import ( from .Utils import (
get_HOME, get_HOME,
file_exist, file_exist,
get_os_type, get_os_type,
fix_path, fix_path,
makedir,
abs_path
check_path
) )
SETTINGS_FILENAME = 'settings'
SETTINGS_FILENAME = 'settings.json'
LINUX_FILES_PATH = get_HOME() + '/.youtube-dl-gui' LINUX_FILES_PATH = get_HOME() + '/.youtube-dl-gui'
WINDOWS_FILES_PATH = get_HOME() + '\\youtube-dl-gui' WINDOWS_FILES_PATH = get_HOME() + '\\youtube-dl-gui'
@ -18,171 +18,73 @@ class OptionsHandler():
settings_abs_path = '' settings_abs_path = ''
def __init__(self, statusBarWrite):
self.statusBarWrite = statusBarWrite
def __init__(self):
self.set_settings_path() self.set_settings_path()
self.load_default()
self.load_settings() self.load_settings()
def load_settings(self): def load_settings(self):
if not file_exist(self.get_config_path()):
makedir(self.get_config_path())
self.load_default()
check_path(self.get_config_path())
if file_exist(self.settings_abs_path): if file_exist(self.settings_abs_path):
self.load_from_file() self.load_from_file()
def load_default(self): def load_default(self):
self.savePath = get_HOME()
self.videoFormat = "default"
self.dashAudioFormat = "NO SOUND"
self.clearDashFiles = False
self.toAudio = False
self.keepVideo = False
self.audioFormat = "mp3"
self.audioQuality = "mid"
self.outputFormat = "title"
self.outputTemplate = '%(uploader)s/%(title)s.%(ext)s'
self.startTrack = 1
self.endTrack = 0
self.maxDownloads = 0
self.minFileSize = "0"
self.maxFileSize = "0"
self.writeSubs = False
self.writeAllSubs = False
self.writeAutoSubs = False
self.embedSubs = False
self.subsLang = "English"
self.openDownloadDir = False
self.ignoreErrors = True
self.writeDescription = False
self.writeInfo = False
self.writeThumbnail = False
self.retries = 10
self.userAgent = ""
self.referer = ""
self.proxy = ""
self.username = ""
self.password = ""
self.videoPass = ""
self.updatePath = self.get_config_path()
self.cmdArgs = ""
self.enableLog = True
self.writeTimeToLog = True
self.options = {
'save_path': get_HOME(),
'video_format': 'default',
'dash_audio_format': 'NO SOUND',
'clear_dash_files': False,
'to_audio': False,
'keep_video': False,
'audio_format': 'mp3',
'audio_quality': 'mid',
'output_format': 'title',
'output_template': '%(uploader)s/%(title)s.%(ext)s',
'playlist_start': 1,
'playlist_end': 0,
'max_downloads': 0,
'min_filesize': '0',
'max_filesize': '0',
'write_subs': False,
'write_all_subs': False,
'write_auto_subs': False,
'embed_subs': False,
'subs_lang': 'English',
'open_dl_dir': False,
'ignore_errors': True,
'write_description': False,
'write_info': False,
'write_thumbnail': False,
'retries': 10,
'user_agent': '',
'referer': '',
'proxy': '',
'username': '',
'password': '',
'video_password': '',
'youtubedl_path': self.get_config_path(),
'cmd_args': '',
'enable_log': True,
'log_time': True
}
def get_config_path(self): def get_config_path(self):
if get_os_type() == 'nt': if get_os_type() == 'nt':
return WINDOWS_FILES_PATH return WINDOWS_FILES_PATH
else:
return LINUX_FILES_PATH
return LINUX_FILES_PATH
def set_settings_path(self): def set_settings_path(self):
self.settings_abs_path = self.get_config_path()
self.settings_abs_path = fix_path(self.settings_abs_path)
self.settings_abs_path += SETTINGS_FILENAME
def read_from_file(self):
f = open(self.settings_abs_path, 'r')
options = f.readlines()
f.close()
return options
def extract_options(self, options):
opts = []
for option in options:
opt = option.split('=')
if not len(opt) < 2:
opts.append(opt[1].rstrip('\n'))
return opts
def check_settings_file_version(self, options):
data = options.pop(0).rstrip('\n')
name, version = data.split('=')
if name == 'Version' and version == __version__:
return True
else:
return False
self.settings_abs_path = fix_path(self.get_config_path()) + SETTINGS_FILENAME
def load_from_file(self): def load_from_file(self):
options = self.read_from_file()
if self.check_settings_file_version(options):
opts = self.extract_options(options)
with open(self.settings_abs_path, 'rb') as f:
try: try:
self.savePath = opts[0].decode('utf8')
self.videoFormat = opts[1]
self.dashAudioFormat = opts[2]
self.clearDashFiles = opts[3] in ['True']
self.toAudio = opts[4] in ['True']
self.keepVideo = opts[5] in ['True']
self.audioFormat = opts[6]
self.audioQuality = opts[7]
self.outputFormat = opts[8]
self.outputTemplate = opts[9]
self.startTrack = int(opts[10])
self.endTrack = int(opts[11])
self.maxDownloads = int(opts[12])
self.minFileSize = opts[13]
self.maxFileSize = opts[14]
self.writeSubs = opts[15] in ['True']
self.writeAllSubs = opts[16] in ['True']
self.writeAutoSubs = opts[17] in ['True']
self.embedSubs = opts[18] in ['True']
self.subsLang = opts[19]
self.openDownloadDir = opts[20] in ['True']
self.ignoreErrors = opts[21] in ['True']
self.writeDescription = opts[22] in ['True']
self.writeInfo = opts[23] in ['True']
self.writeThumbnail = opts[24] in ['True']
self.retries = int(opts[25])
self.userAgent = opts[26]
self.referer = opts[27]
self.proxy = opts[28]
self.username = opts[29]
self.cmdArgs = opts[30]
self.enableLog = opts[31] in ['True']
self.writeTimeToLog = opts[32] in ['True']
self.options = json.load(f)
except: except:
self.statusBarWrite('Error while loading settings file. Loading default settings.')
self.load_default() self.load_default()
else:
self.statusBarWrite('Settings file version problem. Loading default settings.')
self.load_default()
def save_to_file(self): def save_to_file(self):
if not file_exist(self.get_config_path()):
makedir(self.get_config_path())
f = open(self.settings_abs_path, 'w')
f.write('Version='+__version__+'\n')
f.write('SavePath='+self.savePath.encode('utf-8')+'\n')
f.write('VideoFormat='+str(self.videoFormat)+'\n')
f.write('DashAudioFormat='+str(self.dashAudioFormat)+'\n')
f.write('ClearDashFiles='+str(self.clearDashFiles)+'\n')
f.write('ToAudio='+str(self.toAudio)+'\n')
f.write('KeepVideo='+str(self.keepVideo)+'\n')
f.write('AudioFormat='+str(self.audioFormat)+'\n')
f.write('AudioQuality='+str(self.audioQuality)+'\n')
f.write('OutputFormat='+str(self.outputFormat)+'\n')
f.write('OutputTemplate='+str(self.outputTemplate)+'\n')
f.write('StartTrack='+str(self.startTrack)+'\n')
f.write('EndTrack='+str(self.endTrack)+'\n')
f.write('MaxDownloads='+str(self.maxDownloads)+'\n')
f.write('MinFileSize='+str(self.minFileSize)+'\n')
f.write('MaxFileSize='+str(self.maxFileSize)+'\n')
f.write('WriteSubtitles='+str(self.writeSubs)+'\n')
f.write('WriteAllSubtitles='+str(self.writeAllSubs)+'\n')
f.write('WriteAutoSubtitles='+str(self.writeAutoSubs)+'\n')
f.write('EmbedSubs='+str(self.embedSubs)+'\n')
f.write('SubtitlesLanguage='+str(self.subsLang)+'\n')
f.write('OpenDownloadDirectory='+str(self.openDownloadDir)+'\n')
f.write('IgnoreErrors='+str(self.ignoreErrors)+'\n')
f.write('WriteDescription='+str(self.writeDescription)+'\n')
f.write('WriteInfo='+str(self.writeInfo)+'\n')
f.write('WriteThumbnail='+str(self.writeThumbnail)+'\n')
f.write('Retries='+str(self.retries)+'\n')
f.write('UserAgent='+str(self.userAgent)+'\n')
f.write('Referer='+str(self.referer)+'\n')
f.write('Proxy='+str(self.proxy)+'\n')
f.write('Username='+str(self.username)+'\n')
# We dont store password & videoPass for security reasons
f.write('CmdArgs='+str(self.cmdArgs)+'\n')
f.write('EnableLog='+str(self.enableLog)+'\n')
f.write('WriteTimeToLog='+str(self.writeTimeToLog)+'\n')
f.close()
check_path(self.get_config_path())
with open(self.settings_abs_path, 'wb') as f:
json.dump(self.options, f, indent=4, separators=(',', ': '))

266
youtube_dl_gui/YoutubeDLGUI.py

@ -90,15 +90,15 @@ class MainFrame(wx.Frame):
Publisher.subscribe(self.download_handler, "download") Publisher.subscribe(self.download_handler, "download")
# init Options and DownloadHandler objects # init Options and DownloadHandler objects
self.optionsList = OptionsHandler(self.status_bar_write)
self.optManager = OptionsHandler()
self.downloadHandler = None self.downloadHandler = None
# init log manager # init log manager
self.logManager = None self.logManager = None
if self.optionsList.enableLog:
if self.optManager.options['enable_log']:
self.logManager = LogManager( self.logManager = LogManager(
self.optionsList.get_config_path(),
self.optionsList.writeTimeToLog
self.optManager.get_config_path(),
self.optManager.options['log_time']
) )
# init some thread variables # init some thread variables
@ -143,14 +143,14 @@ class MainFrame(wx.Frame):
self.panel.SetSizer(mainBoxSizer) self.panel.SetSizer(mainBoxSizer)
def check_if_youtube_dl_exist(self): def check_if_youtube_dl_exist(self):
path = fix_path(self.optionsList.updatePath)+YOUTUBE_DL_FILENAME
path = fix_path(self.optManager.options['youtubedl_path'])+YOUTUBE_DL_FILENAME
if not file_exist(path): if not file_exist(path):
self.status_bar_write("Youtube-dl is missing, trying to download it...") self.status_bar_write("Youtube-dl is missing, trying to download it...")
self.update_youtube_dl() self.update_youtube_dl()
def update_youtube_dl(self): def update_youtube_dl(self):
self.downloadButton.Disable() self.downloadButton.Disable()
self.updateThread = UpdateThread(self.optionsList.updatePath, YOUTUBE_DL_FILENAME)
self.updateThread = UpdateThread(self.optManager.options['youtubedl_path'], YOUTUBE_DL_FILENAME)
def status_bar_write(self, msg): def status_bar_write(self, msg):
self.statusBar.SetLabel(msg) self.statusBar.SetLabel(msg)
@ -167,8 +167,8 @@ class MainFrame(wx.Frame):
self.open_destination_dir() self.open_destination_dir()
def open_destination_dir(self): def open_destination_dir(self):
if self.optionsList.openDownloadDir:
open_dir(self.optionsList.savePath)
if self.optManager.options['open_dl_dir']:
open_dir(self.optManager.options['save_path'])
def download_handler(self, msg): def download_handler(self, msg):
self.downloadHandler.handle(msg) self.downloadHandler.handle(msg)
@ -209,11 +209,11 @@ class MainFrame(wx.Frame):
self.check_if_youtube_dl_exist() self.check_if_youtube_dl_exist()
if self.updateThread is not None: if self.updateThread is not None:
self.updateThread.join() self.updateThread.join()
options = YoutubeDLInterpreter(self.optionsList, YOUTUBE_DL_FILENAME).get_options()
options = YoutubeDLInterpreter(self.optManager, YOUTUBE_DL_FILENAME).get_options()
self.downloadThread = DownloadManager( self.downloadThread = DownloadManager(
options, options,
self.statusList._get_items(), self.statusList._get_items(),
self.optionsList.clearDashFiles,
self.optManager.options['clear_dash_files'],
self.logManager self.logManager
) )
self.downloadHandler = DownloadHandler(self.statusList) self.downloadHandler = DownloadHandler(self.statusList)
@ -224,7 +224,7 @@ class MainFrame(wx.Frame):
self.no_url_popup() self.no_url_popup()
def save_options(self): def save_options(self):
self.optionsList.save_to_file()
self.optManager.save_to_file()
def finished_popup(self): def finished_popup(self):
wx.MessageBox('Downloads completed.', 'Info', wx.OK | wx.ICON_INFORMATION) wx.MessageBox('Downloads completed.', 'Info', wx.OK | wx.ICON_INFORMATION)
@ -264,7 +264,7 @@ class MainFrame(wx.Frame):
self.update_youtube_dl() self.update_youtube_dl()
def OnOptions(self, event): def OnOptions(self, event):
optionsFrame = OptionsFrame(self.optionsList, parent=self, logger=self.logManager)
optionsFrame = OptionsFrame(self.optManager, parent=self, logger=self.logManager)
optionsFrame.Show() optionsFrame.Show()
def OnClose(self, event): def OnClose(self, event):
@ -331,11 +331,11 @@ class LogPanel(wx.Panel):
path = '' path = ''
win_box_border = 0 win_box_border = 0
def __init__(self, parent, optList, log):
def __init__(self, parent, optManager, log):
wx.Panel.__init__(self, parent) wx.Panel.__init__(self, parent)
self.SetBoxBorder() self.SetBoxBorder()
self.optList = optList
self.optManager = optManager
self.log = log self.log = log
self.set_data() self.set_data()
mainBoxSizer = wx.BoxSizer(wx.VERTICAL) mainBoxSizer = wx.BoxSizer(wx.VERTICAL)
@ -357,7 +357,7 @@ class LogPanel(wx.Panel):
butBox.Add(self.viewLogButton, flag = wx.LEFT, border=20) butBox.Add(self.viewLogButton, flag = wx.LEFT, border=20)
mainBoxSizer.Add(butBox, flag = wx.ALIGN_CENTER_HORIZONTAL | wx.TOP, border=15) mainBoxSizer.Add(butBox, flag = wx.ALIGN_CENTER_HORIZONTAL | wx.TOP, border=15)
if self.optList.enableLog:
if self.optManager.options['enable_log']:
self.SetDataSizers(mainBoxSizer) self.SetDataSizers(mainBoxSizer)
self.SetSizer(mainBoxSizer) self.SetSizer(mainBoxSizer)
@ -408,27 +408,27 @@ class LogPanel(wx.Panel):
log_gui.Show() log_gui.Show()
def load_options(self): def load_options(self):
self.enableLogChk.SetValue(self.optList.enableLog)
self.enableTimeChk.SetValue(self.optList.writeTimeToLog)
if self.optList.enableLog == False:
self.enableLogChk.SetValue(self.optManager.options['enable_log'])
self.enableTimeChk.SetValue(self.optManager.options['log_time'])
if self.optManager.options['enable_log'] == False:
self.enableTimeChk.Disable() self.enableTimeChk.Disable()
if self.log == None: if self.log == None:
self.clearLogButton.Disable() self.clearLogButton.Disable()
self.viewLogButton.Disable() self.viewLogButton.Disable()
def save_options(self): def save_options(self):
self.optList.enableLog = self.enableLogChk.GetValue()
self.optList.writeTimeToLog = self.enableTimeChk.GetValue()
self.optManager.options['enable_log'] = self.enableLogChk.GetValue()
self.optManager.options['log_time'] = self.enableTimeChk.GetValue()
def restart_popup(self): def restart_popup(self):
wx.MessageBox('Please restart ' + __appname__, 'Restart', wx.OK | wx.ICON_INFORMATION) wx.MessageBox('Please restart ' + __appname__, 'Restart', wx.OK | wx.ICON_INFORMATION)
class PlaylistPanel(wx.Panel): class PlaylistPanel(wx.Panel):
def __init__(self, parent, optList):
def __init__(self, parent, optManager):
wx.Panel.__init__(self, parent) wx.Panel.__init__(self, parent)
self.optList = optList
self.optManager = optManager
mainBoxSizer = wx.StaticBoxSizer(wx.StaticBox(self, label='Playlist Options'), wx.VERTICAL) mainBoxSizer = wx.StaticBoxSizer(wx.StaticBox(self, label='Playlist Options'), wx.VERTICAL)
mainBoxSizer.Add((-1, 10)) mainBoxSizer.Add((-1, 10))
@ -462,21 +462,21 @@ class PlaylistPanel(wx.Panel):
return 10 return 10
def load_options(self): def load_options(self):
self.startSpnr.SetValue(self.optList.startTrack)
self.stopSpnr.SetValue(self.optList.endTrack)
self.maxSpnr.SetValue(self.optList.maxDownloads)
self.startSpnr.SetValue(self.optManager.options['playlist_start'])
self.stopSpnr.SetValue(self.optManager.options['playlist_end'])
self.maxSpnr.SetValue(self.optManager.options['max_downloads'])
def save_options(self): def save_options(self):
self.optList.startTrack = self.startSpnr.GetValue()
self.optList.endTrack = self.stopSpnr.GetValue()
self.optList.maxDownloads = self.maxSpnr.GetValue()
self.optManager.options['playlist_start'] = self.startSpnr.GetValue()
self.optManager.options['playlist_end'] = self.stopSpnr.GetValue()
self.optManager.options['max_downloads'] = self.maxSpnr.GetValue()
class ConnectionPanel(wx.Panel): class ConnectionPanel(wx.Panel):
def __init__(self, parent, optList):
def __init__(self, parent, optManager):
wx.Panel.__init__(self, parent) wx.Panel.__init__(self, parent)
self.optList = optList
self.optManager = optManager
mainBoxSizer = wx.BoxSizer(wx.VERTICAL) mainBoxSizer = wx.BoxSizer(wx.VERTICAL)
retBox = wx.BoxSizer(wx.HORIZONTAL) retBox = wx.BoxSizer(wx.HORIZONTAL)
@ -522,23 +522,23 @@ class ConnectionPanel(wx.Panel):
self.SetSizer(mainBoxSizer) self.SetSizer(mainBoxSizer)
def load_options(self): def load_options(self):
self.userAgentBox.SetValue(self.optList.userAgent)
self.refererBox.SetValue(self.optList.referer)
self.proxyBox.SetValue(self.optList.proxy)
self.retriesSpnr.SetValue(self.optList.retries)
self.userAgentBox.SetValue(self.optManager.options['user_agent'])
self.refererBox.SetValue(self.optManager.options['referer'])
self.proxyBox.SetValue(self.optManager.options['proxy'])
self.retriesSpnr.SetValue(self.optManager.options['retries'])
def save_options(self): def save_options(self):
self.optList.userAgent = self.userAgentBox.GetValue()
self.optList.referer = self.refererBox.GetValue()
self.optList.proxy = self.proxyBox.GetValue()
self.optList.retries = self.retriesSpnr.GetValue()
self.optManager.options['user_agent'] = self.userAgentBox.GetValue()
self.optManager.options['referer'] = self.refererBox.GetValue()
self.optManager.options['proxy'] = self.proxyBox.GetValue()
self.optManager.options['retries'] = self.retriesSpnr.GetValue()
class AuthenticationPanel(wx.Panel): class AuthenticationPanel(wx.Panel):
def __init__(self, parent, optList):
def __init__(self, parent, optManager):
wx.Panel.__init__(self,parent) wx.Panel.__init__(self,parent)
self.optList = optList
self.optManager = optManager
mainBoxSizer = wx.BoxSizer(wx.VERTICAL) mainBoxSizer = wx.BoxSizer(wx.VERTICAL)
usrTextBox = wx.BoxSizer(wx.HORIZONTAL) usrTextBox = wx.BoxSizer(wx.HORIZONTAL)
@ -571,25 +571,25 @@ class AuthenticationPanel(wx.Panel):
self.SetSizer(mainBoxSizer) self.SetSizer(mainBoxSizer)
def load_options(self): def load_options(self):
self.usernameBox.SetValue(self.optList.username)
self.passwordBox.SetValue(self.optList.password)
self.videopassBox.SetValue(self.optList.videoPass)
self.usernameBox.SetValue(self.optManager.options['username'])
self.passwordBox.SetValue(self.optManager.options['password'])
self.videopassBox.SetValue(self.optManager.options['video_password'])
def save_options(self): def save_options(self):
self.optList.username = self.usernameBox.GetValue()
self.optList.password = self.passwordBox.GetValue()
self.optList.videoPass = self.videopassBox.GetValue()
self.optManager.options['username'] = self.usernameBox.GetValue()
self.optManager.options['password'] = self.passwordBox.GetValue()
self.optManager.options['video_password'] = self.videopassBox.GetValue()
class AudioPanel(wx.Panel): class AudioPanel(wx.Panel):
win_box_border = 0 win_box_border = 0
quality = ['high', 'mid', 'low'] quality = ['high', 'mid', 'low']
def __init__(self, parent, optList):
def __init__(self, parent, optManager):
wx.Panel.__init__(self, parent) wx.Panel.__init__(self, parent)
self.SetBoxBorder() self.SetBoxBorder()
self.optList = optList
self.optManager = optManager
mainBoxSizer = wx.BoxSizer(wx.VERTICAL) mainBoxSizer = wx.BoxSizer(wx.VERTICAL)
toaBox = wx.BoxSizer(wx.HORIZONTAL) toaBox = wx.BoxSizer(wx.HORIZONTAL)
@ -640,27 +640,27 @@ class AudioPanel(wx.Panel):
self.audioQualityCombo.Disable() self.audioQualityCombo.Disable()
def load_options(self): def load_options(self):
self.toAudioChk.SetValue(self.optList.toAudio)
self.keepVideoChk.SetValue(self.optList.keepVideo)
self.audioFormatCombo.SetValue(self.optList.audioFormat)
self.audioQualityCombo.SetValue(self.optList.audioQuality)
if self.optList.toAudio == False:
self.toAudioChk.SetValue(self.optManager.options['to_audio'])
self.keepVideoChk.SetValue(self.optManager.options['keep_video'])
self.audioFormatCombo.SetValue(self.optManager.options['audio_format'])
self.audioQualityCombo.SetValue(self.optManager.options['audio_quality'])
if self.optManager.options['to_audio'] == False:
self.keepVideoChk.Disable() self.keepVideoChk.Disable()
self.audioFormatCombo.Disable() self.audioFormatCombo.Disable()
self.audioQualityCombo.Disable() self.audioQualityCombo.Disable()
def save_options(self): def save_options(self):
self.optList.toAudio = self.toAudioChk.GetValue()
self.optList.keepVideo = self.keepVideoChk.GetValue()
self.optList.audioFormat = self.audioFormatCombo.GetValue()
self.optList.audioQuality = self.audioQualityCombo.GetValue()
self.optManager.options['to_audio'] = self.toAudioChk.GetValue()
self.optManager.options['keep_video'] = self.keepVideoChk.GetValue()
self.optManager.options['audio_format'] = self.audioFormatCombo.GetValue()
self.optManager.options['audio_quality'] = self.audioQualityCombo.GetValue()
class VideoPanel(wx.Panel): class VideoPanel(wx.Panel):
def __init__(self, parent, optList):
def __init__(self, parent, optManager):
wx.Panel.__init__(self, parent) wx.Panel.__init__(self, parent)
self.optList = optList
self.optManager = optManager
mainBoxSizer = wx.BoxSizer(wx.VERTICAL) mainBoxSizer = wx.BoxSizer(wx.VERTICAL)
vfTextBox = wx.BoxSizer(wx.HORIZONTAL) vfTextBox = wx.BoxSizer(wx.HORIZONTAL)
@ -709,29 +709,29 @@ class VideoPanel(wx.Panel):
self.dashAudioFormatCombo.Disable() self.dashAudioFormatCombo.Disable()
def load_options(self): def load_options(self):
self.videoFormatCombo.SetValue(self.optList.videoFormat)
self.dashAudioFormatCombo.SetValue(self.optList.dashAudioFormat)
self.clearDashFilesChk.SetValue(self.optList.clearDashFiles)
if not video_is_dash(self.optList.videoFormat):
self.videoFormatCombo.SetValue(self.optManager.options['video_format'])
self.dashAudioFormatCombo.SetValue(self.optManager.options['dash_audio_format'])
self.clearDashFilesChk.SetValue(self.optManager.options['clear_dash_files'])
if not video_is_dash(self.optManager.options['video_format']):
self.dashAudioFormatCombo.Disable() self.dashAudioFormatCombo.Disable()
if not have_dash_audio(self.optList.dashAudioFormat):
if not have_dash_audio(self.optManager.options['dash_audio_format']):
self.clearDashFilesChk.SetValue(False) self.clearDashFilesChk.SetValue(False)
self.clearDashFilesChk.Disable() self.clearDashFilesChk.Disable()
def save_options(self): def save_options(self):
self.optList.videoFormat = self.videoFormatCombo.GetValue()
self.optList.dashAudioFormat = self.dashAudioFormatCombo.GetValue()
self.optList.clearDashFiles = self.clearDashFilesChk.GetValue()
self.optManager.options['video_format'] = self.videoFormatCombo.GetValue()
self.optManager.options['dash_audio_format'] = self.dashAudioFormatCombo.GetValue()
self.optManager.options['clear_dash_files'] = self.clearDashFilesChk.GetValue()
class OutputPanel(wx.Panel): class OutputPanel(wx.Panel):
win_box_border = 0 win_box_border = 0
def __init__(self, parent, optList):
def __init__(self, parent, optManager):
wx.Panel.__init__(self, parent) wx.Panel.__init__(self, parent)
self.SetBoxBorder() self.SetBoxBorder()
self.optList = optList
self.optManager = optManager
mainBoxSizer = wx.BoxSizer(wx.VERTICAL) mainBoxSizer = wx.BoxSizer(wx.VERTICAL)
idBox = wx.BoxSizer(wx.HORIZONTAL) idBox = wx.BoxSizer(wx.HORIZONTAL)
@ -802,22 +802,22 @@ class OutputPanel(wx.Panel):
return 'custom' return 'custom'
def load_options(self): def load_options(self):
self.group_load(self.optList.outputFormat)
self.customTitleBox.SetValue(self.optList.outputTemplate)
self.group_load(self.optManager.options['output_format'])
self.customTitleBox.SetValue(self.optManager.options['output_template'])
def save_options(self): def save_options(self):
self.optList.outputTemplate = self.customTitleBox.GetValue()
self.optList.outputFormat = self.get_output_format()
self.optManager.options['output_template'] = self.customTitleBox.GetValue()
self.optManager.options['output_format'] = self.get_output_format()
class FilesystemPanel(wx.Panel): class FilesystemPanel(wx.Panel):
win_box_border = 0 win_box_border = 0
def __init__(self, parent, optList):
def __init__(self, parent, optManager):
wx.Panel.__init__(self, parent) wx.Panel.__init__(self, parent)
self.SetBoxBorder() self.SetBoxBorder()
self.optList = optList
self.optManager = optManager
mainBoxSizer = wx.BoxSizer(wx.HORIZONTAL) mainBoxSizer = wx.BoxSizer(wx.HORIZONTAL)
leftBoxSizer = wx.BoxSizer(wx.VERTICAL) leftBoxSizer = wx.BoxSizer(wx.VERTICAL)
rightBoxSizer = wx.StaticBoxSizer(wx.StaticBox(self, label='Filesize (e.g. 50k or 44.6m)'), wx.VERTICAL) rightBoxSizer = wx.StaticBoxSizer(wx.StaticBox(self, label='Filesize (e.g. 50k or 44.6m)'), wx.VERTICAL)
@ -875,41 +875,41 @@ class FilesystemPanel(wx.Panel):
box.Add(maxBox, flag = wx.TOP | wx.ALIGN_CENTER_HORIZONTAL, border=10) box.Add(maxBox, flag = wx.TOP | wx.ALIGN_CENTER_HORIZONTAL, border=10)
def load_options(self): def load_options(self):
self.writeDescriptionChk.SetValue(self.optList.writeDescription)
self.writeInfoChk.SetValue(self.optList.writeInfo)
self.writeThumbnailChk.SetValue(self.optList.writeThumbnail)
self.ignoreErrorsChk.SetValue(self.optList.ignoreErrors)
self.openDirChk.SetValue(self.optList.openDownloadDir)
self.minFilesizeBox.SetValue(self.optList.minFileSize)
self.maxFilesizeBox.SetValue(self.optList.maxFileSize)
self.writeDescriptionChk.SetValue(self.optManager.options['write_description'])
self.writeInfoChk.SetValue(self.optManager.options['write_info'])
self.writeThumbnailChk.SetValue(self.optManager.options['write_thumbnail'])
self.ignoreErrorsChk.SetValue(self.optManager.options['ignore_errors'])
self.openDirChk.SetValue(self.optManager.options['open_dl_dir'])
self.minFilesizeBox.SetValue(self.optManager.options['min_filesize'])
self.maxFilesizeBox.SetValue(self.optManager.options['max_filesize'])
def save_options(self): def save_options(self):
self.optList.writeDescription = self.writeDescriptionChk.GetValue()
self.optList.writeInfo = self.writeInfoChk.GetValue()
self.optList.writeThumbnail = self.writeThumbnailChk.GetValue()
self.optList.ignoreErrors = self.ignoreErrorsChk.GetValue()
self.optList.openDownloadDir = self.openDirChk.GetValue()
self.optList.minFileSize = self.minFilesizeBox.GetValue()
self.optList.maxFileSize = self.maxFilesizeBox.GetValue()
self.optManager.options['write_description'] = self.writeDescriptionChk.GetValue()
self.optManager.options['write_info'] = self.writeInfoChk.GetValue()
self.optManager.options['write_thumbnail'] = self.writeThumbnailChk.GetValue()
self.optManager.options['ignore_errors'] = self.ignoreErrorsChk.GetValue()
self.optManager.options['open_dl_dir'] = self.openDirChk.GetValue()
self.optManager.options['min_filesize'] = self.minFilesizeBox.GetValue()
self.optManager.options['max_filesize'] = self.maxFilesizeBox.GetValue()
self.check_input() self.check_input()
def check_input(self): def check_input(self):
self.optList.minFileSize.replace('-', '')
self.optList.maxFileSize.replace('-', '')
if self.optList.minFileSize == '':
self.optList.minFileSize = '0'
if self.optList.maxFileSize == '':
self.optList.maxFileSize = '0'
self.optManager.options['min_filesize'].replace('-', '')
self.optManager.options['max_filesize'].replace('-', '')
if self.optManager.options['min_filesize'] == '':
self.optManager.options['min_filesize'] = '0'
if self.optManager.options['max_filesize'] == '':
self.optManager.options['max_filesize'] = '0'
class SubtitlesPanel(wx.Panel): class SubtitlesPanel(wx.Panel):
win_box_border = 0 win_box_border = 0
def __init__(self, parent, optList):
def __init__(self, parent, optManager):
wx.Panel.__init__(self, parent) wx.Panel.__init__(self, parent)
self.SetBoxBorder() self.SetBoxBorder()
self.optList = optList
self.optManager = optManager
mainBoxSizer = wx.BoxSizer(wx.VERTICAL) mainBoxSizer = wx.BoxSizer(wx.VERTICAL)
dlSubsBox = wx.BoxSizer(wx.HORIZONTAL) dlSubsBox = wx.BoxSizer(wx.HORIZONTAL)
@ -995,20 +995,20 @@ class SubtitlesPanel(wx.Panel):
self.subsLangCombo.Enable() self.subsLangCombo.Enable()
self.writeAllSubsChk.Enable() self.writeAllSubsChk.Enable()
self.writeAutoSubsChk.Enable() self.writeAutoSubsChk.Enable()
self.writeSubsChk.SetValue(self.optList.writeSubs)
self.writeAllSubsChk.SetValue(self.optList.writeAllSubs)
self.subsLangCombo.SetValue(self.optList.subsLang)
self.writeAutoSubsChk.SetValue(self.optList.writeAutoSubs)
self.embedSubsChk.SetValue(self.optList.embedSubs)
if self.optList.writeSubs:
self.writeSubsChk.SetValue(self.optManager.options['write_subs'])
self.writeAllSubsChk.SetValue(self.optManager.options['write_all_subs'])
self.subsLangCombo.SetValue(self.optManager.options['subs_lang'])
self.writeAutoSubsChk.SetValue(self.optManager.options['write_auto_subs'])
self.embedSubsChk.SetValue(self.optManager.options['embed_subs'])
if self.optManager.options['write_subs']:
self.writeAllSubsChk.Disable() self.writeAllSubsChk.Disable()
self.writeAutoSubsChk.Disable() self.writeAutoSubsChk.Disable()
self.embedSubsChk.Enable() self.embedSubsChk.Enable()
if self.optList.writeAllSubs:
if self.optManager.options['write_all_subs']:
self.writeSubsChk.Disable() self.writeSubsChk.Disable()
self.subsLangCombo.Disable() self.subsLangCombo.Disable()
self.writeAutoSubsChk.Disable() self.writeAutoSubsChk.Disable()
if self.optList.writeAutoSubs:
if self.optManager.options['write_auto_subs']:
self.writeAllSubsChk.Disable() self.writeAllSubsChk.Disable()
self.writeSubsChk.Disable() self.writeSubsChk.Disable()
self.subsLangCombo.Disable() self.subsLangCombo.Disable()
@ -1017,18 +1017,18 @@ class SubtitlesPanel(wx.Panel):
self.embedSubsChk.Disable() self.embedSubsChk.Disable()
def save_options(self): def save_options(self):
self.optList.writeSubs = self.writeSubsChk.GetValue()
self.optList.writeAllSubs = self.writeAllSubsChk.GetValue()
self.optList.subsLang = self.subsLangCombo.GetValue()
self.optList.writeAutoSubs = self.writeAutoSubsChk.GetValue()
self.optList.embedSubs = self.embedSubsChk.GetValue()
self.optManager.options['write_subs'] = self.writeSubsChk.GetValue()
self.optManager.options['write_all_subs'] = self.writeAllSubsChk.GetValue()
self.optManager.options['subs_lang'] = self.subsLangCombo.GetValue()
self.optManager.options['write_auto_subs'] = self.writeAutoSubsChk.GetValue()
self.optManager.options['embed_subs'] = self.embedSubsChk.GetValue()
class GeneralPanel(wx.Panel): class GeneralPanel(wx.Panel):
def __init__(self, parent, optList, resetHandler):
def __init__(self, parent, optManager, resetHandler):
wx.Panel.__init__(self, parent) wx.Panel.__init__(self, parent)
self.optList = optList
self.optManager = optManager
self.resetHandler = resetHandler self.resetHandler = resetHandler
mainBoxSizer = wx.BoxSizer(wx.VERTICAL) mainBoxSizer = wx.BoxSizer(wx.VERTICAL)
@ -1051,7 +1051,7 @@ class GeneralPanel(wx.Panel):
mainBoxSizer.Add(buttonsBox, flag = wx.ALIGN_CENTER_HORIZONTAL | wx.TOP, border=20) mainBoxSizer.Add(buttonsBox, flag = wx.ALIGN_CENTER_HORIZONTAL | wx.TOP, border=20)
setngsBox = wx.BoxSizer(wx.HORIZONTAL) setngsBox = wx.BoxSizer(wx.HORIZONTAL)
text = 'Settings: ' + self.optList.settings_abs_path
text = 'Settings: ' + self.optManager.settings_abs_path
setngsBox.Add(wx.StaticText(self, label=text), flag = wx.TOP, border=30) setngsBox.Add(wx.StaticText(self, label=text), flag = wx.TOP, border=30)
mainBoxSizer.Add(setngsBox, flag = wx.ALIGN_CENTER_HORIZONTAL) mainBoxSizer.Add(setngsBox, flag = wx.ALIGN_CENTER_HORIZONTAL)
@ -1083,17 +1083,17 @@ class GeneralPanel(wx.Panel):
wx.AboutBox(info) wx.AboutBox(info)
def load_options(self): def load_options(self):
self.savePathBox.SetValue(self.optList.savePath)
self.savePathBox.SetValue(self.optManager.options['save_path'])
def save_options(self): def save_options(self):
self.optList.savePath = fix_path(self.savePathBox.GetValue())
self.optManager.options['save_path'] = fix_path(self.savePathBox.GetValue())
class OtherPanel(wx.Panel): class OtherPanel(wx.Panel):
def __init__(self, parent, optList):
def __init__(self, parent, optManager):
wx.Panel.__init__(self, parent) wx.Panel.__init__(self, parent)
self.optList = optList
self.optManager = optManager
mainBoxSizer = wx.BoxSizer(wx.VERTICAL) mainBoxSizer = wx.BoxSizer(wx.VERTICAL)
textBox = wx.BoxSizer(wx.HORIZONTAL) textBox = wx.BoxSizer(wx.HORIZONTAL)
@ -1108,32 +1108,32 @@ class OtherPanel(wx.Panel):
self.SetSizer(mainBoxSizer) self.SetSizer(mainBoxSizer)
def load_options(self): def load_options(self):
self.cmdArgsBox.SetValue(self.optList.cmdArgs)
self.cmdArgsBox.SetValue(self.optManager.options['cmd_args'])
def save_options(self): def save_options(self):
self.optList.cmdArgs = self.cmdArgsBox.GetValue()
self.optManager.options['cmd_args'] = self.cmdArgsBox.GetValue()
class OptionsFrame(wx.Frame): class OptionsFrame(wx.Frame):
def __init__(self, optionsList, parent=None, id=-1, logger=None):
def __init__(self, optManager, parent=None, id=-1, logger=None):
wx.Frame.__init__(self, parent, id, "Options", size=self.SetFrameSizer()) wx.Frame.__init__(self, parent, id, "Options", size=self.SetFrameSizer())
self.optionsList = optionsList
self.optManager = optManager
panel = wx.Panel(self) panel = wx.Panel(self)
notebook = wx.Notebook(panel) notebook = wx.Notebook(panel)
self.generalTab = GeneralPanel(notebook, self.optionsList, self.reset)
self.audioTab = AudioPanel(notebook, self.optionsList)
self.connectionTab = ConnectionPanel(notebook, self.optionsList)
self.videoTab = VideoPanel(notebook, self.optionsList)
self.filesysTab = FilesystemPanel(notebook, self.optionsList)
self.subtitlesTab = SubtitlesPanel(notebook, self.optionsList)
self.otherTab = OtherPanel(notebook, self.optionsList)
self.authTab = AuthenticationPanel(notebook, self.optionsList)
self.videoselTab = PlaylistPanel(notebook, self.optionsList)
self.logTab = LogPanel(notebook, self.optionsList, logger)
self.outputTab = OutputPanel(notebook, self.optionsList)
self.generalTab = GeneralPanel(notebook, self.optManager, self.reset)
self.audioTab = AudioPanel(notebook, self.optManager)
self.connectionTab = ConnectionPanel(notebook, self.optManager)
self.videoTab = VideoPanel(notebook, self.optManager)
self.filesysTab = FilesystemPanel(notebook, self.optManager)
self.subtitlesTab = SubtitlesPanel(notebook, self.optManager)
self.otherTab = OtherPanel(notebook, self.optManager)
self.authTab = AuthenticationPanel(notebook, self.optManager)
self.videoselTab = PlaylistPanel(notebook, self.optManager)
self.logTab = LogPanel(notebook, self.optManager, logger)
self.outputTab = OutputPanel(notebook, self.optManager)
notebook.AddPage(self.generalTab, "General") notebook.AddPage(self.generalTab, "General")
notebook.AddPage(self.videoTab, "Video") notebook.AddPage(self.videoTab, "Video")
@ -1166,7 +1166,7 @@ class OptionsFrame(wx.Frame):
self.Destroy() self.Destroy()
def reset(self): def reset(self):
self.optionsList.load_default()
self.optManager.load_default()
self.load_all_options() self.load_all_options()
def load_all_options(self): def load_all_options(self):

110
youtube_dl_gui/YoutubeDLInterpreter.py

@ -45,9 +45,9 @@ AUDIO_Q = {"high":"0",
class YoutubeDLInterpreter(): class YoutubeDLInterpreter():
def __init__(self, optionsList, youtubeDLFile):
def __init__(self, optManager, youtubeDLFile):
self.youtubeDLFile = youtubeDLFile self.youtubeDLFile = youtubeDLFile
self.optionsList = optionsList
self.optManager = optManager
self.opts = [] self.opts = []
self.set_os() self.set_os()
self.set_progress_opts() self.set_progress_opts()
@ -67,9 +67,9 @@ class YoutubeDLInterpreter():
def set_os(self): def set_os(self):
if get_os_type() == 'nt': if get_os_type() == 'nt':
self.opts = [self.youtubeDLFile] self.opts = [self.youtubeDLFile]
add_PATH(self.optionsList.updatePath)
add_PATH(self.optManager.options['youtubedl_path'])
else: else:
path = fix_path(self.optionsList.updatePath)
path = fix_path(self.optManager.options['youtubedl_path'])
self.opts = ['python', path + self.youtubeDLFile] self.opts = ['python', path + self.youtubeDLFile]
def set_progress_opts(self): def set_progress_opts(self):
@ -77,105 +77,105 @@ class YoutubeDLInterpreter():
self.opts.append('--newline') self.opts.append('--newline')
def set_playlist_opts(self): def set_playlist_opts(self):
if self.optionsList.startTrack != 1:
if self.optManager.options['playlist_start'] != 1:
self.opts.append('--playlist-start') self.opts.append('--playlist-start')
self.opts.append(str(self.optionsList.startTrack))
if self.optionsList.endTrack != 0:
self.opts.append(str(self.optManager.options['playlist_start']))
if self.optManager.options['playlist_end'] != 0:
self.opts.append('--playlist-end') self.opts.append('--playlist-end')
self.opts.append(str(self.optionsList.endTrack))
if self.optionsList.maxDownloads != 0:
self.opts.append(str(self.optManager.options['playlist_end']))
if self.optManager.options['max_downloads'] != 0:
self.opts.append('--max-downloads') self.opts.append('--max-downloads')
self.opts.append(str(self.optionsList.maxDownloads))
if self.optionsList.minFileSize != '0':
self.opts.append(str(self.optManager.options['max_downloads']))
if self.optManager.options['min_filesize'] != '0':
self.opts.append('--min-filesize') self.opts.append('--min-filesize')
self.opts.append(self.optionsList.minFileSize)
if self.optionsList.maxFileSize != '0':
self.opts.append(self.optManager.options['min_filesize'])
if self.optManager.options['max_filesize'] != '0':
self.opts.append('--max-filesize') self.opts.append('--max-filesize')
self.opts.append(self.optionsList.maxFileSize)
self.opts.append(self.optManager.options['max_filesize'])
def set_auth_opts(self): def set_auth_opts(self):
if self.optionsList.username != '':
if self.optManager.options['username'] != '':
self.opts.append('-u') self.opts.append('-u')
self.opts.append(self.optionsList.username)
if self.optionsList.password != '':
self.opts.append(self.optManager.options['username'])
if self.optManager.options['password'] != '':
self.opts.append('-p') self.opts.append('-p')
self.opts.append(self.optionsList.password)
if self.optionsList.videoPass != '':
self.opts.append(self.optManager.options['password'])
if self.optManager.options['video_password'] != '':
self.opts.append('--video-password') self.opts.append('--video-password')
self.opts.append(self.optionsList.videoPass)
self.opts.append(self.optManager.options['video_password'])
def set_connection_opts(self): def set_connection_opts(self):
if self.optionsList.retries != 10:
if self.optManager.options['retries'] != 10:
self.opts.append('-R') self.opts.append('-R')
self.opts.append(str(self.optionsList.retries))
if self.optionsList.proxy != '':
self.opts.append(str(self.optManager.options['retries']))
if self.optManager.options['proxy'] != '':
self.opts.append('--proxy') self.opts.append('--proxy')
self.opts.append(self.optionsList.proxy)
if self.optionsList.userAgent != '':
self.opts.append(self.optManager.options['proxy'])
if self.optManager.options['user_agent'] != '':
self.opts.append('--user-agent') self.opts.append('--user-agent')
self.opts.append(self.optionsList.userAgent)
if self.optionsList.referer != '':
self.opts.append(self.optManager.options['user_agent'])
if self.optManager.options['referer'] != '':
self.opts.append('--referer') self.opts.append('--referer')
self.opts.append(self.optionsList.referer)
self.opts.append(self.optManager.options['referer'])
def set_video_opts(self): def set_video_opts(self):
if self.optionsList.videoFormat != 'default':
if self.optManager.options['video_format'] != 'default':
self.opts.append('-f') self.opts.append('-f')
if video_is_dash(self.optionsList.videoFormat):
vf = VIDEOFORMATS[self.optionsList.videoFormat]
af = DASH_AUDIO_FORMATS[self.optionsList.dashAudioFormat]
if video_is_dash(self.optManager.options['video_format']):
vf = VIDEOFORMATS[self.optManager.options['video_format']]
af = DASH_AUDIO_FORMATS[self.optManager.options['dash_audio_format']]
if af != 'None': if af != 'None':
self.opts.append(vf+'+'+af) self.opts.append(vf+'+'+af)
else: else:
self.opts.append(vf) self.opts.append(vf)
else: else:
self.opts.append(VIDEOFORMATS[self.optionsList.videoFormat])
self.opts.append(VIDEOFORMATS[self.optManager.options['video_format']])
def set_filesystem_opts(self): def set_filesystem_opts(self):
if self.optionsList.ignoreErrors:
if self.optManager.options['ignore_errors']:
self.opts.append('-i') self.opts.append('-i')
if self.optionsList.writeDescription:
if self.optManager.options['write_description']:
self.opts.append('--write-description') self.opts.append('--write-description')
if self.optionsList.writeInfo:
if self.optManager.options['write_info']:
self.opts.append('--write-info-json') self.opts.append('--write-info-json')
if self.optionsList.writeThumbnail:
if self.optManager.options['write_thumbnail']:
self.opts.append('--write-thumbnail') self.opts.append('--write-thumbnail')
def set_subtitles_opts(self): def set_subtitles_opts(self):
if self.optionsList.writeAllSubs:
if self.optManager.options['write_all_subs']:
self.opts.append('--all-subs') self.opts.append('--all-subs')
if (self.optionsList.writeAutoSubs):
if self.optManager.options['write_auto_subs']:
self.opts.append('--write-auto-sub') self.opts.append('--write-auto-sub')
if self.optionsList.writeSubs:
if self.optManager.options['write_subs']:
self.opts.append('--write-sub') self.opts.append('--write-sub')
if self.optionsList.subsLang != 'English':
if self.optManager.options['subs_lang'] != 'English':
self.opts.append('--sub-lang') self.opts.append('--sub-lang')
self.opts.append(LANGUAGES[self.optionsList.subsLang])
if self.optionsList.embedSubs:
self.opts.append(LANGUAGES[self.optManager.options['subs_lang']])
if self.optManager.options['embed_subs']:
self.opts.append('--embed-subs') self.opts.append('--embed-subs')
def set_output_opts(self): def set_output_opts(self):
path = fix_path(self.optionsList.savePath)
path = fix_path(self.optManager.options['save_path'])
self.opts.append('-o') self.opts.append('-o')
if self.optionsList.outputFormat == 'id':
if self.optManager.options['output_format'] == 'id':
self.opts.append(path + '%(id)s.%(ext)s') self.opts.append(path + '%(id)s.%(ext)s')
elif self.optionsList.outputFormat == 'title':
elif self.optManager.options['output_format'] == 'title':
self.opts.append(path + '%(title)s.%(ext)s') self.opts.append(path + '%(title)s.%(ext)s')
elif self.optionsList.outputFormat == 'custom':
self.opts.append(path + self.optionsList.outputTemplate)
elif self.optManager.options['output_format'] == 'custom':
self.opts.append(path + self.optManager.options['output_template'])
def set_audio_opts(self): def set_audio_opts(self):
if self.optionsList.toAudio:
if self.optManager.options['to_audio']:
self.opts.append('-x') self.opts.append('-x')
self.opts.append('--audio-format') self.opts.append('--audio-format')
self.opts.append(self.optionsList.audioFormat)
if self.optionsList.audioQuality != 'mid':
self.opts.append(self.optManager.options['audio_format'])
if self.optManager.options['audio_quality'] != 'mid':
self.opts.append('--audio-quality') self.opts.append('--audio-quality')
self.opts.append(AUDIO_Q[self.optionsList.audioQuality])
if self.optionsList.keepVideo:
self.opts.append(AUDIO_Q[self.optManager.options['audio_quality']])
if self.optManager.options['keep_video']:
self.opts.append('-k') self.opts.append('-k')
def set_other_opts(self): def set_other_opts(self):
if self.optionsList.cmdArgs != '':
for option in self.optionsList.cmdArgs.split():
if self.optManager.options['cmd_args'] != '':
for option in self.optManager.options['cmd_args'].split():
self.opts.append(option) self.opts.append(option)
Loading…
Cancel
Save