2006-02-04 14:21:07 +01:00
|
|
|
|
|
|
|
#
|
2006-04-07 22:22:30 +02:00
|
|
|
# gPodder (a media aggregator / podcast client)
|
|
|
|
# Copyright (C) 2005-2006 Thomas Perl <thp at perli.net>
|
2006-02-04 14:21:07 +01:00
|
|
|
#
|
2006-04-07 22:22:30 +02:00
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# 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 General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
|
|
# MA 02110-1301, USA.
|
|
|
|
#
|
|
|
|
|
2006-02-04 14:21:07 +01:00
|
|
|
|
|
|
|
#
|
|
|
|
# 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):
|
2006-04-08 09:22:30 +02:00
|
|
|
if delete_if_empty and len( channel) == 0:
|
2006-03-24 20:08:59 +01:00
|
|
|
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
|
|
|
|
2006-04-08 09:22:30 +02:00
|
|
|
for item in channel:
|
2006-02-04 14:21:07 +01:00
|
|
|
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")
|
|
|
|
|
|
|
|
|