5 import xml.etree.ElementTree as ET
6 import xml.dom.minidom as minidom
10 if len(sys.argv) <= 1:
11 print('Specify the version number as parameter')
15 out_file = "atom.atom"
18 now = datetime.datetime.now()
19 now_iso = now.isoformat()
21 atom_url = "http://www.w3.org/2005/Atom"
23 #Some utilities functions
25 #Return a tag in the atom namespace
26 return "{{{}}}{}".format(atom_url,tag)
28 def atom_SubElement(parent,tag):
29 return ET.SubElement(parent,atom_tag(tag))
31 class YDLUpdateAtomEntry(object):
32 def __init__(self,parent,title,id ,link, downloads_link):
33 self.entry = entry = atom_SubElement(parent, "entry")
35 atom_id = atom_SubElement(entry, "id")
37 atom_title = atom_SubElement(entry, "title")
38 atom_title.text = title
39 atom_link = atom_SubElement(entry, "link")
40 atom_link.set("href", link)
41 atom_content = atom_SubElement(entry, "content")
42 atom_content.set("type", "xhtml")
44 div = ET.SubElement(atom_content,"div")
45 div.set("xmlns", "http://www.w3.org/1999/xhtml")
46 div.text = "Downloads available at "
47 a = ET.SubElement(div, "a")
48 a.set("href", downloads_link)
49 a.text = downloads_link
52 atom_author = atom_SubElement(entry, "author")
53 author_name = atom_SubElement(atom_author, "name")
54 author_name.text = "The youtube-dl maintainers"
55 #If someone wants to put an email adress:
56 #author_email = atom_SubElement(atom_author, "email")
57 #author_email.text = the_email
59 atom_updated = atom_SubElement(entry,"updated")
60 up = parent.find(atom_tag("updated"))
61 atom_updated.text = up.text = now_iso
64 def entry(cls,parent, version):
65 update_id = "youtube-dl-{}".format(version)
66 update_title = "New version {}".format(version)
67 downloads_link = "http://youtube-dl.org/downloads/{}/".format(version)
68 #There's probably no better link
69 link = "http://rg3.github.com/youtube-dl"
70 return cls(parent, update_title, update_id, link, downloads_link)
73 atom = ET.parse(in_file)
77 #Otherwise when saving all tags will be prefixed with a 'ns0:'
78 ET.register_namespace("atom",atom_url)
80 update_entry = YDLUpdateAtomEntry.entry(root, version)
82 #Find some way of pretty printing
83 atom.write(out_file,encoding="utf-8",xml_declaration=True)