Fixed some use cases where Edition tags weren't being cleaned up.

This commit is contained in:
Joseph Milazzo 2021-01-24 10:57:09 -06:00
parent 6097a2acf0
commit 8498d25aa7
2 changed files with 58 additions and 14 deletions

View File

@ -176,6 +176,14 @@ namespace API.Tests
FullFilePath = filepath FullFilePath = filepath
}); });
filepath = @"E:\Manga\Tenjo Tenge (Color)\Tenjo Tenge {Full Contact Edition} v01 (2011) (Digital) (ASTC).cbz";
expected.Add(filepath, new ParserInfo
{
Series = "Tenjo Tenge", Volumes = "1", Edition = "Full Contact Edition",
Chapters = "0", Filename = "Tenjo Tenge {Full Contact Edition} v01 (2011) (Digital) (ASTC).cbz", Format = MangaFormat.Archive,
FullFilePath = filepath
});

View File

@ -121,8 +121,7 @@ namespace API.Parser
RegexOptions.IgnoreCase | RegexOptions.Compiled), RegexOptions.IgnoreCase | RegexOptions.Compiled),
}; };
private static readonly Regex[] MangaEditionRegex = new[] private static readonly Regex[] MangaEditionRegex = {
{
//Tenjo Tenge {Full Contact Edition} v01 (2011) (Digital) (ASTC).cbz //Tenjo Tenge {Full Contact Edition} v01 (2011) (Digital) (ASTC).cbz
new Regex( new Regex(
@"(?<Edition>({|\(|\[).* Edition(}|\)|\]))", @"(?<Edition>({|\(|\[).* Edition(}|\)|\]))",
@ -133,6 +132,13 @@ namespace API.Parser
RegexOptions.IgnoreCase | RegexOptions.Compiled), RegexOptions.IgnoreCase | RegexOptions.Compiled),
}; };
private static readonly Regex[] CleanupRegex =
{
new Regex(
@"(?<Cleanup>(\{\}|\[\]|\(\)))",
RegexOptions.IgnoreCase | RegexOptions.Compiled),
};
/// <summary> /// <summary>
/// Parses information out of a file path. Will fallback to using directory name if Series couldn't be parsed /// Parses information out of a file path. Will fallback to using directory name if Series couldn't be parsed
@ -161,14 +167,18 @@ namespace API.Parser
if (ret.Series == string.Empty) ret.Series = CleanTitle(directoryName); if (ret.Series == string.Empty) ret.Series = CleanTitle(directoryName);
} }
var edition = ParseEdition(filePath); var edition = ParseEdition(fileName);
if (edition != string.Empty) ret.Series = ret.Series.Replace(edition, ""); if (edition != string.Empty)
{
ret.Series = CleanTitle(ret.Series.Replace(edition, ""));
ret.Edition = edition; ret.Edition = edition;
}
return ret.Series == string.Empty ? null : ret; return ret.Series == string.Empty ? null : ret;
} }
public static MangaFormat ParseFormat(string filePath) private static MangaFormat ParseFormat(string filePath)
{ {
if (IsArchive(filePath)) return MangaFormat.Archive; if (IsArchive(filePath)) return MangaFormat.Archive;
if (IsImage(filePath)) return MangaFormat.Image; if (IsImage(filePath)) return MangaFormat.Image;
@ -187,7 +197,7 @@ namespace API.Parser
var edition = match.Groups["Edition"].Value.Replace("{", "").Replace("}", "") var edition = match.Groups["Edition"].Value.Replace("{", "").Replace("}", "")
.Replace("[", "").Replace("]", "").Replace("(", "").Replace(")", ""); .Replace("[", "").Replace("]", "").Replace("(", "").Replace(")", "");
return CleanTitle(edition); return edition;
} }
} }
} }
@ -265,12 +275,44 @@ namespace API.Parser
return "0"; return "0";
} }
private static string RemoveEditionTagHolders(string title)
{
foreach (var regex in CleanupRegex)
{
var matches = regex.Matches(title);
foreach (Match match in matches)
{
if (match.Success)
{
title = title.Replace(match.Value, "");
}
}
}
return title;
}
/// <summary> /// <summary>
/// Translates _ -> spaces, trims front and back of string, removes release groups /// Translates _ -> spaces, trims front and back of string, removes release groups
/// </summary> /// </summary>
/// <param name="title"></param> /// <param name="title"></param>
/// <returns></returns> /// <returns></returns>
public static string CleanTitle(string title) public static string CleanTitle(string title)
{
title = RemoveReleaseGroup(title);
title = RemoveEditionTagHolders(title);
title = title.Replace("_", " ").Trim();
if (title.EndsWith("-"))
{
title = title.Substring(0, title.Length - 1);
}
return title.Trim();
}
private static string RemoveReleaseGroup(string title)
{ {
foreach (var regex in ReleaseGroupRegex) foreach (var regex in ReleaseGroupRegex)
{ {
@ -284,13 +326,7 @@ namespace API.Parser
} }
} }
title = title.Replace("_", " ").Trim(); return title;
if (title.EndsWith("-"))
{
title = title.Substring(0, title.Length - 1);
}
return title.Trim();
} }