summaryrefslogtreecommitdiffstats
path: root/devscripts/update-formulae.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-05 17:37:42 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-05 17:37:42 +0000
commitc7bab7c39fd51c0812f70020172766303191bc01 (patch)
tree56c05fbdd4fc47409d48ba318a4b621a7b0d299a /devscripts/update-formulae.py
parentInitial commit. (diff)
downloadyt-dlp-upstream.tar.xz
yt-dlp-upstream.zip
Adding upstream version 2023.03.04.upstream/2023.03.04upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'devscripts/update-formulae.py')
-rw-r--r--devscripts/update-formulae.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/devscripts/update-formulae.py b/devscripts/update-formulae.py
new file mode 100644
index 0000000..e79297f
--- /dev/null
+++ b/devscripts/update-formulae.py
@@ -0,0 +1,39 @@
+#!/usr/bin/env python3
+
+"""
+Usage: python3 ./devscripts/update-formulae.py <path-to-formulae-rb> <version>
+version can be either 0-aligned (yt-dlp version) or normalized (PyPi version)
+"""
+
+# Allow direct execution
+import os
+import sys
+
+sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+
+
+import json
+import re
+import urllib.request
+
+from devscripts.utils import read_file, write_file
+
+filename, version = sys.argv[1:]
+
+normalized_version = '.'.join(str(int(x)) for x in version.split('.'))
+
+pypi_release = json.loads(urllib.request.urlopen(
+ 'https://pypi.org/pypi/yt-dlp/%s/json' % normalized_version
+).read().decode())
+
+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']
+
+formulae_text = read_file(filename)
+
+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)
+
+write_file(filename, formulae_text)