def handle(self, *args, **options): groups = PodcastGroupsMissingSlugs() total = len(groups) for n, group in enumerate(groups): assign_slug(group, PodcastGroupSlug) progress(n+1, total) # only consider podcasts that have enough subscribers min_subscribers = settings.PODCAST_SLUG_SUBSCRIBER_LIMIT enough_subscribers = lambda p: p.subscriber_count() >= min_subscribers podcasts = PodcastsMissingSlugs() total = len(podcasts) for n, podcast in enumerate(takewhile(enough_subscribers, podcasts)): assign_slug(podcast, PodcastSlug) progress(n+1, total)
changed = True if changed: print 'updating podcast' podcast.last_update = datetime.utcnow() podcast.save() else: print 'podcast not updated' except Exception, e: print podcast.url print >>sys.stderr, 'Exception:', e assign_slug(podcast, PodcastSlug) assign_missing_episode_slugs(podcast) def get_podcast_logo(podcast, feed): cover_art = podcast.logo_url image = feed.feed.get('image', None) if image is not None: for key in ('href', 'url'): cover_art = getattr(image, key, None) if cover_art: break if podcast.link: yturl = youtube.get_real_cover(podcast.link) if yturl:
def _update_podcast(self, podcast, parsed, episodes): """ updates a podcast according to new parser results """ # we need that later to decide if we can "bump" a category prev_latest_episode_timestamp = podcast.latest_episode_timestamp old_json = copy.deepcopy(podcast.to_json()) podcast.title = parsed.title or podcast.title podcast.urls = list(set(podcast.urls + parsed.urls)) podcast.description = parsed.description or podcast.description podcast.subtitle = parsed.subtitle or podcast.subtitle podcast.link = parsed.link or podcast.link podcast.logo_url = parsed.logo or podcast.logo_url podcast.author = parsed.author or podcast.author podcast.language = parsed.language or podcast.language podcast.content_types = parsed.content_types or podcast.content_types podcast.tags['feed'] = parsed.tags or podcast.tags.get('feed', []) podcast.common_episode_title = parsed.common_title or podcast.common_episode_title podcast.new_location = parsed.new_location or podcast.new_location podcast.flattr_url = parsed.flattr or podcast.flattr_url podcast.hub = parsed.hub or podcast.hub podcast.license = parsed.license or podcast.license if podcast.new_location: new_podcast = podcast_for_url(podcast.new_location) if new_podcast != podcast: self._mark_outdated(podcast, 'redirected to different podcast') return elif not new_podcast: podcast.urls.insert(0, podcast.new_location) logger.info('Retrieved %d episodes in total', len(episodes)) # latest episode timestamp eps = filter(lambda e: bool(e.released), episodes) eps = sorted(eps, key=lambda e: e.released) podcast.update_interval = get_update_interval(eps) if eps: podcast.latest_episode_timestamp = eps[-1].released podcast.episode_count = episode_count_for_podcast(podcast) self._update_categories(podcast, prev_latest_episode_timestamp) # try to download the logo and reset logo_url to None on http errors found = self._save_podcast_logo(podcast.logo_url) if not found: podcast.logo_url = None # The podcast is always saved (not just when there are changes) because # we need to record the last update logger.info('Saving podcast.') podcast.last_update = datetime.utcnow() podcast.save() try: subscribe_at_hub(podcast) except SubscriptionError as se: logger.warn('subscribing to hub failed: %s', str(se)) assign_slug(podcast, PodcastSlug) assign_missing_episode_slugs(podcast)