Support movie collections

This commit is contained in:
cxfksword 2023-02-17 12:19:11 +08:00
parent fefcc7ab11
commit aa4e8dae59
5 changed files with 66 additions and 2 deletions

View File

@ -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);

View File

@ -42,6 +42,10 @@ public class PluginConfiguration : BasePluginConfiguration
public bool EnableTmdbSearch { get; set; } = false;
public bool EnableTmdbBackdrop { get; set; } = false;
/// <summary>
/// 是否获取电影系列信息
/// </summary>
public bool EnableTmdbCollection { get; set; } = true;
public string TmdbApiKey { get; set; } = string.Empty;

View File

@ -85,6 +85,14 @@
</label>
<div class="fieldDescription">勾选后当影片在豆瓣找不到背景图时改使用TheMovieDb的补全</div>
</div>
<div class="checkboxContainer checkboxContainer-withDescription">
<label class="emby-checkbox-label" for="EnableTmdbCollection">
<input id="EnableTmdbCollection" name="EnableTmdbCollection" type="checkbox"
is="emby-checkbox" />
<span>从TheMovieDb获取电影系列信息</span>
</label>
<div class="fieldDescription">勾选后,刮削会变慢,会自动创建电影系列合集(需先在媒体库配置中打开<b>自动添加到合集</b>功能)</div>
</div>
<div class="inputContainer">
<label class="inputLabel inputLabelUnfocused" for="TmdbApiKey">Api Key</label>
<input id="TmdbApiKey" name="TmdbApiKey" type="text" is="emby-input" />
@ -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) {

View File

@ -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<PluginConfiguration>, IHasWebPages
/// </summary>
public const string ProviderId = "MetaSharkID";
protected readonly IHttpContextAccessor _httpContextAccessor;
/// <summary>
/// Initializes a new instance of the <see cref="Plugin"/> class.
/// </summary>
/// <param name="applicationPaths">Instance of the <see cref="IApplicationPaths"/> interface.</param>
/// <param name="xmlSerializer">Instance of the <see cref="IXmlSerializer"/> interface.</param>
public Plugin(IApplicationPaths applicationPaths, IXmlSerializer xmlSerializer)
/// /// <param name="httpContextAccessor">Instance of the <see cref="IHttpContextAccessor"/> interface.</param>
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<PluginConfiguration>, IHasWebPages
}
};
}
/// <summary>
/// jellyfin web服务域名
/// 注意经过nginx代理后会拿不到真正的域名需要用户配置http服务传入真正host
/// </summary>
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;
}
}
}
}

View File

@ -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;