From 9f8c0e50a8bd4ddc982b7e4b74c918b5138741c5 Mon Sep 17 00:00:00 2001
From: garret
Date: Mon, 26 Aug 2024 16:14:33 +0100
Subject: add changelog generating script
---
misc/generate_changelog.py | 116 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 116 insertions(+)
create mode 100755 misc/generate_changelog.py
(limited to 'misc')
diff --git a/misc/generate_changelog.py b/misc/generate_changelog.py
new file mode 100755
index 0000000..1bce073
--- /dev/null
+++ b/misc/generate_changelog.py
@@ -0,0 +1,116 @@
+#!/usr/bin/env python3
+import email.utils
+import feedgenerator
+
+def parse_changelog(lines):
+ got_version = False
+ got_date = False
+ got_url = False
+ done_remarks = False
+ releases = []
+ release = {}
+ release_remarks = []
+ release_changes = []
+ current_change = ""
+
+ for idx, line in enumerate(lines):
+ line = line.rstrip()
+
+ if not got_version:
+ got_version = True
+ release["version"] = line
+ continue
+
+ if not got_date:
+ release["date"] = email.utils.parsedate_to_datetime(line)
+ got_date = True
+ continue
+
+ key, sep, val = line.partition(": ")
+ if key in ["url", "sha256", "released"] and val != "":
+ release[key] = val
+ continue
+
+ if not done_remarks:
+ if line == "":
+ done_remarks = True
+ release["remarks"] = release_remarks
+ release_remarks = []
+ continue
+ else:
+ release_remarks.append(line)
+ continue
+
+ if line != "":
+ release_changes.append(line.rstrip())
+
+ if idx + 1 != len(lines):
+ continue
+
+ release["changes"] = release_changes
+ if release.get("released") != "no":
+ releases.append(release)
+
+ got_version = False
+ got_date = False
+ done_remarks = False
+ release = {}
+ release_changes = []
+
+ return releases
+
+def generate_rss_feed(releases):
+ feed = feedgenerator.Rss201rev2Feed(
+ title="yt-dlp-rajiko changelog",
+ description="Notifications for new yt-dlp-rajiko releases, with changelogs",
+ link="https://427738.xyz/yt-dlp-rajiko/",
+ language="en-GB",
+ ttl=180, # 3 hours
+ )
+
+ for release in releases:
+ title = "yt-dlp-rajiko " + release["version"] + " has been released"
+ description = ""
+ description += ""
+ for remark in release["remarks"]:
+ description += remark
+ description += "
"
+ description += "
"
+ description += "This release:
\n"
+ description += ""
+ for change in release["changes"]:
+ description += "- "
+ description += change
+ description += "
\n"
+ description += "
"
+
+ if release.get("url"):
+ if release["version"] != "1.0":
+ description += "\nIf you use pip, you should be able to upgrade with pip install yt-dlp-rajiko --upgrade --extra-index-url https://427738.xyz/yt-dlp-rajiko/pip/
.
"
+ description += "If you installed manually, you can download the updated .whl
from this post's link."
+ if release.get("sha256"):
+ description += " The SHA256 checksum should be "
+ description += release.get("sha256")
+ description += "
."
+ description += "
"
+ else:
+ description += '\nPlease see the homepage for initial installation instructions.
'
+
+ feed.add_item(
+ title=title,
+ description=description,
+ link=release.get("url"),
+ pubdate=release["date"]
+ )
+ return feed
+
+if __name__ == "__main__":
+ with open("CHANGELOG") as f:
+ releases = parse_changelog(f.readlines())
+
+ feed = generate_rss_feed(releases)
+ feed_contents = feed.writeString("utf-8")
+ feed_contents = feed_contents.replace("\n