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.

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