diff --git a/Jellyfin.Plugin.Douban.Tests/Jellyfin.Plugin.Douban.Tests.csproj b/Jellyfin.Plugin.Douban.Tests/Jellyfin.Plugin.Douban.Tests.csproj index 43ed413..3b86b4a 100644 --- a/Jellyfin.Plugin.Douban.Tests/Jellyfin.Plugin.Douban.Tests.csproj +++ b/Jellyfin.Plugin.Douban.Tests/Jellyfin.Plugin.Douban.Tests.csproj @@ -1,7 +1,7 @@ - netstandard2.1 + netcoreapp3.0 false diff --git a/Jellyfin.Plugin.Douban.Tests/MovieProviderTest.cs b/Jellyfin.Plugin.Douban.Tests/MovieProviderTest.cs index d5d83a6..c80c5e5 100644 --- a/Jellyfin.Plugin.Douban.Tests/MovieProviderTest.cs +++ b/Jellyfin.Plugin.Douban.Tests/MovieProviderTest.cs @@ -1,34 +1,34 @@ -using System; -using System.Net.Http; -using System.Threading; - -using MediaBrowser.Controller.Providers; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; -using Xunit; - -using Jellyfin.Plugin.Douban.Tests.Mock; - -namespace Jellyfin.Plugin.Douban.Tests -{ - public class MovieProviderTest - { - private readonly MovieProvider _doubanProvider; - private readonly IServiceProvider _serviceProvider; - - public MovieProviderTest() - { - _serviceProvider = new ServiceCollection().AddLogging(builder => builder.AddConsole()) - .BuildServiceProvider(); - var loggerFactory = _serviceProvider.GetService(); - var logger = loggerFactory.CreateLogger("test"); - - var httpClient = new MockHttpClient(); - var jsonSerializer = new MockJsonSerializer(); - _doubanProvider = new MovieProvider(httpClient, jsonSerializer, logger); - } - - [Fact] +using System; +using System.Net.Http; +using System.Threading; + +using MediaBrowser.Controller.Providers; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using Xunit; + +using Jellyfin.Plugin.Douban.Tests.Mock; + +namespace Jellyfin.Plugin.Douban.Tests +{ + public class MovieProviderTest + { + private readonly MovieProvider _doubanProvider; + private readonly IServiceProvider _serviceProvider; + + public MovieProviderTest() + { + _serviceProvider = new ServiceCollection().AddLogging(builder => builder.AddConsole()) + .BuildServiceProvider(); + var loggerFactory = _serviceProvider.GetService(); + var logger = loggerFactory.CreateLogger("test"); + + var httpClient = new MockHttpClient(); + var jsonSerializer = new MockJsonSerializer(); + _doubanProvider = new MovieProvider(httpClient, jsonSerializer, logger); + } + + [Fact] public void TestGetMetadata() { MovieInfo info = new MovieInfo() @@ -64,10 +64,10 @@ public void TestGetMetadata() info = new MovieInfo() { MetadataLanguage = "zh", - Name = "亮剑" + Name = "三国演义" }; meta = _doubanProvider.GetMetadata(info, CancellationToken.None).Result; Assert.False(meta.HasMetadata); - } - } -} + } + } +} diff --git a/Jellyfin.Plugin.Douban/BaseProvider.cs b/Jellyfin.Plugin.Douban/BaseProvider.cs index 90c67d6..465fcc6 100644 --- a/Jellyfin.Plugin.Douban/BaseProvider.cs +++ b/Jellyfin.Plugin.Douban/BaseProvider.cs @@ -18,7 +18,7 @@ namespace Jellyfin.Plugin.Douban { public abstract class BaseProvider { - protected const string ProviderID = "DoubanID"; + internal const string ProviderID = "DoubanID"; protected IHttpClient _httpClient; protected IJsonSerializer _jsonSerializer; @@ -111,7 +111,7 @@ protected async Task> GetMetaFromDouban(string sid, var data = await GetDoubanSubject(sid, cancellationToken); if (!String.IsNullOrEmpty(type) && data.Subtype != type) { - _logger.LogInformation("Douban: Sid {1}'s type is {2}, " + + _logger.LogInformation("Douban: Sid {1}'s type is {2}, " + "but require {3}", sid, data.Subtype, type); return result; } @@ -135,7 +135,7 @@ protected async Task> GetMetaFromDouban(string sid, internal async Task GetDoubanSubject(string sid, CancellationToken cancellationToken) { - _logger.LogInformation("Douban: Trying to get douban subject by " + + _logger.LogInformation("Douban: Trying to get douban subject by " + "sid: {0}", sid); cancellationToken.ThrowIfCancellationRequested(); @@ -145,7 +145,7 @@ protected async Task> GetMetaFromDouban(string sid, } String apikey = _config.ApiKey; - var url = String.Format("http://api.douban.com/v2/movie/subject" + + var url = String.Format("http://api.douban.com/v2/movie/subject" + "/{0}?apikey={1}", sid, apikey); var options = new HttpRequestOptions { diff --git a/Jellyfin.Plugin.Douban/MovieProvider.cs b/Jellyfin.Plugin.Douban/MovieProvider.cs index d8f81e3..d304b2b 100644 --- a/Jellyfin.Plugin.Douban/MovieProvider.cs +++ b/Jellyfin.Plugin.Douban/MovieProvider.cs @@ -86,8 +86,23 @@ public async Task> GetSearchResults( return results; } - var sidList = await SearchSidByName(info.Name, cancellationToken). - ConfigureAwait(false); + IEnumerable sidList; + + string doubanId = info.GetProviderId(ProviderID); + _logger.LogInformation("douban id is {0}", doubanId); + if (!string.IsNullOrEmpty(doubanId)) + { + sidList = new List + { + doubanId + }; + } + else + { + sidList = await SearchSidByName(info.Name, cancellationToken). + ConfigureAwait(false); + } + foreach (String sid in sidList) { var subject = await GetDoubanSubject(sid, cancellationToken). diff --git a/Jellyfin.Plugin.Douban/TVProvider.cs b/Jellyfin.Plugin.Douban/TVProvider.cs index dadab9f..e01da29 100644 --- a/Jellyfin.Plugin.Douban/TVProvider.cs +++ b/Jellyfin.Plugin.Douban/TVProvider.cs @@ -44,11 +44,11 @@ public async Task> GetMetadata(SeriesInfo info, _logger.LogInformation($"Douban:GetMetadata name: {info.Name}"); - // Only handle it when launguage is "zh" + // Only handle it when language is "zh" if (info.MetadataLanguage != "zh") { - _logger.LogInformation("DoubanProvider: the required " + - "launguage is not zh, so just bypass DoubanProvider"); + _logger.LogInformation("DoubanProvider: the required " + + "language is not zh, so just bypass DoubanProvider"); return new MetadataResult(); } @@ -77,6 +77,7 @@ public async Task> GetMetadata(SeriesInfo info, if (result.HasMetadata) { info.SetProviderId(ProviderID, sid); + result.QueriedById = true; } return result; @@ -89,16 +90,31 @@ public async Task> GetSearchResults( var results = new List(); - // Only handle it when launguage is "zh" + // Only handle it when language is "zh" if (info.MetadataLanguage != "zh") { - _logger.LogInformation("DoubanProvider: the required " + - "launguage is not zh, so just bypass DoubanProvider"); + _logger.LogInformation("DoubanProvider: the required " + + "language is not zh, so just bypass DoubanProvider"); return results; } - var sidList = await SearchSidByName(info.Name, cancellationToken). - ConfigureAwait(false); + IEnumerable sidList; + + string doubanId = info.GetProviderId(ProviderID); + _logger.LogInformation("douban id is {0}", doubanId); + if (!string.IsNullOrEmpty(doubanId)) + { + sidList = new List + { + doubanId + }; + } + else + { + sidList = await SearchSidByName(info.Name, cancellationToken). + ConfigureAwait(false); + } + foreach (String sid in sidList) { var subject = await GetDoubanSubject(sid, cancellationToken). @@ -190,12 +206,12 @@ public async Task> GetMetadata(EpisodeInfo info, if (!info.IndexNumber.HasValue) { - _logger.LogInformation("No episode num found, please check " + + _logger.LogInformation("No episode num found, please check " + "the format of file name"); return result; } // Start to get information from douban - var url = String.Format("https://movie.douban.com/subject/{0}" + + var url = String.Format("https://movie.douban.com/subject/{0}" + "/episode/{1}/", sid, info.IndexNumber); var options = new HttpRequestOptions {