aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorgarret1317 <garret@airmail.cc>2025-06-05 18:06:37 +0100
committergarret1317 <garret@airmail.cc>2025-06-05 18:06:37 +0100
commit50bfb27bd17236ccdc5dadf87b461c418edf2508 (patch)
tree998f75990da8cea18a6d4259ca6444846b70cf8a
parent12801d5e2648b1e9cec2a9c3dfa5a77668ed638b (diff)
downloadyt-dlp-rajiko-50bfb27bd17236ccdc5dadf87b461c418edf2508.tar.gz
yt-dlp-rajiko-50bfb27bd17236ccdc5dadf87b461c418edf2508.tar.bz2
yt-dlp-rajiko-50bfb27bd17236ccdc5dadf87b461c418edf2508.zip
add useful scripts used in release/development
-rwxr-xr-xmisc/generate_html.py84
-rwxr-xr-xmisc/old_generate_changelog.py (renamed from misc/generate_changelog.py)0
-rwxr-xr-xmisc/streammon.py53
3 files changed, 137 insertions, 0 deletions
diff --git a/misc/generate_html.py b/misc/generate_html.py
new file mode 100755
index 0000000..0e15d6a
--- /dev/null
+++ b/misc/generate_html.py
@@ -0,0 +1,84 @@
+#!/usr/bin/env python3
+import os
+import hashlib
+import re
+
+pip_index = open("index.html", "w")
+
+pip_index.write("""<!DOCTYPE HTML>
+<html lang="en-GB">
+<head>
+ <title>yt-dlp-rajiko pip index</title>
+ <link rel="canonical" href="https://427738.xyz/yt-dlp-rajiko/pip/yt-dlp-rajiko/">
+</head>
+<body>
+
+<ul>
+""")
+
+site_sha256 = []
+
+tarballs = []
+wheels = []
+
+for item in sorted(os.listdir()):#, key=lambda x: x.name):
+ if os.path.islink(item):
+ continue
+
+ if item.endswith(".tar.gz"):
+ tarballs.append(item)
+ elif item.endswith(".whl"):
+ wheels.append(item)
+ else:
+ continue
+
+ pip_index.write("\t<li>")
+ pip_index.write('<a href="')
+ pip_index.write(item)
+
+ with open(item, "rb") as f:
+ checksum = hashlib.sha256(f.read()).hexdigest()
+
+ pip_index.write("#sha256=")
+ pip_index.write(checksum)
+ pip_index.write('">')
+ pip_index.write(item)
+ pip_index.write("</a>\n")
+
+ site_string = checksum + "&nbsp;&nbsp;" + '<a href="dl/' + item + '">' + item + "</a><br>"
+ site_sha256.append(site_string)
+
+pip_index.write("""</ul>
+
+</body>
+</html>""")
+
+latest_tarball = tarballs[-1]
+latest_wheel = wheels[-1]
+print(latest_tarball, latest_wheel)
+
+os.remove("yt_dlp_rajiko-latest.tar.gz")
+os.symlink(latest_tarball, "yt_dlp_rajiko-latest.tar.gz")
+
+os.remove("yt_dlp_rajiko-latest.whl")
+os.symlink(latest_wheel, "yt_dlp_rajiko-latest.whl")
+
+site_sha256.reverse()
+
+latest_list = site_sha256[:2]
+previous_list = site_sha256[2:]
+
+latest = "\n".join(["<!-- LATEST SHA256 START -->", "<code>", "\n".join(latest_list), "</code>", "<!-- LATEST SHA256 END -->"])
+
+previous = "\n".join(["<!-- PREVIOUS SHA256 START -->", "<code>", "\n".join(previous_list), "</code>", "<!-- PREVIOUS SHA256 END -->"])
+
+for i in ["../../index.html", "../../index.ja.html"]:
+ with open(i, "r+") as f:
+ page = f.read()
+
+ page = re.sub(r"<!-- LATEST SHA256 START -->.+<!-- LATEST SHA256 END -->", latest, page, flags=re.DOTALL)
+ page = re.sub(r"<!-- PREVIOUS SHA256 START -->.+<!-- PREVIOUS SHA256 END -->", previous, page, flags=re.DOTALL)
+
+ f.seek(0)
+ f.truncate(0)
+ f.write(page)
diff --git a/misc/generate_changelog.py b/misc/old_generate_changelog.py
index 1bce073..1bce073 100755
--- a/misc/generate_changelog.py
+++ b/misc/old_generate_changelog.py
diff --git a/misc/streammon.py b/misc/streammon.py
new file mode 100755
index 0000000..4051833
--- /dev/null
+++ b/misc/streammon.py
@@ -0,0 +1,53 @@
+#!/usr/bin/env python3
+# monitor stream APIs for any changes, so I can check they don't break anything
+# run via cronjob every now and then
+
+import difflib
+import os
+import sys
+from datetime import datetime
+
+import requests
+
+s = requests.Session()
+
+DISCORD_WEBHOOK = "PUT WEBHOOK HERE"
+STREAMS_API = "https://radiko.jp/v3/station/stream/{device}/{station}.xml"
+
+if len(sys.argv) > 1:
+ PATH = sys.argv[1]
+else:
+ PATH = ""
+
+devices = ('pc_html5', 'aSmartPhone7a', 'aSmartPhone8')
+stations = ('FMT', 'CCL', 'NORTHWAVE', 'TBS')
+
+for device in devices:
+ for station in stations:
+ url = STREAMS_API.format(device=device, station=station)
+ now = s.get(url).text
+
+ filename = f"{PATH}{station}-{device}.xml"
+ with open(filename, "a+") as f:
+ f.seek(0)
+ past = f.read()
+
+ modtime = datetime.fromtimestamp(os.path.getmtime(filename))
+ diff = difflib.unified_diff(
+ past.splitlines(), now.splitlines(),
+ fromfile=url, tofile=url,
+ fromfiledate=str(modtime), tofiledate=str(datetime.now()),
+ )
+
+ diff_str = "\n".join(diff)
+ if diff_str != "":
+ f.truncate(0)
+ f.write(now)
+
+ s.post(DISCORD_WEBHOOK, json={
+ "embeds": [{
+ "type": "rich",
+ "title": f"Streams changed: {station} {device}",
+ "description": "\n".join(("```diff", diff_str, "```"))
+ }]
+ })