/// <summary> /// Search for release group /// </summary> private void SearchForReleaseGroup() { for (int tokenBegin = 0, tokenEnd = tokenBegin; tokenBegin < Tokens.Count;) { // Find the first enclosed unknown token tokenBegin = Token.FindToken(Tokens, tokenEnd, Tokens.Count, Token.TokenFlag.FlagEnclosed, Token.TokenFlag.FlagUnknown); if (!Token.InListRange(tokenBegin, Tokens)) return; // Continue until a bracket or identifier is found tokenEnd = Token.FindToken(Tokens, tokenBegin, Tokens.Count, Token.TokenFlag.FlagBracket, Token.TokenFlag.FlagIdentifier); if (!Token.InListRange(tokenEnd, Tokens) || Tokens[tokenEnd].Category != Token.TokenCategory.Bracket) continue; // Ignore if it's not the first non-delimiter token in group var prevToken = Token.FindPrevToken(Tokens, tokenBegin, Token.TokenFlag.FlagNotDelimiter); if (Token.InListRange(prevToken, Tokens) && Tokens[prevToken].Category != Token.TokenCategory.Bracket) continue; ParseHelper.BuildElement(Element.ElementCategory.ElementReleaseGroup, true, Tokens.GetRange(tokenBegin, tokenEnd - tokenBegin)); return; } }
/// <summary> /// Search for episode title /// </summary> private void SearchForEpisodeTitle() { int tokenBegin; var tokenEnd = 0; do { // Find the first non-enclosed unknown token tokenBegin = Token.FindToken(Tokens, tokenEnd, Tokens.Count, Token.TokenFlag.FlagNotEnclosed, Token.TokenFlag.FlagUnknown); if (!Token.InListRange(tokenBegin, Tokens)) return; // Continue until a bracket or identifier is found tokenEnd = Token.FindToken(Tokens, tokenBegin, Tokens.Count, Token.TokenFlag.FlagBracket, Token.TokenFlag.FlagIdentifier); // Ignore if it's only a dash if (tokenEnd - tokenBegin <= 2 && ParserHelper.IsDashCharacter(Tokens[tokenBegin].Content[0])) continue; //if (tokenBegin.Pos == null || tokenEnd.Pos == null) continue; ParseHelper.BuildElement(Element.ElementCategory.ElementEpisodeTitle, false, Tokens.GetRange(tokenBegin, tokenEnd - tokenBegin)); return; } while (Token.InListRange(tokenBegin, Tokens)); }
/// <summary> /// Search for anime title /// </summary> private void SearchForAnimeTitle() { var enclosedTitle = false; var tokenBegin = Token.FindToken(Tokens, 0, Tokens.Count, Token.TokenFlag.FlagNotEnclosed, Token.TokenFlag.FlagUnknown); // If that doesn't work, find the first unknown token in the second enclosed // group, assuming that the first one is the release group if (!Token.InListRange(tokenBegin, Tokens)) { tokenBegin = 0; enclosedTitle = true; var skippedPreviousGroup = false; do { tokenBegin = Token.FindToken(Tokens, tokenBegin, Tokens.Count, Token.TokenFlag.FlagUnknown); if (!Token.InListRange(tokenBegin, Tokens)) break; // Ignore groups that are composed of non-Latin characters if (StringHelper.IsMostlyLatinString(Tokens[tokenBegin].Content) && skippedPreviousGroup) { break; } // Get the first unknown token of the next group tokenBegin = Token.FindToken(Tokens, tokenBegin, Tokens.Count, Token.TokenFlag.FlagBracket); tokenBegin = Token.FindToken(Tokens, tokenBegin, Tokens.Count, Token.TokenFlag.FlagUnknown); skippedPreviousGroup = true; } while (Token.InListRange(tokenBegin, Tokens)); } if (!Token.InListRange(tokenBegin, Tokens)) return; // Continue until an identifier (or a bracket, if the title is enclosed) is found var tokenEnd = Token.FindToken( Tokens, tokenBegin, Tokens.Count, Token.TokenFlag.FlagIdentifier, enclosedTitle ? Token.TokenFlag.FlagBracket : Token.TokenFlag.FlagNone); // If within the interval there's an open bracket without its matching pair, // move the upper endpoint back to the bracket if (!enclosedTitle) { var lastBracket = tokenEnd; var bracketOpen = false; for (var i = tokenBegin; i < tokenEnd; i++) { if (Tokens[i].Category == Token.TokenCategory.Bracket) { lastBracket = i; bracketOpen = !bracketOpen; } } if (bracketOpen) tokenEnd = lastBracket; } // If the interval ends with an enclosed group (e.g. "Anime Title [Fansub]"), // move the upper endpoint back to the beginning of the group. We ignore // parenthese in order to keep certain groups (e.g. "(TV)") intact. if (!enclosedTitle) { var token = Token.FindPrevToken(Tokens, tokenEnd, Token.TokenFlag.FlagNotDelimiter); while (ParseHelper.IsTokenCategory(token, Token.TokenCategory.Bracket) && Tokens[token].Content[0] != ')') { token = Token.FindPrevToken(Tokens, token, Token.TokenFlag.FlagBracket); if (Token.InListRange(token, Tokens)) { tokenEnd = token; token = Token.FindPrevToken(Tokens, tokenEnd, Token.TokenFlag.FlagNotDelimiter); } } } ParseHelper.BuildElement(Element.ElementCategory.ElementAnimeTitle, false, Tokens.GetRange(tokenBegin, tokenEnd - tokenBegin)); }