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