Esempio n. 1
0
void Parser::SearchForKeywords() {
  for (auto it = tokens_.begin(); it != tokens_.end(); ++it) {
    auto& token = *it;

    if (token.category != kUnknown)
      continue;

    auto word = token.content;
    TrimString(word, L" -");

    if (word.empty())
      continue;
    // Don't bother if the word is a number that cannot be CRC
    if (word.size() != 8 && IsNumericString(word))
      continue;

    // Performs better than making a case-insensitive Find
    auto keyword = keyword_manager.Normalize(word);
    ElementCategory category = kElementUnknown;
    KeywordOptions options;

    if (keyword_manager.Find(keyword, category, options)) {
      if (!options_.parse_release_group && category == kElementReleaseGroup)
        continue;
      if (!IsElementCategorySearchable(category) || !options.searchable)
        continue;
      if (IsElementCategorySingular(category) && !elements_.empty(category))
        continue;
      if (category == kElementAnimeSeasonPrefix) {
        CheckAnimeSeasonKeyword(it);
        continue;
      } else if (category == kElementEpisodePrefix) {
        if (options.valid)
          CheckExtentKeyword(kElementEpisodeNumber, it);
        continue;
      } else if (category == kElementReleaseVersion) {
        word = word.substr(1);  // number without "v"
      } else if (category == kElementVolumePrefix) {
        CheckExtentKeyword(kElementVolumeNumber, it);
        continue;
      }
    } else {
      if (elements_.empty(kElementFileChecksum) && IsCrc32(word)) {
        category = kElementFileChecksum;
      } else if (elements_.empty(kElementVideoResolution) &&
                 IsResolution(word)) {
        category = kElementVideoResolution;
      }
    }

    if (category != kElementUnknown) {
      elements_.insert(category, word);
      if (options.identifiable)
        token.category = kIdentifier;
    }
  }
}
Esempio n. 2
0
void Parser::SearchForKeywords() {
  for (auto& token : tokens_) {
    if (token.category != kUnknown)
      continue;

    auto word = token.content;
    TrimString(word);

    // Don't bother if the word is a number that cannot be CRC
    if (word.size() != 8 && IsNumericString(word))
      continue;

    // Performs better than making a case-insensitive Find
    auto keyword = StringToUpperCopy(word);

    for (int i = kElementIterateFirst; i < kElementIterateLast; i++) {
      auto category = static_cast<ElementCategory>(i);

      if (!parse_options.parse_release_group)
        if (category == kElementReleaseGroup)
          continue;

      if (!IsElementCategorySearchable(category))
        continue;

      if (IsElementCategorySingular(category))
        if (!elements_.empty(category))
          continue;

      bool add_keyword = false;
      KeywordOptions options;

      switch (category) {
        case kElementFileChecksum:
          add_keyword = IsCrc32(word);
          break;
        case kElementVideoResolution:
          add_keyword = IsResolution(word);
          break;
        default:
          add_keyword = keyword_manager.Find(category, keyword, options);
          break;
      }

      if (add_keyword) {
        switch (category) {
          case kElementReleaseVersion:
            elements_.insert(category, word.substr(1));  // number without "v"
            break;
          default:
            elements_.insert(category, word);
            break;
        }

        if (options.safe || token.enclosed)
          token.category = kIdentifier;

        break;
      }
    }
  }
}