2
# Copyright 2009, Martin Owens.
4
# This program is free software: you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation, either version 3 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program. If not, see <http://www.gnu.org/licenses/>.
18
Plugin base for RSS based wallpaper sources.
21
from gwc.base import ListerBase
23
class rssBase(ListerBase):
24
"""Get a random wallpaper from an RSS feed"""
25
def __init__(self, folder, url):
26
self._url = unicode(url)
27
lister.__init__(self, folder)
30
"""Download rss feed, turn into list of addresses"""
31
feedxml = self.get_url(self._url)
33
xmldoc = minidom.parseString(feedxml)
34
for part in xmldoc.childNodes:
35
if part.nodeType==1 and part.tagName=='rss':
36
for channel in part.childNodes:
37
if channel.nodeType==1 and channel.tagName=='channel':
38
for item in self.listFromRSS(channel):
41
def listFromRSS(self, channel):
42
for item in channel.childNodes:
43
if item.nodeType==1 and item.tagName=='item':
44
item = self.rssItem(item)
48
def rssItem(self, item):
50
for attr in item.childNodes:
52
if attr.tagName=='link':
53
# This allows feeds that put their images as links, or for hops.
55
for text in attr.childNodes:
58
elif attr.tagName=='media:content' and attr.getAttribute('type')=='image/jpeg':
59
# This allows rss feeds targeting media content to be used.
60
return attr.getAttribute('url')