2021-08-30 14:37:43 +00:00
|
|
|
#!/usr/bin/env python3
|
2022-06-24 08:10:17 +00:00
|
|
|
|
|
|
|
# Allow direct execution
|
2021-08-30 14:37:43 +00:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
|
|
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
|
|
|
2022-06-24 08:10:17 +00:00
|
|
|
|
|
|
|
import json
|
|
|
|
import re
|
|
|
|
import urllib.request
|
2021-08-30 14:37:43 +00:00
|
|
|
|
|
|
|
# usage: python3 ./devscripts/update-formulae.py <path-to-formulae-rb> <version>
|
|
|
|
# version can be either 0-aligned (yt-dlp version) or normalized (PyPl version)
|
|
|
|
|
|
|
|
filename, version = sys.argv[1:]
|
|
|
|
|
|
|
|
normalized_version = '.'.join(str(int(x)) for x in version.split('.'))
|
|
|
|
|
2022-06-24 08:10:17 +00:00
|
|
|
pypi_release = json.loads(urllib.request.urlopen(
|
2021-08-30 14:37:43 +00:00
|
|
|
'https://pypi.org/pypi/yt-dlp/%s/json' % normalized_version
|
2022-05-09 11:54:28 +00:00
|
|
|
).read().decode())
|
2021-08-30 14:37:43 +00:00
|
|
|
|
|
|
|
tarball_file = next(x for x in pypi_release['urls'] if x['filename'].endswith('.tar.gz'))
|
|
|
|
|
|
|
|
sha256sum = tarball_file['digests']['sha256']
|
|
|
|
url = tarball_file['url']
|
|
|
|
|
2022-04-11 15:10:28 +00:00
|
|
|
with open(filename) as r:
|
2021-08-30 14:37:43 +00:00
|
|
|
formulae_text = r.read()
|
|
|
|
|
2022-07-01 11:58:39 +00:00
|
|
|
formulae_text = re.sub(r'sha256 "[0-9a-f]*?"', 'sha256 "%s"' % sha256sum, formulae_text, count=1)
|
|
|
|
formulae_text = re.sub(r'url "[^"]*?"', 'url "%s"' % url, formulae_text, count=1)
|
2021-08-30 14:37:43 +00:00
|
|
|
|
|
|
|
with open(filename, 'w') as w:
|
|
|
|
w.write(formulae_text)
|