#!/usr/bin/env python # tvitem, a small script to add videos to rss channel feed # Copyright (c) 2008 Kushal Das # # Version: 0.1.1 # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this program; if not, write to the # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. import sys import os from optparse import OptionParser import xml.dom.minidom from datetime import datetime def main(argv): """tvtime -f rssfilename""" parser = OptionParser() parser.add_option('-f', '--file', type="string", help="Filename of the channel rss file") (options, throwaway) = parser.parse_args(argv[1:]) if options.file: if not os.path.lexists(options.file): print "The rss file does not exist" sys.exit(1) f = open(options.file) doc = xml.dom.minidom.parse(f) f.close() newtime = doc.childNodes[0].childNodes[1].childNodes[11] newtime.childNodes[0].data = datetime.now().strftime("%a, %d %b %Y %H:%M:%S") + " GMT" channel = doc.childNodes[0].childNodes[1] title = raw_input("Enter the title of the video:") link = raw_input("Enter the link of the video:") desc = raw_input("Enter the description of the video:") localpath = raw_input("Enter the localpath of the video:") if not os.path.lexists(localpath): print "The video/audio file does not exist" sys.exit(1) newitem = doc.createElement('item') channel.insertBefore(newitem, channel.childNodes[15]) #To add title newElement = doc.createElement('title') newitem.appendChild(newElement) newTextNode = doc.createTextNode(title) newElement.appendChild(newTextNode) #To add link newElement = doc.createElement('link') newitem.appendChild(newElement) newTextNode = doc.createTextNode(link) newElement.appendChild(newTextNode) #To add description newElement = doc.createElement('description') newitem.appendChild(newElement) newTextNode = doc.createTextNode(desc) newElement.appendChild(newTextNode) #To add pubDate newElement = doc.createElement('pubDate') newitem.appendChild(newElement) newTextNode = doc.createTextNode(datetime.now().strftime("%a, %d %b %Y %H:%M:%S") + " GMT") newElement.appendChild(newTextNode) #To add enclouser newElement = doc.createElement('enclosure') newElement.setAttribute("url", link) newElement.setAttribute("type", "video/x-theora+ogg") newElement.setAttribute("length", str(os.path.getsize(localpath))) newitem.appendChild(newElement) #To add guid newElement = doc.createElement('guid') newitem.appendChild(newElement) newTextNode = doc.createTextNode(link) newElement.appendChild(newTextNode) f = open(options.file, "w") f.write(doc.toprettyxml(indent=" ")) f.close() else: print """Usage: tvitem [options] Options: -h, --help show this help message and exit -f FILE, --file=FILE Filename of the channel rss file""" if __name__ == "__main__": main(sys.argv)