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