You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1290 lines
46 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. #! /usr/bin/env python
  2. '''
  3. This file contains all gui classes
  4. MainFrame
  5. Custom wx.ListCtrl class
  6. OptionsFrame
  7. GeneralPanel
  8. AudioPanel
  9. ConnectionPanel
  10. VideoPanel
  11. FilesystemPanel
  12. SubtitlesPanel
  13. OtherPanel
  14. UpdatePanel
  15. AuthenticationPanel
  16. PlaylistPanel
  17. '''
  18. import wx
  19. from wx.lib.pubsub import setuparg1
  20. from wx.lib.pubsub import pub as Publisher
  21. from wx.lib.mixins.listctrl import ListCtrlAutoWidthMixin
  22. from .version import __version__
  23. from .UpdateThread import UpdateThread
  24. from .DownloadThread import DownloadManager
  25. from .OptionsHandler import OptionsHandler
  26. from .YoutubeDLInterpreter import YoutubeDLInterpreter
  27. from .OutputHandler import DownloadHandler
  28. from .LogManager import LogManager, LogGUI
  29. from .Utils import (
  30. video_is_dash,
  31. have_dash_audio,
  32. get_os_type,
  33. file_exist,
  34. fix_path,
  35. abs_path,
  36. open_dir,
  37. remove_spaces
  38. )
  39. if get_os_type() == 'nt':
  40. YOUTUBE_DL_FILENAME = 'youtube-dl.exe'
  41. else:
  42. YOUTUBE_DL_FILENAME = 'youtube-dl'
  43. TITLE = 'Youtube-dlG'
  44. AUDIOFORMATS = ["mp3", "wav", "aac", "m4a"]
  45. VIDEOFORMATS = ["default",
  46. "mp4 [1280x720]",
  47. "mp4 [640x360]",
  48. "webm [640x360]",
  49. "flv [400x240]",
  50. "3gp [320x240]",
  51. "mp4 1080p(DASH)",
  52. "mp4 720p(DASH)",
  53. "mp4 480p(DASH)",
  54. "mp4 360p(DASH)"]
  55. DASH_AUDIO_FORMATS = ["NO SOUND",
  56. "DASH m4a audio 128k",
  57. "DASH webm audio 48k"]
  58. LANGUAGES = ["English",
  59. "Greek",
  60. "Portuguese",
  61. "French",
  62. "Italian",
  63. "Russian",
  64. "Spanish",
  65. "German"]
  66. ICON = 'icons/youtube-dl-gui.png'
  67. class MainFrame(wx.Frame):
  68. def __init__(self, parent=None, id=-1):
  69. wx.Frame.__init__(self, parent, id, TITLE+' '+__version__, size=(600, 420))
  70. # init gui
  71. self.InitGUI()
  72. # bind events
  73. self.Bind(wx.EVT_BUTTON, self.OnDownload, self.downloadButton)
  74. self.Bind(wx.EVT_BUTTON, self.OnUpdate, self.updateButton)
  75. self.Bind(wx.EVT_BUTTON, self.OnOptions, self.optionsButton)
  76. self.Bind(wx.EVT_TEXT, self.OnTrackListChange, self.trackList)
  77. self.Bind(wx.EVT_CLOSE, self.OnClose)
  78. # set app icon
  79. icon = wx.Icon(ICON, wx.BITMAP_TYPE_ICO)
  80. self.SetIcon(icon)
  81. # set publisher for update thread
  82. Publisher.subscribe(self.update_handler, "update")
  83. # set publisher for download thread
  84. Publisher.subscribe(self.download_handler, "download")
  85. # init Options and DownloadHandler objects
  86. self.optionsList = OptionsHandler(self.status_bar_write)
  87. self.downloadHandler = None
  88. # init log manager
  89. self.logManager = None
  90. if self.optionsList.enableLog:
  91. self.logManager = LogManager(
  92. self.optionsList.get_config_path(),
  93. self.optionsList.writeTimeToLog
  94. )
  95. # init some thread variables
  96. self.downloadThread = None
  97. self.updateThread = None
  98. # init urlList for evt_text on self.trackList
  99. self.urlList = []
  100. # check & update libraries (youtube-dl)
  101. self.check_if_youtube_dl_exist()
  102. if (self.optionsList.autoUpdate):
  103. self.status_bar_write("Auto update enable")
  104. self.update_youtube_dl()
  105. def InitGUI(self):
  106. self.panel = wx.Panel(self)
  107. mainBoxSizer = wx.BoxSizer(wx.VERTICAL)
  108. urlTextBox = wx.BoxSizer(wx.HORIZONTAL)
  109. urlTextBox.Add(wx.StaticText(self.panel, label='URLs'), flag = wx.TOP, border=10)
  110. mainBoxSizer.Add(urlTextBox, flag = wx.LEFT, border=20)
  111. trckListBox = wx.BoxSizer(wx.HORIZONTAL)
  112. self.trackList = wx.TextCtrl(self.panel, size=(-1, 120), style = wx.TE_MULTILINE | wx.TE_DONTWRAP)
  113. trckListBox.Add(self.trackList, 1)
  114. mainBoxSizer.Add(trckListBox, flag = wx.EXPAND | wx.LEFT | wx.RIGHT, border=20)
  115. buttonsBox = wx.BoxSizer(wx.HORIZONTAL)
  116. self.downloadButton = wx.Button(self.panel, label='Download', size=(90, 30))
  117. buttonsBox.Add(self.downloadButton)
  118. self.updateButton = wx.Button(self.panel, label='Update', size=(90, 30))
  119. buttonsBox.Add(self.updateButton, flag = wx.LEFT | wx.RIGHT, border=80)
  120. self.optionsButton = wx.Button(self.panel, label='Options', size=(90, 30))
  121. buttonsBox.Add(self.optionsButton)
  122. mainBoxSizer.Add(buttonsBox, flag = wx.ALIGN_CENTER_HORIZONTAL | wx.BOTTOM | wx.TOP, border=10)
  123. stListBox = wx.BoxSizer(wx.HORIZONTAL)
  124. self.statusList = ListCtrl(self.panel, style = wx.LC_REPORT | wx.LC_HRULES | wx.LC_VRULES)
  125. stListBox.Add(self.statusList, 1, flag = wx.EXPAND)
  126. mainBoxSizer.Add(stListBox, 1, flag = wx.EXPAND | wx.LEFT | wx.RIGHT, border=20)
  127. stBarBox = wx.BoxSizer(wx.HORIZONTAL)
  128. self.statusBar = wx.StaticText(self.panel, label='Author: Sotiris Papadopoulos')
  129. stBarBox.Add(self.statusBar, flag = wx.TOP | wx.BOTTOM, border=5)
  130. mainBoxSizer.Add(stBarBox, flag = wx.LEFT, border=20)
  131. self.panel.SetSizer(mainBoxSizer)
  132. def check_if_youtube_dl_exist(self):
  133. path = fix_path(self.optionsList.updatePath)+YOUTUBE_DL_FILENAME
  134. if not file_exist(path):
  135. self.status_bar_write("Youtube-dl is missing, trying to download it...")
  136. self.update_youtube_dl()
  137. def update_youtube_dl(self):
  138. self.downloadButton.Disable()
  139. self.updateThread = UpdateThread(self.optionsList.updatePath, YOUTUBE_DL_FILENAME)
  140. def status_bar_write(self, msg):
  141. self.statusBar.SetLabel(msg)
  142. def fin_task(self, msg):
  143. self.status_bar_write(msg)
  144. self.downloadButton.SetLabel('Download')
  145. self.updateButton.Enable()
  146. self.downloadThread.join()
  147. self.downloadThread = None
  148. self.downloadHandler = None
  149. self.urlList = []
  150. self.finished_popup()
  151. self.open_destination_dir()
  152. def open_destination_dir(self):
  153. if self.optionsList.openDownloadDir:
  154. open_dir(self.optionsList.savePath)
  155. def download_handler(self, msg):
  156. self.downloadHandler.handle(msg)
  157. if self.downloadHandler._has_closed():
  158. self.status_bar_write('Stoping downloads')
  159. if self.downloadHandler._has_finished():
  160. if self.downloadHandler._has_error():
  161. if self.logManager != None:
  162. msg = 'An error occured while downloading. See Options>Log.'
  163. else:
  164. msg = 'An error occured while downloading'
  165. else:
  166. msg = 'Done'
  167. self.fin_task(msg)
  168. def update_handler(self, msg):
  169. if msg.data == 'finish':
  170. self.downloadButton.Enable()
  171. self.updateThread.join()
  172. self.updateThread = None
  173. else:
  174. self.status_bar_write(msg.data)
  175. def stop_download(self):
  176. self.downloadThread.close()
  177. def load_tracklist(self, trackList):
  178. for url in trackList:
  179. url = remove_spaces(url)
  180. if url != '':
  181. self.urlList.append(url)
  182. self.statusList._add_item(url)
  183. def start_download(self):
  184. self.statusList._clear_list()
  185. self.load_tracklist(self.trackList.GetValue().split('\n'))
  186. if not self.statusList._is_empty():
  187. options = YoutubeDLInterpreter(self.optionsList, YOUTUBE_DL_FILENAME).get_options()
  188. self.downloadThread = DownloadManager(
  189. options,
  190. self.statusList._get_items(),
  191. self.optionsList.clearDashFiles,
  192. self.logManager
  193. )
  194. self.downloadHandler = DownloadHandler(self.statusList)
  195. self.status_bar_write('Download started')
  196. self.downloadButton.SetLabel('Stop')
  197. self.updateButton.Disable()
  198. else:
  199. self.no_url_popup()
  200. def save_options(self):
  201. self.optionsList.save_to_file()
  202. def finished_popup(self):
  203. wx.MessageBox('Downloads completed.', 'Info', wx.OK | wx.ICON_INFORMATION)
  204. def no_url_popup(self):
  205. wx.MessageBox('You need to provide at least one url.', 'Error', wx.OK | wx.ICON_EXCLAMATION)
  206. def OnTrackListChange(self, event):
  207. if self.downloadThread != None:
  208. ''' Get current url list from trackList textCtrl '''
  209. curList = self.trackList.GetValue().split('\n')
  210. ''' For each url in current url list '''
  211. for url in curList:
  212. ''' Remove spaces from url '''
  213. url = remove_spaces(url)
  214. ''' If url is not in self.urlList (original downloads list) and url is not empty '''
  215. if url not in self.urlList and url != '':
  216. ''' Add url into original download list '''
  217. self.urlList.append(url)
  218. ''' Add handler for url '''
  219. self.downloadHandler._add_empty_handler()
  220. ''' Add url into statusList '''
  221. self.statusList._add_item(url)
  222. ''' Retrieve last item as {url:url, index:indexNo} '''
  223. item = self.statusList._get_last_item()
  224. ''' Pass that item into downloadThread '''
  225. self.downloadThread._add_download_item(item)
  226. def OnDownload(self, event):
  227. if self.downloadThread != None:
  228. self.stop_download()
  229. else:
  230. self.start_download()
  231. def OnUpdate(self, event):
  232. if (self.downloadThread == None and self.updateThread == None):
  233. self.update_youtube_dl()
  234. def OnOptions(self, event):
  235. optionsFrame = OptionsFrame(self.optionsList, parent=self, logger=self.logManager)
  236. optionsFrame.Show()
  237. def OnClose(self, event):
  238. self.save_options()
  239. self.Destroy()
  240. class ListCtrl(wx.ListCtrl, ListCtrlAutoWidthMixin):
  241. ''' Custom ListCtrl class '''
  242. def __init__(self, parent=None, id=-1, pos=wx.DefaultPosition, size=wx.DefaultSize, style=0):
  243. wx.ListCtrl.__init__(self, parent, id, pos, size, style)
  244. ListCtrlAutoWidthMixin.__init__(self)
  245. self.InsertColumn(0, 'Video', width=150)
  246. self.InsertColumn(1, 'Size', width=80)
  247. self.InsertColumn(2, 'Percent', width=65)
  248. self.InsertColumn(3, 'ETA', width=45)
  249. self.InsertColumn(4, 'Speed', width=90)
  250. self.InsertColumn(5, 'Status', width=160)
  251. self.setResizeColumn(0)
  252. self.ListIndex = 0
  253. ''' Add single item on list '''
  254. def _add_item(self, item):
  255. self.InsertStringItem(self.ListIndex, item)
  256. self.ListIndex += 1
  257. ''' Write data on index, column '''
  258. def _write_data(self, index, column, data):
  259. self.SetStringItem(index, column, data)
  260. ''' Clear list and set index to 0'''
  261. def _clear_list(self):
  262. self.DeleteAllItems()
  263. self.ListIndex = 0
  264. ''' Return True if list is empty '''
  265. def _is_empty(self):
  266. return self.ListIndex == 0
  267. ''' Get last item inserted, Returns dictionary '''
  268. def _get_last_item(self):
  269. data = {}
  270. last_item = self.GetItem(itemId=self.ListIndex-1, col=0)
  271. data['url'] = last_item.GetText()
  272. data['index'] = self.ListIndex-1
  273. return data
  274. ''' Retrieve all items [start, self.ListIndex), Returns list '''
  275. def _get_items(self, start=0):
  276. items = []
  277. for row in range(start, self.ListIndex):
  278. item = self.GetItem(itemId=row, col=0)
  279. data = {}
  280. data['url'] = item.GetText()
  281. data['index'] = row
  282. items.append(data)
  283. return items
  284. class LogPanel(wx.Panel):
  285. size = ''
  286. path = ''
  287. win_box_border = 0
  288. def __init__(self, parent, optList, log):
  289. wx.Panel.__init__(self, parent)
  290. self.SetBoxBorder()
  291. self.optList = optList
  292. self.log = log
  293. self.set_data()
  294. mainBoxSizer = wx.BoxSizer(wx.VERTICAL)
  295. enLogBox = wx.BoxSizer(wx.HORIZONTAL)
  296. self.enableLogChk = wx.CheckBox(self, label='Enable Log')
  297. enLogBox.Add(self.enableLogChk)
  298. mainBoxSizer.Add(enLogBox, flag = wx.ALIGN_CENTER_HORIZONTAL | wx.TOP, border=20+self.win_box_border)
  299. wrTimeBox = wx.BoxSizer(wx.HORIZONTAL)
  300. self.enableTimeChk = wx.CheckBox(self, label='Write Time')
  301. wrTimeBox.Add(self.enableTimeChk)
  302. mainBoxSizer.Add(wrTimeBox, flag = wx.ALIGN_CENTER_HORIZONTAL | wx.TOP, border=5+self.win_box_border)
  303. butBox = wx.BoxSizer(wx.HORIZONTAL)
  304. self.clearLogButton = wx.Button(self, label='Clear Log')
  305. butBox.Add(self.clearLogButton)
  306. self.viewLogButton = wx.Button(self, label='View Log')
  307. butBox.Add(self.viewLogButton, flag = wx.LEFT, border=20)
  308. mainBoxSizer.Add(butBox, flag = wx.ALIGN_CENTER_HORIZONTAL | wx.TOP, border=15)
  309. if self.optList.enableLog:
  310. self.SetDataSizers(mainBoxSizer)
  311. self.SetSizer(mainBoxSizer)
  312. self.Bind(wx.EVT_CHECKBOX, self.OnEnable, self.enableLogChk)
  313. self.Bind(wx.EVT_CHECKBOX, self.OnTime, self.enableTimeChk)
  314. self.Bind(wx.EVT_BUTTON, self.OnClear, self.clearLogButton)
  315. self.Bind(wx.EVT_BUTTON, self.OnView, self.viewLogButton)
  316. def SetBoxBorder(self):
  317. ''' Set border for windows '''
  318. if get_os_type() == 'nt':
  319. self.win_box_border = 10
  320. def SetDataSizers(self, box):
  321. logPathText = wx.BoxSizer(wx.HORIZONTAL)
  322. logPathText.Add(wx.StaticText(self, label='Path: ' + self.path))
  323. box.Add(logPathText, flag = wx.ALIGN_CENTER_HORIZONTAL | wx.TOP, border=20)
  324. logSizeText = wx.BoxSizer(wx.HORIZONTAL)
  325. self.sizeText = wx.StaticText(self, label='Log Size: ' + self.size)
  326. logSizeText.Add(self.sizeText)
  327. box.Add(logSizeText, flag = wx.ALIGN_CENTER_HORIZONTAL | wx.TOP, border=10)
  328. def set_data(self):
  329. if self.log != None:
  330. self.size = str(self.log.size()) + ' Bytes'
  331. self.path = self.log.path
  332. def OnTime(self, event):
  333. if self.log != None:
  334. self.log.add_time = self.enableTimeChk.GetValue()
  335. def OnEnable(self, event):
  336. if self.enableLogChk.GetValue():
  337. self.enableTimeChk.Enable()
  338. else:
  339. self.enableTimeChk.Disable()
  340. self.restart_popup()
  341. def OnClear(self, event):
  342. if self.log != None:
  343. self.log.clear()
  344. self.sizeText.SetLabel('Log Size: 0 Bytes')
  345. def OnView(self, event):
  346. if self.log != None:
  347. log_gui = LogGUI(self.path, parent=self)
  348. log_gui.Show()
  349. def load_options(self):
  350. self.enableLogChk.SetValue(self.optList.enableLog)
  351. self.enableTimeChk.SetValue(self.optList.writeTimeToLog)
  352. if self.optList.enableLog == False:
  353. self.enableTimeChk.Disable()
  354. if self.log == None:
  355. self.clearLogButton.Disable()
  356. self.viewLogButton.Disable()
  357. def save_options(self):
  358. self.optList.enableLog = self.enableLogChk.GetValue()
  359. self.optList.writeTimeToLog = self.enableTimeChk.GetValue()
  360. def restart_popup(self):
  361. wx.MessageBox('Please restart ' + TITLE, 'Restart', wx.OK | wx.ICON_INFORMATION)
  362. class UpdatePanel(wx.Panel):
  363. def __init__(self, parent, optList):
  364. wx.Panel.__init__(self, parent)
  365. self.optList = optList
  366. mainBoxSizer = wx.BoxSizer(wx.VERTICAL)
  367. text = '''Enter the path where youtube-dlG should
  368. download the latest youtube-dl.'''
  369. helpText = wx.BoxSizer(wx.HORIZONTAL)
  370. helpText.Add(wx.StaticText(self, label=text), flag = wx.TOP, border=10)
  371. mainBoxSizer.Add(helpText, flag = wx.LEFT, border=80)
  372. pathText = wx.BoxSizer(wx.HORIZONTAL)
  373. pathText.Add(wx.StaticText(self, label='Path'), flag = wx.TOP, border=20)
  374. mainBoxSizer.Add(pathText, flag = wx.LEFT, border=95)
  375. upPathBox = wx.BoxSizer(wx.HORIZONTAL)
  376. self.updatePathBox = wx.TextCtrl(self)
  377. upPathBox.Add(self.updatePathBox, 1, flag = wx.TOP, border=5)
  378. mainBoxSizer.Add(upPathBox, flag = wx.EXPAND | wx.LEFT | wx.RIGHT, border=90)
  379. autoUpBox = wx.BoxSizer(wx.HORIZONTAL)
  380. self.autoUpdateChk = wx.CheckBox(self, label='Auto Update youtube-dl')
  381. autoUpBox.Add(self.autoUpdateChk, flag = wx.TOP, border=30)
  382. mainBoxSizer.Add(autoUpBox, flag = wx.LEFT, border=100)
  383. self.SetSizer(mainBoxSizer)
  384. def load_options(self):
  385. self.updatePathBox.SetValue(self.optList.updatePath)
  386. self.autoUpdateChk.SetValue(self.optList.autoUpdate)
  387. def save_options(self):
  388. self.optList.updatePath = abs_path(self.updatePathBox.GetValue())
  389. self.optList.autoUpdate = self.autoUpdateChk.GetValue()
  390. class PlaylistPanel(wx.Panel):
  391. def __init__(self, parent, optList):
  392. wx.Panel.__init__(self, parent)
  393. self.optList = optList
  394. mainBoxSizer = wx.StaticBoxSizer(wx.StaticBox(self, label='Playlist Options'), wx.VERTICAL)
  395. mainBoxSizer.Add((-1, 10))
  396. startBox = wx.BoxSizer(wx.HORIZONTAL)
  397. startBox.Add(wx.StaticText(self, label='Start'), flag = wx.RIGHT, border=32)
  398. self.startSpnr = wx.SpinCtrl(self, size=(60, -1))
  399. self.startSpnr.SetRange(1, 999)
  400. startBox.Add(self.startSpnr)
  401. mainBoxSizer.Add(startBox, flag = wx.TOP | wx.LEFT, border=20)
  402. stopBox = wx.BoxSizer(wx.HORIZONTAL)
  403. stopBox.Add(wx.StaticText(self, label='Stop'), flag = wx.RIGHT, border=34)
  404. self.stopSpnr = wx.SpinCtrl(self, size=(60, -1))
  405. self.stopSpnr.SetRange(0, 999)
  406. stopBox.Add(self.stopSpnr)
  407. mainBoxSizer.Add(stopBox, flag = wx.TOP | wx.LEFT, border=20)
  408. maxBox = wx.BoxSizer(wx.HORIZONTAL)
  409. maxBox.Add(wx.StaticText(self, label='Max DLs'), flag = wx.RIGHT, border=self.get_border())
  410. self.maxSpnr = wx.SpinCtrl(self, size=(60, -1))
  411. self.maxSpnr.SetRange(0, 999)
  412. maxBox.Add(self.maxSpnr)
  413. mainBoxSizer.Add(maxBox, flag = wx.TOP | wx.LEFT, border=20)
  414. self.SetSizer(mainBoxSizer)
  415. def get_border(self):
  416. if get_os_type() == 'nt':
  417. return 16
  418. return 10
  419. def load_options(self):
  420. self.startSpnr.SetValue(self.optList.startTrack)
  421. self.stopSpnr.SetValue(self.optList.endTrack)
  422. self.maxSpnr.SetValue(self.optList.maxDownloads)
  423. def save_options(self):
  424. self.optList.startTrack = self.startSpnr.GetValue()
  425. self.optList.endTrack = self.stopSpnr.GetValue()
  426. self.optList.maxDownloads = self.maxSpnr.GetValue()
  427. class ConnectionPanel(wx.Panel):
  428. def __init__(self, parent, optList):
  429. wx.Panel.__init__(self, parent)
  430. self.optList = optList
  431. mainBoxSizer = wx.BoxSizer(wx.VERTICAL)
  432. retBox = wx.BoxSizer(wx.HORIZONTAL)
  433. retBox.Add(wx.StaticText(self, label='Retries'), flag = wx.RIGHT, border=8)
  434. self.retriesSpnr = wx.SpinCtrl(self, size=(50, -1))
  435. self.retriesSpnr.SetRange(1, 99)
  436. retBox.Add(self.retriesSpnr)
  437. mainBoxSizer.Add(retBox, flag = wx.LEFT | wx.TOP, border=10)
  438. uaText = wx.BoxSizer(wx.HORIZONTAL)
  439. uaText.Add(wx.StaticText(self, label='User Agent'), flag = wx.LEFT, border=15)
  440. mainBoxSizer.Add(uaText, flag = wx.TOP, border=10)
  441. mainBoxSizer.Add((-1, 5))
  442. uaBox = wx.BoxSizer(wx.HORIZONTAL)
  443. self.userAgentBox = wx.TextCtrl(self)
  444. uaBox.Add(self.userAgentBox, 1, flag = wx.LEFT, border=10)
  445. mainBoxSizer.Add(uaBox, flag = wx.EXPAND | wx.RIGHT, border=200)
  446. refText = wx.BoxSizer(wx.HORIZONTAL)
  447. refText.Add(wx.StaticText(self, label='Referer'), flag = wx.LEFT, border=15)
  448. mainBoxSizer.Add(refText, flag = wx.TOP, border=10)
  449. mainBoxSizer.Add((-1, 5))
  450. refBox = wx.BoxSizer(wx.HORIZONTAL)
  451. self.refererBox = wx.TextCtrl(self)
  452. refBox.Add(self.refererBox, 1, flag = wx.LEFT, border=10)
  453. mainBoxSizer.Add(refBox, flag = wx.EXPAND | wx.RIGHT, border=200)
  454. prxyText = wx.BoxSizer(wx.HORIZONTAL)
  455. prxyText.Add(wx.StaticText(self, label='Proxy'), flag = wx.LEFT, border=15)
  456. mainBoxSizer.Add(prxyText, flag = wx.TOP, border=10)
  457. mainBoxSizer.Add((-1, 5))
  458. prxyBox = wx.BoxSizer(wx.HORIZONTAL)
  459. self.proxyBox = wx.TextCtrl(self)
  460. prxyBox.Add(self.proxyBox, 1, flag = wx.LEFT, border=10)
  461. mainBoxSizer.Add(prxyBox, flag = wx.EXPAND | wx.RIGHT, border=100)
  462. self.SetSizer(mainBoxSizer)
  463. def load_options(self):
  464. self.userAgentBox.SetValue(self.optList.userAgent)
  465. self.refererBox.SetValue(self.optList.referer)
  466. self.proxyBox.SetValue(self.optList.proxy)
  467. self.retriesSpnr.SetValue(self.optList.retries)
  468. def save_options(self):
  469. self.optList.userAgent = self.userAgentBox.GetValue()
  470. self.optList.referer = self.refererBox.GetValue()
  471. self.optList.proxy = self.proxyBox.GetValue()
  472. self.optList.retries = self.retriesSpnr.GetValue()
  473. class AuthenticationPanel(wx.Panel):
  474. def __init__(self, parent, optList):
  475. wx.Panel.__init__(self,parent)
  476. self.optList = optList
  477. mainBoxSizer = wx.BoxSizer(wx.VERTICAL)
  478. usrTextBox = wx.BoxSizer(wx.HORIZONTAL)
  479. usrTextBox.Add(wx.StaticText(self, label='Username'))
  480. mainBoxSizer.Add(usrTextBox, flag = wx.ALIGN_CENTER_HORIZONTAL | wx.TOP, border=15)
  481. usrBox = wx.BoxSizer(wx.HORIZONTAL)
  482. self.usernameBox = wx.TextCtrl(self, size=(-1, 25))
  483. usrBox.Add(self.usernameBox, 1, flag = wx.TOP, border=5)
  484. mainBoxSizer.Add(usrBox, flag = wx.EXPAND | wx.LEFT | wx.RIGHT, border=160)
  485. passTextBox = wx.BoxSizer(wx.HORIZONTAL)
  486. passTextBox.Add(wx.StaticText(self, label='Password'))
  487. mainBoxSizer.Add(passTextBox, flag = wx.ALIGN_CENTER_HORIZONTAL | wx.TOP, border=15)
  488. passBox = wx.BoxSizer(wx.HORIZONTAL)
  489. self.passwordBox = wx.TextCtrl(self, size=(-1, 25), style = wx.TE_PASSWORD)
  490. passBox.Add(self.passwordBox, 1, flag = wx.TOP, border=5)
  491. mainBoxSizer.Add(passBox, flag = wx.EXPAND | wx.LEFT | wx.RIGHT, border=160)
  492. vPassTextBox = wx.BoxSizer(wx.HORIZONTAL)
  493. vPassTextBox.Add(wx.StaticText(self, label='Video Password (vimeo, smotri)'))
  494. mainBoxSizer.Add(vPassTextBox, flag = wx.ALIGN_CENTER_HORIZONTAL | wx.TOP, border=15)
  495. vPassBox = wx.BoxSizer(wx.HORIZONTAL)
  496. self.videopassBox = wx.TextCtrl(self, size=(-1, 25), style = wx.TE_PASSWORD)
  497. vPassBox.Add(self.videopassBox, 1, flag = wx.TOP, border=5)
  498. mainBoxSizer.Add(vPassBox, flag = wx.EXPAND | wx.LEFT | wx.RIGHT, border=160)
  499. self.SetSizer(mainBoxSizer)
  500. def load_options(self):
  501. self.usernameBox.SetValue(self.optList.username)
  502. self.passwordBox.SetValue(self.optList.password)
  503. self.videopassBox.SetValue(self.optList.videoPass)
  504. def save_options(self):
  505. self.optList.username = self.usernameBox.GetValue()
  506. self.optList.password = self.passwordBox.GetValue()
  507. self.optList.videoPass = self.videopassBox.GetValue()
  508. class AudioPanel(wx.Panel):
  509. win_box_border = 0
  510. quality = ['high', 'mid', 'low']
  511. def __init__(self, parent, optList):
  512. wx.Panel.__init__(self, parent)
  513. self.SetBoxBorder()
  514. self.optList = optList
  515. mainBoxSizer = wx.BoxSizer(wx.VERTICAL)
  516. toaBox = wx.BoxSizer(wx.HORIZONTAL)
  517. self.toAudioChk = wx.CheckBox(self, label='Convert to Audio')
  518. toaBox.Add(self.toAudioChk)
  519. mainBoxSizer.Add(toaBox, flag = wx.ALIGN_CENTER_HORIZONTAL | wx.TOP, border=15+self.win_box_border)
  520. keepVBox = wx.BoxSizer(wx.HORIZONTAL)
  521. self.keepVideoChk = wx.CheckBox(self, label='Keep Video')
  522. keepVBox.Add(self.keepVideoChk)
  523. mainBoxSizer.Add(keepVBox, flag = wx.ALIGN_CENTER_HORIZONTAL | wx.TOP, border=5+self.win_box_border)
  524. afTextBox = wx.BoxSizer(wx.HORIZONTAL)
  525. afTextBox.Add(wx.StaticText(self, label='Audio Format'))
  526. mainBoxSizer.Add(afTextBox, flag = wx.ALIGN_CENTER_HORIZONTAL | wx.TOP, border=10)
  527. afComboBox = wx.BoxSizer(wx.HORIZONTAL)
  528. self.audioFormatCombo = wx.ComboBox(self, choices=AUDIOFORMATS, size=(160, 30))
  529. afComboBox.Add(self.audioFormatCombo)
  530. mainBoxSizer.Add(afComboBox, flag = wx.ALIGN_CENTER_HORIZONTAL | wx.TOP, border=5)
  531. aqTextBox = wx.BoxSizer(wx.HORIZONTAL)
  532. aqTextBox.Add(wx.StaticText(self, label='Audio Quality'))
  533. mainBoxSizer.Add(aqTextBox, flag = wx.ALIGN_CENTER_HORIZONTAL | wx.TOP, border=10)
  534. aqComboBox = wx.BoxSizer(wx.HORIZONTAL)
  535. self.audioQualityCombo = wx.ComboBox(self, choices=self.quality, size=(80, 25))
  536. aqComboBox.Add(self.audioQualityCombo)
  537. mainBoxSizer.Add(aqComboBox, flag = wx.ALIGN_CENTER_HORIZONTAL | wx.TOP, border=5)
  538. self.SetSizer(mainBoxSizer)
  539. self.Bind(wx.EVT_CHECKBOX, self.OnAudioCheck, self.toAudioChk)
  540. def SetBoxBorder(self):
  541. ''' Set border for windows '''
  542. if get_os_type() == 'nt':
  543. self.win_box_border = 5
  544. def OnAudioCheck(self, event):
  545. if self.toAudioChk.GetValue():
  546. self.keepVideoChk.Enable()
  547. self.audioFormatCombo.Enable()
  548. self.audioQualityCombo.Enable()
  549. else:
  550. self.keepVideoChk.Disable()
  551. self.audioFormatCombo.Disable()
  552. self.audioQualityCombo.Disable()
  553. def load_options(self):
  554. self.toAudioChk.SetValue(self.optList.toAudio)
  555. self.keepVideoChk.SetValue(self.optList.keepVideo)
  556. self.audioFormatCombo.SetValue(self.optList.audioFormat)
  557. self.audioQualityCombo.SetValue(self.optList.audioQuality)
  558. if self.optList.toAudio == False:
  559. self.keepVideoChk.Disable()
  560. self.audioFormatCombo.Disable()
  561. self.audioQualityCombo.Disable()
  562. def save_options(self):
  563. self.optList.toAudio = self.toAudioChk.GetValue()
  564. self.optList.keepVideo = self.keepVideoChk.GetValue()
  565. self.optList.audioFormat = self.audioFormatCombo.GetValue()
  566. self.optList.audioQuality = self.audioQualityCombo.GetValue()
  567. class VideoPanel(wx.Panel):
  568. def __init__(self, parent, optList):
  569. wx.Panel.__init__(self, parent)
  570. self.optList = optList
  571. mainBoxSizer = wx.BoxSizer(wx.VERTICAL)
  572. vfTextBox = wx.BoxSizer(wx.HORIZONTAL)
  573. vfTextBox.Add(wx.StaticText(self, label='Video Format'))
  574. mainBoxSizer.Add(vfTextBox, flag = wx.ALIGN_CENTER_HORIZONTAL | wx.TOP, border=20)
  575. vfComboBox = wx.BoxSizer(wx.HORIZONTAL)
  576. self.videoFormatCombo = wx.ComboBox(self, choices=VIDEOFORMATS, size=(160, 30))
  577. vfComboBox.Add(self.videoFormatCombo)
  578. mainBoxSizer.Add(vfComboBox, flag = wx.ALIGN_CENTER_HORIZONTAL | wx.TOP, border=5)
  579. daTextBox = wx.BoxSizer(wx.HORIZONTAL)
  580. daTextBox.Add(wx.StaticText(self, label='DASH Audio'))
  581. mainBoxSizer.Add(daTextBox, flag = wx.ALIGN_CENTER_HORIZONTAL | wx.TOP, border=10)
  582. daComboBox = wx.BoxSizer(wx.HORIZONTAL)
  583. self.dashAudioFormatCombo = wx.ComboBox(self, choices=DASH_AUDIO_FORMATS, size=(160, 30))
  584. daComboBox.Add(self.dashAudioFormatCombo)
  585. mainBoxSizer.Add(daComboBox, flag = wx.ALIGN_CENTER_HORIZONTAL | wx.TOP, border=5)
  586. clrDashBox = wx.BoxSizer(wx.HORIZONTAL)
  587. self.clearDashFilesChk = wx.CheckBox(self, label='Clear DASH audio/video files')
  588. clrDashBox.Add(self.clearDashFilesChk)
  589. mainBoxSizer.Add(clrDashBox, flag = wx.ALIGN_CENTER_HORIZONTAL | wx.TOP, border=20)
  590. self.SetSizer(mainBoxSizer)
  591. self.Bind(wx.EVT_COMBOBOX, self.OnVideoFormatPick, self.videoFormatCombo)
  592. self.Bind(wx.EVT_COMBOBOX, self.OnAudioFormatPick, self.dashAudioFormatCombo)
  593. def OnAudioFormatPick(self, event):
  594. if have_dash_audio(self.dashAudioFormatCombo.GetValue()):
  595. self.clearDashFilesChk.Enable()
  596. else:
  597. self.clearDashFilesChk.SetValue(False)
  598. self.clearDashFilesChk.Disable()
  599. def OnVideoFormatPick(self, event):
  600. if video_is_dash(self.videoFormatCombo.GetValue()):
  601. self.dashAudioFormatCombo.Enable()
  602. if have_dash_audio(self.dashAudioFormatCombo.GetValue()):
  603. self.clearDashFilesChk.Enable()
  604. else:
  605. self.clearDashFilesChk.SetValue(False)
  606. self.clearDashFilesChk.Disable()
  607. self.dashAudioFormatCombo.Disable()
  608. def load_options(self):
  609. self.videoFormatCombo.SetValue(self.optList.videoFormat)
  610. self.dashAudioFormatCombo.SetValue(self.optList.dashAudioFormat)
  611. self.clearDashFilesChk.SetValue(self.optList.clearDashFiles)
  612. if not video_is_dash(self.optList.videoFormat):
  613. self.dashAudioFormatCombo.Disable()
  614. if not have_dash_audio(self.optList.dashAudioFormat):
  615. self.clearDashFilesChk.SetValue(False)
  616. self.clearDashFilesChk.Disable()
  617. def save_options(self):
  618. self.optList.videoFormat = self.videoFormatCombo.GetValue()
  619. self.optList.dashAudioFormat = self.dashAudioFormatCombo.GetValue()
  620. self.optList.clearDashFiles = self.clearDashFilesChk.GetValue()
  621. class OutputPanel(wx.Panel):
  622. win_box_border = 0
  623. def __init__(self, parent, optList):
  624. wx.Panel.__init__(self, parent)
  625. self.SetBoxBorder()
  626. self.optList = optList
  627. mainBoxSizer = wx.BoxSizer(wx.VERTICAL)
  628. idBox = wx.BoxSizer(wx.HORIZONTAL)
  629. self.idAsNameChk = wx.CheckBox(self, label='ID as Name')
  630. idBox.Add(self.idAsNameChk, flag = wx.LEFT, border=5)
  631. mainBoxSizer.Add(idBox, flag = wx.TOP, border=15)
  632. titleBox = wx.BoxSizer(wx.HORIZONTAL)
  633. self.titleBoxChk = wx.CheckBox(self, label='Title as Name')
  634. titleBox.Add(self.titleBoxChk, flag = wx.LEFT, border=5)
  635. mainBoxSizer.Add(titleBox, flag = wx.TOP, border=5+self.win_box_border)
  636. customChkBox = wx.BoxSizer(wx.HORIZONTAL)
  637. self.customTitleChk = wx.CheckBox(self, label='Custom Template (youtube-dl)')
  638. customChkBox.Add(self.customTitleChk, flag = wx.LEFT, border=5)
  639. mainBoxSizer.Add(customChkBox, flag = wx.TOP, border=5+self.win_box_border)
  640. mainBoxSizer.Add((-1, 10))
  641. customBox = wx.BoxSizer(wx.HORIZONTAL)
  642. self.customTitleBox = wx.TextCtrl(self)
  643. customBox.Add(self.customTitleBox, 1, flag = wx.RIGHT, border=300)
  644. mainBoxSizer.Add(customBox, flag = wx.EXPAND | wx.LEFT, border=5)
  645. self.SetSizer(mainBoxSizer)
  646. self.Bind(wx.EVT_CHECKBOX, self.OnId, self.idAsNameChk)
  647. self.Bind(wx.EVT_CHECKBOX, self.OnTitle, self.titleBoxChk)
  648. self.Bind(wx.EVT_CHECKBOX, self.OnCustom, self.customTitleChk)
  649. def OnId(self, event):
  650. self.group_load('id')
  651. def OnTitle(self, event):
  652. self.group_load('title')
  653. def OnCustom(self, event):
  654. self.group_load('custom')
  655. def SetBoxBorder(self):
  656. ''' Set border for windows '''
  657. if get_os_type() == 'nt':
  658. self.win_box_border = 10
  659. def group_load(self, oformat):
  660. if oformat == 'id':
  661. self.idAsNameChk.SetValue(True)
  662. self.titleBoxChk.SetValue(False)
  663. self.customTitleChk.SetValue(False)
  664. self.customTitleBox.Disable()
  665. elif oformat == 'title':
  666. self.idAsNameChk.SetValue(False)
  667. self.titleBoxChk.SetValue(True)
  668. self.customTitleChk.SetValue(False)
  669. self.customTitleBox.Disable()
  670. elif oformat == 'custom':
  671. self.idAsNameChk.SetValue(False)
  672. self.titleBoxChk.SetValue(False)
  673. self.customTitleChk.SetValue(True)
  674. self.customTitleBox.Enable()
  675. def get_output_format(self):
  676. if self.idAsNameChk.GetValue():
  677. return 'id'
  678. elif self.titleBoxChk.GetValue():
  679. return 'title'
  680. elif self.customTitleChk.GetValue():
  681. return 'custom'
  682. def load_options(self):
  683. self.group_load(self.optList.outputFormat)
  684. self.customTitleBox.SetValue(self.optList.outputTemplate)
  685. def save_options(self):
  686. self.optList.outputTemplate = self.customTitleBox.GetValue()
  687. self.optList.outputFormat = self.get_output_format()
  688. class FilesystemPanel(wx.Panel):
  689. win_box_border = 0
  690. def __init__(self, parent, optList):
  691. wx.Panel.__init__(self, parent)
  692. self.SetBoxBorder()
  693. self.optList = optList
  694. mainBoxSizer = wx.BoxSizer(wx.HORIZONTAL)
  695. leftBoxSizer = wx.BoxSizer(wx.VERTICAL)
  696. rightBoxSizer = wx.StaticBoxSizer(wx.StaticBox(self, label='Filesize (e.g. 50k or 44.6m)'), wx.VERTICAL)
  697. self.SetLeftBox(leftBoxSizer)
  698. self.SetRightBox(rightBoxSizer)
  699. mainBoxSizer.Add(leftBoxSizer, 1, flag = wx.EXPAND | wx.ALL, border=10)
  700. mainBoxSizer.Add(rightBoxSizer, 1, flag = wx.EXPAND | wx.ALL, border=10)
  701. self.SetSizer(mainBoxSizer)
  702. def SetBoxBorder(self):
  703. ''' Set border for windows '''
  704. if get_os_type() == 'nt':
  705. self.win_box_border = 10
  706. def SetLeftBox(self, box):
  707. ignrBox = wx.BoxSizer(wx.HORIZONTAL)
  708. self.ignoreErrorsChk = wx.CheckBox(self, label='Ignore Errors')
  709. ignrBox.Add(self.ignoreErrorsChk, flag = wx.LEFT, border=5)
  710. box.Add(ignrBox, flag = wx.TOP, border=15)
  711. wrtDescBox = wx.BoxSizer(wx.HORIZONTAL)
  712. self.writeDescriptionChk = wx.CheckBox(self, label='Write description to file')
  713. wrtDescBox.Add(self.writeDescriptionChk, flag = wx.LEFT, border=5)
  714. box.Add(wrtDescBox, flag = wx.TOP, border=5+self.win_box_border)
  715. wrtInfoBox = wx.BoxSizer(wx.HORIZONTAL)
  716. self.writeInfoChk = wx.CheckBox(self, label='Write info to (.json) file')
  717. wrtInfoBox.Add(self.writeInfoChk, flag = wx.LEFT, border=5)
  718. box.Add(wrtInfoBox, flag = wx.TOP, border=5+self.win_box_border)
  719. wrtThumBox = wx.BoxSizer(wx.HORIZONTAL)
  720. self.writeThumbnailChk = wx.CheckBox(self, label='Write thumbnail to disk')
  721. wrtThumBox.Add(self.writeThumbnailChk, flag = wx.LEFT, border=5)
  722. box.Add(wrtThumBox, flag = wx.TOP, border=5+self.win_box_border)
  723. openDirBox = wx.BoxSizer(wx.HORIZONTAL)
  724. self.openDirChk = wx.CheckBox(self, label='Open destination folder when done')
  725. openDirBox.Add(self.openDirChk, flag = wx.LEFT, border=5)
  726. box.Add(openDirBox, flag = wx.TOP, border=5+self.win_box_border)
  727. def SetRightBox(self, box):
  728. minBox = wx.BoxSizer(wx.HORIZONTAL)
  729. minBox.Add(wx.StaticText(self, label='Min'), flag = wx.RIGHT, border=12)
  730. self.minFilesizeBox = wx.TextCtrl(self, size=(80, -1))
  731. minBox.Add(self.minFilesizeBox)
  732. box.Add(minBox, flag = wx.TOP | wx.ALIGN_CENTER_HORIZONTAL, border=10)
  733. maxBox = wx.BoxSizer(wx.HORIZONTAL)
  734. maxBox.Add(wx.StaticText(self, label='Max'), flag = wx.RIGHT, border=8)
  735. self.maxFilesizeBox = wx.TextCtrl(self, size=(80, -1))
  736. maxBox.Add(self.maxFilesizeBox)
  737. box.Add(maxBox, flag = wx.TOP | wx.ALIGN_CENTER_HORIZONTAL, border=10)
  738. def load_options(self):
  739. self.writeDescriptionChk.SetValue(self.optList.writeDescription)
  740. self.writeInfoChk.SetValue(self.optList.writeInfo)
  741. self.writeThumbnailChk.SetValue(self.optList.writeThumbnail)
  742. self.ignoreErrorsChk.SetValue(self.optList.ignoreErrors)
  743. self.openDirChk.SetValue(self.optList.openDownloadDir)
  744. self.minFilesizeBox.SetValue(self.optList.minFileSize)
  745. self.maxFilesizeBox.SetValue(self.optList.maxFileSize)
  746. def save_options(self):
  747. self.optList.writeDescription = self.writeDescriptionChk.GetValue()
  748. self.optList.writeInfo = self.writeInfoChk.GetValue()
  749. self.optList.writeThumbnail = self.writeThumbnailChk.GetValue()
  750. self.optList.ignoreErrors = self.ignoreErrorsChk.GetValue()
  751. self.optList.openDownloadDir = self.openDirChk.GetValue()
  752. self.optList.minFileSize = self.minFilesizeBox.GetValue()
  753. self.optList.maxFileSize = self.maxFilesizeBox.GetValue()
  754. self.check_input()
  755. def check_input(self):
  756. self.optList.minFileSize.replace('-', '')
  757. self.optList.maxFileSize.replace('-', '')
  758. if self.optList.minFileSize == '':
  759. self.optList.minFileSize = '0'
  760. if self.optList.maxFileSize == '':
  761. self.optList.maxFileSize = '0'
  762. class SubtitlesPanel(wx.Panel):
  763. win_box_border = 0
  764. def __init__(self, parent, optList):
  765. wx.Panel.__init__(self, parent)
  766. self.SetBoxBorder()
  767. self.optList = optList
  768. mainBoxSizer = wx.BoxSizer(wx.VERTICAL)
  769. dlSubsBox = wx.BoxSizer(wx.HORIZONTAL)
  770. self.writeSubsChk = wx.CheckBox(self, label='Download subtitle file by language')
  771. dlSubsBox.Add(self.writeSubsChk, flag = wx.LEFT, border=10)
  772. mainBoxSizer.Add(dlSubsBox, flag = wx.TOP, border=15)
  773. dlAllSubBox = wx.BoxSizer(wx.HORIZONTAL)
  774. self.writeAllSubsChk = wx.CheckBox(self, label='Download all available subtitles')
  775. dlAllSubBox.Add(self.writeAllSubsChk, flag = wx.LEFT, border=10)
  776. mainBoxSizer.Add(dlAllSubBox, flag = wx.TOP, border=5+self.win_box_border)
  777. dlAutoSubBox = wx.BoxSizer(wx.HORIZONTAL)
  778. self.writeAutoSubsChk = wx.CheckBox(self, label='Download automatic subtitle file (YOUTUBE ONLY)')
  779. dlAutoSubBox.Add(self.writeAutoSubsChk, flag = wx.LEFT, border=10)
  780. mainBoxSizer.Add(dlAutoSubBox, flag = wx.TOP, border=5+self.win_box_border)
  781. embSubBox = wx.BoxSizer(wx.HORIZONTAL)
  782. self.embedSubsChk = wx.CheckBox(self, label='Embed subtitles in the video (only for mp4 videos)')
  783. self.embedSubsChk.Disable()
  784. embSubBox.Add(self.embedSubsChk, flag = wx.LEFT, border=10)
  785. mainBoxSizer.Add(embSubBox, flag = wx.TOP, border=5+self.win_box_border)
  786. slangTextBox = wx.BoxSizer(wx.HORIZONTAL)
  787. slangTextBox.Add(wx.StaticText(self, label='Subtitles Language'), flag = wx.LEFT, border=15)
  788. mainBoxSizer.Add(slangTextBox, flag = wx.TOP, border=10+self.win_box_border)
  789. slangBox = wx.BoxSizer(wx.HORIZONTAL)
  790. self.subsLangCombo = wx.ComboBox(self, choices=LANGUAGES, size=(140, 30))
  791. slangBox.Add(self.subsLangCombo, flag = wx.LEFT, border=10)
  792. mainBoxSizer.Add(slangBox, flag = wx.TOP, border=5)
  793. self.SetSizer(mainBoxSizer)
  794. self.Bind(wx.EVT_CHECKBOX, self.OnWriteSubsChk, self.writeSubsChk)
  795. self.Bind(wx.EVT_CHECKBOX, self.OnWriteAllSubsChk, self.writeAllSubsChk)
  796. self.Bind(wx.EVT_CHECKBOX, self.OnWriteAutoSubsChk, self.writeAutoSubsChk)
  797. def SetBoxBorder(self):
  798. ''' Set border for windows '''
  799. if get_os_type() == 'nt':
  800. self.win_box_border = 5
  801. def subs_are_on(self):
  802. return self.writeAutoSubsChk.GetValue() or self.writeSubsChk.GetValue()
  803. def OnWriteAutoSubsChk(self, event):
  804. if self.writeAutoSubsChk.GetValue():
  805. self.writeAllSubsChk.Disable()
  806. self.writeSubsChk.Disable()
  807. self.subsLangCombo.Disable()
  808. self.embedSubsChk.Enable()
  809. else:
  810. self.writeAllSubsChk.Enable()
  811. self.writeSubsChk.Enable()
  812. self.subsLangCombo.Enable()
  813. self.embedSubsChk.Disable()
  814. self.embedSubsChk.SetValue(False)
  815. def OnWriteSubsChk(self, event):
  816. if self.writeSubsChk.GetValue():
  817. self.writeAllSubsChk.Disable()
  818. self.writeAutoSubsChk.Disable()
  819. self.embedSubsChk.Enable()
  820. else:
  821. self.writeAllSubsChk.Enable()
  822. self.writeAutoSubsChk.Enable()
  823. self.embedSubsChk.Disable()
  824. self.embedSubsChk.SetValue(False)
  825. def OnWriteAllSubsChk(self, event):
  826. if self.writeAllSubsChk.GetValue():
  827. self.writeSubsChk.Disable()
  828. self.subsLangCombo.Disable()
  829. self.writeAutoSubsChk.Disable()
  830. else:
  831. self.writeSubsChk.Enable()
  832. self.subsLangCombo.Enable()
  833. self.writeAutoSubsChk.Enable()
  834. def load_options(self):
  835. self.writeSubsChk.Enable()
  836. self.subsLangCombo.Enable()
  837. self.writeAllSubsChk.Enable()
  838. self.writeAutoSubsChk.Enable()
  839. self.writeSubsChk.SetValue(self.optList.writeSubs)
  840. self.writeAllSubsChk.SetValue(self.optList.writeAllSubs)
  841. self.subsLangCombo.SetValue(self.optList.subsLang)
  842. self.writeAutoSubsChk.SetValue(self.optList.writeAutoSubs)
  843. self.embedSubsChk.SetValue(self.optList.embedSubs)
  844. if self.optList.writeSubs:
  845. self.writeAllSubsChk.Disable()
  846. self.writeAutoSubsChk.Disable()
  847. self.embedSubsChk.Enable()
  848. if self.optList.writeAllSubs:
  849. self.writeSubsChk.Disable()
  850. self.subsLangCombo.Disable()
  851. self.writeAutoSubsChk.Disable()
  852. if self.optList.writeAutoSubs:
  853. self.writeAllSubsChk.Disable()
  854. self.writeSubsChk.Disable()
  855. self.subsLangCombo.Disable()
  856. self.embedSubsChk.Enable()
  857. if not self.subs_are_on():
  858. self.embedSubsChk.Disable()
  859. def save_options(self):
  860. self.optList.writeSubs = self.writeSubsChk.GetValue()
  861. self.optList.writeAllSubs = self.writeAllSubsChk.GetValue()
  862. self.optList.subsLang = self.subsLangCombo.GetValue()
  863. self.optList.writeAutoSubs = self.writeAutoSubsChk.GetValue()
  864. self.optList.embedSubs = self.embedSubsChk.GetValue()
  865. class GeneralPanel(wx.Panel):
  866. def __init__(self, parent, optList, resetHandler):
  867. wx.Panel.__init__(self, parent)
  868. self.optList = optList
  869. self.resetHandler = resetHandler
  870. mainBoxSizer = wx.BoxSizer(wx.VERTICAL)
  871. svTextBox = wx.BoxSizer(wx.HORIZONTAL)
  872. svTextBox.Add(wx.StaticText(self, label='Save Path'))
  873. mainBoxSizer.Add(svTextBox, flag = wx.ALIGN_CENTER_HORIZONTAL | wx.TOP, border=20)
  874. svPathBox = wx.BoxSizer(wx.HORIZONTAL)
  875. self.savePathBox = wx.TextCtrl(self)
  876. svPathBox.Add(self.savePathBox, 1, flag = wx.TOP, border=10)
  877. mainBoxSizer.Add(svPathBox, flag = wx.EXPAND | wx.LEFT | wx.RIGHT, border=40)
  878. buttonsBox = wx.BoxSizer(wx.HORIZONTAL)
  879. self.aboutButton = wx.Button(self, label='About', size=(110, 40))
  880. buttonsBox.Add(self.aboutButton)
  881. self.openButton = wx.Button(self, label='Open', size=(110, 40))
  882. buttonsBox.Add(self.openButton, flag = wx.LEFT | wx.RIGHT, border=50)
  883. self.resetButton = wx.Button(self, label='Reset Options', size=(110, 40))
  884. buttonsBox.Add(self.resetButton)
  885. mainBoxSizer.Add(buttonsBox, flag = wx.ALIGN_CENTER_HORIZONTAL | wx.TOP, border=20)
  886. setngsBox = wx.BoxSizer(wx.HORIZONTAL)
  887. text = 'Settings: ' + self.optList.settings_abs_path
  888. setngsBox.Add(wx.StaticText(self, label=text), flag = wx.TOP, border=30)
  889. mainBoxSizer.Add(setngsBox, flag = wx.ALIGN_CENTER_HORIZONTAL)
  890. self.SetSizer(mainBoxSizer)
  891. self.Bind(wx.EVT_BUTTON, self.OnAbout, self.aboutButton)
  892. self.Bind(wx.EVT_BUTTON, self.OnOpen, self.openButton)
  893. self.Bind(wx.EVT_BUTTON, self.OnReset, self.resetButton)
  894. def OnReset(self, event):
  895. self.resetHandler()
  896. def OnOpen(self, event):
  897. dlg = wx.DirDialog(None, "Choose directory")
  898. if dlg.ShowModal() == wx.ID_OK:
  899. self.savePathBox.SetValue(dlg.GetPath())
  900. dlg.Destroy()
  901. def OnAbout(self, event):
  902. description = '''A cross platform front-end GUI of
  903. the popular youtube-dl written in Python.'''
  904. license = '''This is free and unencumbered software released into the public domain.
  905. Anyone is free to copy, modify, publish, use, compile, sell, or
  906. distribute this software, either in source code form or as a compiled
  907. binary, for any purpose, commercial or non-commercial, and by any
  908. means.
  909. In jurisdictions that recognize copyright laws, the author or authors
  910. of this software dedicate any and all copyright interest in the
  911. software to the public domain. We make this dedication for the benefit
  912. of the public at large and to the detriment of our heirs and
  913. successors. We intend this dedication to be an overt act of
  914. relinquishment in perpetuity of all present and future rights to this
  915. software under copyright law.
  916. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  917. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  918. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  919. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  920. OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  921. ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  922. OTHER DEALINGS IN THE SOFTWARE.
  923. For more information, please refer to <http://unlicense.org/>'''
  924. info = wx.AboutDialogInfo()
  925. info.SetIcon(wx.Icon(ICON, wx.BITMAP_TYPE_ICO))
  926. info.SetName(TITLE)
  927. info.SetVersion(__version__)
  928. info.SetDescription(description)
  929. info.SetWebSite('http://mrs0m30n3.github.io/youtube-dl-gui/')
  930. info.SetLicense(license)
  931. info.AddDeveloper('Sotiris Papadopoulos')
  932. wx.AboutBox(info)
  933. def load_options(self):
  934. self.savePathBox.SetValue(self.optList.savePath)
  935. def save_options(self):
  936. self.optList.savePath = abs_path(self.savePathBox.GetValue())
  937. class OtherPanel(wx.Panel):
  938. def __init__(self, parent, optList):
  939. wx.Panel.__init__(self, parent)
  940. self.optList = optList
  941. mainBoxSizer = wx.BoxSizer(wx.VERTICAL)
  942. textBox = wx.BoxSizer(wx.HORIZONTAL)
  943. textBox.Add(wx.StaticText(self, label='Command line arguments (e.g. --help)'), flag = wx.TOP, border=30)
  944. mainBoxSizer.Add(textBox, flag = wx.LEFT, border=50)
  945. inputBox = wx.BoxSizer(wx.HORIZONTAL)
  946. self.cmdArgsBox = wx.TextCtrl(self)
  947. inputBox.Add(self.cmdArgsBox, 1, flag = wx.TOP, border=10)
  948. mainBoxSizer.Add(inputBox, flag = wx.EXPAND | wx.LEFT | wx.RIGHT, border=50)
  949. self.SetSizer(mainBoxSizer)
  950. def load_options(self):
  951. self.cmdArgsBox.SetValue(self.optList.cmdArgs)
  952. def save_options(self):
  953. self.optList.cmdArgs = self.cmdArgsBox.GetValue()
  954. class OptionsFrame(wx.Frame):
  955. def __init__(self, optionsList, parent=None, id=-1, logger=None):
  956. wx.Frame.__init__(self, parent, id, "Options", size=self.SetFrameSizer())
  957. self.optionsList = optionsList
  958. panel = wx.Panel(self)
  959. notebook = wx.Notebook(panel)
  960. self.generalTab = GeneralPanel(notebook, self.optionsList, self.reset)
  961. self.audioTab = AudioPanel(notebook, self.optionsList)
  962. self.connectionTab = ConnectionPanel(notebook, self.optionsList)
  963. self.videoTab = VideoPanel(notebook, self.optionsList)
  964. self.filesysTab = FilesystemPanel(notebook, self.optionsList)
  965. self.subtitlesTab = SubtitlesPanel(notebook, self.optionsList)
  966. self.otherTab = OtherPanel(notebook, self.optionsList)
  967. self.updateTab = UpdatePanel(notebook, self.optionsList)
  968. self.authTab = AuthenticationPanel(notebook, self.optionsList)
  969. self.videoselTab = PlaylistPanel(notebook, self.optionsList)
  970. self.logTab = LogPanel(notebook, self.optionsList, logger)
  971. self.outputTab = OutputPanel(notebook, self.optionsList)
  972. notebook.AddPage(self.generalTab, "General")
  973. notebook.AddPage(self.videoTab, "Video")
  974. notebook.AddPage(self.audioTab, "Audio")
  975. notebook.AddPage(self.outputTab, "Output")
  976. notebook.AddPage(self.videoselTab, "Playlist")
  977. notebook.AddPage(self.subtitlesTab, "Subtitles")
  978. notebook.AddPage(self.filesysTab, "Filesystem")
  979. notebook.AddPage(self.connectionTab, "Connection")
  980. notebook.AddPage(self.authTab, "Authentication")
  981. notebook.AddPage(self.updateTab, "Update")
  982. notebook.AddPage(self.logTab, "Log")
  983. notebook.AddPage(self.otherTab, "Commands")
  984. sizer = wx.BoxSizer()
  985. sizer.Add(notebook, 1, wx.EXPAND)
  986. panel.SetSizer(sizer)
  987. self.Bind(wx.EVT_CLOSE, self.OnClose)
  988. self.load_all_options()
  989. def SetFrameSizer(self):
  990. if get_os_type() == 'nt':
  991. return (580, 270)
  992. else:
  993. return (580, 250)
  994. def OnClose(self, event):
  995. self.save_all_options()
  996. if not file_exist(fix_path(self.optionsList.updatePath)+YOUTUBE_DL_FILENAME):
  997. self.wrong_youtubedl_path()
  998. self.Destroy()
  999. def wrong_youtubedl_path(self):
  1000. text = '''The path under Options>Update is invalid
  1001. please do one of the following:
  1002. *) restart youtube-dlG
  1003. *) click the update button
  1004. *) change the path to point where youtube-dl is'''
  1005. wx.MessageBox(text, 'Error', wx.OK | wx.ICON_EXCLAMATION)
  1006. def reset(self):
  1007. self.optionsList.load_default()
  1008. self.load_all_options()
  1009. def load_all_options(self):
  1010. self.generalTab.load_options()
  1011. self.audioTab.load_options()
  1012. self.connectionTab.load_options()
  1013. self.videoTab.load_options()
  1014. self.filesysTab.load_options()
  1015. self.subtitlesTab.load_options()
  1016. self.otherTab.load_options()
  1017. self.updateTab.load_options()
  1018. self.authTab.load_options()
  1019. self.videoselTab.load_options()
  1020. self.logTab.load_options()
  1021. self.outputTab.load_options()
  1022. def save_all_options(self):
  1023. self.generalTab.save_options()
  1024. self.audioTab.save_options()
  1025. self.connectionTab.save_options()
  1026. self.videoTab.save_options()
  1027. self.filesysTab.save_options()
  1028. self.subtitlesTab.save_options()
  1029. self.otherTab.save_options()
  1030. self.updateTab.save_options()
  1031. self.authTab.save_options()
  1032. self.videoselTab.save_options()
  1033. self.logTab.save_options()
  1034. self.outputTab.save_options()