]>
jfr.im git - yt-dlp.git/blob - devscripts/update-formulae.py
7 sys
.path
.insert(0, os
.path
.dirname(os
.path
.dirname(os
.path
.abspath(__file__
))))
9 from yt_dlp
.compat
import compat_urllib_request
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)
14 filename
, version
= sys
.argv
[1:]
16 normalized_version
= '.'.join(str(int(x
)) for x
in version
.split('.'))
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'))
22 tarball_file
= next(x
for x
in pypi_release
['urls'] if x
['filename'].endswith('.tar.gz'))
24 sha256sum
= tarball_file
['digests']['sha256']
25 url
= tarball_file
['url']
27 with open(filename
) as r
:
28 formulae_text
= r
.read()
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
)
33 with open(filename
, 'w') as w
:
34 w
.write(formulae_text
)