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.

45 lines
1.3 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
  1. #! /usr/bin/env python
  2. from wx import CallAfter
  3. from wx.lib.pubsub import setuparg1
  4. from wx.lib.pubsub import pub as Publisher
  5. from threading import Thread
  6. from urllib2 import urlopen, URLError, HTTPError
  7. from .Utils import (
  8. fix_path,
  9. file_exist,
  10. makedir
  11. )
  12. LATEST_YOUTUBE_DL = 'https://yt-dl.org/latest/'
  13. PUBLISHER_TOPIC = 'update'
  14. DOWNLOAD_TIMEOUT = 20
  15. class UpdateThread(Thread):
  16. def __init__(self, updatePath, youtubeDLFile):
  17. super(UpdateThread, self).__init__()
  18. self.youtubeDLFile = youtubeDLFile
  19. self.updatePath = fix_path(updatePath)
  20. self.url = LATEST_YOUTUBE_DL + youtubeDLFile
  21. self.check_path()
  22. self.start()
  23. def run(self):
  24. CallAfter(Publisher.sendMessage, PUBLISHER_TOPIC, "Downloading latest youtube-dl. Please wait...")
  25. try:
  26. f = urlopen(self.url, timeout=DOWNLOAD_TIMEOUT)
  27. with open(self.updatePath + self.youtubeDLFile, 'wb') as lf:
  28. lf.write(f.read())
  29. msg = 'Youtube-dl downloaded correctly'
  30. except (HTTPError, URLError, IOError) as e:
  31. msg = 'Youtube-dl download failed ' + str(e)
  32. CallAfter(Publisher.sendMessage, PUBLISHER_TOPIC, msg)
  33. CallAfter(Publisher.sendMessage, PUBLISHER_TOPIC, 'finish')
  34. def check_path(self):
  35. if not file_exist(self.updatePath):
  36. makedir(self.updatePath)