Пример #1
0
    /** Search for anime keywords. */
    private void SearchForKeywords()
    {
      for (var i = 0; i < Tokens.Count; i++)
      {
        var token = Tokens[i];
        if (token.Category != Token.TokenCategory.Unknown) continue;

        var word = token.Content;
        word = word.Trim(" -".ToCharArray());
        if (string.IsNullOrEmpty(word)) continue;

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

        var keyword = KeywordManager.Normalize(word);
        var category = Element.ElementCategory.ElementUnknown;
        var options = new KeywordOptions();

        if (KeywordManager.Instance.FindAndSet(keyword, ref category, ref options))
        {
          if (!Options.ParseReleaseGroup && category == Element.ElementCategory.ElementReleaseGroup) continue;
          if (!ParseHelper.IsElementCategorySearchable(category) || !options.Searchable) continue;
          if (ParseHelper.IsElementCategorySingular(category) && !Empty(category)) continue;
          if (category == Element.ElementCategory.ElementAnimeSeasonPrefix)
          {
            ParseHelper.CheckAndSetAnimeSeasonKeyword(token, i);
            continue;
          }

          if (category == Element.ElementCategory.ElementEpisodePrefix)
          {
            if (options.Valid)
            {
              ParseHelper.CheckExtentKeyword(Element.ElementCategory.ElementEpisodeNumber, i, token);
              continue;
            }
          }
          else if (category == Element.ElementCategory.ElementReleaseVersion)
          {
            word = word.Substring(1);
          }
          else if (category == Element.ElementCategory.ElementVolumePrefix)
          {
            ParseHelper.CheckExtentKeyword(Element.ElementCategory.ElementVolumeNumber, i, token);
            continue;
          }
        }
        else
        {
          if (Empty(Element.ElementCategory.ElementFileChecksum) && ParserHelper.IsCrc32(word))
          {
            category = Element.ElementCategory.ElementFileChecksum;
          } else if (Empty(Element.ElementCategory.ElementVideoResolution) && ParserHelper.IsResolution(word))
          {
            category = Element.ElementCategory.ElementVideoResolution;
          }
        }

        if (category != Element.ElementCategory.ElementUnknown)
        {
          Elements.Add(new Element(category, word));
          if (options.Identifiable)
          {
            token.Category = Token.TokenCategory.Identifier;
          }
        }
      }
    }