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.

1183 lines
42 KiB

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