1 # -*- coding: utf-8 -*-
3 # gPodder - A media aggregator and podcast client
4 # Copyright (c) 2005-2013 Thomas Perl and the gPodder Team
6 # gPodder is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # gPodder is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 from mygpoclient
import feeds
23 logger
= logging
.getLogger(__name__
)
26 def parse_entry(podcast
, entry
):
27 download_url
= entry
['default_file']['url']
28 return podcast
.episode_factory({
29 'title': entry
['title'],
30 'description': entry
.get('description', ''),
32 'mime_type': entry
['default_file']['mime_type'],
33 'file_size': entry
.get('filesize', -1),
34 'guid': entry
.get('guid', download_url
),
35 'link': entry
.get('link', ''),
36 'published': entry
.get('released', 0),
37 'total_time': entry
.get('duration', 0),
41 def update_using_feedservice(podcasts
):
42 urls
= [podcast
.url
for podcast
in podcasts
]
43 client
= feeds
.FeedserviceClient()
44 # Last modified + logo/etc..
45 result
= client
.parse_feeds(urls
)
47 for podcast
in podcasts
:
48 feed
= result
.get_feed(podcast
.url
)
50 logger
.info('Feed not updated: %s', podcast
.url
)
53 # Handle permanent redirects
54 if feed
.get('new_location', False):
55 new_url
= feed
['new_location']
56 logger
.info('Redirect %s => %s', podcast
.url
, new_url
)
60 if feed
.get('errors', False):
61 logger
.error('Error parsing feed: %s', repr(feed
['errors']))
64 # Update per-podcast metadata
65 podcast
.title
= feed
.get('title', podcast
.url
)
66 podcast
.link
= feed
.get('link', podcast
.link
)
67 podcast
.description
= feed
.get('description', podcast
.description
)
68 podcast
.cover_url
= feed
.get('logo', podcast
.cover_url
)
69 #podcast.http_etag = feed.get('http_etag', podcast.http_etag)
70 #podcast.http_last_modified = feed.get('http_last_modified', \
71 # podcast.http_last_modified)
75 parsed_episodes
= [parse_entry(podcast
, entry
) for entry
in feed
['episodes']]