X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;ds=inline;f=devscripts%2Fgh-pages%2Fupdate-feed.py;h=e93eb60fb8af28a72b7aceb5d62d1c2e16b69bc5;hb=ca0f500ecfde0a0ada7002348e8b04ac5c79d4b4;hp=7158d7a0bd023c07094502446813dc6ce9dd2d5d;hpb=db74c11d2b8ceea7ba04ef9cc3086d0209de10d4;p=youtube-dl
diff --git a/devscripts/gh-pages/update-feed.py b/devscripts/gh-pages/update-feed.py
index 7158d7a0b..e93eb60fb 100755
--- a/devscripts/gh-pages/update-feed.py
+++ b/devscripts/gh-pages/update-feed.py
@@ -1,83 +1,76 @@
#!/usr/bin/env python3
-
-import sys
-
-import xml.etree.ElementTree as ET
-import xml.dom.minidom as minidom
+from __future__ import unicode_literals
import datetime
+import io
+import json
+import textwrap
-if len(sys.argv) <= 1:
- print('Specify the version number as parameter')
- sys.exit()
-version = sys.argv[1]
-out_file = "atom.atom"
-in_file = out_file
+atom_template = textwrap.dedent("""\
+
+
+
+ youtube-dl releases
+ https://yt-dl.org/feed/youtube-dl-updates-feed
+ @TIMESTAMP@
+ @ENTRIES@
+ """)
-now = datetime.datetime.now()
-now_iso = now.isoformat()
+entry_template = textwrap.dedent("""
+
+ https://yt-dl.org/feed/youtube-dl-updates-feed/youtube-dl-@VERSION@
+ New version @VERSION@
+
+
+
+
+
+ The youtube-dl maintainers
+
+ @TIMESTAMP@
+
+ """)
-atom_url = "http://www.w3.org/2005/Atom"
+now = datetime.datetime.now()
+now_iso = now.isoformat() + 'Z'
-#Some utilities functions
-def atom_tag(tag):
- #Return a tag in the atom namespace
- return "{{{}}}{}".format(atom_url,tag)
-
-def atom_SubElement(parent,tag):
- return ET.SubElement(parent,atom_tag(tag))
-
-class YDLUpdateAtomEntry(object):
- def __init__(self,parent,title,id ,link, downloads_link):
- self.entry = entry = atom_SubElement(parent, "entry")
- #We set the values:
- atom_id = atom_SubElement(entry, "id")
- atom_id.text = id
- atom_title = atom_SubElement(entry, "title")
- atom_title.text = title
- atom_link = atom_SubElement(entry, "link")
- atom_link.set("href", link)
- atom_content = atom_SubElement(entry, "content")
- atom_content.set("type", "xhtml")
- #Here we go:
- div = ET.SubElement(atom_content,"div")
- div.set("xmlns", "http://www.w3.org/1999/xhtml")
- div.text = "Downloads available at "
- a = ET.SubElement(div, "a")
- a.set("href", downloads_link)
- a.text = downloads_link
-
- #Author info
- atom_author = atom_SubElement(entry, "author")
- author_name = atom_SubElement(atom_author, "name")
- author_name.text = "The youtube-dl maintainers"
- #If someone wants to put an email adress:
- #author_email = atom_SubElement(atom_author, "email")
- #author_email.text = the_email
-
- atom_updated = atom_SubElement(entry,"updated")
- up = parent.find(atom_tag("updated"))
- atom_updated.text = up.text = now_iso
-
- @classmethod
- def entry(cls,parent, version):
- update_id = "youtube-dl-{}".format(version)
- update_title = "New version {}".format(version)
- downloads_link = "http://youtube-dl.org/downloads/{}/".format(version)
- #There's probably no better link
- link = "http://rg3.github.com/youtube-dl"
- return cls(parent, update_title, update_id, link, downloads_link)
-
+atom_template = atom_template.replace('@TIMESTAMP@', now_iso)
-atom = ET.parse(in_file)
+versions_info = json.load(open('update/versions.json'))
+versions = list(versions_info['versions'].keys())
+versions.sort()
-root = atom.getroot()
+entries = []
+for v in versions:
+ fields = v.split('.')
+ year, month, day = map(int, fields[:3])
+ faked = 0
+ patchlevel = 0
+ while True:
+ try:
+ datetime.date(year, month, day)
+ except ValueError:
+ day -= 1
+ faked += 1
+ assert day > 0
+ continue
+ break
+ if len(fields) >= 4:
+ try:
+ patchlevel = int(fields[3])
+ except ValueError:
+ patchlevel = 1
+ timestamp = '%04d-%02d-%02dT00:%02d:%02dZ' % (year, month, day, faked, patchlevel)
-#Otherwise when saving all tags will be prefixed with a 'ns0:'
-ET.register_namespace("atom",atom_url)
+ entry = entry_template.replace('@TIMESTAMP@', timestamp)
+ entry = entry.replace('@VERSION@', v)
+ entries.append(entry)
-update_entry = YDLUpdateAtomEntry.entry(root, version)
+entries_str = textwrap.indent(''.join(entries), '\t')
+atom_template = atom_template.replace('@ENTRIES@', entries_str)
-#Find some way of pretty printing
-atom.write(out_file,encoding="utf-8",xml_declaration=True)
+with io.open('update/releases.atom', 'w', encoding='utf-8') as atom_file:
+ atom_file.write(atom_template)