def get_common_episode_title(self, num_episodes=100): if self.common_episode_title: return self.common_episode_title episodes = self.episode_set.all()[:num_episodes] # We take all non-empty titles titles = [_f for _f in (e.title for e in episodes) if _f] # there can not be a "common" title of a single title if len(titles) < 2: return None # get the longest common substring common_title = utils.longest_substr(titles) # but consider only the part up to the first number. Otherwise we risk # removing part of the number (eg if a feed contains episodes 100-199) common_title = re.search(r"^\D*", common_title).group(0) if len(common_title.strip()) < 2: return None return common_title
def get_common_episode_title(self, num_episodes=100): if self.common_episode_title: return self.common_episode_title episodes = self.episode_set.all()[:num_episodes] # We take all non-empty titles titles = [_f for _f in (e.title for e in episodes) if _f] # there can not be a "common" title of a single title if len(titles) < 2: return None # get the longest common substring common_title = utils.longest_substr(titles) # but consider only the part up to the first number. Otherwise we risk # removing part of the number (eg if a feed contains episodes 100-199) common_title = re.search(r'^\D*', common_title).group(0) if len(common_title.strip()) < 2: return None return common_title
def get_common_episode_title(self, num_episodes=100): if self.common_episode_title: return self.common_episode_title from mygpo.db.couchdb.episode import episodes_for_podcast episodes = episodes_for_podcast(self, descending=True, limit=num_episodes) # We take all non-empty titles titles = filter(None, (e.title for e in episodes)) # there can not be a "common" title of a single title if len(titles) < 2: return None # get the longest common substring common_title = utils.longest_substr(titles) # but consider only the part up to the first number. Otherwise we risk # removing part of the number (eg if a feed contains episodes 100-199) common_title = re.search(r'^\D*', common_title).group(0) if len(common_title.strip()) < 2: return None return common_title
def get_common_episode_title(self, num_episodes=100): if self.common_episode_title: return self.common_episode_title episodes = self.get_episodes(descending=True, limit=num_episodes) # We take all non-empty titles titles = filter(None, (e.title for e in episodes)) # get the longest common substring common_title = utils.longest_substr(titles) # but consider only the part up to the first number. Otherwise we risk # removing part of the number (eg if a feed contains episodes 100-199) common_title = re.search(r'^\D*', common_title).group(0) if len(common_title.strip()) < 2: return None return common_title