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.

33 lines
1.1 KiB

  1. #!/usr/bin/env python3
  2. import hashlib
  3. import shutil
  4. import subprocess
  5. import tempfile
  6. import urllib.request
  7. URL = 'https://github.com/downloads/rg3/youtube-dl/youtube-dl'
  8. with tempfile.NamedTemporaryFile(suffix='youtube-dl', delete=True) as ytdl_file:
  9. with urllib.request.urlopen(URL) as dl:
  10. shutil.copyfileobj(dl, ytdl_file)
  11. ytdl_file.seek(0)
  12. data = ytdl_file.read()
  13. ytdl_file.flush()
  14. version = subprocess.check_output(['python3', ytdl_file.name, '--version']).decode('ascii').strip()
  15. # Read template page
  16. with open('download.html.in', 'r', encoding='utf-8') as tmplf:
  17. template = tmplf.read()
  18. md5sum = hashlib.md5(data).hexdigest()
  19. sha1sum = hashlib.sha1(data).hexdigest()
  20. sha256sum = hashlib.sha256(data).hexdigest()
  21. template = template.replace('@PROGRAM_VERSION@', version)
  22. template = template.replace('@PROGRAM_URL@', URL)
  23. template = template.replace('@PROGRAM_MD5SUM@', md5sum)
  24. template = template.replace('@PROGRAM_SHA1SUM@', sha1sum)
  25. template = template.replace('@PROGRAM_SHA256SUM@', sha256sum)
  26. with open('download.html', 'w', encoding='utf-8') as dlf:
  27. dlf.write(template)