aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/misc/generate_changelog.py
blob: 1bce0739ea0c5aaeb9f3d2fe11dfc29a57fb63e7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
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 += "<p>"
		for remark in release["remarks"]:
			description += remark
			description += "<br/>"
		description += "</p>"
		description += "<p>This release:</p>\n"
		description += "<ul>"
		for change in release["changes"]:
			description += "<li>"
			description += change
			description += "</li>\n"
		description += "</ul></p>"

		if release.get("url"):
			if release["version"] != "1.0":
				description += "\n<p>If you use pip, you should be able to upgrade with <code>pip install yt-dlp-rajiko --upgrade --extra-index-url https://427738.xyz/yt-dlp-rajiko/pip/</code>.<br>"
				description += "If you installed manually, you can download the updated <code>.whl</code> from this post's link."
				if release.get("sha256"):
					description += " The SHA256 checksum should be <code>"
					description += release.get("sha256")
					description += "</code>."
				description += "</p>"
			else:
				description += '\n<p>Please see <a href="https://427738.xyz/yt-dlp-rajiko/#install">the homepage</a> for initial installation instructions.</p>'

		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("<rss", '<?xml-stylesheet href="rss-style.xsl" type="text/xsl"?>\n<rss')

	with open('CHANGELOG.xml', 'w') as fp:
		fp.write(feed_contents)