diff --git a/Jellyfin.Plugin.Bangumi/Anitomy.cs b/Jellyfin.Plugin.Bangumi/Anitomy.cs
index 287054d..c5780e1 100644
--- a/Jellyfin.Plugin.Bangumi/Anitomy.cs
+++ b/Jellyfin.Plugin.Bangumi/Anitomy.cs
@@ -4,34 +4,264 @@
namespace Jellyfin.Plugin.Bangumi;
+///
+/// The Anitomy class contains methods for extracting various elements from a string path using the AnitomySharp library.
+///
public class Anitomy
{
- public static List ElementsOutput(string path)
+ // This variable stores the elements obtained from parsing a file path using the AnitomySharp library
+ private readonly IEnumerable _elements;
+
+ // The constructor takes a file path as input and calls the AnitomySharp.Parse method to parse the file and store the result in the _elements variable
+ public Anitomy(string path)
+ {
+ _elements = AnitomySharp.AnitomySharp.Parse(path);
+ }
+ // The constructor takes a file path and option as input and calls the AnitomySharp.Parse method to parse the file and store the result in the _elements variable
+ // default: Options(string AllowedDelimiters = " _.+,| ", bool ParseEpisodeNumber = true, bool ParseEpisodeTitle = true, bool ParseFileExtension = true, bool ParseReleaseGroup = true)
+ public Anitomy(string path, Options options)
+ {
+ _elements = AnitomySharp.AnitomySharp.Parse(path, options);
+ }
+
+ // This method returns a List of Element objects from the _elements variable
+ public List GetElements()
{
- return new List(AnitomySharp.AnitomySharp.Parse(path));
+ return new List(_elements);
}
- public static string? ExtractAnimeTitle(string path)
+ ///
+ /// Extracts the ElementAnimeSeason.
+ ///
+ /// The extracted ElementAnimeSeason, or null if not found.
+ public string? ExtractAnimeSeason()
{
- var elements = AnitomySharp.AnitomySharp.Parse(path);
- return elements.FirstOrDefault(p => p.Category == Element.ElementCategory.ElementAnimeTitle)?.Value;
+ return _elements.FirstOrDefault(p => p.Category == Element.ElementCategory.ElementAnimeSeason)?.Value;
}
- public static string? ExtractEpisodeTitle(string path)
+ ///
+ /// Extracts the ElementAnimeSeasonPrefix.
+ ///
+ /// The extracted ElementAnimeSeasonPrefix, or null if not found.
+ public string? ExtractAnimeSeasonPrefix()
{
- var elements = AnitomySharp.AnitomySharp.Parse(path);
- return elements.FirstOrDefault(p => p.Category == Element.ElementCategory.ElementEpisodeTitle)?.Value;
+ return _elements.FirstOrDefault(p => p.Category == Element.ElementCategory.ElementAnimeSeasonPrefix)?.Value;
}
- public static string? ExtractEpisodeNumber(string path)
+ ///
+ /// Extracts the ElementAnimeTitle.
+ ///
+ /// The extracted ElementAnimeTitle, or null if not found.
+ public string? ExtractAnimeTitle()
+ {
+ return _elements.FirstOrDefault(p => p.Category == Element.ElementCategory.ElementAnimeTitle)?.Value;
+ }
+ ///
+ /// Extracts the ElementAnimeType.
+ ///
+ /// The extracted ElementAnimeType, or null if not found.
+ public string[]? ExtractAnimeType()
{
- var elements = AnitomySharp.AnitomySharp.Parse(path);
- return elements.FirstOrDefault(p => p.Category == Element.ElementCategory.ElementEpisodeNumber)?.Value;
+ return _elements.Where(p => p.Category == Element.ElementCategory.ElementAnimeType).Select(type => type.Value).ToArray();
}
- public static string? ExtractSeasonNumber(string path)
+ ///
+ /// Extracts the ElementAnimeYear.
+ ///
+ /// The extracted ElementAnimeYear, or null if not found.
+ public string? ExtractAnimeYear()
{
- var elements = AnitomySharp.AnitomySharp.Parse(path);
- return elements.FirstOrDefault(p => p.Category == Element.ElementCategory.ElementAnimeSeason)?.Value;
+ return _elements.FirstOrDefault(p => p.Category == Element.ElementCategory.ElementAnimeYear)?.Value;
}
+
+ ///
+ /// Extracts the ElementAudioTerm.
+ ///
+ /// The extracted ElementAudioTerm, or null if not found.
+ public string? ExtractAudioTerm()
+ {
+ return _elements.FirstOrDefault(p => p.Category == Element.ElementCategory.ElementAudioTerm)?.Value;
+ }
+
+ ///
+ /// Extracts the ElementDeviceCompatibility.
+ ///
+ /// The extracted ElementDeviceCompatibility, or null if not found.
+ public string? ExtractDeviceCompatibility()
+ {
+ return _elements.FirstOrDefault(p => p.Category == Element.ElementCategory.ElementDeviceCompatibility)?.Value;
+ }
+
+ ///
+ /// Extracts the ElementEpisodeNumber.
+ ///
+ /// The extracted ElementEpisodeNumber, or null if not found.
+ public string? ExtractEpisodeNumber()
+ {
+ return _elements.FirstOrDefault(p => p.Category == Element.ElementCategory.ElementEpisodeNumber)?.Value;
+ }
+
+ ///
+ /// Extracts the ElementEpisodeNumberAlt.
+ ///
+ /// The extracted ElementEpisodeNumberAlt, or null if not found.
+ public string? ExtractEpisodeNumberAlt()
+ {
+ return _elements.FirstOrDefault(p => p.Category == Element.ElementCategory.ElementEpisodeNumberAlt)?.Value;
+ }
+
+ ///
+ /// Extracts the ElementEpisodePrefix.
+ ///
+ /// The extracted ElementEpisodePrefix, or null if not found.
+ public string? ExtractEpisodePrefix()
+ {
+ return _elements.FirstOrDefault(p => p.Category == Element.ElementCategory.ElementEpisodePrefix)?.Value;
+ }
+
+ ///
+ /// Extracts the ElementEpisodeTitle.
+ ///
+ /// The extracted ElementEpisodeTitle, or null if not found.
+ public string? ExtractEpisodeTitle()
+ {
+ return _elements.FirstOrDefault(p => p.Category == Element.ElementCategory.ElementEpisodeTitle)?.Value;
+ }
+
+ ///
+ /// Extracts the ElementFileChecksum.
+ ///
+ /// The extracted ElementFileChecksum, or null if not found.
+ public string? ExtractFileChecksum()
+ {
+ return _elements.FirstOrDefault(p => p.Category == Element.ElementCategory.ElementFileChecksum)?.Value;
+ }
+
+ ///
+ /// Extracts the ElementFileExtension.
+ ///
+ /// The extracted ElementFileExtension, or null if not found.
+ public string? ExtractFileExtension()
+ {
+ return _elements.FirstOrDefault(p => p.Category == Element.ElementCategory.ElementFileExtension)?.Value;
+ }
+
+ ///
+ /// Extracts the ElementFileName.
+ ///
+ /// The extracted ElementFileName, or null if not found.
+ public string? ExtractFileName()
+ {
+ return _elements.FirstOrDefault(p => p.Category == Element.ElementCategory.ElementFileName)?.Value;
+ }
+
+ ///
+ /// Extracts the ElementLanguage.
+ ///
+ /// The extracted ElementLanguage, or null if not found.
+ public string? ExtractLanguage()
+ {
+ return _elements.FirstOrDefault(p => p.Category == Element.ElementCategory.ElementLanguage)?.Value;
+ }
+
+ ///
+ /// Extracts the ElementOther.
+ ///
+ /// The extracted ElementOther, or null if not found.
+ public string? ExtractOther()
+ {
+ return _elements.FirstOrDefault(p => p.Category == Element.ElementCategory.ElementOther)?.Value;
+ }
+
+ ///
+ /// Extracts the ElementReleaseGroup.
+ ///
+ /// The extracted ElementReleaseGroup, or null if not found.
+ public string? ExtractReleaseGroup()
+ {
+ return _elements.FirstOrDefault(p => p.Category == Element.ElementCategory.ElementReleaseGroup)?.Value;
+ }
+
+ ///
+ /// Extracts the ElementReleaseInformation.
+ ///
+ /// The extracted ElementReleaseInformation, or null if not found.
+ public string? ExtractReleaseInformation()
+ {
+ return _elements.FirstOrDefault(p => p.Category == Element.ElementCategory.ElementReleaseInformation)?.Value;
+ }
+
+ ///
+ /// Extracts the ElementReleaseVersion.
+ ///
+ /// The extracted ElementReleaseVersion, or null if not found.
+ public string? ExtractReleaseVersion()
+ {
+ return _elements.FirstOrDefault(p => p.Category == Element.ElementCategory.ElementReleaseVersion)?.Value;
+ }
+
+ ///
+ /// Extracts the ElementSource.
+ ///
+ /// The extracted ElementSource, or null if not found.
+ public string? ExtractSource()
+ {
+ return _elements.FirstOrDefault(p => p.Category == Element.ElementCategory.ElementSource)?.Value;
+ }
+
+ ///
+ /// Extracts the ElementSubtitles.
+ ///
+ /// The extracted ElementSubtitles, or null if not found.
+ public string? ExtractSubtitles()
+ {
+ return _elements.FirstOrDefault(p => p.Category == Element.ElementCategory.ElementSubtitles)?.Value;
+ }
+
+ ///
+ /// Extracts the ElementUnknown.
+ ///
+ /// The extracted ElementUnknown, or null if not found.
+ public string? ExtractUnknown()
+ {
+ return _elements.FirstOrDefault(p => p.Category == Element.ElementCategory.ElementUnknown)?.Value;
+ }
+
+ ///
+ /// Extracts the ElementVideoResolution.
+ ///
+ /// The extracted ElementVideoResolution, or null if not found.
+ public string? ExtractVideoResolution()
+ {
+ return _elements.FirstOrDefault(p => p.Category == Element.ElementCategory.ElementVideoResolution)?.Value;
+ }
+
+ ///
+ /// Extracts the ElementVideoTerm.
+ ///
+ /// The extracted ElementVideoTerm, or null if not found.
+ public string? ExtractVideoTerm()
+ {
+ return _elements.FirstOrDefault(p => p.Category == Element.ElementCategory.ElementVideoTerm)?.Value;
+ }
+
+ ///
+ /// Extracts the ElementVolumeNumber.
+ ///
+ /// The extracted ElementVolumeNumber, or null if not found.
+ public string? ExtractVolumeNumber()
+ {
+ return _elements.FirstOrDefault(p => p.Category == Element.ElementCategory.ElementVolumeNumber)?.Value;
+ }
+
+ ///
+ /// Extracts the ElementVolumePrefix.
+ ///
+ /// The extracted ElementVolumePrefix, or null if not found.
+ public string? ExtractVolumePrefix()
+ {
+ return _elements.FirstOrDefault(p => p.Category == Element.ElementCategory.ElementVolumePrefix)?.Value;
+ }
+
+
}
\ No newline at end of file
diff --git a/Jellyfin.Plugin.Bangumi/Providers/AlbumProvider.cs b/Jellyfin.Plugin.Bangumi/Providers/AlbumProvider.cs
index 12885b9..04c0af5 100644
--- a/Jellyfin.Plugin.Bangumi/Providers/AlbumProvider.cs
+++ b/Jellyfin.Plugin.Bangumi/Providers/AlbumProvider.cs
@@ -57,7 +57,8 @@ public async Task> GetMetadata(AlbumInfo info, Cancel
if (subjectId == 0 && Configuration.AlwaysGetTitleByAnitomySharp)
{
- var searchName = Anitomy.ExtractAnimeTitle(baseName) ?? info.Name;
+ var anitomy = new Anitomy(baseName);
+ var searchName = anitomy.ExtractAnimeTitle() ?? info.Name;
log.LogInformation("Searching {Name} in bgm.tv", searchName);
// 不保证使用非原名或中文进行查询时返回正确结果
var searchResult = await api.SearchSubject(searchName, SubjectType.Music, token);
diff --git a/Jellyfin.Plugin.Bangumi/Providers/EpisodeProvider.cs b/Jellyfin.Plugin.Bangumi/Providers/EpisodeProvider.cs
index d5b2f07..a9f1136 100644
--- a/Jellyfin.Plugin.Bangumi/Providers/EpisodeProvider.cs
+++ b/Jellyfin.Plugin.Bangumi/Providers/EpisodeProvider.cs
@@ -295,7 +295,8 @@ private double GuessEpisodeNumber(double? current, string fileName, double max =
if (Configuration.AlwaysGetEpisodeByAnitomySharp)
{
- var anitomyIndex = Anitomy.ExtractEpisodeNumber(fileName);
+ var anitomy = new Anitomy(fileName);
+ var anitomyIndex = anitomy.ExtractEpisodeNumber();
if (!string.IsNullOrEmpty(anitomyIndex))
{
log.LogInformation("used episode number {index} from anitomy", anitomyIndex);
diff --git a/Jellyfin.Plugin.Bangumi/Providers/MovieProvider.cs b/Jellyfin.Plugin.Bangumi/Providers/MovieProvider.cs
index 47d6ffe..2467357 100644
--- a/Jellyfin.Plugin.Bangumi/Providers/MovieProvider.cs
+++ b/Jellyfin.Plugin.Bangumi/Providers/MovieProvider.cs
@@ -57,7 +57,8 @@ public async Task> GetMetadata(MovieInfo info, Cancellatio
if (subjectId == 0 && Configuration.AlwaysGetTitleByAnitomySharp)
{
- var searchName = Anitomy.ExtractAnimeTitle(baseName) ?? info.Name;
+ var anitomy = new Anitomy(baseName);
+ var searchName = anitomy.ExtractAnimeTitle() ?? info.Name;
logger.LogInformation("Searching {Name} in bgm.tv", searchName);
// 不保证使用非原名或中文进行查询时返回正确结果
var searchResult = await api.SearchSubject(searchName, token);
diff --git a/Jellyfin.Plugin.Bangumi/Providers/SeriesProvider.cs b/Jellyfin.Plugin.Bangumi/Providers/SeriesProvider.cs
index 388c58d..fca5210 100644
--- a/Jellyfin.Plugin.Bangumi/Providers/SeriesProvider.cs
+++ b/Jellyfin.Plugin.Bangumi/Providers/SeriesProvider.cs
@@ -70,7 +70,8 @@ public async Task> GetMetadata(SeriesInfo info, Cancellat
if (subjectId == 0 && Configuration.AlwaysGetTitleByAnitomySharp)
{
- var searchName = Anitomy.ExtractAnimeTitle(baseName) ?? info.Name;
+ var anitomy = new Anitomy(baseName);
+ var searchName = anitomy.ExtractAnimeTitle() ?? info.Name;
log.LogInformation("Searching {Name} in bgm.tv", searchName);
// 不保证使用非原名或中文进行查询时返回正确结果
var searchResult = await api.SearchSubject(searchName, token);