Optimize anime identity

This commit is contained in:
cxfksword 2023-02-21 21:33:26 +08:00
parent ea3dfec554
commit 7f347542fa
5 changed files with 41 additions and 30 deletions

View File

@ -46,8 +46,9 @@ namespace Jellyfin.Plugin.MetaShark.Test
var info = new EpisodeInfo() var info = new EpisodeInfo()
{ {
Name = "Spice and Wolf", Name = "Spice and Wolf",
Path = "/test/Spice and Wolf/Spice and Wolf II/[VCB-Studio] Spice and Wolf II [01][Ma10p_1080p][x265_flac].mp4", Path = "/test/Spice and Wolf/S00/[VCB-Studio] Spice and Wolf II [01][Hi444pp_1080p][x264_flac].mkv",
MetadataLanguage = "zh", MetadataLanguage = "zh",
ParentIndexNumber = 0,
SeriesProviderIds = new Dictionary<string, string>() { { MetadataProvider.Tmdb.ToString(), "26707" } }, SeriesProviderIds = new Dictionary<string, string>() { { MetadataProvider.Tmdb.ToString(), "26707" } },
IsAutomated = false, IsAutomated = false,
}; };

View File

@ -220,6 +220,10 @@ namespace Jellyfin.Plugin.MetaShark.Test
parseResult = NameParser.Parse(fileName); parseResult = NameParser.Parse(fileName);
Assert.IsTrue(parseResult.IsExtra); Assert.IsTrue(parseResult.IsExtra);
fileName = "[VCB-Studio] Spice and Wolf II [Drama02][Ma10p_1080p][x265_flac].mp4";
parseResult = NameParser.Parse(fileName);
Assert.IsTrue(parseResult.IsExtra);
} }

View File

@ -1,3 +1,4 @@
using System.Collections.Specialized;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -65,13 +66,30 @@ namespace Jellyfin.Plugin.MetaShark.Model
{ {
if (IndexNumber.HasValue) if (IndexNumber.HasValue)
{ {
return $"{Name} {AnimeType} {PaddingZeroIndexNumber}"; return $"{AnimeType} {PaddingZeroIndexNumber}";
} }
else else
{ {
return $"{Name} {AnimeType}"; return $"{AnimeType}";
} }
} }
} }
public string SpecialName
{
get
{
if (!string.IsNullOrEmpty(EpisodeName) && IndexNumber.HasValue)
{
return $"{EpisodeName} {IndexNumber}";
}
else if (!string.IsNullOrEmpty(EpisodeName))
{
return EpisodeName;
}
return Name;
}
}
} }
} }

View File

@ -28,16 +28,6 @@ namespace Jellyfin.Plugin.MetaShark.Providers
{ {
private readonly IMemoryCache _memoryCache; private readonly IMemoryCache _memoryCache;
private static readonly Regex[] EpisodeFileNameRegex =
{
new(@"\[([\d\.]{2,})\]"),
new(@"- ?([\d\.]{2,})"),
new(@"EP?([\d\.]{2,})", RegexOptions.IgnoreCase),
new(@"\[([\d\.]{2,})"),
new(@"#([\d\.]{2,})"),
new(@"(\d{2,})")
};
public EpisodeProvider(IHttpClientFactory httpClientFactory, ILoggerFactory loggerFactory, ILibraryManager libraryManager, IHttpContextAccessor httpContextAccessor, DoubanApi doubanApi, TmdbApi tmdbApi, OmdbApi omdbApi) public EpisodeProvider(IHttpClientFactory httpClientFactory, ILoggerFactory loggerFactory, ILibraryManager libraryManager, IHttpContextAccessor httpContextAccessor, DoubanApi doubanApi, TmdbApi tmdbApi, OmdbApi omdbApi)
: base(httpClientFactory, loggerFactory.CreateLogger<EpisodeProvider>(), libraryManager, httpContextAccessor, doubanApi, tmdbApi, omdbApi) : base(httpClientFactory, loggerFactory.CreateLogger<EpisodeProvider>(), libraryManager, httpContextAccessor, doubanApi, tmdbApi, omdbApi)
{ {
@ -87,9 +77,9 @@ namespace Jellyfin.Plugin.MetaShark.Providers
Name = info.Name, Name = info.Name,
}; };
if (episodeNumber is null or 0 || seasonNumber is null or 0 || string.IsNullOrEmpty(seriesTmdbId)) if (episodeNumber is null or 0 || seasonNumber is null || string.IsNullOrEmpty(seriesTmdbId))
{ {
this.Log("Lack meta message. episodeNumber: {0} seasonNumber: {1} seriesTmdbId:{2}", episodeNumber, seasonNumber, seriesTmdbId); this.Log("Lack meta data. episodeNumber: {0} seasonNumber: {1} seriesTmdbId:{2}", episodeNumber, seasonNumber, seriesTmdbId);
return result; return result;
} }
@ -148,8 +138,8 @@ namespace Jellyfin.Plugin.MetaShark.Providers
// 使用AnitomySharp进行重新解析解决anime识别错误 // 使用AnitomySharp进行重新解析解决anime识别错误
var fileName = Path.GetFileNameWithoutExtension(info.Path) ?? info.Name; var fileName = Path.GetFileNameWithoutExtension(info.Path) ?? info.Name;
var parseResult = NameParser.Parse(fileName); var parseResult = NameParser.Parse(fileName);
info.Name = parseResult.Name;
info.Year = parseResult.Year; info.Year = parseResult.Year;
info.Name = parseResult.Name;
// 没有season级目录或文件命名不规范时ParentIndexNumber会为null // 没有season级目录或文件命名不规范时ParentIndexNumber会为null
if (info.ParentIndexNumber is null) if (info.ParentIndexNumber is null)
@ -184,21 +174,19 @@ namespace Jellyfin.Plugin.MetaShark.Providers
info.ParentIndexNumber = 1; info.ParentIndexNumber = 1;
} }
if (NameParser.IsAnime(fileName)) // 特典
if (NameParser.IsAnime(fileName) && parseResult.IsSpecial)
{ {
// 特典 info.ParentIndexNumber = 0;
if (parseResult.IsSpecial)
{
info.ParentIndexNumber = 0;
}
// 动画的OP/ED/MENU等
if (parseResult.IsExtra)
{
info.ParentIndexNumber = null;
}
} }
// 特典优先使用文件名
if (info.ParentIndexNumber.HasValue && info.ParentIndexNumber == 0)
{
info.Name = parseResult.SpecialName == info.Name ? fileName : parseResult.SpecialName;
}
// 大于1000可能错误解析了分辨率 // 大于1000可能错误解析了分辨率
if (parseResult.IndexNumber.HasValue && parseResult.IndexNumber < 1000) if (parseResult.IndexNumber.HasValue && parseResult.IndexNumber < 1000)
{ {
@ -252,7 +240,7 @@ namespace Jellyfin.Plugin.MetaShark.Providers
{ {
ParentIndexNumber = 0, ParentIndexNumber = 0,
IndexNumber = parseResult.IndexNumber, IndexNumber = parseResult.IndexNumber,
Name = parseResult.EpisodeName ?? parseResult.Name, Name = parseResult.SpecialName == info.Name ? fileName : parseResult.SpecialName,
AirsAfterSeasonNumber = 1, AirsAfterSeasonNumber = 1,
}; };

View File

@ -90,7 +90,7 @@ namespace AnitomySharp
// 广告 Commercial Message 电视放送广告,时长一般在 7s/15s/30s/45s/... 左右 // 广告 Commercial Message 电视放送广告,时长一般在 7s/15s/30s/45s/... 左右
"CM","SPOT", "CM","SPOT",
// 宣传片/预告片 Promotion Video / Trailer 一般时长在 1~2min 命名参考原盘和 jsum // 宣传片/预告片 Promotion Video / Trailer 一般时长在 1~2min 命名参考原盘和 jsum
"PV", "Teaser","TRAILER", "PV", "Teaser","TRAILER", "DRAMA",
// 真人特典 Interview/Talk/Stage... 目前我们对于节目、采访、舞台活动、制作等三次元画面的长视频,一概怼成 IV。 // 真人特典 Interview/Talk/Stage... 目前我们对于节目、采访、舞台活动、制作等三次元画面的长视频,一概怼成 IV。
"INTERVIEW", "INTERVIEW",
"EVENT", "TOKUTEN", "LOGO"}); "EVENT", "TOKUTEN", "LOGO"});