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.

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