mirror of
https://github.com/Kareadita/Kavita.git
synced 2025-06-23 15:30:34 -04:00
Fixed some use cases where Edition tags weren't being cleaned up.
This commit is contained in:
parent
6097a2acf0
commit
8498d25aa7
@ -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
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -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.Edition = edition;
|
{
|
||||||
|
ret.Series = CleanTitle(ret.Series.Replace(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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -264,6 +274,23 @@ 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
|
||||||
@ -271,6 +298,21 @@ namespace API.Parser
|
|||||||
/// <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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user