def validate_elements(self): # Validate anime type and episode title if Elements.contains(ElementCategory.ANIME_TYPE) and \ Elements.contains(ElementCategory.EPISODE_TITLE): # Here we check whether the episode title contains an anime type episode_title = Elements.get(ElementCategory.EPISODE_TITLE)[0] # Copy list because we may modify it anime_type_list = list(Elements.get(ElementCategory.ANIME_TYPE)) for anime_type in anime_type_list: if anime_type == episode_title: # Invalid episode title Elements.erase(ElementCategory.EPISODE_TITLE) elif anime_type in episode_title: norm_anime_type = keyword_manager.normalize(anime_type) if keyword_manager.find( norm_anime_type, ElementCategory.ANIME_TYPE): Elements.remove(ElementCategory.ANIME_TYPE, anime_type) continue
def set_episode_number(number, token, validate): if validate and not is_valid_episode_number(number): return False token.category = TokenCategory.IDENTIFIER category = ElementCategory.EPISODE_NUMBER # Handle equivalent numbers if Elements.get_check_alt_number(): # TODO: check if getting only the first episode number is enough episode_number = Elements.get(ElementCategory.EPISODE_NUMBER)[0] if str2int(number) > str2int(episode_number): category = ElementCategory.EPISODE_NUMBER_ALT elif str2int(number) < str2int(episode_number): Elements.remove(ElementCategory.EPISODE_NUMBER, episode_number) Elements.insert(ElementCategory.EPISODE_NUMBER_ALT, episode_number) else: return False Elements.insert(category, number) return True