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.

34 lines
1.2 KiB

  1. #!/usr/bin/env python
  2. import hashlib
  3. import os.path
  4. import subprocess
  5. try:
  6. from subprocess import check_output
  7. except ImportError: # Python < 2.7
  8. def check_output(*args, **kwargs):
  9. p = subprocess.Popen(*args, stdout=subprocess.PIPE, **kwargs)
  10. out,err = p.communicate()
  11. if p.returncode != 0:
  12. raise subprocess.CalledProcessError(p.returncode, p.args)
  13. return out
  14. youtubeDlDir = os.path.join(os.path.dirname(__file__), '..', 'youtube-dl')
  15. # Read template page
  16. template = file('download.html.in', 'r').read()
  17. # Build replacement strings
  18. version = check_output([os.path.join(youtubeDlDir, 'youtube-dl'), '--version']).strip()
  19. data = check_output(['git', 'show', '%s:youtube-dl' % version], cwd=youtubeDlDir)
  20. url = 'https://github.com/rg3/youtube-dl/raw/%s/youtube-dl' % version
  21. md5sum = hashlib.md5(data).hexdigest()
  22. sha1sum = hashlib.sha1(data).hexdigest()
  23. sha256sum = hashlib.sha256(data).hexdigest()
  24. template = template.replace('@PROGRAM_VERSION@', version)
  25. template = template.replace('@PROGRAM_URL@', url)
  26. template = template.replace('@PROGRAM_MD5SUM@', md5sum)
  27. template = template.replace('@PROGRAM_SHA1SUM@', sha1sum)
  28. template = template.replace('@PROGRAM_SHA256SUM@', sha256sum)
  29. file('download.html', 'w').write(template)