]> jfr.im git - yt-dlp.git/blob - devscripts/update-formulae.py
[devscripts/update-formulae] Do not change dependency section
[yt-dlp.git] / devscripts / update-formulae.py
1 #!/usr/bin/env python3
2
3 # Allow direct execution
4 import os
5 import sys
6
7 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
8
9
10 import json
11 import re
12 import urllib.request
13
14 # usage: python3 ./devscripts/update-formulae.py <path-to-formulae-rb> <version>
15 # version can be either 0-aligned (yt-dlp version) or normalized (PyPl version)
16
17 filename, version = sys.argv[1:]
18
19 normalized_version = '.'.join(str(int(x)) for x in version.split('.'))
20
21 pypi_release = json.loads(urllib.request.urlopen(
22 'https://pypi.org/pypi/yt-dlp/%s/json' % normalized_version
23 ).read().decode())
24
25 tarball_file = next(x for x in pypi_release['urls'] if x['filename'].endswith('.tar.gz'))
26
27 sha256sum = tarball_file['digests']['sha256']
28 url = tarball_file['url']
29
30 with open(filename) as r:
31 formulae_text = r.read()
32
33 formulae_text = re.sub(r'sha256 "[0-9a-f]*?"', 'sha256 "%s"' % sha256sum, formulae_text, count=1)
34 formulae_text = re.sub(r'url "[^"]*?"', 'url "%s"' % url, formulae_text, count=1)
35
36 with open(filename, 'w') as w:
37 w.write(formulae_text)