From 7656bb60940843fab21e3448d5ec2ee208f97103 Mon Sep 17 00:00:00 2001 From: cxfksword <718792+cxfksword@users.noreply.github.com> Date: Sun, 5 Feb 2023 15:23:41 +0800 Subject: [PATCH] Optimize identity --- Jellyfin.Plugin.MetaShark/Api/DoubanApi.cs | 5 +- .../Providers/BaseProvider.cs | 20 +++--- .../Providers/MovieProvider.cs | 2 +- .../Providers/SeasonProvider.cs | 68 ++----------------- .../Providers/SeriesProvider.cs | 2 +- 5 files changed, 22 insertions(+), 75 deletions(-) diff --git a/Jellyfin.Plugin.MetaShark/Api/DoubanApi.cs b/Jellyfin.Plugin.MetaShark/Api/DoubanApi.cs index 7c9f41a..bd88d09 100644 --- a/Jellyfin.Plugin.MetaShark/Api/DoubanApi.cs +++ b/Jellyfin.Plugin.MetaShark/Api/DoubanApi.cs @@ -62,7 +62,7 @@ namespace Jellyfin.Plugin.MetaShark.Api Regex regCountry = new Regex(@"制片国家/地区: (.+?)\n", RegexOptions.Compiled); Regex regLanguage = new Regex(@"语言: (.+?)\n", RegexOptions.Compiled); Regex regDuration = new Regex(@"片长: (.+?)\n", RegexOptions.Compiled); - Regex regScreen = new Regex(@"上映日期: (.+?)\n", RegexOptions.Compiled); + Regex regScreen = new Regex(@"(上映日期|首播): (.+?)\n", RegexOptions.Compiled); Regex regSubname = new Regex(@"又名: (.+?)\n", RegexOptions.Compiled); Regex regImdb = new Regex(@"IMDb: (tt\d+)", RegexOptions.Compiled); Regex regSite = new Regex(@"官方网站: (.+?)\n", RegexOptions.Compiled); @@ -344,10 +344,11 @@ namespace Jellyfin.Plugin.MetaShark.Api var country = info.GetMatchGroup(this.regCountry); var language = info.GetMatchGroup(this.regLanguage); var duration = info.GetMatchGroup(this.regDuration); - var screen = info.GetMatchGroup(this.regScreen); var subname = info.GetMatchGroup(this.regSubname); var imdb = info.GetMatchGroup(this.regImdb); var site = info.GetMatchGroup(this.regSite); + var matchs = this.regScreen.Match(info); + var screen = matchs.Groups.Count > 2 ? matchs.Groups[2].Value : string.Empty; movie.Sid = sid; movie.Name = name; diff --git a/Jellyfin.Plugin.MetaShark/Providers/BaseProvider.cs b/Jellyfin.Plugin.MetaShark/Providers/BaseProvider.cs index b6e7aad..2e6f86a 100644 --- a/Jellyfin.Plugin.MetaShark/Providers/BaseProvider.cs +++ b/Jellyfin.Plugin.MetaShark/Providers/BaseProvider.cs @@ -51,7 +51,7 @@ namespace Jellyfin.Plugin.MetaShark.Providers protected readonly IHttpContextAccessor _httpContextAccessor; protected Regex regMetaSourcePrefix = new Regex(@"^\[.+\]", RegexOptions.Compiled); - protected Regex regSeasonNameSuffix = new Regex(@"\s第.季$", RegexOptions.Compiled); + protected Regex regSeasonNameSuffix = new Regex(@"\s第[0-9一二三四五六七八九十]+?季$", RegexOptions.Compiled); protected PluginConfiguration config { @@ -127,13 +127,13 @@ namespace Jellyfin.Plugin.MetaShark.Providers item = result.Where(x => x.Year == info.Year && x.Name == searchName).FirstOrDefault(); if (item != null) { - this.Log($"GuessByDouban found [name]: {item.Name} [Sid]: {item.Sid} (suggest)"); + this.Log($"GuessByDouban found -> {item.Name}({item.Sid}) (suggest)"); return item.Sid; } item = result.Where(x => x.Year == info.Year).FirstOrDefault(); if (item != null) { - this.Log($"GuessByDouban found [name]: {item.Name} [Sid]: {item.Sid} (suggest)"); + this.Log($"GuessByDouban found -> {item.Name}({item.Sid}) (suggest)"); return item.Sid; } } @@ -149,7 +149,7 @@ namespace Jellyfin.Plugin.MetaShark.Providers item = result.Where(x => x.Category == cat && x.Year == info.Year).FirstOrDefault(); if (item != null) { - this.Log($"GuessByDouban found [name]: {item.Name} [Sid]: {item.Sid}"); + this.Log($"GuessByDouban found -> {item.Name}({item.Sid})"); return item.Sid; } } @@ -158,7 +158,7 @@ namespace Jellyfin.Plugin.MetaShark.Providers item = result.Where(x => x.Category == cat).FirstOrDefault(); if (item != null) { - this.Log($"GuessByDouban found [name]: {item.Name} [Sid]: {item.Sid}"); + this.Log($"GuessByDouban found -> {item.Name}({item.Sid})"); return item.Sid; } @@ -181,13 +181,13 @@ namespace Jellyfin.Plugin.MetaShark.Providers var suggestItem = suggestResult.Where(x => x.Year == year && x.Name == name).FirstOrDefault(); if (suggestItem != null) { - this.Log($"GuestDoubanSeasonByYear found [name]: {suggestItem.Name} [Sid]: {suggestItem.Sid} (suggest)"); + this.Log($"GuestDoubanSeasonByYear found -> {suggestItem.Name}({suggestItem.Sid}) (suggest)"); return suggestItem.Sid; } suggestItem = suggestResult.Where(x => x.Year == year).FirstOrDefault(); if (suggestItem != null) { - this.Log($"GuestDoubanSeasonByYear found [name]: {suggestItem.Name} [Sid]: {suggestItem.Sid} (suggest)"); + this.Log($"GuestDoubanSeasonByYear found -> {suggestItem.Name}({suggestItem.Sid}) (suggest)"); return suggestItem.Sid; } } @@ -198,7 +198,7 @@ namespace Jellyfin.Plugin.MetaShark.Providers var item = result.Where(x => x.Category == "电视剧" && x.Year == year).FirstOrDefault(); if (item != null && !string.IsNullOrEmpty(item.Sid)) { - this.Log($"GuestDoubanSeasonByYear found [name]: {item.Name} [Sid]: {item.Sid}"); + this.Log($"GuestDoubanSeasonByYear found -> {item.Name}({item.Sid})"); return item.Sid; } @@ -226,7 +226,7 @@ namespace Jellyfin.Plugin.MetaShark.Providers if (movieItem != null) { // bt种子都是英文名,但电影是中日韩泰印法地区时,都不适用相似匹配,去掉限制 - this.Log($"GuestByTmdb found [name]: {movieItem.Title} [tmdbID]: {movieItem.Id}"); + this.Log($"GuestByTmdb found -> {movieItem.Title}({movieItem.Id})"); return movieItem.Id.ToString(CultureInfo.InvariantCulture); } break; @@ -236,7 +236,7 @@ namespace Jellyfin.Plugin.MetaShark.Providers if (seriesItem != null) { // bt种子都是英文名,但电影是中日韩泰印法地区时,都不适用相似匹配,去掉限制 - this.Log($"GuestByTmdb found [name]: {seriesItem.Name} [tmdbID]: {seriesItem.Id}"); + this.Log($"GuestByTmdb found -> {seriesItem.Name}({seriesItem.Id})"); return seriesItem.Id.ToString(CultureInfo.InvariantCulture); } break; diff --git a/Jellyfin.Plugin.MetaShark/Providers/MovieProvider.cs b/Jellyfin.Plugin.MetaShark/Providers/MovieProvider.cs index 6fed18e..b13c027 100644 --- a/Jellyfin.Plugin.MetaShark/Providers/MovieProvider.cs +++ b/Jellyfin.Plugin.MetaShark/Providers/MovieProvider.cs @@ -75,7 +75,7 @@ namespace Jellyfin.Plugin.MetaShark.Providers { SearchProviderName = TmdbProviderName, ProviderIds = new Dictionary { { MetadataProvider.Tmdb.ToString(), x.Id.ToString(CultureInfo.InvariantCulture) } }, - Name = x.Title ?? x.OriginalTitle, + Name = string.Format("[TMDB]{0}", x.Title ?? x.OriginalTitle), ImageUrl = this._tmdbApi.GetPosterUrl(x.PosterPath), Overview = x.Overview, ProductionYear = x.ReleaseDate?.Year, diff --git a/Jellyfin.Plugin.MetaShark/Providers/SeasonProvider.cs b/Jellyfin.Plugin.MetaShark/Providers/SeasonProvider.cs index 1774b2c..ed05a6c 100644 --- a/Jellyfin.Plugin.MetaShark/Providers/SeasonProvider.cs +++ b/Jellyfin.Plugin.MetaShark/Providers/SeasonProvider.cs @@ -57,13 +57,13 @@ namespace Jellyfin.Plugin.MetaShark.Providers if (metaSource != MetaSource.Tmdb && !string.IsNullOrEmpty(sid)) { - // 从sereis获取正确名称,季名称有时不对 + // 从sereis获取正确名称,info的季名称是第x季 var series = await this._doubanApi.GetMovieAsync(sid, cancellationToken).ConfigureAwait(false); if (series == null) { return result; } - var seriesName = RemoveSeasonSubfix(series.Name); + var seasonName = RemoveSeasonSubfix(series.Name); // 没有季id,但存在tmdbid,尝试从tmdb获取对应季的年份信息,用于从豆瓣搜索对应季数据 if (string.IsNullOrEmpty(seasonSid)) @@ -77,9 +77,9 @@ namespace Jellyfin.Plugin.MetaShark.Providers seasonYear = season?.AirDate?.Year ?? 0; } - if (!string.IsNullOrEmpty(seriesName) && seasonYear > 0) + if (!string.IsNullOrEmpty(seasonName) && seasonYear > 0) { - seasonSid = await this.GuestDoubanSeasonByYearAsync(seriesName, seasonYear, cancellationToken).ConfigureAwait(false); + seasonSid = await this.GuestDoubanSeasonByYearAsync(seasonName, seasonYear, cancellationToken).ConfigureAwait(false); } } @@ -101,7 +101,7 @@ namespace Jellyfin.Plugin.MetaShark.Providers Overview = subject.Intro, ProductionYear = subject.Year, Genres = subject.Genres, - PremiereDate = subject.ScreenTime, + PremiereDate = subject.ScreenTime, // 发行日期 IndexNumber = info.IndexNumber, }; @@ -132,21 +132,7 @@ namespace Jellyfin.Plugin.MetaShark.Providers } - // 从豆瓣获取不到季信息,直接使用series信息(还是不替换旧有信息好??) - result.Item = new Season - { - ProviderIds = new Dictionary { { DoubanProviderId, sid } }, - Name = series.Name, - OriginalTitle = series.OriginalName, - CommunityRating = series.Rating, - Overview = series.Intro, - ProductionYear = series.Year, - Genres = series.Genres, - PremiereDate = series.ScreenTime, - }; - - result.QueriedById = true; - result.HasMetadata = true; + // 从豆瓣获取不到季信息 return result; } @@ -162,47 +148,6 @@ namespace Jellyfin.Plugin.MetaShark.Providers } } - - // 季手工修正(先手工修改元数据,再刷新元数据->覆盖所有元数据),通过季名称重新搜索 - // var guessName = Regex.Replace(info.Name, Pattern, " "); - // this.Log($"Try search season by name. original name: {info.Name} guess name: {guessName}"); - // var guessSid = await this.GuestByDoubanAsync(info, cancellationToken).ConfigureAwait(false); - // if (!string.IsNullOrEmpty(guessSid)) - // { - - // var subject = await this._doubanApi.GetMovieAsync(guessSid, cancellationToken).ConfigureAwait(false); - // if (subject != null) - // { - // subject.Celebrities = await this._doubanApi.GetCelebritiesBySidAsync(guessSid, cancellationToken).ConfigureAwait(false); - - // var movie = new Season - // { - // ProviderIds = new Dictionary { { DoubanProviderId, subject.Sid } }, - // Name = subject.Name, - // OriginalTitle = subject.OriginalName, - // CommunityRating = subject.Rating, - // Overview = subject.Intro, - // ProductionYear = subject.Year, - // Genres = subject.Genres, - // PremiereDate = subject.ScreenTime, - // IndexNumber = info.IndexNumber, - // }; - - // result.Item = movie; - // result.HasMetadata = true; - // subject.Celebrities.Take(this.config.MaxCastMembers).ToList().ForEach(c => result.AddPerson(new PersonInfo - // { - // Name = c.Name, - // Type = c.RoleType, - // Role = c.Role, - // ImageUrl = c.Img, - // ProviderIds = new Dictionary { { DoubanProviderId, c.Id } }, - // })); - - // return result; - // } - // } - return result; } @@ -222,6 +167,7 @@ namespace Jellyfin.Plugin.MetaShark.Providers result.HasMetadata = true; result.Item = new Season { + Name = seasonResult.Name, IndexNumber = seasonNumber, Overview = seasonResult.Overview, PremiereDate = seasonResult.AirDate, diff --git a/Jellyfin.Plugin.MetaShark/Providers/SeriesProvider.cs b/Jellyfin.Plugin.MetaShark/Providers/SeriesProvider.cs index a321e14..a41737b 100644 --- a/Jellyfin.Plugin.MetaShark/Providers/SeriesProvider.cs +++ b/Jellyfin.Plugin.MetaShark/Providers/SeriesProvider.cs @@ -67,7 +67,7 @@ namespace Jellyfin.Plugin.MetaShark.Providers { SearchProviderName = TmdbProviderName, ProviderIds = new Dictionary { { MetadataProvider.Tmdb.ToString(), x.Id.ToString(CultureInfo.InvariantCulture) } }, - Name = x.Name ?? x.OriginalName, + Name = string.Format("[TMDB]{0}", x.Name ?? x.OriginalName), ImageUrl = this._tmdbApi.GetPosterUrl(x.PosterPath), Overview = x.Overview, ProductionYear = x.FirstAirDate?.Year,