Exemplo n.º 1
0
void Parser::SearchForIsolatedNumbers() {
  for (token_container_t::iterator token = tokens_.begin(); token != tokens_.end(); ++token) {
    if (token->category != kUnknown ||
        !IsNumericString(token->content) ||
        !IsTokenIsolated(token))
      continue;

    int number = StringToInt(token->content);

    // Anime year
    if (number >= kAnimeYearMin && number <= kAnimeYearMax) {
      if (elements_.empty(kElementAnimeYear)) {
        elements_.insert(kElementAnimeYear, token->content);
        token->category = kIdentifier;
        continue;
      }
    }

    // Video resolution
    if (number == 480 || number == 720 || number == 1080) {
      // If these numbers are isolated, it's more likely for them to be the
      // video resolution rather than the episode number. Some fansub groups
      // use these without the "p" suffix.
      if (elements_.empty(kElementVideoResolution)) {
        elements_.insert(kElementVideoResolution, token->content);
        token->category = kIdentifier;
        continue;
      }
    }
  }
}
Exemplo n.º 2
0
bool Parser::SearchForIsolatedNumbers(std::vector<size_t>& tokens) {
  for (auto token_index = tokens.begin();
       token_index != tokens.end(); ++token_index) {
    auto token = tokens_.begin() + *token_index;

    if (!token->enclosed || !IsTokenIsolated(token))
      continue;

    if (SetEpisodeNumber(token->content, *token, true))
      return true;
  }

  return false;
}
Exemplo n.º 3
0
bool Parser::SearchForEquivalentNumbers(std::vector<size_t>& tokens) {
  for (auto token_index = tokens.begin();
       token_index != tokens.end(); ++token_index) {
    auto token = tokens_.begin() + *token_index;

    if (IsTokenIsolated(token))
      continue;

    // Find the first enclosed, non-delimiter token
    auto next_token = FindNextToken(tokens_, token, kFlagNotDelimiter);
    if (next_token != tokens_.end() &&
        next_token->category == kBracket) {
      next_token = FindNextToken(tokens_, next_token,
                                 kFlagEnclosed | kFlagNotDelimiter);
    } else {
      continue;
    }

    // See if it's an isolated number
    if (next_token != tokens_.end() &&
        next_token->category == kUnknown &&
        IsTokenIsolated(next_token) &&
        IsNumericString(next_token->content)) {
      if (IsValidEpisodeNumber(token->content) &&
          IsValidEpisodeNumber(next_token->content)) {
        auto lower_token =
            StringToInt(token->content) < StringToInt(next_token->content) ?
            token : next_token;
        SetEpisodeNumber(lower_token->content, *token, false);
        next_token->category = kIdentifier;
        return true;
      }
    }
  }

  return false;
}