Example #1
0
    def reassign_episodes(self, podcast1, podcast2):

        logger.info("Re-assigning episodes of %s into %s", podcast2, podcast1)

        # re-assign episodes to new podcast
        # if necessary, they will be merged later anyway
        for e in episodes_for_podcast_uncached(podcast2):
            self.actions["reassign-episode"] += 1

            for s in all_episode_states(e):
                self.actions["reassign-episode-state"] += 1

                update_episode_state_object(s, podcast1.get_id())

            self._save_episode(e=e, podcast1=podcast1)
Example #2
0
def unify_slugs(podcast):
    """ Removes duplicate slugs of a podcast's episodes """

    logger.warn("unifying slugs for podcast %s", podcast)
    episodes = episodes_for_podcast_uncached(podcast)
    logger.info("found %d episodes", len(episodes))

    common_title = podcast.get_common_episode_title()
    actions = Counter()

    # get episodes with duplicate slugs
    for slug, dups in get_duplicate_slugs(episodes):
        actions["dup-slugs"] += 1
        # and remove their slugs
        logger.info("Found %d duplicates for slug %s", len(dups), slug)
        for dup in dups:
            actions["dup-episodes"] += 1

            # check if we're removing the "main" slug
            if dup.slug == slug:

                # if possible, replace it with a "merged" slug
                if dup.merged_slugs:
                    dup.slug = dup.merged_slugs.pop()
                    actions["replaced-with-merged"] += 1
                    logger.info("Replacing slug with merged slug %s", dup.slug)

                # try to find a new slug
                else:
                    dup.slug = EpisodeSlug(dup, common_title, override_existing=True).get_slug()
                    actions["replaced-with-new"] += 1
                    logger.info("Replacing slug with new slug %s", dup.slug)

            # if the problematic slug is a merged one, remove it
            if slug in dup.merged_slugs:
                actions["removed-merged"] += 1
                logger.info("Removing merged slug %s", slug)
                dup.merged_slugs.remove(slug)

            dup.save()

    return actions, podcast