]> jfr.im git - yt-dlp.git/blame - devscripts/gh-pages/update-feed.py
Start moving to ytdl-org
[yt-dlp.git] / devscripts / gh-pages / update-feed.py
CommitLineData
db74c11d 1#!/usr/bin/env python3
dcddc10a 2from __future__ import unicode_literals
db74c11d 3
db74c11d 4import datetime
9b12003c
PH
5import io
6import json
60607880
JMF
7import textwrap
8
60607880 9
9b12003c 10atom_template = textwrap.dedent("""\
317d4edf
PH
11 <?xml version="1.0" encoding="utf-8"?>
12 <feed xmlns="http://www.w3.org/2005/Atom">
067aa17e 13 <link rel="self" href="http://ytdl-org.github.io/youtube-dl/update/releases.atom" />
317d4edf
PH
14 <title>youtube-dl releases</title>
15 <id>https://yt-dl.org/feed/youtube-dl-updates-feed</id>
16 <updated>@TIMESTAMP@</updated>
9b12003c 17 @ENTRIES@
317d4edf 18 </feed>""")
9b12003c
PH
19
20entry_template = textwrap.dedent("""
317d4edf
PH
21 <entry>
22 <id>https://yt-dl.org/feed/youtube-dl-updates-feed/youtube-dl-@VERSION@</id>
23 <title>New version @VERSION@</title>
067aa17e 24 <link href="http://ytdl-org.github.io/youtube-dl" />
317d4edf 25 <content type="xhtml">
9b12003c
PH
26 <div xmlns="http://www.w3.org/1999/xhtml">
27 Downloads available at <a href="https://yt-dl.org/downloads/@VERSION@/">https://yt-dl.org/downloads/@VERSION@/</a>
28 </div>
317d4edf
PH
29 </content>
30 <author>
31 <name>The youtube-dl maintainers</name>
32 </author>
33 <updated>@TIMESTAMP@</updated>
34 </entry>
9b12003c 35 """)
db74c11d
JMF
36
37now = datetime.datetime.now()
317d4edf 38now_iso = now.isoformat() + 'Z'
db74c11d 39
9b12003c 40atom_template = atom_template.replace('@TIMESTAMP@', now_iso)
60607880 41
60607880
JMF
42versions_info = json.load(open('update/versions.json'))
43versions = list(versions_info['versions'].keys())
44versions.sort()
db74c11d 45
317d4edf 46entries = []
60607880 47for v in versions:
3e34db31
PH
48 fields = v.split('.')
49 year, month, day = map(int, fields[:3])
50 faked = 0
51 patchlevel = 0
52 while True:
53 try:
54 datetime.date(year, month, day)
55 except ValueError:
56 day -= 1
57 faked += 1
58 assert day > 0
59 continue
60 break
61 if len(fields) >= 4:
62 try:
63 patchlevel = int(fields[3])
64 except ValueError:
65 patchlevel = 1
66 timestamp = '%04d-%02d-%02dT00:%02d:%02dZ' % (year, month, day, faked, patchlevel)
67
68 entry = entry_template.replace('@TIMESTAMP@', timestamp)
317d4edf 69 entry = entry.replace('@VERSION@', v)
9b12003c 70 entries.append(entry)
db74c11d 71
60607880
JMF
72entries_str = textwrap.indent(''.join(entries), '\t')
73atom_template = atom_template.replace('@ENTRIES@', entries_str)
db74c11d 74
9b12003c
PH
75with io.open('update/releases.atom', 'w', encoding='utf-8') as atom_file:
76 atom_file.write(atom_template)