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.

40 lines
1.2 KiB

  1. #!/usr/bin/env python
  2. import sys, os
  3. try:
  4. import urllib.request as compat_urllib_request
  5. except ImportError: # Python 2
  6. import urllib2 as compat_urllib_request
  7. sys.stderr.write(u'Hi! We changed distribution method and now youtube-dl needs to update itself one more time.\n')
  8. sys.stderr.write(u'This will only happen once. Simply press enter to go on. Sorry for the trouble!\n')
  9. sys.stderr.write(u'The new location of the binaries is https://github.com/rg3/youtube-dl/downloads, not the git repository.\n\n')
  10. try:
  11. raw_input()
  12. except NameError: # Python 3
  13. input()
  14. filename = sys.argv[0]
  15. API_URL = "https://api.github.com/repos/rg3/youtube-dl/downloads"
  16. BIN_URL = "https://github.com/downloads/rg3/youtube-dl/youtube-dl"
  17. if not os.access(filename, os.W_OK):
  18. sys.exit('ERROR: no write permissions on %s' % filename)
  19. try:
  20. urlh = compat_urllib_request.urlopen(BIN_URL)
  21. newcontent = urlh.read()
  22. urlh.close()
  23. except (IOError, OSError) as err:
  24. sys.exit('ERROR: unable to download latest version')
  25. try:
  26. with open(filename, 'wb') as outf:
  27. outf.write(newcontent)
  28. except (IOError, OSError) as err:
  29. sys.exit('ERROR: unable to overwrite current version')
  30. sys.stderr.write(u'Done! Now you can run youtube-dl.\n')