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.

31 lines
1.0 KiB

10 years ago
  1. #! /usr/bin/env python
  2. from threading import Thread
  3. from wx import CallAfter
  4. from wx.lib.pubsub import setuparg1
  5. from wx.lib.pubsub import pub as Publisher
  6. from urllib2 import urlopen, URLError, HTTPError
  7. LATEST_YOUTUBE_DL = 'https://yt-dl.org/latest/'
  8. PUBLISHER_TOPIC = 'update'
  9. DOWNLOAD_TIMEOUT = 10
  10. class UpdateThread(Thread):
  11. def __init__(self, youtubeDLFile):
  12. super(UpdateThread, self).__init__()
  13. self.youtubeDLFile = youtubeDLFile
  14. self.url = LATEST_YOUTUBE_DL + youtubeDLFile
  15. self.start()
  16. def run(self):
  17. CallAfter(Publisher.sendMessage, PUBLISHER_TOPIC, "Downloading latest youtube-dl...")
  18. try:
  19. f = urlopen(self.url, timeout=DOWNLOAD_TIMEOUT)
  20. with open(self.youtubeDLFile, 'wb') as lf:
  21. lf.write(f.read())
  22. msg = 'Youtube-dl downloaded correctly'
  23. except (HTTPError, URLError, IOError) as e:
  24. msg = 'Youtube-dl download failed ' + str(e)
  25. CallAfter(Publisher.sendMessage, PUBLISHER_TOPIC, msg)
  26. CallAfter(Publisher.sendMessage, PUBLISHER_TOPIC, 'finish')