]>
jfr.im git - yt-dlp.git/blob - devscripts/update-formulae.py
2 from __future__
import unicode_literals
9 sys
.path
.insert(0, os
.path
.dirname(os
.path
.dirname(os
.path
.abspath(__file__
))))
11 from yt_dlp
.compat
import compat_urllib_request
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)
17 filename
, version
= sys
.argv
[1:]
19 normalized_version
= '.'.join(str(int(x
)) for x
in version
.split('.'))
21 pypi_release
= json
.loads(compat_urllib_request
.urlopen(
22 'https://pypi.org/pypi/yt-dlp/%s/json' % normalized_version
23 ).read().decode('utf-8'))
25 tarball_file
= next(x
for x
in pypi_release
['urls'] if x
['filename'].endswith('.tar.gz'))
27 sha256sum
= tarball_file
['digests']['sha256']
28 url
= tarball_file
['url']
30 with open(filename
, 'r') as r
:
31 formulae_text
= r
.read()
33 formulae_text
= re
.sub(r
'sha256 "[0-9a-f]*?"', 'sha256 "%s"' % sha256sum
, formulae_text
)
34 formulae_text
= re
.sub(r
'url "[^"]*?"', 'url "%s"' % url
, formulae_text
)
36 with open(filename
, 'w') as w
:
37 w
.write(formulae_text
)