diff --git a/Jellyfin.Plugin.MetaShark/Providers/BaseProvider.cs b/Jellyfin.Plugin.MetaShark/Providers/BaseProvider.cs index 0291564..7f05a16 100644 --- a/Jellyfin.Plugin.MetaShark/Providers/BaseProvider.cs +++ b/Jellyfin.Plugin.MetaShark/Providers/BaseProvider.cs @@ -1,11 +1,9 @@ using Jellyfin.Plugin.MetaShark.Api; using Jellyfin.Plugin.MetaShark.Model; -using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Providers; using MediaBrowser.Model.Entities; using Microsoft.Extensions.Logging; -using StringMetric; using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; @@ -13,7 +11,6 @@ using System.Globalization; using System.Linq; using System.IO; using System.Net.Http; -using System.Text; using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; @@ -104,6 +101,25 @@ namespace Jellyfin.Plugin.MetaShark.Providers this._httpContextAccessor = httpContextAccessor; } + /// + public async Task GetImageResponse(string url, CancellationToken cancellationToken) + { + this.Log("GetImageResponse url: {0}", url); + if (url.Contains("doubanio.com")) + { + // 豆瓣图,带referer下载 + using (var requestMessage = new HttpRequestMessage(HttpMethod.Get, url)) + { + requestMessage.Headers.Add("Referer", "https://www.douban.com/"); + return await this._httpClientFactory.CreateClient().SendAsync(requestMessage, cancellationToken).ConfigureAwait(false); + } + } + else + { + return await this._httpClientFactory.CreateClient().GetAsync(new Uri(url), cancellationToken).ConfigureAwait(false); + } + } + protected async Task GuessByDoubanAsync(ItemLookupInfo info, CancellationToken cancellationToken) { var fileName = GetOriginalFileName(info); diff --git a/Jellyfin.Plugin.MetaShark/Providers/EpisodeImageProvider.cs b/Jellyfin.Plugin.MetaShark/Providers/EpisodeImageProvider.cs index 90ee14c..45041c7 100644 --- a/Jellyfin.Plugin.MetaShark/Providers/EpisodeImageProvider.cs +++ b/Jellyfin.Plugin.MetaShark/Providers/EpisodeImageProvider.cs @@ -1,15 +1,9 @@ using Jellyfin.Plugin.MetaShark.Api; -using Jellyfin.Plugin.MetaShark.Core; -using Jellyfin.Plugin.MetaShark.Model; -using MediaBrowser.Common.Net; using MediaBrowser.Controller.Entities; -using MediaBrowser.Controller.Entities.Movies; using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Providers; -using MediaBrowser.Model.Dto; using MediaBrowser.Model.Entities; -using MediaBrowser.Model.Extensions; using MediaBrowser.Model.Providers; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; @@ -18,11 +12,8 @@ using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Net.Http; -using System.Text; using System.Threading; using System.Threading.Tasks; -using TMDbLib.Objects.Languages; -using static System.Net.Mime.MediaTypeNames; namespace Jellyfin.Plugin.MetaShark.Providers { @@ -103,14 +94,5 @@ namespace Jellyfin.Plugin.MetaShark.Providers return result; } - /// - public Task GetImageResponse(string url, CancellationToken cancellationToken) - { - this.Log("[GetEpisodeImages] GetImageResponse url: {0}", url); - return this._httpClientFactory.CreateClient().GetAsync(new Uri(url), cancellationToken); - } - - - } } diff --git a/Jellyfin.Plugin.MetaShark/Providers/EpisodeProvider.cs b/Jellyfin.Plugin.MetaShark/Providers/EpisodeProvider.cs index c08a4b7..2048bf4 100644 --- a/Jellyfin.Plugin.MetaShark/Providers/EpisodeProvider.cs +++ b/Jellyfin.Plugin.MetaShark/Providers/EpisodeProvider.cs @@ -1,8 +1,5 @@ using Jellyfin.Plugin.MetaShark.Api; using Jellyfin.Plugin.MetaShark.Core; -using Jellyfin.Plugin.MetaShark.Model; -using MediaBrowser.Common.Net; -using MediaBrowser.Common.Plugins; using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Providers; @@ -15,11 +12,8 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Net.Http; -using System.Text; -using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; -using MediaBrowser.Controller.Entities; using Microsoft.AspNetCore.Http; namespace Jellyfin.Plugin.MetaShark.Providers @@ -297,13 +291,6 @@ namespace Jellyfin.Plugin.MetaShark.Providers return videoFilesCount; } - /// - public Task GetImageResponse(string url, CancellationToken cancellationToken) - { - this.Log("GetImageResponse url: {0}", url); - return _httpClientFactory.CreateClient().GetAsync(new Uri(url), cancellationToken); - } - public void Dispose() { diff --git a/Jellyfin.Plugin.MetaShark/Providers/MovieImageProvider.cs b/Jellyfin.Plugin.MetaShark/Providers/MovieImageProvider.cs index da8890f..3033672 100644 --- a/Jellyfin.Plugin.MetaShark/Providers/MovieImageProvider.cs +++ b/Jellyfin.Plugin.MetaShark/Providers/MovieImageProvider.cs @@ -3,7 +3,6 @@ using Jellyfin.Plugin.MetaShark.Core; using Jellyfin.Plugin.MetaShark.Model; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Movies; -using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Providers; using MediaBrowser.Model.Dto; @@ -12,14 +11,11 @@ using MediaBrowser.Model.Extensions; using MediaBrowser.Model.Providers; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; -using System; using System.Collections.Generic; using System.Linq; using System.Net.Http; -using System.Text; using System.Threading; using System.Threading.Tasks; -using TMDbLib.Objects.Languages; namespace Jellyfin.Plugin.MetaShark.Providers { @@ -130,25 +126,6 @@ namespace Jellyfin.Plugin.MetaShark.Providers return new List(); } - /// - public async Task GetImageResponse(string url, CancellationToken cancellationToken) - { - this.Log("GetImageResponse url: {0}", url); - - if (url.Contains("doubanio.com")) - {// 豆瓣图,带referer下载 - using (var requestMessage = new HttpRequestMessage(HttpMethod.Get, url)) - { - requestMessage.Headers.Add("Referer", "https://www.douban.com/"); - return await this._httpClientFactory.CreateClient().SendAsync(requestMessage, cancellationToken).ConfigureAwait(false); - } - } - else - { - return await this._httpClientFactory.CreateClient().GetAsync(new Uri(url), cancellationToken).ConfigureAwait(false); - } - } - /// /// Query for a background photo /// diff --git a/Jellyfin.Plugin.MetaShark/Providers/MovieProvider.cs b/Jellyfin.Plugin.MetaShark/Providers/MovieProvider.cs index 5c00686..07d9d20 100644 --- a/Jellyfin.Plugin.MetaShark/Providers/MovieProvider.cs +++ b/Jellyfin.Plugin.MetaShark/Providers/MovieProvider.cs @@ -4,12 +4,8 @@ using System.Globalization; using System.IO; using System.Linq; using System.Net.Http; -using System.Security.Cryptography; -using System.Text; -using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; -using System.Xml.Linq; using AngleSharp.Text; using Jellyfin.Plugin.MetaShark.Api; using Jellyfin.Plugin.MetaShark.Core; @@ -22,12 +18,6 @@ using MediaBrowser.Model.Entities; using MediaBrowser.Model.Providers; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; -using Newtonsoft.Json.Linq; -using StringMetric; -using TMDbLib.Client; -using TMDbLib.Objects.Find; -using TMDbLib.Objects.Languages; -using TMDbLib.Objects.TvShows; namespace Jellyfin.Plugin.MetaShark.Providers { @@ -137,9 +127,7 @@ namespace Jellyfin.Plugin.MetaShark.Providers ProductionYear = subject.Year, HomePageUrl = "https://www.douban.com", Genres = subject.Genres, - // ProductionLocations = [x?.Country], PremiereDate = subject.ScreenTime, - Tagline = string.Empty, }; if (!string.IsNullOrEmpty(subject.Imdb)) { @@ -204,67 +192,73 @@ namespace Jellyfin.Plugin.MetaShark.Providers if (metaSource == MetaSource.Tmdb && !string.IsNullOrEmpty(tmdbId)) { - this.Log($"GetMovieMetadata of tmdb [id]: \"{tmdbId}\""); - var movieResult = await _tmdbApi + return await this.GetMetadataByTmdb(tmdbId, info, cancellationToken).ConfigureAwait(false); + } + + return result; + } + + private async Task> GetMetadataByTmdb(string tmdbId, MovieInfo info, CancellationToken cancellationToken) + { + this.Log($"GetMovieMetadata of tmdb [id]: \"{tmdbId}\""); + var result = new MetadataResult(); + var movieResult = await _tmdbApi .GetMovieAsync(Convert.ToInt32(tmdbId, CultureInfo.InvariantCulture), info.MetadataLanguage, info.MetadataLanguage, cancellationToken) .ConfigureAwait(false); - if (movieResult == null) - { - return result; - } - - var movie = new Movie - { - Name = movieResult.Title ?? movieResult.OriginalTitle, - OriginalTitle = movieResult.OriginalTitle, - Overview = movieResult.Overview?.Replace("\n\n", "\n", StringComparison.InvariantCulture), - Tagline = movieResult.Tagline, - ProductionLocations = movieResult.ProductionCountries.Select(pc => pc.Name).ToArray() - }; - result = new MetadataResult - { - QueriedById = true, - HasMetadata = true, - ResultLanguage = info.MetadataLanguage, - Item = movie - }; - - movie.SetProviderId(MetadataProvider.Tmdb, tmdbId); - 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.OfficialRating = this.GetTmdbOfficialRatingByData(movieResult, info.MetadataCountryCode); - movie.PremiereDate = movieResult.ReleaseDate; - movie.ProductionYear = movieResult.ReleaseDate?.Year; - - if (movieResult.ProductionCompanies != null) - { - movie.SetStudios(movieResult.ProductionCompanies.Select(c => c.Name)); - } - - var genres = movieResult.Genres; - - foreach (var genre in genres.Select(g => g.Name)) - { - movie.AddGenre(genre); - } - - foreach (var person in GetPersons(movieResult)) - { - result.AddPerson(person); - } - + if (movieResult == null) + { return result; } + var movie = new Movie + { + Name = movieResult.Title ?? movieResult.OriginalTitle, + OriginalTitle = movieResult.OriginalTitle, + Overview = movieResult.Overview?.Replace("\n\n", "\n", StringComparison.InvariantCulture), + Tagline = movieResult.Tagline, + ProductionLocations = movieResult.ProductionCountries.Select(pc => pc.Name).ToArray() + }; + result = new MetadataResult + { + QueriedById = true, + HasMetadata = true, + ResultLanguage = info.MetadataLanguage, + Item = movie + }; + + movie.SetProviderId(MetadataProvider.Tmdb, tmdbId); + 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.OfficialRating = this.GetTmdbOfficialRatingByData(movieResult, info.MetadataCountryCode); + movie.PremiereDate = movieResult.ReleaseDate; + movie.ProductionYear = movieResult.ReleaseDate?.Year; + + if (movieResult.ProductionCompanies != null) + { + movie.SetStudios(movieResult.ProductionCompanies.Select(c => c.Name)); + } + + var genres = movieResult.Genres; + + foreach (var genre in genres.Select(g => g.Name)) + { + movie.AddGenre(genre); + } + + foreach (var person in GetPersons(movieResult)) + { + result.AddPerson(person); + } + return result; } @@ -423,14 +417,5 @@ namespace Jellyfin.Plugin.MetaShark.Providers return null; } - - - /// - public async Task GetImageResponse(string url, CancellationToken cancellationToken) - { - this.Log("GetImageResponse url: {0}", url); - return await this._httpClientFactory.CreateClient().GetAsync(new Uri(url), cancellationToken).ConfigureAwait(false); - } - } } diff --git a/Jellyfin.Plugin.MetaShark/Providers/PersonImageProvider.cs b/Jellyfin.Plugin.MetaShark/Providers/PersonImageProvider.cs index 179d8c8..a2b7ad7 100644 --- a/Jellyfin.Plugin.MetaShark/Providers/PersonImageProvider.cs +++ b/Jellyfin.Plugin.MetaShark/Providers/PersonImageProvider.cs @@ -1,25 +1,16 @@ using Jellyfin.Plugin.MetaShark.Api; -using Jellyfin.Plugin.MetaShark.Core; -using Jellyfin.Plugin.MetaShark.Model; using MediaBrowser.Controller.Entities; -using MediaBrowser.Controller.Entities.Movies; -using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Providers; -using MediaBrowser.Model.Dto; using MediaBrowser.Model.Entities; -using MediaBrowser.Model.Extensions; using MediaBrowser.Model.Providers; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; -using System; using System.Collections.Generic; using System.Linq; using System.Net.Http; -using System.Text; using System.Threading; using System.Threading.Tasks; -using TMDbLib.Objects.Languages; namespace Jellyfin.Plugin.MetaShark.Providers { @@ -74,13 +65,6 @@ namespace Jellyfin.Plugin.MetaShark.Providers return new List(); } - /// - public async Task GetImageResponse(string url, CancellationToken cancellationToken) - { - this.Log("GetImageResponse url: {0}", url); - return await this._httpClientFactory.CreateClient().GetAsync(new Uri(url), cancellationToken).ConfigureAwait(false); - } - /// /// Query for a background photo /// diff --git a/Jellyfin.Plugin.MetaShark/Providers/PersonProvider.cs b/Jellyfin.Plugin.MetaShark/Providers/PersonProvider.cs index 0e1e478..4345fe0 100644 --- a/Jellyfin.Plugin.MetaShark/Providers/PersonProvider.cs +++ b/Jellyfin.Plugin.MetaShark/Providers/PersonProvider.cs @@ -1,8 +1,5 @@ -using System.Net.Mime; -using System.Xml.Schema; -using Jellyfin.Plugin.MetaShark.Api; +using Jellyfin.Plugin.MetaShark.Api; using Jellyfin.Plugin.MetaShark.Core; -using Jellyfin.Plugin.MetaShark.Model; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Providers; @@ -14,7 +11,6 @@ using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Net.Http; -using System.Text; using System.Threading; using System.Threading.Tasks; using TMDbLib.Objects.Find; @@ -166,11 +162,5 @@ namespace Jellyfin.Plugin.MetaShark.Providers return result; } - /// - public Task GetImageResponse(string url, CancellationToken cancellationToken) - { - this.Log("Person GetImageResponse url: {0}", url); - return this._httpClientFactory.CreateClient().GetAsync(new Uri(url), cancellationToken); - } } } diff --git a/Jellyfin.Plugin.MetaShark/Providers/SeasonImageProvider.cs b/Jellyfin.Plugin.MetaShark/Providers/SeasonImageProvider.cs index 37ea950..8d30da8 100644 --- a/Jellyfin.Plugin.MetaShark/Providers/SeasonImageProvider.cs +++ b/Jellyfin.Plugin.MetaShark/Providers/SeasonImageProvider.cs @@ -1,12 +1,9 @@ using Jellyfin.Plugin.MetaShark.Api; -using Jellyfin.Plugin.MetaShark.Core; using Jellyfin.Plugin.MetaShark.Model; using MediaBrowser.Controller.Entities; -using MediaBrowser.Controller.Entities.Movies; using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Providers; -using MediaBrowser.Model.Dto; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Extensions; using MediaBrowser.Model.Providers; @@ -17,10 +14,8 @@ using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Net.Http; -using System.Text; using System.Threading; using System.Threading.Tasks; -using TMDbLib.Objects.Languages; namespace Jellyfin.Plugin.MetaShark.Providers { @@ -116,12 +111,5 @@ namespace Jellyfin.Plugin.MetaShark.Providers return remoteImages.OrderByLanguageDescending(language); } - /// - public async Task GetImageResponse(string url, CancellationToken cancellationToken) - { - this.Log("[GetSeasonImages] GetImageResponse url: {0}", url); - return await this._httpClientFactory.CreateClient().GetAsync(new Uri(url), cancellationToken).ConfigureAwait(false); - } - } } diff --git a/Jellyfin.Plugin.MetaShark/Providers/SeasonProvider.cs b/Jellyfin.Plugin.MetaShark/Providers/SeasonProvider.cs index 045d166..e405823 100644 --- a/Jellyfin.Plugin.MetaShark/Providers/SeasonProvider.cs +++ b/Jellyfin.Plugin.MetaShark/Providers/SeasonProvider.cs @@ -8,18 +8,11 @@ using MediaBrowser.Controller.Providers; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Providers; using Microsoft.Extensions.Logging; -using System; using System.Collections.Generic; -using System.Globalization; -using System.IO; using System.Linq; using System.Net.Http; -using System.Text; using System.Threading; using System.Threading.Tasks; -using TMDbLib.Objects.Find; -using TMDbLib.Objects.TvShows; -using System.Text.RegularExpressions; using Microsoft.AspNetCore.Http; namespace Jellyfin.Plugin.MetaShark.Providers @@ -227,17 +220,5 @@ namespace Jellyfin.Plugin.MetaShark.Providers return result; } - - /// - public async Task GetImageResponse(string url, CancellationToken cancellationToken) - { - this.Log("GetImageResponse url: {0}", url); - return await this._httpClientFactory.CreateClient().GetAsync(new Uri(url), cancellationToken).ConfigureAwait(false); - } - - private void Log(string? message, params object?[] args) - { - this._logger.LogInformation($"[MetaShark] {message}", args); - } } } diff --git a/Jellyfin.Plugin.MetaShark/Providers/SeriesImageProvider.cs b/Jellyfin.Plugin.MetaShark/Providers/SeriesImageProvider.cs index 2dcb992..6778805 100644 --- a/Jellyfin.Plugin.MetaShark/Providers/SeriesImageProvider.cs +++ b/Jellyfin.Plugin.MetaShark/Providers/SeriesImageProvider.cs @@ -2,7 +2,6 @@ using Jellyfin.Plugin.MetaShark.Core; using Jellyfin.Plugin.MetaShark.Model; using MediaBrowser.Controller.Entities; -using MediaBrowser.Controller.Entities.Movies; using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Providers; @@ -12,14 +11,11 @@ using MediaBrowser.Model.Extensions; using MediaBrowser.Model.Providers; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; -using System; using System.Collections.Generic; using System.Linq; using System.Net.Http; -using System.Text; using System.Threading; using System.Threading.Tasks; -using TMDbLib.Objects.Languages; namespace Jellyfin.Plugin.MetaShark.Providers { @@ -130,25 +126,6 @@ namespace Jellyfin.Plugin.MetaShark.Providers return new List(); } - /// - public async Task GetImageResponse(string url, CancellationToken cancellationToken) - { - this.Log("GetImageResponse url: {0}", url); - - if (url.Contains("doubanio.com")) - {// 豆瓣图,带referer下载 - using (var requestMessage = new HttpRequestMessage(HttpMethod.Get, url)) - { - requestMessage.Headers.Add("Referer", "https://www.douban.com/"); - return await this._httpClientFactory.CreateClient().SendAsync(requestMessage, cancellationToken).ConfigureAwait(false); - } - } - else - { - return await this._httpClientFactory.CreateClient().GetAsync(new Uri(url), cancellationToken).ConfigureAwait(false); - } - } - /// /// Query for a background photo /// diff --git a/Jellyfin.Plugin.MetaShark/Providers/SeriesProvider.cs b/Jellyfin.Plugin.MetaShark/Providers/SeriesProvider.cs index 3bd9b2f..81b59bb 100644 --- a/Jellyfin.Plugin.MetaShark/Providers/SeriesProvider.cs +++ b/Jellyfin.Plugin.MetaShark/Providers/SeriesProvider.cs @@ -1,5 +1,4 @@ using Jellyfin.Plugin.MetaShark.Api; -using Jellyfin.Plugin.MetaShark.Core; using Jellyfin.Plugin.MetaShark.Model; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.TV; @@ -14,10 +13,8 @@ using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Net.Http; -using System.Text; using System.Threading; using System.Threading.Tasks; -using TMDbLib.Objects.Find; using TMDbLib.Objects.TvShows; using MetadataProvider = MediaBrowser.Model.Entities.MetadataProvider; @@ -414,13 +411,5 @@ namespace Jellyfin.Plugin.MetaShark.Providers } - - /// - public Task GetImageResponse(string url, CancellationToken cancellationToken) - { - this.Log("GetImageResponse url: {0}", url); - return this._httpClientFactory.CreateClient().GetAsync(new Uri(url), cancellationToken); - } - } }