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.

755 lines
27 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
  1. #! /usr/bin/env python
  2. '''
  3. This file contains all gui classes
  4. MainFrame
  5. Custom wx.ListCtrl class
  6. UpdateDialog
  7. OptionsFrame
  8. ConnectionPanel
  9. AudioPanel
  10. videoPanel
  11. DownloadPanel
  12. SubtitlesPanel
  13. GeneralPanel
  14. OtherPanel
  15. '''
  16. import wx
  17. from wx.lib.pubsub import setuparg1
  18. from wx.lib.pubsub import pub as Publisher
  19. from .version import __version__
  20. from .UpdateThread import UpdateThread
  21. from .DownloadThread import DownloadManager
  22. from .OptionsHandler import OptionsHandler
  23. from .YoutubeDLInterpreter import YoutubeDLInterpreter
  24. from .SignalHandler import DownloadHandler
  25. from .Utils import (
  26. video_is_dash,
  27. have_dash_audio,
  28. add_PATH,
  29. get_HOME,
  30. get_os_type,
  31. file_exist,
  32. fix_path,
  33. get_abs_path
  34. )
  35. if get_os_type() == 'nt':
  36. YOUTUBE_DL_FILENAME = 'youtube-dl.exe'
  37. else:
  38. YOUTUBE_DL_FILENAME = 'youtube-dl'
  39. TITLE = 'Youtube-dlG'
  40. AUDIOFORMATS = ["mp3", "wav", "aac", "m4a"]
  41. VIDEOFORMATS = ["highest available",
  42. "mp4 [1280x720]",
  43. "mp4 [640x360]",
  44. "webm [640x360]",
  45. "flv [400x240]",
  46. "3gp [320x240]",
  47. "mp4 1080p(DASH)",
  48. "mp4 720p(DASH)",
  49. "mp4 480p(DASH)",
  50. "mp4 360p(DASH)"]
  51. DASH_AUDIO_FORMATS = ["NO SOUND",
  52. "DASH m4a audio 128k",
  53. "DASH webm audio 48k"]
  54. LANGUAGES = ["English",
  55. "Greek",
  56. "Portuguese",
  57. "French",
  58. "Italian",
  59. "Russian",
  60. "Spanish",
  61. "German"]
  62. class MainFrame(wx.Frame):
  63. def __init__(self, parent=None, id=-1):
  64. wx.Frame.__init__(self, parent, id, TITLE+' '+__version__, size=(600, 410), style = wx.DEFAULT_FRAME_STYLE ^ wx.RESIZE_BORDER)
  65. # set sizers for status box (Windows & Linux)
  66. if get_os_type() == 'nt':
  67. statusListSizer = (580, 165)
  68. statusBarSizer = (15, 365)
  69. else:
  70. statusListSizer = (580, 195)
  71. statusBarSizer = (15, 390)
  72. # create panel, trackList, statusBox using global statusBoxSizer
  73. self.panel = wx.Panel(self)
  74. wx.StaticText(self.panel, -1, "URLs", (15, 10))
  75. self.trackList = wx.TextCtrl(self.panel, -1, pos=(10, 25), size=(580, 110), style = wx.TE_MULTILINE | wx.TE_DONTWRAP)
  76. self.statusList = ListCtrl(self.panel, -1, pos=(10, 190), size=statusListSizer, style = wx.LC_REPORT | wx.LC_HRULES | wx.LC_VRULES)
  77. self.statusBar = wx.StaticText(self.panel, -1, 'Author: Sotiris Papadopoulos', pos=statusBarSizer)
  78. # create buttons
  79. self.downloadButton = wx.Button(self.panel, label="Download", pos=(100, 145), size=(-1, 30))
  80. self.updateButton = wx.Button(self.panel, label="Update", pos=(250, 145), size=(-1, 30))
  81. self.optionsButton = wx.Button(self.panel, label="Options", pos=(390, 145), size=(-1, 30))
  82. # bind events
  83. self.Bind(wx.EVT_BUTTON, self.OnDownload, self.downloadButton)
  84. self.Bind(wx.EVT_BUTTON, self.OnUpdate, self.updateButton)
  85. self.Bind(wx.EVT_BUTTON, self.OnOptions, self.optionsButton)
  86. self.Bind(wx.EVT_TEXT, self.OnTrackListChange, self.trackList)
  87. self.Bind(wx.EVT_CLOSE, self.OnClose)
  88. # set app icon
  89. icon = wx.Icon('../icons/ytube.png', wx.BITMAP_TYPE_ICO)
  90. self.SetIcon(icon)
  91. # set publisher for update thread
  92. Publisher.subscribe(self.update_handler, "update")
  93. # set publisher for download thread
  94. Publisher.subscribe(self.download_handler, "download")
  95. # init Options and DownloadHandler objects
  96. self.optionsList = OptionsHandler(self.status_bar_write)
  97. self.downloadHandler = None
  98. # init some thread variables
  99. self.downloadThread = None
  100. self.updateThread = None
  101. # init urlList for evt_text on self.trackList
  102. self.urlList = []
  103. # fix update path
  104. self.check_update_path()
  105. # check & update libraries (youtube-dl)
  106. self.check_if_youtube_dl_exist()
  107. if (self.optionsList.autoUpdate):
  108. self.status_bar_write("Auto update enable")
  109. self.update_youtube_dl()
  110. def check_update_path(self):
  111. if self.optionsList.updatePath == '':
  112. self.pop_update_dialog()
  113. if self.optionsList.updatePath == '':
  114. self.optionsList.updatePath = get_HOME()
  115. self.optionsList.updatePath = get_abs_path(self.optionsList.updatePath)
  116. if get_os_type() == 'nt':
  117. add_PATH(self.optionsList.updatePath)
  118. def pop_update_dialog(self):
  119. upDialog = UpdateDialog(self.optionsList)
  120. upDialog.ShowModal()
  121. upDialog.Destroy()
  122. def check_if_youtube_dl_exist(self):
  123. path = fix_path(self.optionsList.updatePath)+YOUTUBE_DL_FILENAME
  124. if not file_exist(path):
  125. self.status_bar_write("Youtube-dl is missing, trying to download it...")
  126. self.update_youtube_dl()
  127. def update_youtube_dl(self):
  128. self.downloadButton.Disable()
  129. self.updateThread = UpdateThread(YOUTUBE_DL_FILENAME, self.optionsList.updatePath)
  130. def status_bar_write(self, msg):
  131. self.statusBar.SetLabel(msg)
  132. def download_handler(self, msg):
  133. self.downloadHandler.handle(msg)
  134. if self.downloadHandler._has_closed():
  135. self.status_bar_write('Stoping downloads')
  136. if self.downloadHandler._has_finished():
  137. self.finished_popup()
  138. self.status_bar_write('Done')
  139. self.downloadButton.SetLabel('Download')
  140. self.updateButton.Enable()
  141. self.downloadThread = None
  142. self.urlList = []
  143. self.downloadHandler = None
  144. def update_handler(self, msg):
  145. if msg.data == 'finish':
  146. self.downloadButton.Enable()
  147. self.updateThread = None
  148. else:
  149. self.status_bar_write(msg.data)
  150. def stop_download(self):
  151. self.downloadThread.close()
  152. self.downloadThread.join()
  153. self.downloadThread = None
  154. self.urlList = []
  155. def start_download(self, trackList):
  156. self.check_update_path()
  157. self.check_if_youtube_dl_exist()
  158. self.statusList._clear_list()
  159. for url in trackList:
  160. if url != '':
  161. self.urlList.append(url)
  162. self.statusList._add_item(url)
  163. if not self.statusList._is_empty():
  164. options = YoutubeDLInterpreter(self.optionsList, YOUTUBE_DL_FILENAME).get_options()
  165. self.status_bar_write('Download started')
  166. self.downloadThread = DownloadManager(
  167. options,
  168. self.statusList._get_items(),
  169. self.optionsList.clearDashFiles
  170. )
  171. self.downloadHandler = DownloadHandler(self.statusList)
  172. self.downloadButton.SetLabel('Stop')
  173. self.updateButton.Disable()
  174. else:
  175. self.no_url_popup()
  176. def save_options(self):
  177. self.optionsList.save_to_file()
  178. def finished_popup(self):
  179. wx.MessageBox('Downloads completed.', 'Info', wx.OK | wx.ICON_INFORMATION)
  180. def no_url_popup(self):
  181. wx.MessageBox('You need to provide at least one url.', 'Error', wx.OK | wx.ICON_EXCLAMATION)
  182. def OnTrackListChange(self, event):
  183. if self.downloadThread != None:
  184. ''' Get current url list from trackList textCtrl '''
  185. curList = self.trackList.GetValue().split('\n')
  186. ''' For each url in current url list '''
  187. for url in curList:
  188. ''' If url is not in self.urlList (original downloads list) and url is not empty '''
  189. if url not in self.urlList and url != '':
  190. ''' Add url into original download list '''
  191. self.urlList.append(url)
  192. ''' Add url into statusList '''
  193. index = self.statusList._add_item(url)
  194. ''' Retrieve last item as {url:url, index:indexNo} '''
  195. item = self.statusList._get_last_item()
  196. ''' Pass that item into downloadThread '''
  197. self.downloadThread.add_download_item(item)
  198. def OnDownload(self, event):
  199. if self.downloadThread != None:
  200. self.stop_download()
  201. else:
  202. self.start_download(self.trackList.GetValue().split('\n'))
  203. def OnUpdate(self, event):
  204. if (self.downloadThread == None and self.updateThread == None):
  205. self.status_bar_write("Updating youtube-dl...")
  206. self.update_youtube_dl()
  207. def OnOptions(self, event):
  208. optionsFrame = OptionsFrame(self.optionsList, self)
  209. optionsFrame.Show()
  210. def OnClose(self, event):
  211. self.save_options()
  212. self.Destroy()
  213. class ListCtrl(wx.ListCtrl):
  214. ''' Custom ListCtrl class '''
  215. def __init__(self, parent, id, pos, size, style):
  216. wx.ListCtrl.__init__(self, parent, id, pos, size, style)
  217. self.InsertColumn(0, 'URL', width=150)
  218. self.InsertColumn(1, 'Size', width=90)
  219. self.InsertColumn(2, 'Percent', width=80)
  220. self.InsertColumn(3, 'ETA', width=50)
  221. self.InsertColumn(4, 'Speed', width=90)
  222. self.InsertColumn(5, 'Status', width=150)
  223. self.ListIndex = 0
  224. ''' Add single item on list '''
  225. def _add_item(self, item):
  226. self.InsertStringItem(self.ListIndex, item)
  227. self.ListIndex += 1
  228. return self.ListIndex
  229. ''' Write data on index, column '''
  230. def _write_data(self, index, column, data):
  231. self.SetStringItem(index, column, data)
  232. ''' Clear list and set index to 0'''
  233. def _clear_list(self):
  234. self.DeleteAllItems()
  235. self.ListIndex = 0
  236. ''' Return True if list is empty '''
  237. def _is_empty(self):
  238. if self.ListIndex == 0:
  239. return True
  240. else:
  241. return False
  242. ''' Get last item inserted, Returns dictionary '''
  243. def _get_last_item(self):
  244. data = {}
  245. last_item = self.GetItem(itemId=self.ListIndex-1, col=0)
  246. data['url'] = last_item.GetText()
  247. data['index'] = self.ListIndex-1
  248. return data
  249. ''' Retrieve all items [start, self.ListIndex), Returns list '''
  250. def _get_items(self, start=0):
  251. items = []
  252. for row in range(start, self.ListIndex):
  253. item = self.GetItem(itemId=row, col=0)
  254. data = {}
  255. data['url'] = item.GetText()
  256. data['index'] = row
  257. items.append(data)
  258. return items
  259. class UpdateDialog(wx.Dialog):
  260. def __init__(self, optionsList, parent=None, id=-1):
  261. wx.Dialog.__init__(self, parent, id, 'Update Path', size=(380, 180))
  262. self.optionsList = optionsList
  263. self.initGUI()
  264. def initGUI(self):
  265. panel = wx.Panel(self)
  266. text = '''Plase enter the path where youtube-dlG
  267. should download latest updates (Default is $HOME)'''
  268. wx.StaticText(panel, -1, text, (15, 10))
  269. wx.StaticText(panel, -1, 'Update Path', (15, 60))
  270. self.updatePathBox = wx.TextCtrl(panel, -1, pos=(10, 80), size=(360, -1))
  271. wx.StaticText(panel, -1, '*** NEED WRITE PERMISSION', (15, 110))
  272. saveButton = wx.Button(panel, label='Save Path', pos=(140, 140))
  273. saveButton.Bind(wx.EVT_BUTTON, self.OnSave)
  274. def OnSave(self, event):
  275. self.setPath()
  276. self.Close(True)
  277. def setPath(self):
  278. self.optionsList.updatePath = self.updatePathBox.GetValue()
  279. class UpdatePanel(wx.Panel):
  280. def __init__(self, parent, optionsList):
  281. self.optionsList = optionsList
  282. wx.Panel.__init__(self, parent)
  283. wx.StaticText(self, -1, 'Update Path (Should point where youtube-dl is)', (25, 20))
  284. self.updatePathBox = wx.TextCtrl(self, -1, pos=(20, 40), size=(450, -1))
  285. self.autoUpdateChk = wx.CheckBox(self, -1, 'Auto Update', (25, 80))
  286. def load_options(self):
  287. self.updatePathBox.SetValue(self.optionsList.updatePath)
  288. self.autoUpdateChk.SetValue(self.optionsList.autoUpdate)
  289. def save_options(self):
  290. self.optionsList.updatePath = self.updatePathBox.GetValue()
  291. self.optionsList.autoUpdate = self.autoUpdateChk.GetValue()
  292. class ConnectionPanel(wx.Panel):
  293. def __init__(self, parent, optList):
  294. self.optList = optList
  295. wx.Panel.__init__(self, parent)
  296. wx.StaticText(self, -1, 'User Agent', (15, 10))
  297. self.userAgentBox = wx.TextCtrl(self, -1, pos=(10, 30), size=(230, -1))
  298. wx.StaticText(self, -1, 'Referer', (270, 10))
  299. self.refererBox = wx.TextCtrl(self, -1, pos=(265, 30), size=(230, -1))
  300. wx.StaticText(self, -1, 'Username', (15, 60))
  301. self.usernameBox = wx.TextCtrl(self, -1, pos=(10, 80), size=(230, -1))
  302. wx.StaticText(self, -1, 'Password', (270, 60))
  303. self.passwordBox = wx.TextCtrl(self, -1, pos=(265, 80), size=(230, -1), style = wx.TE_PASSWORD)
  304. wx.StaticText(self, -1, 'Proxy', (15, 110))
  305. self.proxyBox = wx.TextCtrl(self, -1, pos=(10, 130), size=(350, -1))
  306. def load_options(self):
  307. self.userAgentBox.SetValue(self.optList.userAgent)
  308. self.refererBox.SetValue(self.optList.referer)
  309. self.usernameBox.SetValue(self.optList.username)
  310. self.proxyBox.SetValue(self.optList.proxy)
  311. def save_options(self):
  312. self.optList.userAgent = self.userAgentBox.GetValue()
  313. self.optList.referer = self.refererBox.GetValue()
  314. self.optList.username = self.usernameBox.GetValue()
  315. self.optList.proxy = self.proxyBox.GetValue()
  316. class AudioPanel(wx.Panel):
  317. def __init__(self, parent, optList):
  318. self.optList = optList
  319. wx.Panel.__init__(self, parent)
  320. self.toAudioChk = wx.CheckBox(self, -1, 'Convert to Audio', (10, 10))
  321. self.keepVideoChk = wx.CheckBox(self, -1, 'Keep Video', (30, 40))
  322. wx.StaticText(self, -1, 'Audio Format', (35, 80))
  323. self.audioFormatCombo = wx.ComboBox(self, choices=AUDIOFORMATS, pos=(30, 100), size=(95, -1))
  324. wx.StaticText(self, -1, "Audio Quality 0 (best) 9 (worst)", (35, 130))
  325. self.audioQualitySpnr = wx.SpinCtrl(self, -1, "", (30, 150))
  326. self.audioQualitySpnr.SetRange(0, 9)
  327. self.Bind(wx.EVT_CHECKBOX, self.OnAudioCheck, self.toAudioChk)
  328. def OnAudioCheck(self, event):
  329. if (self.toAudioChk.GetValue()):
  330. self.keepVideoChk.Enable()
  331. self.audioFormatCombo.Enable()
  332. self.audioQualitySpnr.Enable()
  333. else:
  334. self.keepVideoChk.Disable()
  335. self.audioFormatCombo.Disable()
  336. self.audioQualitySpnr.Disable()
  337. def load_options(self):
  338. self.toAudioChk.SetValue(self.optList.toAudio)
  339. self.keepVideoChk.SetValue(self.optList.keepVideo)
  340. self.audioFormatCombo.SetValue(self.optList.audioFormat)
  341. self.audioQualitySpnr.SetValue(self.optList.audioQuality)
  342. if (self.optList.toAudio == False):
  343. self.keepVideoChk.Disable()
  344. self.audioFormatCombo.Disable()
  345. self.audioQualitySpnr.Disable()
  346. def save_options(self):
  347. self.optList.toAudio = self.toAudioChk.GetValue()
  348. self.optList.keepVideo = self.keepVideoChk.GetValue()
  349. self.optList.audioFormat = self.audioFormatCombo.GetValue()
  350. self.optList.audioQuality = self.audioQualitySpnr.GetValue()
  351. class VideoPanel(wx.Panel):
  352. def __init__(self, parent, optList):
  353. self.optList = optList
  354. wx.Panel.__init__(self, parent)
  355. wx.StaticText(self, -1, 'Video Format', (15, 10))
  356. self.videoFormatCombo = wx.ComboBox(self, choices=VIDEOFORMATS, pos=(10, 30), size=(160, 30))
  357. wx.StaticText(self, -1, 'DASH Audio', (15, 100))
  358. self.dashAudioFormatCombo = wx.ComboBox(self, choices=DASH_AUDIO_FORMATS, pos=(10, 120), size=(160, 30))
  359. self.clearDashFilesChk = wx.CheckBox(self, -1, 'Clear DASH audio/video files', (10, 160))
  360. wx.StaticText(self, -1, 'Playlist Options', (350, 30))
  361. wx.StaticText(self, -1, 'Start', (300, 60))
  362. self.startBox = wx.TextCtrl(self, -1, pos=(370, 55), size=(50, -1))
  363. wx.StaticText(self, -1, 'Stop', (300, 100))
  364. self.stopBox = wx.TextCtrl(self, -1, pos=(370, 95), size=(50, -1))
  365. wx.StaticText(self, -1, 'Max DLs', (300, 140))
  366. self.maxBox = wx.TextCtrl(self, -1, pos=(370, 135), size=(50, -1))
  367. self.Bind(wx.EVT_COMBOBOX, self.OnVideoFormatPick, self.videoFormatCombo)
  368. self.Bind(wx.EVT_COMBOBOX, self.OnAudioFormatPick, self.dashAudioFormatCombo)
  369. def OnAudioFormatPick(self, event):
  370. if have_dash_audio(self.dashAudioFormatCombo.GetValue()):
  371. self.clearDashFilesChk.Enable()
  372. else:
  373. self.clearDashFilesChk.SetValue(False)
  374. self.clearDashFilesChk.Disable()
  375. def OnVideoFormatPick(self, event):
  376. if video_is_dash(self.videoFormatCombo.GetValue()):
  377. self.dashAudioFormatCombo.Enable()
  378. if have_dash_audio(self.dashAudioFormatCombo.GetValue()):
  379. self.clearDashFilesChk.Enable()
  380. else:
  381. self.clearDashFilesChk.SetValue(False)
  382. self.clearDashFilesChk.Disable()
  383. self.dashAudioFormatCombo.Disable()
  384. def load_options(self):
  385. self.videoFormatCombo.SetValue(self.optList.videoFormat)
  386. self.startBox.SetValue(self.optList.startTrack)
  387. self.stopBox.SetValue(self.optList.endTrack)
  388. self.maxBox.SetValue(self.optList.maxDownloads)
  389. self.dashAudioFormatCombo.SetValue(self.optList.dashAudioFormat)
  390. self.clearDashFilesChk.SetValue(self.optList.clearDashFiles)
  391. if not video_is_dash(self.optList.videoFormat):
  392. self.dashAudioFormatCombo.Disable()
  393. if not have_dash_audio(self.optList.dashAudioFormat):
  394. self.clearDashFilesChk.SetValue(False)
  395. self.clearDashFilesChk.Disable()
  396. def save_options(self):
  397. self.optList.videoFormat = self.videoFormatCombo.GetValue()
  398. self.optList.startTrack = self.startBox.GetValue()
  399. self.optList.endTrack = self.stopBox.GetValue()
  400. self.optList.maxDownloads = self.maxBox.GetValue()
  401. self.optList.dashAudioFormat = self.dashAudioFormatCombo.GetValue()
  402. self.optList.clearDashFiles = self.clearDashFilesChk.GetValue()
  403. class DownloadPanel(wx.Panel):
  404. def __init__(self, parent, optList):
  405. self.optList = optList
  406. wx.Panel.__init__(self, parent)
  407. wx.StaticText(self, -1, 'Rate Limit (e.g. 50k or 44.6m)', (250, 15))
  408. self.limitBox = wx.TextCtrl(self, -1, pos=(245, 35), size=(80, -1))
  409. wx.StaticText(self, -1, 'Retries', (15, 15))
  410. self.retriesBox = wx.TextCtrl(self, -1, pos=(10, 35), size=(50, -1))
  411. self.writeDescriptionChk = wx.CheckBox(self, -1, 'Write description to file', (10, 60))
  412. self.writeInfoChk = wx.CheckBox(self, -1, 'Write info to (.json) file', (10, 85))
  413. self.writeThumbnailChk = wx.CheckBox(self, -1, 'Write thumbnail to disk', (10, 110))
  414. self.ignoreErrorsChk = wx.CheckBox(self, -1, 'Ignore Errors', (10, 135))
  415. wx.StaticText(self, -1, 'Min Filesize (e.g. 50k or 44.6m)', (250, 65))
  416. self.minFilesizeBox = wx.TextCtrl(self, -1, pos=(245, 85), size=(80, -1))
  417. wx.StaticText(self, -1, 'Max Filesize (e.g. 50k or 44.6m)', (250, 115))
  418. self.maxFilesizeBox = wx.TextCtrl(self, -1, pos=(245, 135), size=(80, -1))
  419. def load_options(self):
  420. self.limitBox.SetValue(self.optList.rateLimit)
  421. self.retriesBox.SetValue(self.optList.retries)
  422. self.writeDescriptionChk.SetValue(self.optList.writeDescription)
  423. self.writeInfoChk.SetValue(self.optList.writeInfo)
  424. self.writeThumbnailChk.SetValue(self.optList.writeThumbnail)
  425. self.ignoreErrorsChk.SetValue(self.optList.ignoreErrors)
  426. self.minFilesizeBox.SetValue(self.optList.minFileSize)
  427. self.maxFilesizeBox.SetValue(self.optList.maxFileSize)
  428. def save_options(self):
  429. self.optList.rateLimit = self.limitBox.GetValue()
  430. self.optList.retries = self.retriesBox.GetValue()
  431. self.optList.writeDescription = self.writeDescriptionChk.GetValue()
  432. self.optList.writeInfo = self.writeInfoChk.GetValue()
  433. self.optList.writeThumbnail = self.writeThumbnailChk.GetValue()
  434. self.optList.ignoreErrors = self.ignoreErrorsChk.GetValue()
  435. self.optList.minFileSize = self.minFilesizeBox.GetValue()
  436. self.optList.maxFileSize = self.maxFilesizeBox.GetValue()
  437. class SubtitlesPanel(wx.Panel):
  438. def __init__(self, parent, optList):
  439. self.optList = optList
  440. wx.Panel.__init__(self, parent)
  441. self.writeSubsChk = wx.CheckBox(self, -1, 'Write subtitle file', (10, 10))
  442. self.writeAllSubsChk = wx.CheckBox(self, -1, 'Download all available subtitles', (10, 40))
  443. self.writeAutoSubsChk = wx.CheckBox(self, -1, 'Write automatic subtitle file (YOUTUBE ONLY)', (10, 70))
  444. wx.StaticText(self, -1, 'Subtitles Language', (15, 105))
  445. self.subsLangCombo = wx.ComboBox(self, choices=LANGUAGES, pos=(10, 125), size=(140, 30))
  446. self.Bind(wx.EVT_CHECKBOX, self.OnWriteSubsChk, self.writeSubsChk)
  447. self.Bind(wx.EVT_CHECKBOX, self.OnWriteAllSubsChk, self.writeAllSubsChk)
  448. self.Bind(wx.EVT_CHECKBOX, self.OnWriteAutoSubsChk, self.writeAutoSubsChk)
  449. def OnWriteAutoSubsChk(self, event):
  450. if (self.writeAutoSubsChk.GetValue()):
  451. self.writeAllSubsChk.Disable()
  452. self.writeSubsChk.Disable()
  453. self.subsLangCombo.Disable()
  454. else:
  455. self.writeAllSubsChk.Enable()
  456. self.writeSubsChk.Enable()
  457. self.subsLangCombo.Enable()
  458. def OnWriteSubsChk(self, event):
  459. if (self.writeSubsChk.GetValue()):
  460. self.writeAllSubsChk.Disable()
  461. self.writeAutoSubsChk.Disable()
  462. else:
  463. self.writeAllSubsChk.Enable()
  464. self.writeAutoSubsChk.Enable()
  465. def OnWriteAllSubsChk(self, event):
  466. if (self.writeAllSubsChk.GetValue()):
  467. self.writeSubsChk.Disable()
  468. self.subsLangCombo.Disable()
  469. self.writeAutoSubsChk.Disable()
  470. else:
  471. self.writeSubsChk.Enable()
  472. self.subsLangCombo.Enable()
  473. self.writeAutoSubsChk.Enable()
  474. def load_options(self):
  475. self.writeSubsChk.Enable()
  476. self.subsLangCombo.Enable()
  477. self.writeAllSubsChk.Enable()
  478. self.writeAutoSubsChk.Enable()
  479. self.writeSubsChk.SetValue(self.optList.writeSubs)
  480. self.writeAllSubsChk.SetValue(self.optList.writeAllSubs)
  481. self.subsLangCombo.SetValue(self.optList.subsLang)
  482. self.writeAutoSubsChk.SetValue(self.optList.writeAutoSubs)
  483. if (self.writeSubsChk.GetValue()):
  484. self.writeAllSubsChk.Disable()
  485. self.writeAllSubsChk.SetValue(False)
  486. self.writeAutoSubsChk.Disable()
  487. self.writeAutoSubsChk.SetValue(False)
  488. if (self.writeAllSubsChk.GetValue()):
  489. self.writeSubsChk.Disable()
  490. self.writeSubsChk.SetValue(False)
  491. self.subsLangCombo.Disable()
  492. self.writeAutoSubsChk.Disable()
  493. self.writeAutoSubsChk.SetValue(False)
  494. if (self.writeAutoSubsChk.GetValue()):
  495. self.writeAllSubsChk.Disable()
  496. self.writeAllSubsChk.SetValue(False)
  497. self.writeSubsChk.Disable()
  498. self.writeSubsChk.SetValue(False)
  499. self.subsLangCombo.Disable()
  500. def save_options(self):
  501. self.optList.writeSubs = self.writeSubsChk.GetValue()
  502. self.optList.writeAllSubs = self.writeAllSubsChk.GetValue()
  503. self.optList.subsLang = self.subsLangCombo.GetValue()
  504. self.optList.writeAutoSubs = self.writeAutoSubsChk.GetValue()
  505. class GeneralPanel(wx.Panel):
  506. def __init__(self, parent, optList, controlParent):
  507. self.optList = optList
  508. self.parent = controlParent
  509. wx.Panel.__init__(self, parent)
  510. wx.StaticText(self, -1, "Save Path", (15, 10))
  511. self.savePathBox = wx.TextCtrl(self, -1, pos=(10, 30), size=(350, -1))
  512. self.idAsNameChk = wx.CheckBox(self, -1, 'ID as Name', (10, 70))
  513. self.aboutButton = wx.Button(self, label="About", pos=(380, 80), size=(100, 40))
  514. self.openButton = wx.Button(self, label="Open", pos=(380, 20), size=(100, 40))
  515. self.resetButton = wx.Button(self, label="Reset", pos=(380, 140), size=(100, 40))
  516. wx.StaticText(self, -1, "Settings: " + self.optList.settings_abs_path, (20, 155))
  517. self.Bind(wx.EVT_BUTTON, self.OnAbout, self.aboutButton)
  518. self.Bind(wx.EVT_BUTTON, self.OnOpen, self.openButton)
  519. self.Bind(wx.EVT_BUTTON, self.OnReset, self.resetButton)
  520. def OnReset(self, event):
  521. self.parent.reset()
  522. def OnOpen(self, event):
  523. dlg = wx.DirDialog(None, "Choose directory")
  524. if dlg.ShowModal() == wx.ID_OK:
  525. self.savePathBox.SetValue(dlg.GetPath())
  526. dlg.Destroy()
  527. def OnAbout(self, event):
  528. description = '''A cross platform front-end GUI of
  529. the popular youtube-dl written in Python.'''
  530. license = '''This is free and unencumbered software released into the public domain.
  531. Anyone is free to copy, modify, publish, use, compile, sell, or
  532. distribute this software, either in source code form or as a compiled
  533. binary, for any purpose, commercial or non-commercial, and by any
  534. means.
  535. In jurisdictions that recognize copyright laws, the author or authors
  536. of this software dedicate any and all copyright interest in the
  537. software to the public domain. We make this dedication for the benefit
  538. of the public at large and to the detriment of our heirs and
  539. successors. We intend this dedication to be an overt act of
  540. relinquishment in perpetuity of all present and future rights to this
  541. software under copyright law.
  542. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  543. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  544. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  545. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  546. OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  547. ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  548. OTHER DEALINGS IN THE SOFTWARE.
  549. For more information, please refer to <http://unlicense.org/>'''
  550. info = wx.AboutDialogInfo()
  551. info.SetIcon(wx.Icon('../icons/ytube.png', wx.BITMAP_TYPE_ICO))
  552. info.SetName(TITLE)
  553. info.SetVersion(__version__)
  554. info.SetDescription(description)
  555. info.SetWebSite('https://github.com/MrS0m30n3/youtube-dl-gui')
  556. info.SetLicense(license)
  557. info.AddDeveloper('Sotiris Papadopoulos')
  558. wx.AboutBox(info)
  559. def load_options(self):
  560. self.savePathBox.SetValue(self.optList.savePath)
  561. self.idAsNameChk.SetValue(self.optList.idAsName)
  562. def save_options(self):
  563. self.optList.savePath = self.savePathBox.GetValue()
  564. self.optList.idAsName = self.idAsNameChk.GetValue()
  565. class OtherPanel(wx.Panel):
  566. def __init__(self, parent, optList):
  567. self.optList = optList
  568. wx.Panel.__init__(self, parent)
  569. wx.StaticText(self, -1, 'Command line arguments (e.g. --help)', (25, 20))
  570. self.cmdArgsBox = wx.TextCtrl(self, -1, pos=(20, 40), size=(450, -1))
  571. def load_options(self):
  572. self.cmdArgsBox.SetValue(self.optList.cmdArgs)
  573. def save_options(self):
  574. self.optList.cmdArgs = self.cmdArgsBox.GetValue()
  575. class OptionsFrame(wx.Frame):
  576. def __init__(self, optionsList, parent=None, id=-1):
  577. wx.Frame.__init__(self, parent, id, "Options", size=(540, 250))
  578. self.optionsList = optionsList
  579. panel = wx.Panel(self)
  580. notebook = wx.Notebook(panel)
  581. self.generalTab = GeneralPanel(notebook, self.optionsList, self)
  582. self.audioTab = AudioPanel(notebook, self.optionsList)
  583. self.connectionTab = ConnectionPanel(notebook, self.optionsList)
  584. self.videoTab = VideoPanel(notebook, self.optionsList)
  585. self.downloadTab = DownloadPanel(notebook, self.optionsList)
  586. self.subtitlesTab = SubtitlesPanel(notebook, self.optionsList)
  587. self.otherTab = OtherPanel(notebook, self.optionsList)
  588. self.updateTab = UpdatePanel(notebook, self.optionsList)
  589. notebook.AddPage(self.generalTab, "General")
  590. notebook.AddPage(self.audioTab, "Audio")
  591. notebook.AddPage(self.videoTab, "Video")
  592. notebook.AddPage(self.subtitlesTab, "Subtitles")
  593. notebook.AddPage(self.downloadTab, "Download")
  594. notebook.AddPage(self.connectionTab, "Connection")
  595. notebook.AddPage(self.updateTab, "Update")
  596. notebook.AddPage(self.otherTab, "Commands")
  597. sizer = wx.BoxSizer()
  598. sizer.Add(notebook, 1, wx.EXPAND)
  599. panel.SetSizer(sizer)
  600. self.Bind(wx.EVT_CLOSE, self.OnClose)
  601. self.load_all_options()
  602. def OnClose(self, event):
  603. self.save_all_options()
  604. self.Destroy()
  605. def reset(self):
  606. self.optionsList.load_default()
  607. self.load_all_options()
  608. def load_all_options(self):
  609. self.generalTab.load_options()
  610. self.audioTab.load_options()
  611. self.connectionTab.load_options()
  612. self.videoTab.load_options()
  613. self.downloadTab.load_options()
  614. self.subtitlesTab.load_options()
  615. self.otherTab.load_options()
  616. self.updateTab.load_options()
  617. def save_all_options(self):
  618. self.generalTab.save_options()
  619. self.audioTab.save_options()
  620. self.connectionTab.save_options()
  621. self.videoTab.save_options()
  622. self.downloadTab.save_options()
  623. self.subtitlesTab.save_options()
  624. self.otherTab.save_options()
  625. self.updateTab.save_options()