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.

49 lines
1.5 KiB

  1. #!/usr/bin/env python
  2. import sys, os
  3. import urllib2
  4. sys.stderr.write(u'Hi! We changed distribution method and now youtube-dl needs to update itself one more time.\n')
  5. sys.stderr.write(u'This will only happen once. Simply press enter to go on. Sorry for the trouble!\n')
  6. sys.stderr.write(u'The new location of the binaries is https://github.com/rg3/youtube-dl/downloads, not the git repository.\n\n')
  7. raw_input()
  8. filename = sys.argv[0]
  9. API_URL = "https://api.github.com/repos/rg3/youtube-dl/downloads"
  10. EXE_URL = "https://github.com/downloads/rg3/youtube-dl/youtube-dl.exe"
  11. if not os.access(filename, os.W_OK):
  12. sys.exit('ERROR: no write permissions on %s' % filename)
  13. exe = os.path.abspath(filename)
  14. directory = os.path.dirname(exe)
  15. if not os.access(directory, os.W_OK):
  16. sys.exit('ERROR: no write permissions on %s' % directory)
  17. try:
  18. urlh = urllib2.urlopen(EXE_URL)
  19. newcontent = urlh.read()
  20. urlh.close()
  21. with open(exe + '.new', 'wb') as outf:
  22. outf.write(newcontent)
  23. except (IOError, OSError) as err:
  24. sys.exit('ERROR: unable to download latest version')
  25. try:
  26. bat = os.path.join(directory, 'youtube-dl-updater.bat')
  27. b = open(bat, 'w')
  28. b.write("""
  29. echo Updating youtube-dl...
  30. ping 127.0.0.1 -n 5 -w 1000 > NUL
  31. move /Y "%s.new" "%s"
  32. del "%s"
  33. \n""" %(exe, exe, bat))
  34. b.close()
  35. os.startfile(bat)
  36. except (IOError, OSError) as err:
  37. sys.exit('ERROR: unable to overwrite current version')
  38. sys.stderr.write(u'Done! Now you can run youtube-dl.\n')