From aa4e8dae59bac9a2bb53942d6df773881df8a0f4 Mon Sep 17 00:00:00 2001 From: cxfksword <718792+cxfksword@users.noreply.github.com> Date: Fri, 17 Feb 2023 12:19:11 +0800 Subject: [PATCH] Support movie collections --- .../MovieProviderTest.cs | 3 +- .../Configuration/PluginConfiguration.cs | 4 +++ .../Configuration/configPage.html | 10 ++++++ Jellyfin.Plugin.MetaShark/Plugin.cs | 33 ++++++++++++++++++- .../Providers/MovieProvider.cs | 18 ++++++++++ 5 files changed, 66 insertions(+), 2 deletions(-) diff --git a/Jellyfin.Plugin.MetaShark.Test/MovieProviderTest.cs b/Jellyfin.Plugin.MetaShark.Test/MovieProviderTest.cs index 6cc168f..2c8095d 100644 --- a/Jellyfin.Plugin.MetaShark.Test/MovieProviderTest.cs +++ b/Jellyfin.Plugin.MetaShark.Test/MovieProviderTest.cs @@ -32,7 +32,7 @@ namespace Jellyfin.Plugin.MetaShark.Test [TestMethod] public void TestGetMetadata() { - var info = new MovieInfo() { Name = "南极料理人" }; + var doubanApi = new DoubanApi(loggerFactory); var tmdbApi = new TmdbApi(loggerFactory); var omdbApi = new OmdbApi(loggerFactory); @@ -42,6 +42,7 @@ namespace Jellyfin.Plugin.MetaShark.Test Task.Run(async () => { + var info = new MovieInfo() { Name = "南极料理人", MetadataLanguage = "zh" }; var provider = new MovieProvider(httpClientFactory, loggerFactory, libraryManagerStub.Object, httpContextAccessorStub.Object, doubanApi, tmdbApi, omdbApi); var result = await provider.GetMetadata(info, CancellationToken.None); Assert.IsNotNull(result); diff --git a/Jellyfin.Plugin.MetaShark/Configuration/PluginConfiguration.cs b/Jellyfin.Plugin.MetaShark/Configuration/PluginConfiguration.cs index 4b47352..9e1fd2b 100644 --- a/Jellyfin.Plugin.MetaShark/Configuration/PluginConfiguration.cs +++ b/Jellyfin.Plugin.MetaShark/Configuration/PluginConfiguration.cs @@ -42,6 +42,10 @@ public class PluginConfiguration : BasePluginConfiguration public bool EnableTmdbSearch { get; set; } = false; public bool EnableTmdbBackdrop { get; set; } = false; + /// + /// 是否获取电影系列信息 + /// + public bool EnableTmdbCollection { get; set; } = true; public string TmdbApiKey { get; set; } = string.Empty; diff --git a/Jellyfin.Plugin.MetaShark/Configuration/configPage.html b/Jellyfin.Plugin.MetaShark/Configuration/configPage.html index dc91c5d..1d39105 100644 --- a/Jellyfin.Plugin.MetaShark/Configuration/configPage.html +++ b/Jellyfin.Plugin.MetaShark/Configuration/configPage.html @@ -85,6 +85,14 @@
勾选后,当影片在豆瓣找不到背景图时,改使用TheMovieDb的补全
+
+ +
勾选后,刮削会变慢,会自动创建电影系列合集(需先在媒体库配置中打开自动添加到合集功能)
+
@@ -122,6 +130,7 @@ document.querySelector('#EnableTmdb').checked = config.EnableTmdb; document.querySelector('#EnableTmdbSearch').checked = config.EnableTmdbSearch; document.querySelector('#EnableTmdbBackdrop').checked = config.EnableTmdbBackdrop; + document.querySelector('#EnableTmdbCollection').checked = config.EnableTmdbCollection; document.querySelector('#TmdbApiKey').value = config.TmdbApiKey; document.querySelector('#TmdbHost').value = config.TmdbHost; @@ -141,6 +150,7 @@ config.EnableTmdb = document.querySelector('#EnableTmdb').checked; config.EnableTmdbSearch = document.querySelector('#EnableTmdbSearch').checked; config.EnableTmdbBackdrop = document.querySelector('#EnableTmdbBackdrop').checked; + config.EnableTmdbCollection = document.querySelector('#EnableTmdbCollection').checked; config.TmdbApiKey = document.querySelector('#TmdbApiKey').value; config.TmdbHost = document.querySelector('#TmdbHost').value; ApiClient.updatePluginConfiguration(TemplateConfig.pluginUniqueId, config).then(function (result) { diff --git a/Jellyfin.Plugin.MetaShark/Plugin.cs b/Jellyfin.Plugin.MetaShark/Plugin.cs index b39ebe5..1493519 100644 --- a/Jellyfin.Plugin.MetaShark/Plugin.cs +++ b/Jellyfin.Plugin.MetaShark/Plugin.cs @@ -6,6 +6,7 @@ using MediaBrowser.Common.Configuration; using MediaBrowser.Common.Plugins; using MediaBrowser.Model.Plugins; using MediaBrowser.Model.Serialization; +using Microsoft.AspNetCore.Http; namespace Jellyfin.Plugin.MetaShark; @@ -24,14 +25,19 @@ public class Plugin : BasePlugin, IHasWebPages /// public const string ProviderId = "MetaSharkID"; + protected readonly IHttpContextAccessor _httpContextAccessor; + /// /// Initializes a new instance of the class. /// /// Instance of the interface. /// Instance of the interface. - public Plugin(IApplicationPaths applicationPaths, IXmlSerializer xmlSerializer) + /// /// Instance of the interface. + public Plugin(IApplicationPaths applicationPaths, IXmlSerializer xmlSerializer, IHttpContextAccessor httpContextAccessor) : base(applicationPaths, xmlSerializer) { + this._httpContextAccessor = httpContextAccessor; + Plugin.Instance = this; } @@ -58,4 +64,29 @@ public class Plugin : BasePlugin, IHasWebPages } }; } + + + /// + /// jellyfin web服务域名 + /// 注意:经过nginx代理后,会拿不到真正的域名,需要用户配置http服务传入真正host + /// + public string BaseUrl + { + get + { + if (_httpContextAccessor.HttpContext != null) + { + // // 使用web浏览器访问直接使用相对链接???可解决用户配置了http反代 + // var userAgent = _httpContextAccessor.HttpContext.Request.Headers.UserAgent.ToString(); + // var fromWeb = userAgent.Contains("Chrome") || userAgent.Contains("Safari"); + // if (fromWeb) return string.Empty; + + return _httpContextAccessor.HttpContext.Request.Scheme + System.Uri.SchemeDelimiter + _httpContextAccessor.HttpContext.Request.Host; + } + else + { + return string.Empty; + } + } + } } diff --git a/Jellyfin.Plugin.MetaShark/Providers/MovieProvider.cs b/Jellyfin.Plugin.MetaShark/Providers/MovieProvider.cs index b13c027..42ec160 100644 --- a/Jellyfin.Plugin.MetaShark/Providers/MovieProvider.cs +++ b/Jellyfin.Plugin.MetaShark/Providers/MovieProvider.cs @@ -140,6 +140,18 @@ namespace Jellyfin.Plugin.MetaShark.Providers if (!string.IsNullOrEmpty(tmdbId)) { movie.SetProviderId(MetadataProvider.Tmdb, tmdbId); + + // 获取电影系列信息 + if (this.config.EnableTmdbCollection) + { + var movieResult = await _tmdbApi + .GetMovieAsync(Convert.ToInt32(tmdbId, CultureInfo.InvariantCulture), info.MetadataLanguage, info.MetadataLanguage, cancellationToken) + .ConfigureAwait(false); + if (movieResult != null && movieResult.BelongsToCollection != null) + { + movie.CollectionName = movieResult.BelongsToCollection.Name; + } + } } } } @@ -190,6 +202,12 @@ namespace Jellyfin.Plugin.MetaShark.Providers movie.SetProviderId(MetadataProvider.Imdb, movieResult.ImdbId); movie.SetProviderId(Plugin.ProviderId, MetaSource.Tmdb); + // 获取电影系列信息 + if (this.config.EnableTmdbCollection && movieResult.BelongsToCollection != null) + { + movie.CollectionName = movieResult.BelongsToCollection.Name; + } + movie.CommunityRating = (float)System.Math.Round(movieResult.VoteAverage, 2); movie.PremiereDate = movieResult.ReleaseDate; movie.ProductionYear = movieResult.ReleaseDate?.Year;