Parser Enhancement: Fallback to Folder name (#129)
* More cases for parsing regex * Implemented GetFoldersTillRoot for falling back on parsing when we can't get anything from the filename. * Implemented a fallback strategy. Not tested on large libraries yet. * Fallback tested and working great. * Removed a test case that won't pass and added some trims
This commit is contained in:
parent
d9246b7351
commit
a0deafe75b
4 changed files with 94 additions and 10 deletions
|
@ -3,6 +3,7 @@ using System.IO;
|
|||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using API.Entities.Enums;
|
||||
using API.Services;
|
||||
|
||||
namespace API.Parser
|
||||
{
|
||||
|
@ -343,9 +344,7 @@ namespace API.Parser
|
|||
public static ParserInfo Parse(string filePath, string rootPath, LibraryType type = LibraryType.Manga)
|
||||
{
|
||||
var fileName = Path.GetFileName(filePath);
|
||||
var directoryName = (new FileInfo(filePath)).Directory?.Name;
|
||||
var rootName = (new DirectoryInfo(rootPath)).Name;
|
||||
|
||||
|
||||
var ret = new ParserInfo()
|
||||
{
|
||||
Chapters = type == LibraryType.Manga ? ParseChapter(fileName) : ParseComicChapter(fileName),
|
||||
|
@ -355,11 +354,32 @@ namespace API.Parser
|
|||
Format = ParseFormat(filePath),
|
||||
FullFilePath = filePath
|
||||
};
|
||||
|
||||
if (ret.Series == string.Empty && directoryName != null && directoryName != rootName)
|
||||
|
||||
if (ret.Series == string.Empty)
|
||||
{
|
||||
ret.Series = ParseSeries(directoryName);
|
||||
if (ret.Series == string.Empty) ret.Series = CleanTitle(directoryName);
|
||||
// Try to parse information out of each folder all the way to rootPath
|
||||
var fallbackFolders = DirectoryService.GetFoldersTillRoot(rootPath, Path.GetDirectoryName(filePath)).ToList();
|
||||
for (var i = 0; i < fallbackFolders.Count; i++)
|
||||
{
|
||||
var folder = fallbackFolders[i];
|
||||
if (!string.IsNullOrEmpty(ParseMangaSpecial(folder))) continue;
|
||||
if (ParseVolume(folder) != "0" || ParseChapter(folder) != "0") continue;
|
||||
|
||||
var series = ParseSeries(folder);
|
||||
|
||||
if ((string.IsNullOrEmpty(series) && i == fallbackFolders.Count - 1))
|
||||
{
|
||||
ret.Series = CleanTitle(folder);
|
||||
break;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(series))
|
||||
{
|
||||
ret.Series = series;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
var edition = ParseEdition(fileName);
|
||||
|
@ -562,7 +582,7 @@ namespace API.Parser
|
|||
{
|
||||
if (match.Success)
|
||||
{
|
||||
title = title.Replace(match.Value, "");
|
||||
title = title.Replace(match.Value, "").Trim();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -574,7 +594,7 @@ namespace API.Parser
|
|||
{
|
||||
if (match.Success)
|
||||
{
|
||||
title = title.Replace(match.Value, "");
|
||||
title = title.Replace(match.Value, "").Trim();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -591,7 +611,7 @@ namespace API.Parser
|
|||
{
|
||||
if (match.Success)
|
||||
{
|
||||
title = title.Replace(match.Value, "");
|
||||
title = title.Replace(match.Value, "").Trim();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue