(self, podcast, parsed, episode_updater, update_result)
updates a podcast according to new parser results
updates a podcast according to new parser results
updates a podcast according to new parser results
def _update_podcast(self, podcast, parsed, episode_updater, update_result):
        """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

        # will later be used to see whether the index is outdated
        old_index_fields = get_index_fields(podcast)

        podcast.title = parsed.get("title") or podcast.title
        podcast.description = parsed.get("description") or podcast.description
        podcast.subtitle = parsed.get("subtitle") or podcast.subtitle
        podcast.link = parsed.get("link") or podcast.link
        podcast.logo_url = parsed.get("logo") or podcast.logo_url

        podcast.author = to_maxlength(
            Podcast, "author", parsed.get("author") or podcast.author
        )

        podcast.language = to_maxlength(
            Podcast, "language", parsed.get("language") or podcast.language
        )

        podcast.content_types = (
            ",".join(parsed.get("content_types")) or podcast.content_types
        )

        # podcast.tags['feed'] = parsed.tags or podcast.tags.get('feed', [])

        podcast.common_episode_title = to_maxlength(
            Podcast,
            "common_episode_title",
            parsed.get("common_title") or podcast.common_episode_title,
        )

        podcast.new_location = parsed.get("new_location") or podcast.new_location
        podcast.flattr_url = to_maxlength(
            Podcast, "flattr_url", parsed.get("flattr") or podcast.flattr_url
        )
        podcast.hub = parsed.get("hub") or podcast.hub
        podcast.license = parsed.get("license") or podcast.license
        podcast.max_episode_order = episode_updater.max_episode_order

        podcast.add_missing_urls(parsed.get("urls", []))

        if podcast.new_location:
            try:
                new_podcast = Podcast.objects.get(urls__url=podcast.new_location)

                if new_podcast != podcast:
                    self._mark_outdated(
                        podcast, "redirected to different podcast", episode_updater
                    )
                    return
            except Podcast.DoesNotExist:
                podcast.set_url(podcast.new_location)

        # latest episode timestamp
        episodes = Episode.objects.filter(
            podcast=podcast, released__isnull=False
        ).order_by("released")

        # Determine update interval

        # Update interval is based on intervals between episodes
        podcast.update_interval = episode_updater.get_update_interval(episodes)

        # factor is increased / decreased depending on whether the latest
        # update has returned episodes
        if update_result.episodes_added == 0:  # no episodes, incr factor
            newfactor = podcast.update_interval_factor * 1.2
            podcast.update_interval_factor = min(1000, newfactor)  # never above 1000
        elif update_result.episodes_added > 1:  # new episodes, decr factor
            newfactor = podcast.update_interval_factor / 1.2
            podcast.update_interval_factor = max(1, newfactor)  # never below 1

        latest_episode = episodes.last()
        if latest_episode:
            podcast.latest_episode_timestamp = latest_episode.released

        # podcast.episode_count is not update here on purpose. It is, instead,
        # continuously updated when creating new episodes in
        # EpisodeManager.get_or_create_for_url

        self._update_categories(podcast, prev_latest_episode_timestamp)

        # try to download the logo and reset logo_url to None on http errors
        found = CoverArt.save_podcast_logo(podcast.logo_url)
        if not found:
            podcast.logo_url = None

        # check if search index should be considered out of date
        new_index_fields = get_index_fields(podcast)
        if list(old_index_fields.items()) != list(new_index_fields.items()):
            podcast.search_index_uptodate = False

        # 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.warning("subscribing to hub failed: %s", str(se))

        self.assign_slug(podcast)
        episode_updater.assign_missing_episode_slugs()
        update_related_podcasts.delay(podcast.pk)
def _update_podcast ( self , podcast , parsed , episode_updater , update_result ) : # we need that later to decide if we can "bump" a category prev_latest_episode_timestamp = podcast . latest_episode_timestamp # will later be used to see whether the index is outdated old_index_fields = get_index_fields ( podcast ) podcast . title = parsed . get ( "title" ) or podcast . title podcast . description = parsed . get ( "description" ) or podcast . description podcast . subtitle = parsed . get ( "subtitle" ) or podcast . subtitle podcast . link = parsed . get ( "link" ) or podcast . link podcast . logo_url = parsed . get ( "logo" ) or podcast . logo_url podcast . author = to_maxlength ( Podcast , "author" , parsed . get ( "author" ) or podcast . author ) podcast . language = to_maxlength ( Podcast , "language" , parsed . get ( "language" ) or podcast . language ) podcast . content_types = ( "," . join ( parsed . get ( "content_types" ) ) or podcast . content_types ) # podcast.tags['feed'] = parsed.tags or podcast.tags.get('feed', []) podcast . common_episode_title = to_maxlength ( Podcast , "common_episode_title" , parsed . get ( "common_title" ) or podcast . common_episode_title , ) podcast . new_location = parsed . get ( "new_location" ) or podcast . new_location podcast . flattr_url = to_maxlength ( Podcast , "flattr_url" , parsed . get ( "flattr" ) or podcast . flattr_url ) podcast . hub = parsed . get ( "hub" ) or podcast . hub podcast . license = parsed . get ( "license" ) or podcast . license podcast . max_episode_order = episode_updater . max_episode_order podcast . add_missing_urls ( parsed . get ( "urls" , [ ] ) ) if podcast . new_location : try : new_podcast = Podcast . objects . get ( urls__url = podcast . new_location ) if new_podcast != podcast : self . _mark_outdated ( podcast , "redirected to different podcast" , episode_updater ) return except Podcast . DoesNotExist : podcast . set_url ( podcast . new_location ) # latest episode timestamp episodes = Episode . objects . filter ( podcast = podcast , released__isnull = False ) . order_by ( "released" ) # Determine update interval # Update interval is based on intervals between episodes podcast . update_interval = episode_updater . get_update_interval ( episodes ) # factor is increased / decreased depending on whether the latest # update has returned episodes if update_result . episodes_added == 0 : # no episodes, incr factor newfactor = podcast . update_interval_factor * 1.2 podcast . update_interval_factor = min ( 1000 , newfactor ) # never above 1000 elif update_result . episodes_added > 1 : # new episodes, decr factor newfactor = podcast . update_interval_factor / 1.2 podcast . update_interval_factor = max ( 1 , newfactor ) # never below 1 latest_episode = episodes . last ( ) if latest_episode : podcast . latest_episode_timestamp = latest_episode . released # podcast.episode_count is not update here on purpose. It is, instead, # continuously updated when creating new episodes in # EpisodeManager.get_or_create_for_url self . _update_categories ( podcast , prev_latest_episode_timestamp ) # try to download the logo and reset logo_url to None on http errors found = CoverArt . save_podcast_logo ( podcast . logo_url ) if not found : podcast . logo_url = None # check if search index should be considered out of date new_index_fields = get_index_fields ( podcast ) if list ( old_index_fields . items ( ) ) != list ( new_index_fields . items ( ) ) : podcast . search_index_uptodate = False # 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 . warning ( "subscribing to hub failed: %s" , str ( se ) ) self . assign_slug ( podcast ) episode_updater . assign_missing_episode_slugs ( ) update_related_podcasts . delay ( podcast . pk )