2006-02-04 14:21:07 +01:00
|
|
|
|
|
|
|
#
|
|
|
|
# gPodder
|
|
|
|
# Copyright (c) 2005-2006 Thomas Perl <thp@perli.net>
|
|
|
|
# Released under the GNU General Public License (GPL)
|
|
|
|
#
|
|
|
|
|
|
|
|
#
|
|
|
|
# liblocdbwriter.py -- rss output writer for your downloaded feeds
|
|
|
|
# thomas perl <thp@perli.net> 20060109
|
|
|
|
#
|
|
|
|
#
|
|
|
|
|
2006-03-19 15:21:48 +01:00
|
|
|
import codecs
|
|
|
|
|
2006-02-04 14:21:07 +01:00
|
|
|
from datetime import datetime
|
2006-04-06 16:11:03 +02:00
|
|
|
from xml.sax import saxutils
|
2006-02-04 14:21:07 +01:00
|
|
|
|
2006-03-24 20:08:59 +01:00
|
|
|
import libgpodder
|
|
|
|
|
2006-02-04 14:21:07 +01:00
|
|
|
class writeLocalDB( object):
|
|
|
|
ofile = None
|
|
|
|
|
2006-03-24 20:08:59 +01:00
|
|
|
def __init__( self, filename, channel, delete_if_empty = True):
|
|
|
|
if delete_if_empty and len( channel.items) == 0:
|
|
|
|
if libgpodder.isDebugging():
|
|
|
|
print "Seems like there is no item left in this localDB channel"
|
|
|
|
print "Deleting channel index file of empty local channel.."
|
|
|
|
libgpodder.gPodderLib().deleteFilename( filename)
|
|
|
|
return
|
|
|
|
|
2006-03-19 18:44:47 +01:00
|
|
|
self.ofile = codecs.open( filename, "w", 'iso-8859-1', 'replace')
|
2006-02-04 14:21:07 +01:00
|
|
|
self.ofile.write( '<?xml version="1.0" encoding="ISO-8859-1"?>'+"\n")
|
2006-03-31 15:00:54 +02:00
|
|
|
self.ofile.write( '<!-- '+_('local download database, generated by gPodder')+' -->'+"\n")
|
2006-02-04 14:21:07 +01:00
|
|
|
self.ofile.write( '<rss version="2.0">'+"\n")
|
|
|
|
self.ofile.write( '<channel>'+"\n")
|
|
|
|
self.ofile.write( '<pubDate>' + datetime.now().ctime() + '</pubDate>'+"\n")
|
|
|
|
|
|
|
|
self.writeTitle( channel.title)
|
|
|
|
self.writeDescription( channel.description)
|
|
|
|
self.writeLink( channel.link)
|
2006-04-07 03:43:06 +02:00
|
|
|
self.writeMetadata( channel)
|
2006-02-04 14:21:07 +01:00
|
|
|
|
|
|
|
for item in channel.items:
|
|
|
|
self.addItem( item)
|
|
|
|
|
|
|
|
self.close()
|
|
|
|
|
|
|
|
def writeTitle( self, title):
|
2006-04-06 16:11:03 +02:00
|
|
|
self.ofile.write( '<title>'+saxutils.escape(title)+'</title>'+"\n")
|
2006-02-04 14:21:07 +01:00
|
|
|
|
|
|
|
def writeDescription( self, description):
|
2006-04-06 16:11:03 +02:00
|
|
|
self.ofile.write( '<description><![CDATA['+description+']]></description>'+"\n")
|
2006-02-04 14:21:07 +01:00
|
|
|
|
|
|
|
def writeLink( self, link):
|
|
|
|
self.ofile.write( '<link>'+link+'</link>'+"\n")
|
|
|
|
|
2006-04-07 03:43:06 +02:00
|
|
|
def writeMetadata( self, channel):
|
|
|
|
self.ofile.write( '<gpodder:info')
|
|
|
|
self.ofile.write( ' nosync="%s"' % (str(not channel.sync_to_devices).lower()))
|
|
|
|
self.ofile.write( '/>'+"\n")
|
|
|
|
|
2006-02-04 14:21:07 +01:00
|
|
|
def close( self):
|
|
|
|
self.ofile.write( '</channel>'+"\n")
|
|
|
|
self.ofile.write( '</rss>'+"\n")
|
|
|
|
self.ofile.close()
|
|
|
|
|
|
|
|
def addItem( self, item):
|
|
|
|
self.ofile.write( '<item>'+"\n")
|
2006-04-06 16:11:03 +02:00
|
|
|
self.ofile.write( '<title>'+saxutils.escape(item.title)+'</title>'+"\n")
|
2006-04-03 22:14:07 +02:00
|
|
|
self.ofile.write( '<description><![CDATA['+item.description+']]></description>'+"\n")
|
2006-04-06 16:11:03 +02:00
|
|
|
self.ofile.write( '<url>'+saxutils.escape(item.url)+'</url>'+"\n")
|
2006-02-04 14:21:07 +01:00
|
|
|
self.ofile.write( '</item>'+"\n")
|
|
|
|
|
|
|
|
|