Exemplo n.º 1
0
def search_for_last_number(tokens):
    for token in tokens:
        token_index = Tokens.get_index(token)

        # Assuming that episode number always comes after the title, first
        # token cannot be what we're looking for
        if token_index == 0:
            continue

        # An enclosed token is unlikely to be the episode number at this point
        if token.enclosed:
            continue

        # Ignore if it's the first non-enclosed, non-delimiter token
        if all([
                t.enclosed or t.category == TokenCategory.DELIMITER
                for t in Tokens.get_list()[:token_index]
        ]):
            continue

        # Ignore if the previous token is "Movie" or "Part"
        previous_token = Tokens.find_previous(token, TokenFlags.NOT_DELIMITER)
        if previous_token.category == TokenCategory.UNKNOWN:
            if previous_token.content.lower() == 'movie' or \
                    previous_token.content.lower() == 'part':
                continue

        # We'll use this number after all
        if set_episode_number(token.content, token, validate=True):
            return True

    return False
Exemplo n.º 2
0
def match_type_and_episode_pattern(word, token):
    number_begin = parser_helper.find_number_in_string(word)
    prefix = word[:number_begin]

    keyword = keyword_manager.find(keyword_manager.normalize(prefix),
                                   ElementCategory.ANIME_TYPE)

    if keyword:
        Elements.insert(ElementCategory.ANIME_TYPE, prefix)
        number = word[number_begin:]
        if match_episode_patterns(number, token) or \
                set_episode_number(number, token, validate=True):
            # Split token (we do this last in order to avoid invalidating our
            # token reference earlier)
            token_index = Tokens.get_index(token)
            token.content = number
            Tokens.insert(
                token_index,
                Token(
                    TokenCategory.IDENTIFIER if keyword.options.identifiable
                    else TokenCategory.UNKNOWN, prefix, token.enclosed))
            return True

    return False