From 4a5e8b99a038e3ed41c78b1e06dcc3d6b86cd53a Mon Sep 17 00:00:00 2001 From: Joe Rogers <1337joe@gmail.com> Date: Fri, 22 Oct 2021 00:35:14 +0200 Subject: [PATCH 01/15] Extract duplicate code, add test --- .../Tmdb/BoxSets/TmdbBoxSetImageProvider.cs | 38 +------ .../Tmdb/Movies/TmdbMovieImageProvider.cs | 39 +------ .../Tmdb/People/TmdbPersonImageProvider.cs | 17 +-- .../Tmdb/TV/TmdbEpisodeImageProvider.cs | 21 +--- .../Tmdb/TV/TmdbSeasonImageProvider.cs | 21 +--- .../Tmdb/TV/TmdbSeriesImageProvider.cs | 38 +------ .../Plugins/Tmdb/TmdbClientManager.cs | 50 ++++----- .../Plugins/Tmdb/TmdbUtils.cs | 30 ++++++ .../Tmdb/TmdbUtilsTests.cs | 102 +++++++++++++++++- 9 files changed, 176 insertions(+), 180 deletions(-) diff --git a/MediaBrowser.Providers/Plugins/Tmdb/BoxSets/TmdbBoxSetImageProvider.cs b/MediaBrowser.Providers/Plugins/Tmdb/BoxSets/TmdbBoxSetImageProvider.cs index 35dc36811e..17082e1f0e 100644 --- a/MediaBrowser.Providers/Plugins/Tmdb/BoxSets/TmdbBoxSetImageProvider.cs +++ b/MediaBrowser.Providers/Plugins/Tmdb/BoxSets/TmdbBoxSetImageProvider.cs @@ -67,40 +67,12 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.BoxSets return Enumerable.Empty(); } - var remoteImages = new List(); + var posters = collection.Images.Posters; + var backdrops = collection.Images.Backdrops; + var remoteImages = new List(posters.Count + backdrops.Count); - for (var i = 0; i < collection.Images.Posters.Count; i++) - { - var poster = collection.Images.Posters[i]; - remoteImages.Add(new RemoteImageInfo - { - Url = _tmdbClientManager.GetPosterUrl(poster.FilePath), - CommunityRating = poster.VoteAverage, - VoteCount = poster.VoteCount, - Width = poster.Width, - Height = poster.Height, - Language = TmdbUtils.AdjustImageLanguage(poster.Iso_639_1, language), - ProviderName = Name, - Type = ImageType.Primary, - RatingType = RatingType.Score - }); - } - - for (var i = 0; i < collection.Images.Backdrops.Count; i++) - { - var backdrop = collection.Images.Backdrops[i]; - remoteImages.Add(new RemoteImageInfo - { - Url = _tmdbClientManager.GetBackdropUrl(backdrop.FilePath), - CommunityRating = backdrop.VoteAverage, - VoteCount = backdrop.VoteCount, - Width = backdrop.Width, - Height = backdrop.Height, - ProviderName = Name, - Type = ImageType.Backdrop, - RatingType = RatingType.Score - }); - } + TmdbUtils.ConvertToRemoteImageInfo(posters, _tmdbClientManager.GetPosterUrl, ImageType.Primary, language, remoteImages); + TmdbUtils.ConvertToRemoteImageInfo(backdrops, _tmdbClientManager.GetBackdropUrl, ImageType.Backdrop, language, remoteImages); return remoteImages; } diff --git a/MediaBrowser.Providers/Plugins/Tmdb/Movies/TmdbMovieImageProvider.cs b/MediaBrowser.Providers/Plugins/Tmdb/Movies/TmdbMovieImageProvider.cs index 015eddc1ac..8d96d49552 100644 --- a/MediaBrowser.Providers/Plugins/Tmdb/Movies/TmdbMovieImageProvider.cs +++ b/MediaBrowser.Providers/Plugins/Tmdb/Movies/TmdbMovieImageProvider.cs @@ -13,7 +13,6 @@ using MediaBrowser.Common.Net; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Movies; using MediaBrowser.Controller.Providers; -using MediaBrowser.Model.Dto; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Providers; using TMDbLib.Objects.Find; @@ -84,40 +83,12 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.Movies return Enumerable.Empty(); } - var remoteImages = new List(); + var posters = movie.Images.Posters; + var backdrops = movie.Images.Backdrops; + var remoteImages = new List(posters.Count + backdrops.Count); - for (var i = 0; i < movie.Images.Posters.Count; i++) - { - var poster = movie.Images.Posters[i]; - remoteImages.Add(new RemoteImageInfo - { - Url = _tmdbClientManager.GetPosterUrl(poster.FilePath), - CommunityRating = poster.VoteAverage, - VoteCount = poster.VoteCount, - Width = poster.Width, - Height = poster.Height, - Language = TmdbUtils.AdjustImageLanguage(poster.Iso_639_1, language), - ProviderName = Name, - Type = ImageType.Primary, - RatingType = RatingType.Score - }); - } - - for (var i = 0; i < movie.Images.Backdrops.Count; i++) - { - var backdrop = movie.Images.Backdrops[i]; - remoteImages.Add(new RemoteImageInfo - { - Url = _tmdbClientManager.GetPosterUrl(backdrop.FilePath), - CommunityRating = backdrop.VoteAverage, - VoteCount = backdrop.VoteCount, - Width = backdrop.Width, - Height = backdrop.Height, - ProviderName = Name, - Type = ImageType.Backdrop, - RatingType = RatingType.Score - }); - } + TmdbUtils.ConvertToRemoteImageInfo(posters, _tmdbClientManager.GetPosterUrl, ImageType.Primary, language, remoteImages); + TmdbUtils.ConvertToRemoteImageInfo(backdrops, _tmdbClientManager.GetBackdropUrl, ImageType.Backdrop, language, remoteImages); return remoteImages; } diff --git a/MediaBrowser.Providers/Plugins/Tmdb/People/TmdbPersonImageProvider.cs b/MediaBrowser.Providers/Plugins/Tmdb/People/TmdbPersonImageProvider.cs index 1fc5ccba59..20f019cd1d 100644 --- a/MediaBrowser.Providers/Plugins/Tmdb/People/TmdbPersonImageProvider.cs +++ b/MediaBrowser.Providers/Plugins/Tmdb/People/TmdbPersonImageProvider.cs @@ -60,21 +60,10 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.People return Enumerable.Empty(); } - var remoteImages = new RemoteImageInfo[personResult.Images.Profiles.Count]; + var profiles = personResult.Images.Profiles; + var remoteImages = new List(profiles.Count); - for (var i = 0; i < personResult.Images.Profiles.Count; i++) - { - var image = personResult.Images.Profiles[i]; - remoteImages[i] = new RemoteImageInfo - { - ProviderName = Name, - Type = ImageType.Primary, - Width = image.Width, - Height = image.Height, - Language = TmdbUtils.AdjustImageLanguage(image.Iso_639_1, language), - Url = _tmdbClientManager.GetProfileUrl(image.FilePath) - }; - } + TmdbUtils.ConvertToRemoteImageInfo(profiles, _tmdbClientManager.GetProfileUrl, ImageType.Primary, language, remoteImages); return remoteImages; } diff --git a/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbEpisodeImageProvider.cs b/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbEpisodeImageProvider.cs index eb75e94050..5cc5e75697 100644 --- a/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbEpisodeImageProvider.cs +++ b/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbEpisodeImageProvider.cs @@ -12,7 +12,6 @@ using System.Threading.Tasks; using MediaBrowser.Common.Net; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Providers; -using MediaBrowser.Model.Dto; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Providers; @@ -75,23 +74,9 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV return Enumerable.Empty(); } - var remoteImages = new RemoteImageInfo[stills.Count]; - for (var i = 0; i < stills.Count; i++) - { - var image = stills[i]; - remoteImages[i] = new RemoteImageInfo - { - Url = _tmdbClientManager.GetStillUrl(image.FilePath), - CommunityRating = image.VoteAverage, - VoteCount = image.VoteCount, - Width = image.Width, - Height = image.Height, - Language = TmdbUtils.AdjustImageLanguage(image.Iso_639_1, language), - ProviderName = Name, - Type = ImageType.Primary, - RatingType = RatingType.Score - }; - } + var remoteImages = new List(stills.Count); + + TmdbUtils.ConvertToRemoteImageInfo(stills, _tmdbClientManager.GetStillUrl, ImageType.Primary, language, remoteImages); return remoteImages; } diff --git a/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbSeasonImageProvider.cs b/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbSeasonImageProvider.cs index ca44c9bbc3..0909f3e250 100644 --- a/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbSeasonImageProvider.cs +++ b/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbSeasonImageProvider.cs @@ -11,7 +11,6 @@ using MediaBrowser.Common.Net; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Controller.Providers; -using MediaBrowser.Model.Dto; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Providers; @@ -62,23 +61,9 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV return Enumerable.Empty(); } - var remoteImages = new RemoteImageInfo[posters.Count]; - for (var i = 0; i < posters.Count; i++) - { - var image = posters[i]; - remoteImages[i] = new RemoteImageInfo - { - Url = _tmdbClientManager.GetPosterUrl(image.FilePath), - CommunityRating = image.VoteAverage, - VoteCount = image.VoteCount, - Width = image.Width, - Height = image.Height, - Language = TmdbUtils.AdjustImageLanguage(image.Iso_639_1, language), - ProviderName = Name, - Type = ImageType.Primary, - RatingType = RatingType.Score - }; - } + var remoteImages = new List(posters.Count); + + TmdbUtils.ConvertToRemoteImageInfo(posters, _tmdbClientManager.GetPosterUrl, ImageType.Primary, language, remoteImages); return remoteImages; } diff --git a/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbSeriesImageProvider.cs b/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbSeriesImageProvider.cs index f3f3403789..37bbea6684 100644 --- a/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbSeriesImageProvider.cs +++ b/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbSeriesImageProvider.cs @@ -11,7 +11,6 @@ using MediaBrowser.Common.Net; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Controller.Providers; -using MediaBrowser.Model.Dto; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Providers; @@ -70,41 +69,10 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV var posters = series.Images.Posters; var backdrops = series.Images.Backdrops; + var remoteImages = new List(posters.Count + backdrops.Count); - var remoteImages = new RemoteImageInfo[posters.Count + backdrops.Count]; - - for (var i = 0; i < posters.Count; i++) - { - var poster = posters[i]; - remoteImages[i] = new RemoteImageInfo - { - Url = _tmdbClientManager.GetPosterUrl(poster.FilePath), - CommunityRating = poster.VoteAverage, - VoteCount = poster.VoteCount, - Width = poster.Width, - Height = poster.Height, - Language = TmdbUtils.AdjustImageLanguage(poster.Iso_639_1, language), - ProviderName = Name, - Type = ImageType.Primary, - RatingType = RatingType.Score - }; - } - - for (var i = 0; i < backdrops.Count; i++) - { - var backdrop = series.Images.Backdrops[i]; - remoteImages[posters.Count + i] = new RemoteImageInfo - { - Url = _tmdbClientManager.GetBackdropUrl(backdrop.FilePath), - CommunityRating = backdrop.VoteAverage, - VoteCount = backdrop.VoteCount, - Width = backdrop.Width, - Height = backdrop.Height, - ProviderName = Name, - Type = ImageType.Backdrop, - RatingType = RatingType.Score - }; - } + TmdbUtils.ConvertToRemoteImageInfo(posters, _tmdbClientManager.GetPosterUrl, ImageType.Primary, language, remoteImages); + TmdbUtils.ConvertToRemoteImageInfo(backdrops, _tmdbClientManager.GetBackdropUrl, ImageType.Backdrop, language, remoteImages); return remoteImages; } diff --git a/MediaBrowser.Providers/Plugins/Tmdb/TmdbClientManager.cs b/MediaBrowser.Providers/Plugins/Tmdb/TmdbClientManager.cs index 74be4c7933..3c7e332699 100644 --- a/MediaBrowser.Providers/Plugins/Tmdb/TmdbClientManager.cs +++ b/MediaBrowser.Providers/Plugins/Tmdb/TmdbClientManager.cs @@ -1,4 +1,4 @@ -#nullable disable +#nullable disable using System; using System.Collections.Generic; @@ -471,33 +471,39 @@ namespace MediaBrowser.Providers.Plugins.Tmdb } /// - /// Gets the absolute URL of the poster. + /// Handles bad path checking and builds the absolute url. /// - /// The relative URL of the poster. + /// The image size to fetch. + /// The relative URL of the image. /// The absolute URL. - public string GetPosterUrl(string posterPath) + private string GetUrl(string size, string path) { - if (string.IsNullOrEmpty(posterPath)) + if (string.IsNullOrEmpty(path)) { return null; } - return _tmDbClient.GetImageUrl(_tmDbClient.Config.Images.PosterSizes[^1], posterPath).ToString(); + return _tmDbClient.GetImageUrl(size, path).ToString(); } /// - /// Gets the absolute URL of the backdrop image. + /// Gets the absolute URL of the poster. /// - /// The relative URL of the backdrop image. + /// The relative URL of the poster. /// The absolute URL. - public string GetBackdropUrl(string posterPath) + public string GetPosterUrl(string posterPath) { - if (string.IsNullOrEmpty(posterPath)) - { - return null; - } + return GetUrl(_tmDbClient.Config.Images.PosterSizes[^1], posterPath); + } - return _tmDbClient.GetImageUrl(_tmDbClient.Config.Images.BackdropSizes[^1], posterPath).ToString(); + /// + /// Gets the absolute URL of the backdrop image. + /// + /// The relative URL of the backdrop image. + /// The absolute URL. + public string GetBackdropUrl(string backdropPath) + { + return GetUrl(_tmDbClient.Config.Images.BackdropSizes[^1], backdropPath); } /// @@ -507,12 +513,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb /// The absolute URL. public string GetProfileUrl(string actorProfilePath) { - if (string.IsNullOrEmpty(actorProfilePath)) - { - return null; - } - - return _tmDbClient.GetImageUrl(_tmDbClient.Config.Images.ProfileSizes[^1], actorProfilePath).ToString(); + return GetUrl(_tmDbClient.Config.Images.ProfileSizes[^1], actorProfilePath); } /// @@ -522,12 +523,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb /// The absolute URL. public string GetStillUrl(string filePath) { - if (string.IsNullOrEmpty(filePath)) - { - return null; - } - - return _tmDbClient.GetImageUrl(_tmDbClient.Config.Images.StillSizes[^1], filePath).ToString(); + return GetUrl(_tmDbClient.Config.Images.StillSizes[^1], filePath); } private Task EnsureClientConfigAsync() @@ -542,7 +538,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb GC.SuppressFinalize(this); } -/// + /// /// Releases unmanaged and - optionally - managed resources. /// /// true to release both managed and unmanaged resources; false to release only unmanaged resources. diff --git a/MediaBrowser.Providers/Plugins/Tmdb/TmdbUtils.cs b/MediaBrowser.Providers/Plugins/Tmdb/TmdbUtils.cs index 58ab9f5473..ec4e8373f2 100644 --- a/MediaBrowser.Providers/Plugins/Tmdb/TmdbUtils.cs +++ b/MediaBrowser.Providers/Plugins/Tmdb/TmdbUtils.cs @@ -1,7 +1,9 @@ using System; using System.Collections.Generic; using System.Text.RegularExpressions; +using MediaBrowser.Model.Dto; using MediaBrowser.Model.Entities; +using MediaBrowser.Model.Providers; using TMDbLib.Objects.General; namespace MediaBrowser.Providers.Plugins.Tmdb @@ -192,5 +194,33 @@ namespace MediaBrowser.Providers.Plugins.Tmdb return newRating.Replace("DE-", "FSK-", StringComparison.OrdinalIgnoreCase); } + + /// + /// Converts s into s. + /// + /// The input images. + /// The relevant GetTypeUrl function to get the absolute url of the image. + /// The type of the image. + /// The requested language. + /// The collection to add the remote images into. + public static void ConvertToRemoteImageInfo(List images, Func imageUrlConverter, ImageType type, string requestLanguage, List results) + { + for (var i = 0; i < images.Count; i++) + { + var image = images[i]; + results.Add(new RemoteImageInfo + { + Url = imageUrlConverter(image.FilePath), + CommunityRating = image.VoteAverage, + VoteCount = image.VoteCount, + Width = image.Width, + Height = image.Height, + Language = AdjustImageLanguage(image.Iso_639_1, requestLanguage), + ProviderName = ProviderName, + Type = type, + RatingType = RatingType.Score + }); + } + } } } diff --git a/tests/Jellyfin.Providers.Tests/Tmdb/TmdbUtilsTests.cs b/tests/Jellyfin.Providers.Tests/Tmdb/TmdbUtilsTests.cs index f6a7c676f4..c9a8d11248 100644 --- a/tests/Jellyfin.Providers.Tests/Tmdb/TmdbUtilsTests.cs +++ b/tests/Jellyfin.Providers.Tests/Tmdb/TmdbUtilsTests.cs @@ -1,4 +1,9 @@ -using MediaBrowser.Providers.Plugins.Tmdb; +using System.Collections.Generic; +using MediaBrowser.Model.Dto; +using MediaBrowser.Model.Entities; +using MediaBrowser.Model.Providers; +using MediaBrowser.Providers.Plugins.Tmdb; +using TMDbLib.Objects.General; using Xunit; namespace Jellyfin.Providers.Tests.Tmdb @@ -23,5 +28,100 @@ namespace Jellyfin.Providers.Tests.Tmdb { Assert.Equal(expected, TmdbUtils.NormalizeLanguage(input!)); } + + [Theory] + [InlineData(null, null, null)] + [InlineData(null, "en-US", null)] + [InlineData("en", null, "en")] + [InlineData("en", "en-US", "en-US")] + [InlineData("fr-CA", "fr-BE", "fr-CA")] + [InlineData("fr-CA", "fr", "fr-CA")] + [InlineData("de", "en-US", "de")] + public static void AdjustImageLanguage_Valid_Success(string imageLanguage, string requestLanguage, string expected) + { + Assert.Equal(expected, TmdbUtils.AdjustImageLanguage(imageLanguage, requestLanguage)); + } + + private static TheoryData GetConvertedImages() + { + return new TheoryData + { + { + ImageType.Primary, + new () + { + Width = 1, + Height = 1, + AspectRatio = 1, + FilePath = "path 1", + Iso_639_1 = "en", + VoteAverage = 1.2, + VoteCount = 5 + }, + new () + { + Type = ImageType.Primary, + Width = 1, + Height = 1, + Url = "converted path 1", + Language = "en-US", + CommunityRating = 1.2, + VoteCount = 5, + RatingType = RatingType.Score, + ProviderName = TmdbUtils.ProviderName + } + }, + { + ImageType.Backdrop, + new () + { + Width = 4, + Height = 2, + AspectRatio = 2, + FilePath = "path 2", + Iso_639_1 = null, + VoteAverage = 0, + VoteCount = 0 + }, + new () + { + Type = ImageType.Backdrop, + Width = 4, + Height = 2, + Url = "converted path 2", + Language = null, + CommunityRating = 0, + VoteCount = 0, + RatingType = RatingType.Score, + ProviderName = TmdbUtils.ProviderName + } + } + }; + } + + [Theory] + [MemberData(nameof(GetConvertedImages))] + public static void ConvertToRemoteImageInfo_ImageList_ConvertsAll(ImageType type, ImageData input, RemoteImageInfo expected) + { + var images = new List { input }; + string UrlConverter(string s) + => "converted " + s; + var language = "en-US"; + + var results = new List(images.Count); + TmdbUtils.ConvertToRemoteImageInfo(images, UrlConverter, type, language, results); + + Assert.Single(results); + + Assert.Equal(expected.Type, results[0].Type); + Assert.Equal(expected.Width, results[0].Width); + Assert.Equal(expected.Height, results[0].Height); + Assert.Equal(expected.Url, results[0].Url); + Assert.Equal(expected.Language, results[0].Language); + Assert.Equal(expected.CommunityRating, results[0].CommunityRating); + Assert.Equal(expected.VoteCount, results[0].VoteCount); + Assert.Equal(expected.RatingType, results[0].RatingType); + Assert.Equal(expected.ProviderName, results[0].ProviderName); + } } } From 2b283d249fc040b62d8d4bcd4623896b4aed3d15 Mon Sep 17 00:00:00 2001 From: Joe Rogers <1337joe@gmail.com> Date: Tue, 2 Nov 2021 21:12:13 +0100 Subject: [PATCH 02/15] Switch to method per image conversion --- .../Tmdb/BoxSets/TmdbBoxSetImageProvider.cs | 4 +- .../Tmdb/Movies/TmdbMovieImageProvider.cs | 4 +- .../Tmdb/People/TmdbPersonImageProvider.cs | 2 +- .../Tmdb/TV/TmdbEpisodeImageProvider.cs | 2 +- .../Tmdb/TV/TmdbSeasonImageProvider.cs | 2 +- .../Tmdb/TV/TmdbSeriesImageProvider.cs | 4 +- .../Plugins/Tmdb/TmdbUtils.cs | 50 ++++++++++- .../Tmdb/TmdbUtilsTests.cs | 89 +------------------ 8 files changed, 59 insertions(+), 98 deletions(-) diff --git a/MediaBrowser.Providers/Plugins/Tmdb/BoxSets/TmdbBoxSetImageProvider.cs b/MediaBrowser.Providers/Plugins/Tmdb/BoxSets/TmdbBoxSetImageProvider.cs index 17082e1f0e..17f3e635ff 100644 --- a/MediaBrowser.Providers/Plugins/Tmdb/BoxSets/TmdbBoxSetImageProvider.cs +++ b/MediaBrowser.Providers/Plugins/Tmdb/BoxSets/TmdbBoxSetImageProvider.cs @@ -71,8 +71,8 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.BoxSets var backdrops = collection.Images.Backdrops; var remoteImages = new List(posters.Count + backdrops.Count); - TmdbUtils.ConvertToRemoteImageInfo(posters, _tmdbClientManager.GetPosterUrl, ImageType.Primary, language, remoteImages); - TmdbUtils.ConvertToRemoteImageInfo(backdrops, _tmdbClientManager.GetBackdropUrl, ImageType.Backdrop, language, remoteImages); + TmdbUtils.ConvertPostersToRemoteImageInfo(posters, _tmdbClientManager, language, remoteImages); + TmdbUtils.ConvertBackdropsToRemoteImageInfo(backdrops, _tmdbClientManager, language, remoteImages); return remoteImages; } diff --git a/MediaBrowser.Providers/Plugins/Tmdb/Movies/TmdbMovieImageProvider.cs b/MediaBrowser.Providers/Plugins/Tmdb/Movies/TmdbMovieImageProvider.cs index 8d96d49552..4336efee45 100644 --- a/MediaBrowser.Providers/Plugins/Tmdb/Movies/TmdbMovieImageProvider.cs +++ b/MediaBrowser.Providers/Plugins/Tmdb/Movies/TmdbMovieImageProvider.cs @@ -87,8 +87,8 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.Movies var backdrops = movie.Images.Backdrops; var remoteImages = new List(posters.Count + backdrops.Count); - TmdbUtils.ConvertToRemoteImageInfo(posters, _tmdbClientManager.GetPosterUrl, ImageType.Primary, language, remoteImages); - TmdbUtils.ConvertToRemoteImageInfo(backdrops, _tmdbClientManager.GetBackdropUrl, ImageType.Backdrop, language, remoteImages); + TmdbUtils.ConvertPostersToRemoteImageInfo(posters, _tmdbClientManager, language, remoteImages); + TmdbUtils.ConvertBackdropsToRemoteImageInfo(backdrops, _tmdbClientManager, language, remoteImages); return remoteImages; } diff --git a/MediaBrowser.Providers/Plugins/Tmdb/People/TmdbPersonImageProvider.cs b/MediaBrowser.Providers/Plugins/Tmdb/People/TmdbPersonImageProvider.cs index 20f019cd1d..cad62eca3c 100644 --- a/MediaBrowser.Providers/Plugins/Tmdb/People/TmdbPersonImageProvider.cs +++ b/MediaBrowser.Providers/Plugins/Tmdb/People/TmdbPersonImageProvider.cs @@ -63,7 +63,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.People var profiles = personResult.Images.Profiles; var remoteImages = new List(profiles.Count); - TmdbUtils.ConvertToRemoteImageInfo(profiles, _tmdbClientManager.GetProfileUrl, ImageType.Primary, language, remoteImages); + TmdbUtils.ConvertProfilesToRemoteImageInfo(profiles, _tmdbClientManager, language, remoteImages); return remoteImages; } diff --git a/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbEpisodeImageProvider.cs b/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbEpisodeImageProvider.cs index 5cc5e75697..b7dda9b502 100644 --- a/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbEpisodeImageProvider.cs +++ b/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbEpisodeImageProvider.cs @@ -76,7 +76,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV var remoteImages = new List(stills.Count); - TmdbUtils.ConvertToRemoteImageInfo(stills, _tmdbClientManager.GetStillUrl, ImageType.Primary, language, remoteImages); + TmdbUtils.ConvertStillsToRemoteImageInfo(stills, _tmdbClientManager, language, remoteImages); return remoteImages; } diff --git a/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbSeasonImageProvider.cs b/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbSeasonImageProvider.cs index 0909f3e250..90b324a4fe 100644 --- a/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbSeasonImageProvider.cs +++ b/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbSeasonImageProvider.cs @@ -63,7 +63,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV var remoteImages = new List(posters.Count); - TmdbUtils.ConvertToRemoteImageInfo(posters, _tmdbClientManager.GetPosterUrl, ImageType.Primary, language, remoteImages); + TmdbUtils.ConvertPostersToRemoteImageInfo(posters, _tmdbClientManager, language, remoteImages); return remoteImages; } diff --git a/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbSeriesImageProvider.cs b/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbSeriesImageProvider.cs index 37bbea6684..9f2821c404 100644 --- a/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbSeriesImageProvider.cs +++ b/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbSeriesImageProvider.cs @@ -71,8 +71,8 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV var backdrops = series.Images.Backdrops; var remoteImages = new List(posters.Count + backdrops.Count); - TmdbUtils.ConvertToRemoteImageInfo(posters, _tmdbClientManager.GetPosterUrl, ImageType.Primary, language, remoteImages); - TmdbUtils.ConvertToRemoteImageInfo(backdrops, _tmdbClientManager.GetBackdropUrl, ImageType.Backdrop, language, remoteImages); + TmdbUtils.ConvertPostersToRemoteImageInfo(posters, _tmdbClientManager, language, remoteImages); + TmdbUtils.ConvertBackdropsToRemoteImageInfo(backdrops, _tmdbClientManager, language, remoteImages); return remoteImages; } diff --git a/MediaBrowser.Providers/Plugins/Tmdb/TmdbUtils.cs b/MediaBrowser.Providers/Plugins/Tmdb/TmdbUtils.cs index ec4e8373f2..3cdab601ac 100644 --- a/MediaBrowser.Providers/Plugins/Tmdb/TmdbUtils.cs +++ b/MediaBrowser.Providers/Plugins/Tmdb/TmdbUtils.cs @@ -195,6 +195,54 @@ namespace MediaBrowser.Providers.Plugins.Tmdb return newRating.Replace("DE-", "FSK-", StringComparison.OrdinalIgnoreCase); } + /// + /// Converts poster s into s. + /// + /// The input images. + /// The client manager to use for resolving image urls. + /// The requested language. + /// The collection to add the remote images into. + public static void ConvertPostersToRemoteImageInfo(List images, TmdbClientManager tmdbClientManager, string requestLanguage, List results) + { + ConvertToRemoteImageInfo(images, tmdbClientManager.GetPosterUrl, ImageType.Primary, requestLanguage, results); + } + + /// + /// Converts backdrop s into s. + /// + /// The input images. + /// The client manager to use for resolving image urls. + /// The requested language. + /// The collection to add the remote images into. + public static void ConvertBackdropsToRemoteImageInfo(List images, TmdbClientManager tmdbClientManager, string requestLanguage, List results) + { + ConvertToRemoteImageInfo(images, tmdbClientManager.GetBackdropUrl, ImageType.Backdrop, requestLanguage, results); + } + + /// + /// Converts profile s into s. + /// + /// The input images. + /// The client manager to use for resolving image urls. + /// The requested language. + /// The collection to add the remote images into. + public static void ConvertProfilesToRemoteImageInfo(List images, TmdbClientManager tmdbClientManager, string requestLanguage, List results) + { + ConvertToRemoteImageInfo(images, tmdbClientManager.GetProfileUrl, ImageType.Primary, requestLanguage, results); + } + + /// + /// Converts still s into s. + /// + /// The input images. + /// The client manager to use for resolving image urls. + /// The requested language. + /// The collection to add the remote images into. + public static void ConvertStillsToRemoteImageInfo(List images, TmdbClientManager tmdbClientManager, string requestLanguage, List results) + { + ConvertToRemoteImageInfo(images, tmdbClientManager.GetStillUrl, ImageType.Primary, requestLanguage, results); + } + /// /// Converts s into s. /// @@ -203,7 +251,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb /// The type of the image. /// The requested language. /// The collection to add the remote images into. - public static void ConvertToRemoteImageInfo(List images, Func imageUrlConverter, ImageType type, string requestLanguage, List results) + private static void ConvertToRemoteImageInfo(List images, Func imageUrlConverter, ImageType type, string requestLanguage, List results) { for (var i = 0; i < images.Count; i++) { diff --git a/tests/Jellyfin.Providers.Tests/Tmdb/TmdbUtilsTests.cs b/tests/Jellyfin.Providers.Tests/Tmdb/TmdbUtilsTests.cs index c9a8d11248..efd2d9553f 100644 --- a/tests/Jellyfin.Providers.Tests/Tmdb/TmdbUtilsTests.cs +++ b/tests/Jellyfin.Providers.Tests/Tmdb/TmdbUtilsTests.cs @@ -1,9 +1,4 @@ -using System.Collections.Generic; -using MediaBrowser.Model.Dto; -using MediaBrowser.Model.Entities; -using MediaBrowser.Model.Providers; -using MediaBrowser.Providers.Plugins.Tmdb; -using TMDbLib.Objects.General; +using MediaBrowser.Providers.Plugins.Tmdb; using Xunit; namespace Jellyfin.Providers.Tests.Tmdb @@ -41,87 +36,5 @@ namespace Jellyfin.Providers.Tests.Tmdb { Assert.Equal(expected, TmdbUtils.AdjustImageLanguage(imageLanguage, requestLanguage)); } - - private static TheoryData GetConvertedImages() - { - return new TheoryData - { - { - ImageType.Primary, - new () - { - Width = 1, - Height = 1, - AspectRatio = 1, - FilePath = "path 1", - Iso_639_1 = "en", - VoteAverage = 1.2, - VoteCount = 5 - }, - new () - { - Type = ImageType.Primary, - Width = 1, - Height = 1, - Url = "converted path 1", - Language = "en-US", - CommunityRating = 1.2, - VoteCount = 5, - RatingType = RatingType.Score, - ProviderName = TmdbUtils.ProviderName - } - }, - { - ImageType.Backdrop, - new () - { - Width = 4, - Height = 2, - AspectRatio = 2, - FilePath = "path 2", - Iso_639_1 = null, - VoteAverage = 0, - VoteCount = 0 - }, - new () - { - Type = ImageType.Backdrop, - Width = 4, - Height = 2, - Url = "converted path 2", - Language = null, - CommunityRating = 0, - VoteCount = 0, - RatingType = RatingType.Score, - ProviderName = TmdbUtils.ProviderName - } - } - }; - } - - [Theory] - [MemberData(nameof(GetConvertedImages))] - public static void ConvertToRemoteImageInfo_ImageList_ConvertsAll(ImageType type, ImageData input, RemoteImageInfo expected) - { - var images = new List { input }; - string UrlConverter(string s) - => "converted " + s; - var language = "en-US"; - - var results = new List(images.Count); - TmdbUtils.ConvertToRemoteImageInfo(images, UrlConverter, type, language, results); - - Assert.Single(results); - - Assert.Equal(expected.Type, results[0].Type); - Assert.Equal(expected.Width, results[0].Width); - Assert.Equal(expected.Height, results[0].Height); - Assert.Equal(expected.Url, results[0].Url); - Assert.Equal(expected.Language, results[0].Language); - Assert.Equal(expected.CommunityRating, results[0].CommunityRating); - Assert.Equal(expected.VoteCount, results[0].VoteCount); - Assert.Equal(expected.RatingType, results[0].RatingType); - Assert.Equal(expected.ProviderName, results[0].ProviderName); - } } } From 416894008ea641b8d069ee482f7e63d2b9d5723d Mon Sep 17 00:00:00 2001 From: Bond_009 Date: Wed, 3 Nov 2021 14:02:57 +0100 Subject: [PATCH 03/15] Minor improvements * Removed some allocations * Removed some useless abstractions --- MediaBrowser.Controller/Entities/BaseItem.cs | 106 ++++++------------ .../Manager/ItemImageProviderTests.cs | 55 ++++----- 2 files changed, 64 insertions(+), 97 deletions(-) diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs index 02ee97b23f..0df70705e5 100644 --- a/MediaBrowser.Controller/Entities/BaseItem.cs +++ b/MediaBrowser.Controller/Entities/BaseItem.cs @@ -84,8 +84,6 @@ namespace MediaBrowser.Controller.Entities Model.Entities.ExtraType.Scene }; - public static readonly char[] SlugReplaceChars = { '?', '/', '&' }; - /// /// The supported extra folder names and types. See . /// @@ -354,11 +352,6 @@ namespace MediaBrowser.Controller.Entities { get { - // if (IsOffline) - // { - // return LocationType.Offline; - // } - var path = Path; if (string.IsNullOrEmpty(path)) { @@ -391,7 +384,7 @@ namespace MediaBrowser.Controller.Entities } [JsonIgnore] - public bool IsFileProtocol => IsPathProtocol(MediaProtocol.File); + public bool IsFileProtocol => PathProtocol == MediaProtocol.File; [JsonIgnore] public bool HasPathProtocol => PathProtocol.HasValue; @@ -583,14 +576,7 @@ namespace MediaBrowser.Controller.Entities } [JsonIgnore] - public virtual Guid DisplayParentId - { - get - { - var parentId = ParentId; - return parentId; - } - } + public virtual Guid DisplayParentId => ParentId; [JsonIgnore] public BaseItem DisplayParent @@ -853,13 +839,6 @@ namespace MediaBrowser.Controller.Entities return Id.ToString("N", CultureInfo.InvariantCulture); } - public bool IsPathProtocol(MediaProtocol protocol) - { - var current = PathProtocol; - - return current.HasValue && current.Value == protocol; - } - private List> GetSortChunks(string s1) { var list = new List>(); @@ -987,7 +966,7 @@ namespace MediaBrowser.Controller.Entities ReadOnlySpan idString = Id.ToString("N", CultureInfo.InvariantCulture); - return System.IO.Path.Join(basePath, "library", idString.Slice(0, 2), idString); + return System.IO.Path.Join(basePath, "library", idString[..2], idString); } /// @@ -1302,8 +1281,7 @@ namespace MediaBrowser.Controller.Entities terms.Add(item.Name); } - var video = item as Video; - if (video != null) + if (item is Video video) { if (video.Video3DFormat.HasValue) { @@ -1338,7 +1316,7 @@ namespace MediaBrowser.Controller.Entities } } - return string.Join('/', terms.ToArray()); + return string.Join('/', terms); } /// @@ -1361,9 +1339,7 @@ namespace MediaBrowser.Controller.Entities .Select(audio => { // Try to retrieve it from the db. If we don't find it, use the resolved version - var dbItem = LibraryManager.GetItemById(audio.Id) as Audio.Audio; - - if (dbItem != null) + if (LibraryManager.GetItemById(audio.Id) is Audio.Audio dbItem) { audio = dbItem; } @@ -1570,8 +1546,7 @@ namespace MediaBrowser.Controller.Entities } } - var hasTrailers = this as IHasTrailers; - if (hasTrailers != null) + if (this is IHasTrailers hasTrailers) { localTrailersChanged = await RefreshLocalTrailers(hasTrailers, options, fileSystemChildren, cancellationToken).ConfigureAwait(false); } @@ -2268,7 +2243,11 @@ namespace MediaBrowser.Controller.Entities var existingImage = GetImageInfo(image.Type, index); - if (existingImage != null) + if (existingImage == null) + { + AddImage(image); + } + else { existingImage.Path = image.Path; existingImage.DateModified = image.DateModified; @@ -2276,15 +2255,6 @@ namespace MediaBrowser.Controller.Entities existingImage.Height = image.Height; existingImage.BlurHash = image.BlurHash; } - else - { - var current = ImageInfos; - var currentCount = current.Length; - var newArr = new ItemImageInfo[currentCount + 1]; - current.CopyTo(newArr, 0); - newArr[currentCount] = image; - ImageInfos = newArr; - } } public void SetImagePath(ImageType type, int index, FileSystemMetadata file) @@ -2298,7 +2268,7 @@ namespace MediaBrowser.Controller.Entities if (image == null) { - ImageInfos = ImageInfos.Concat(new[] { GetImageInfo(file, type) }).ToArray(); + AddImage(GetImageInfo(file, type)); } else { @@ -2342,7 +2312,7 @@ namespace MediaBrowser.Controller.Entities public void RemoveImage(ItemImageInfo image) { - RemoveImages(new List { image }); + RemoveImages(new[] { image }); } public void RemoveImages(IEnumerable deletedImages) @@ -2350,6 +2320,16 @@ namespace MediaBrowser.Controller.Entities ImageInfos = ImageInfos.Except(deletedImages).ToArray(); } + public void AddImage(ItemImageInfo image) + { + var current = ImageInfos; + var currentCount = current.Length; + var newArr = new ItemImageInfo[currentCount + 1]; + current.CopyTo(newArr, 0); + newArr[currentCount] = image; + ImageInfos = newArr; + } + public virtual Task UpdateToRepositoryAsync(ItemUpdateType updateReason, CancellationToken cancellationToken) => LibraryManager.UpdateItemAsync(this, GetParent(), updateReason, cancellationToken); @@ -2373,7 +2353,7 @@ namespace MediaBrowser.Controller.Entities if (deletedImages.Count > 0) { - ImageInfos = ImageInfos.Except(deletedImages).ToArray(); + RemoveImages(deletedImages); } return deletedImages.Count > 0; @@ -2715,7 +2695,7 @@ namespace MediaBrowser.Controller.Entities protected static string GetMappedPath(BaseItem item, string path, MediaProtocol? protocol) { - if (protocol.HasValue && protocol.Value == MediaProtocol.File) + if (protocol == MediaProtocol.File) { return LibraryManager.GetPathAfterNetworkSubstitution(path, item); } @@ -2743,8 +2723,10 @@ namespace MediaBrowser.Controller.Entities protected Task RefreshMetadataForOwnedItem(BaseItem ownedItem, bool copyTitleMetadata, MetadataRefreshOptions options, CancellationToken cancellationToken) { - var newOptions = new MetadataRefreshOptions(options); - newOptions.SearchResult = null; + var newOptions = new MetadataRefreshOptions(options) + { + SearchResult = null + }; var item = this; @@ -2805,8 +2787,10 @@ namespace MediaBrowser.Controller.Entities protected Task RefreshMetadataForOwnedVideo(MetadataRefreshOptions options, bool copyTitleMetadata, string path, CancellationToken cancellationToken) { - var newOptions = new MetadataRefreshOptions(options); - newOptions.SearchResult = null; + var newOptions = new MetadataRefreshOptions(options) + { + SearchResult = null + }; var id = LibraryManager.GetNewItemId(path, typeof(Video)); @@ -2820,14 +2804,6 @@ namespace MediaBrowser.Controller.Entities newOptions.ForceSave = true; } - // var parentId = Id; - // if (!video.IsOwnedItem || video.ParentId != parentId) - // { - // video.IsOwnedItem = true; - // video.ParentId = parentId; - // newOptions.ForceSave = true; - // } - if (video == null) { return Task.FromResult(true); @@ -2911,7 +2887,7 @@ namespace MediaBrowser.Controller.Entities .Select(i => i.OfficialRating) .Where(i => !string.IsNullOrEmpty(i)) .Distinct(StringComparer.OrdinalIgnoreCase) - .Select(i => new Tuple(i, LocalizationManager.GetRatingLevel(i))) + .Select(i => (i, LocalizationManager.GetRatingLevel(i))) .OrderBy(i => i.Item2 ?? 1000) .Select(i => i.Item1); @@ -2958,18 +2934,6 @@ namespace MediaBrowser.Controller.Entities .Where(i => i.ExtraType.HasValue && extraTypes.Contains(i.ExtraType.Value)); } - public IEnumerable GetTrailers() - { - if (this is IHasTrailers) - { - return ((IHasTrailers)this).LocalTrailerIds.Select(LibraryManager.GetItemById).Where(i => i != null).OrderBy(i => i.SortName); - } - else - { - return Array.Empty(); - } - } - public virtual long GetRunTimeTicksForPlayState() { return RunTimeTicks ?? 0; diff --git a/tests/Jellyfin.Providers.Tests/Manager/ItemImageProviderTests.cs b/tests/Jellyfin.Providers.Tests/Manager/ItemImageProviderTests.cs index 6d65ba2d7a..f9ac8f46b9 100644 --- a/tests/Jellyfin.Providers.Tests/Manager/ItemImageProviderTests.cs +++ b/tests/Jellyfin.Providers.Tests/Manager/ItemImageProviderTests.cs @@ -28,13 +28,13 @@ namespace Jellyfin.Providers.Tests.Manager { public class ItemImageProviderTests { - private static readonly string TestDataImagePath = "Test Data/Images/blank{0}.jpg"; + private const string TestDataImagePath = "Test Data/Images/blank{0}.jpg"; [Fact] public void ValidateImages_PhotoEmptyProviders_NoChange() { var itemImageProvider = GetItemImageProvider(null, null); - var changed = itemImageProvider.ValidateImages(new Photo(), new List(), null); + var changed = itemImageProvider.ValidateImages(new Photo(), Enumerable.Empty(), null); Assert.False(changed); } @@ -43,7 +43,7 @@ namespace Jellyfin.Providers.Tests.Manager public void ValidateImages_EmptyItemEmptyProviders_NoChange() { var itemImageProvider = GetItemImageProvider(null, null); - var changed = itemImageProvider.ValidateImages(new MovieWithScreenshots(), new List(), null); + var changed = itemImageProvider.ValidateImages(new MovieWithScreenshots(), Enumerable.Empty(), null); Assert.False(changed); } @@ -73,7 +73,7 @@ namespace Jellyfin.Providers.Tests.Manager var imageProvider = GetImageProvider(imageType, imageCount, true); var itemImageProvider = GetItemImageProvider(null, null); - var changed = itemImageProvider.ValidateImages(item, new List { imageProvider }, null); + var changed = itemImageProvider.ValidateImages(item, new[] { imageProvider }, null); Assert.True(changed); Assert.Equal(imageCount, item.GetImages(imageType).Count()); @@ -86,7 +86,7 @@ namespace Jellyfin.Providers.Tests.Manager var item = GetItemWithImages(imageType, imageCount, true); var itemImageProvider = GetItemImageProvider(null, null); - var changed = itemImageProvider.ValidateImages(item, new List(), null); + var changed = itemImageProvider.ValidateImages(item, Enumerable.Empty(), null); Assert.False(changed); Assert.Equal(imageCount, item.GetImages(imageType).Count()); @@ -99,7 +99,7 @@ namespace Jellyfin.Providers.Tests.Manager var item = GetItemWithImages(imageType, imageCount, false); var itemImageProvider = GetItemImageProvider(null, null); - var changed = itemImageProvider.ValidateImages(item, new List(), null); + var changed = itemImageProvider.ValidateImages(item, Enumerable.Empty(), null); Assert.True(changed); Assert.Empty(item.GetImages(imageType)); @@ -109,7 +109,7 @@ namespace Jellyfin.Providers.Tests.Manager public void MergeImages_EmptyItemNewImagesEmpty_NoChange() { var itemImageProvider = GetItemImageProvider(null, null); - var changed = itemImageProvider.MergeImages(new MovieWithScreenshots(), new List()); + var changed = itemImageProvider.MergeImages(new MovieWithScreenshots(), Array.Empty()); Assert.False(changed); } @@ -237,7 +237,8 @@ namespace Jellyfin.Providers.Tests.Manager var refreshOptions = forceRefresh ? new ImageRefreshOptions(null) { - ImageRefreshMode = MetadataRefreshMode.FullRefresh, ReplaceAllImages = true + ImageRefreshMode = MetadataRefreshMode.FullRefresh, + ReplaceAllImages = true } : new ImageRefreshOptions(null); @@ -330,19 +331,20 @@ namespace Jellyfin.Providers.Tests.Manager var refreshOptions = forceRefresh ? new ImageRefreshOptions(null) { - ImageRefreshMode = MetadataRefreshMode.FullRefresh, ReplaceAllImages = true + ImageRefreshMode = MetadataRefreshMode.FullRefresh, + ReplaceAllImages = true } : new ImageRefreshOptions(null); - var remoteInfo = new List(); + var remoteInfo = new RemoteImageInfo[imageCount]; for (int i = 0; i < imageCount; i++) { - remoteInfo.Add(new RemoteImageInfo + remoteInfo[i] = new RemoteImageInfo { Type = imageType, Url = "image url " + i, Width = 1 // min width is set to 0, this will always pass - }); + }; } var providerManager = new Mock(MockBehavior.Strict); @@ -383,7 +385,7 @@ namespace Jellyfin.Providers.Tests.Manager // seek 2 so it won't short-circuit out of downloading when populated var libraryOptions = GetLibraryOptions(item, imageType, 2); - var content = "Content"; + const string Content = "Content"; var remoteProvider = new Mock(MockBehavior.Strict); remoteProvider.Setup(rp => rp.Name).Returns("MockRemoteProvider"); remoteProvider.Setup(rp => rp.GetSupportedImages(item)) @@ -393,7 +395,7 @@ namespace Jellyfin.Providers.Tests.Manager { ReasonPhrase = url, StatusCode = HttpStatusCode.OK, - Content = new StringContent(content, Encoding.UTF8, "image/jpeg") + Content = new StringContent(Content, Encoding.UTF8, "image/jpeg") }); var refreshOptions = fullRefresh @@ -404,15 +406,15 @@ namespace Jellyfin.Providers.Tests.Manager } : new ImageRefreshOptions(null); - var remoteInfo = new List(); + var remoteInfo = new RemoteImageInfo[targetImageCount]; for (int i = 0; i < targetImageCount; i++) { - remoteInfo.Add(new RemoteImageInfo + remoteInfo[i] = new RemoteImageInfo() { Type = imageType, Url = "image url " + i, Width = 1 // min width is set to 0, this will always pass - }); + }; } var providerManager = new Mock(MockBehavior.Strict); @@ -425,7 +427,7 @@ namespace Jellyfin.Providers.Tests.Manager var fileSystem = new Mock(); // match reported file size to image content length - condition for skipping already downloaded multi-images fileSystem.Setup(fs => fs.GetFileInfo(It.IsAny())) - .Returns(new FileSystemMetadata { Length = content.Length }); + .Returns(new FileSystemMetadata { Length = Content.Length }); var itemImageProvider = GetItemImageProvider(providerManager.Object, fileSystem); var result = await itemImageProvider.RefreshImages(item, libraryOptions, new List { remoteProvider.Object }, refreshOptions, CancellationToken.None); @@ -449,15 +451,16 @@ namespace Jellyfin.Providers.Tests.Manager var refreshOptions = new ImageRefreshOptions(null); // populate remote with double the required images to verify count is trimmed to the library option count - var remoteInfo = new List(); - for (int i = 0; i < imageCount * 2; i++) + var remoteInfoCount = imageCount * 2; + var remoteInfo = new RemoteImageInfo[remoteInfoCount]; + for (int i = 0; i < remoteInfoCount; i++) { - remoteInfo.Add(new RemoteImageInfo + remoteInfo[i] = new RemoteImageInfo() { Type = imageType, Url = "image url " + i, Width = 1 // min width is set to 0, this will always pass - }); + }; } var providerManager = new Mock(MockBehavior.Strict); @@ -552,20 +555,20 @@ namespace Jellyfin.Providers.Tests.Manager /// /// Creates a list of references of the specified type and size, optionally pointing to files that exist. /// - private static List GetImages(ImageType type, int count, bool validPaths) + private static LocalImageInfo[] GetImages(ImageType type, int count, bool validPaths) { var path = validPaths ? TestDataImagePath : "invalid path {0}"; - var images = new List(count); + var images = new LocalImageInfo[count]; for (int i = 0; i < count; i++) { - images.Add(new LocalImageInfo + images[i] = new LocalImageInfo { Type = type, FileInfo = new FileSystemMetadata { FullName = string.Format(CultureInfo.InvariantCulture, path, i) } - }); + }; } return images; From 4fc0521d69fc0a1ec6b01588044e1ba5f6022e41 Mon Sep 17 00:00:00 2001 From: Joe Rogers <1337joe@gmail.com> Date: Wed, 3 Nov 2021 17:16:40 +0100 Subject: [PATCH 04/15] Move ConvertToRemoteImage to TmdbClientManager --- .../Tmdb/BoxSets/TmdbBoxSetImageProvider.cs | 5 +- .../Tmdb/Movies/TmdbMovieImageProvider.cs | 4 +- .../Tmdb/People/TmdbPersonImageProvider.cs | 2 +- .../Tmdb/TV/TmdbEpisodeImageProvider.cs | 2 +- .../Tmdb/TV/TmdbSeasonImageProvider.cs | 2 +- .../Tmdb/TV/TmdbSeriesImageProvider.cs | 4 +- .../Plugins/Tmdb/TmdbClientManager.cs | 83 +++++++++++++++---- .../Plugins/Tmdb/TmdbUtils.cs | 78 ----------------- 8 files changed, 78 insertions(+), 102 deletions(-) diff --git a/MediaBrowser.Providers/Plugins/Tmdb/BoxSets/TmdbBoxSetImageProvider.cs b/MediaBrowser.Providers/Plugins/Tmdb/BoxSets/TmdbBoxSetImageProvider.cs index 17f3e635ff..29a557c315 100644 --- a/MediaBrowser.Providers/Plugins/Tmdb/BoxSets/TmdbBoxSetImageProvider.cs +++ b/MediaBrowser.Providers/Plugins/Tmdb/BoxSets/TmdbBoxSetImageProvider.cs @@ -13,7 +13,6 @@ using MediaBrowser.Common.Net; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Movies; using MediaBrowser.Controller.Providers; -using MediaBrowser.Model.Dto; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Providers; @@ -71,8 +70,8 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.BoxSets var backdrops = collection.Images.Backdrops; var remoteImages = new List(posters.Count + backdrops.Count); - TmdbUtils.ConvertPostersToRemoteImageInfo(posters, _tmdbClientManager, language, remoteImages); - TmdbUtils.ConvertBackdropsToRemoteImageInfo(backdrops, _tmdbClientManager, language, remoteImages); + _tmdbClientManager.ConvertPostersToRemoteImageInfo(posters, language, remoteImages); + _tmdbClientManager.ConvertBackdropsToRemoteImageInfo(backdrops, language, remoteImages); return remoteImages; } diff --git a/MediaBrowser.Providers/Plugins/Tmdb/Movies/TmdbMovieImageProvider.cs b/MediaBrowser.Providers/Plugins/Tmdb/Movies/TmdbMovieImageProvider.cs index 4336efee45..f71f7bd10d 100644 --- a/MediaBrowser.Providers/Plugins/Tmdb/Movies/TmdbMovieImageProvider.cs +++ b/MediaBrowser.Providers/Plugins/Tmdb/Movies/TmdbMovieImageProvider.cs @@ -87,8 +87,8 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.Movies var backdrops = movie.Images.Backdrops; var remoteImages = new List(posters.Count + backdrops.Count); - TmdbUtils.ConvertPostersToRemoteImageInfo(posters, _tmdbClientManager, language, remoteImages); - TmdbUtils.ConvertBackdropsToRemoteImageInfo(backdrops, _tmdbClientManager, language, remoteImages); + _tmdbClientManager.ConvertPostersToRemoteImageInfo(posters, language, remoteImages); + _tmdbClientManager.ConvertBackdropsToRemoteImageInfo(backdrops, language, remoteImages); return remoteImages; } diff --git a/MediaBrowser.Providers/Plugins/Tmdb/People/TmdbPersonImageProvider.cs b/MediaBrowser.Providers/Plugins/Tmdb/People/TmdbPersonImageProvider.cs index cad62eca3c..7ce4cfe676 100644 --- a/MediaBrowser.Providers/Plugins/Tmdb/People/TmdbPersonImageProvider.cs +++ b/MediaBrowser.Providers/Plugins/Tmdb/People/TmdbPersonImageProvider.cs @@ -63,7 +63,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.People var profiles = personResult.Images.Profiles; var remoteImages = new List(profiles.Count); - TmdbUtils.ConvertProfilesToRemoteImageInfo(profiles, _tmdbClientManager, language, remoteImages); + _tmdbClientManager.ConvertProfilesToRemoteImageInfo(profiles, language, remoteImages); return remoteImages; } diff --git a/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbEpisodeImageProvider.cs b/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbEpisodeImageProvider.cs index b7dda9b502..5eec776b5b 100644 --- a/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbEpisodeImageProvider.cs +++ b/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbEpisodeImageProvider.cs @@ -76,7 +76,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV var remoteImages = new List(stills.Count); - TmdbUtils.ConvertStillsToRemoteImageInfo(stills, _tmdbClientManager, language, remoteImages); + _tmdbClientManager.ConvertStillsToRemoteImageInfo(stills, language, remoteImages); return remoteImages; } diff --git a/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbSeasonImageProvider.cs b/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbSeasonImageProvider.cs index 90b324a4fe..4446fa9665 100644 --- a/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbSeasonImageProvider.cs +++ b/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbSeasonImageProvider.cs @@ -63,7 +63,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV var remoteImages = new List(posters.Count); - TmdbUtils.ConvertPostersToRemoteImageInfo(posters, _tmdbClientManager, language, remoteImages); + _tmdbClientManager.ConvertPostersToRemoteImageInfo(posters, language, remoteImages); return remoteImages; } diff --git a/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbSeriesImageProvider.cs b/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbSeriesImageProvider.cs index 9f2821c404..5ef3736c4f 100644 --- a/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbSeriesImageProvider.cs +++ b/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbSeriesImageProvider.cs @@ -71,8 +71,8 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV var backdrops = series.Images.Backdrops; var remoteImages = new List(posters.Count + backdrops.Count); - TmdbUtils.ConvertPostersToRemoteImageInfo(posters, _tmdbClientManager, language, remoteImages); - TmdbUtils.ConvertBackdropsToRemoteImageInfo(backdrops, _tmdbClientManager, language, remoteImages); + _tmdbClientManager.ConvertPostersToRemoteImageInfo(posters, language, remoteImages); + _tmdbClientManager.ConvertBackdropsToRemoteImageInfo(backdrops, language, remoteImages); return remoteImages; } diff --git a/MediaBrowser.Providers/Plugins/Tmdb/TmdbClientManager.cs b/MediaBrowser.Providers/Plugins/Tmdb/TmdbClientManager.cs index 3c7e332699..9292530266 100644 --- a/MediaBrowser.Providers/Plugins/Tmdb/TmdbClientManager.cs +++ b/MediaBrowser.Providers/Plugins/Tmdb/TmdbClientManager.cs @@ -5,6 +5,9 @@ using System.Collections.Generic; using System.Globalization; using System.Threading; using System.Threading.Tasks; +using MediaBrowser.Model.Dto; +using MediaBrowser.Model.Entities; +using MediaBrowser.Model.Providers; using Microsoft.Extensions.Caching.Memory; using TMDbLib.Client; using TMDbLib.Objects.Collections; @@ -497,33 +500,85 @@ namespace MediaBrowser.Providers.Plugins.Tmdb } /// - /// Gets the absolute URL of the backdrop image. + /// Gets the absolute URL of the profile image. /// - /// The relative URL of the backdrop image. + /// The relative URL of the profile image. /// The absolute URL. - public string GetBackdropUrl(string backdropPath) + public string GetProfileUrl(string actorProfilePath) { - return GetUrl(_tmDbClient.Config.Images.BackdropSizes[^1], backdropPath); + return GetUrl(_tmDbClient.Config.Images.ProfileSizes[^1], actorProfilePath); } /// - /// Gets the absolute URL of the profile image. + /// Converts poster s into s. /// - /// The relative URL of the profile image. - /// The absolute URL. - public string GetProfileUrl(string actorProfilePath) + /// The input images. + /// The requested language. + /// The collection to add the remote images into. + public void ConvertPostersToRemoteImageInfo(List images, string requestLanguage, List results) { - return GetUrl(_tmDbClient.Config.Images.ProfileSizes[^1], actorProfilePath); + ConvertToRemoteImageInfo(images, _tmDbClient.Config.Images.PosterSizes[^1], ImageType.Primary, requestLanguage, results); } /// - /// Gets the absolute URL of the still image. + /// Converts backdrop s into s. /// - /// The relative URL of the still image. - /// The absolute URL. - public string GetStillUrl(string filePath) + /// The input images. + /// The requested language. + /// The collection to add the remote images into. + public void ConvertBackdropsToRemoteImageInfo(List images, string requestLanguage, List results) + { + ConvertToRemoteImageInfo(images, _tmDbClient.Config.Images.BackdropSizes[^1], ImageType.Backdrop, requestLanguage, results); + } + + /// + /// Converts profile s into s. + /// + /// The input images. + /// The requested language. + /// The collection to add the remote images into. + public void ConvertProfilesToRemoteImageInfo(List images, string requestLanguage, List results) + { + ConvertToRemoteImageInfo(images, _tmDbClient.Config.Images.ProfileSizes[^1], ImageType.Primary, requestLanguage, results); + } + + /// + /// Converts still s into s. + /// + /// The input images. + /// The requested language. + /// The collection to add the remote images into. + public void ConvertStillsToRemoteImageInfo(List images, string requestLanguage, List results) + { + ConvertToRemoteImageInfo(images, _tmDbClient.Config.Images.StillSizes[^1], ImageType.Primary, requestLanguage, results); + } + + /// + /// Converts s into s. + /// + /// The input images. + /// The size of the image to fetch. + /// The type of the image. + /// The requested language. + /// The collection to add the remote images into. + private void ConvertToRemoteImageInfo(List images, string size, ImageType type, string requestLanguage, List results) { - return GetUrl(_tmDbClient.Config.Images.StillSizes[^1], filePath); + for (var i = 0; i < images.Count; i++) + { + var image = images[i]; + results.Add(new RemoteImageInfo + { + Url = GetUrl(size, image.FilePath), + CommunityRating = image.VoteAverage, + VoteCount = image.VoteCount, + Width = image.Width, + Height = image.Height, + Language = TmdbUtils.AdjustImageLanguage(image.Iso_639_1, requestLanguage), + ProviderName = TmdbUtils.ProviderName, + Type = type, + RatingType = RatingType.Score + }); + } } private Task EnsureClientConfigAsync() diff --git a/MediaBrowser.Providers/Plugins/Tmdb/TmdbUtils.cs b/MediaBrowser.Providers/Plugins/Tmdb/TmdbUtils.cs index 3cdab601ac..58ab9f5473 100644 --- a/MediaBrowser.Providers/Plugins/Tmdb/TmdbUtils.cs +++ b/MediaBrowser.Providers/Plugins/Tmdb/TmdbUtils.cs @@ -1,9 +1,7 @@ using System; using System.Collections.Generic; using System.Text.RegularExpressions; -using MediaBrowser.Model.Dto; using MediaBrowser.Model.Entities; -using MediaBrowser.Model.Providers; using TMDbLib.Objects.General; namespace MediaBrowser.Providers.Plugins.Tmdb @@ -194,81 +192,5 @@ namespace MediaBrowser.Providers.Plugins.Tmdb return newRating.Replace("DE-", "FSK-", StringComparison.OrdinalIgnoreCase); } - - /// - /// Converts poster s into s. - /// - /// The input images. - /// The client manager to use for resolving image urls. - /// The requested language. - /// The collection to add the remote images into. - public static void ConvertPostersToRemoteImageInfo(List images, TmdbClientManager tmdbClientManager, string requestLanguage, List results) - { - ConvertToRemoteImageInfo(images, tmdbClientManager.GetPosterUrl, ImageType.Primary, requestLanguage, results); - } - - /// - /// Converts backdrop s into s. - /// - /// The input images. - /// The client manager to use for resolving image urls. - /// The requested language. - /// The collection to add the remote images into. - public static void ConvertBackdropsToRemoteImageInfo(List images, TmdbClientManager tmdbClientManager, string requestLanguage, List results) - { - ConvertToRemoteImageInfo(images, tmdbClientManager.GetBackdropUrl, ImageType.Backdrop, requestLanguage, results); - } - - /// - /// Converts profile s into s. - /// - /// The input images. - /// The client manager to use for resolving image urls. - /// The requested language. - /// The collection to add the remote images into. - public static void ConvertProfilesToRemoteImageInfo(List images, TmdbClientManager tmdbClientManager, string requestLanguage, List results) - { - ConvertToRemoteImageInfo(images, tmdbClientManager.GetProfileUrl, ImageType.Primary, requestLanguage, results); - } - - /// - /// Converts still s into s. - /// - /// The input images. - /// The client manager to use for resolving image urls. - /// The requested language. - /// The collection to add the remote images into. - public static void ConvertStillsToRemoteImageInfo(List images, TmdbClientManager tmdbClientManager, string requestLanguage, List results) - { - ConvertToRemoteImageInfo(images, tmdbClientManager.GetStillUrl, ImageType.Primary, requestLanguage, results); - } - - /// - /// Converts s into s. - /// - /// The input images. - /// The relevant GetTypeUrl function to get the absolute url of the image. - /// The type of the image. - /// The requested language. - /// The collection to add the remote images into. - private static void ConvertToRemoteImageInfo(List images, Func imageUrlConverter, ImageType type, string requestLanguage, List results) - { - for (var i = 0; i < images.Count; i++) - { - var image = images[i]; - results.Add(new RemoteImageInfo - { - Url = imageUrlConverter(image.FilePath), - CommunityRating = image.VoteAverage, - VoteCount = image.VoteCount, - Width = image.Width, - Height = image.Height, - Language = AdjustImageLanguage(image.Iso_639_1, requestLanguage), - ProviderName = ProviderName, - Type = type, - RatingType = RatingType.Score - }); - } - } } } From 924c6682b9e222c138796dcdc6fd7170ef8c268d Mon Sep 17 00:00:00 2001 From: Bond_009 Date: Thu, 4 Nov 2021 01:06:21 +0100 Subject: [PATCH 05/15] Remove unused IHasScreenshots interface --- .../Entities/IHasScreenshots.cs | 9 ------- .../Images/LocalImageProvider.cs | 10 -------- .../Manager/ItemImageProvider.cs | 11 --------- .../Manager/ItemImageProviderTests.cs | 24 ++++++------------- 4 files changed, 7 insertions(+), 47 deletions(-) delete mode 100644 MediaBrowser.Controller/Entities/IHasScreenshots.cs diff --git a/MediaBrowser.Controller/Entities/IHasScreenshots.cs b/MediaBrowser.Controller/Entities/IHasScreenshots.cs deleted file mode 100644 index ae01c223ed..0000000000 --- a/MediaBrowser.Controller/Entities/IHasScreenshots.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace MediaBrowser.Controller.Entities -{ - /// - /// The item has screenshots. - /// - public interface IHasScreenshots - { - } -} diff --git a/MediaBrowser.LocalMetadata/Images/LocalImageProvider.cs b/MediaBrowser.LocalMetadata/Images/LocalImageProvider.cs index 988581df92..f791478038 100644 --- a/MediaBrowser.LocalMetadata/Images/LocalImageProvider.cs +++ b/MediaBrowser.LocalMetadata/Images/LocalImageProvider.cs @@ -256,11 +256,6 @@ namespace MediaBrowser.LocalMetadata.Images { PopulateBackdrops(item, images, files, imagePrefix, isInMixedFolder); } - - if (item is IHasScreenshots) - { - PopulateScreenshots(images, files, imagePrefix, isInMixedFolder); - } } private void PopulatePrimaryImages(BaseItem item, List images, List files, string imagePrefix, bool isInMixedFolder) @@ -363,11 +358,6 @@ namespace MediaBrowser.LocalMetadata.Images })); } - private void PopulateScreenshots(List images, List files, string imagePrefix, bool isInMixedFolder) - { - PopulateBackdrops(images, files, imagePrefix, "screenshot", "screenshot", isInMixedFolder, ImageType.Screenshot); - } - private void PopulateBackdrops(List images, List files, string imagePrefix, string firstFileName, string subsequentFileNamePrefix, bool isInMixedFolder, ImageType type) { AddImage(files, images, imagePrefix + firstFileName, type); diff --git a/MediaBrowser.Providers/Manager/ItemImageProvider.cs b/MediaBrowser.Providers/Manager/ItemImageProvider.cs index 8d5795f8e1..d5959db772 100644 --- a/MediaBrowser.Providers/Manager/ItemImageProvider.cs +++ b/MediaBrowser.Providers/Manager/ItemImageProvider.cs @@ -343,12 +343,6 @@ namespace MediaBrowser.Providers.Manager minWidth = savedOptions.GetMinWidth(ImageType.Backdrop); await DownloadMultiImages(item, ImageType.Backdrop, refreshOptions, backdropLimit, provider, result, list, minWidth, cancellationToken).ConfigureAwait(false); - - if (item is IHasScreenshots) - { - minWidth = savedOptions.GetMinWidth(ImageType.Screenshot); - await DownloadMultiImages(item, ImageType.Screenshot, refreshOptions, screenshotLimit, provider, result, list, minWidth, cancellationToken).ConfigureAwait(false); - } } catch (OperationCanceledException) { @@ -438,11 +432,6 @@ namespace MediaBrowser.Providers.Manager changed = true; } - if (item is IHasScreenshots && UpdateMultiImages(item, images, ImageType.Screenshot)) - { - changed = true; - } - return changed; } diff --git a/tests/Jellyfin.Providers.Tests/Manager/ItemImageProviderTests.cs b/tests/Jellyfin.Providers.Tests/Manager/ItemImageProviderTests.cs index f9ac8f46b9..6011c8dd52 100644 --- a/tests/Jellyfin.Providers.Tests/Manager/ItemImageProviderTests.cs +++ b/tests/Jellyfin.Providers.Tests/Manager/ItemImageProviderTests.cs @@ -10,7 +10,6 @@ using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; using MediaBrowser.Controller.Entities; -using MediaBrowser.Controller.Entities.Movies; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Providers; using MediaBrowser.Model.Configuration; @@ -43,7 +42,7 @@ namespace Jellyfin.Providers.Tests.Manager public void ValidateImages_EmptyItemEmptyProviders_NoChange() { var itemImageProvider = GetItemImageProvider(null, null); - var changed = itemImageProvider.ValidateImages(new MovieWithScreenshots(), Enumerable.Empty(), null); + var changed = itemImageProvider.ValidateImages(new Video(), Enumerable.Empty(), null); Assert.False(changed); } @@ -55,8 +54,7 @@ namespace Jellyfin.Providers.Tests.Manager // minimal test cases that hit different handling { ImageType.Primary, 1 }, { ImageType.Backdrop, 1 }, - { ImageType.Backdrop, 2 }, - { ImageType.Screenshot, 1 } + { ImageType.Backdrop, 2 } }; return theoryTypes; @@ -69,7 +67,7 @@ namespace Jellyfin.Providers.Tests.Manager // Has to exist for querying DateModified time on file, results stored but not checked so not populating BaseItem.FileSystem = Mock.Of(); - var item = new MovieWithScreenshots(); + var item = new Video(); var imageProvider = GetImageProvider(imageType, imageCount, true); var itemImageProvider = GetItemImageProvider(null, null); @@ -109,7 +107,7 @@ namespace Jellyfin.Providers.Tests.Manager public void MergeImages_EmptyItemNewImagesEmpty_NoChange() { var itemImageProvider = GetItemImageProvider(null, null); - var changed = itemImageProvider.MergeImages(new MovieWithScreenshots(), Array.Empty()); + var changed = itemImageProvider.MergeImages(new Video(), Array.Empty()); Assert.False(changed); } @@ -270,7 +268,7 @@ namespace Jellyfin.Providers.Tests.Manager // Has to exist for querying DateModified time on file, results stored but not checked so not populating BaseItem.FileSystem = Mock.Of(); - var item = new MovieWithScreenshots(); + var item = new Video(); var libraryOptions = GetLibraryOptions(item, imageType, imageCount); @@ -312,11 +310,9 @@ namespace Jellyfin.Providers.Tests.Manager [InlineData(ImageType.Primary, 1, false)] [InlineData(ImageType.Backdrop, 1, false)] [InlineData(ImageType.Backdrop, 2, false)] - [InlineData(ImageType.Screenshot, 2, false)] [InlineData(ImageType.Primary, 1, true)] [InlineData(ImageType.Backdrop, 1, true)] [InlineData(ImageType.Backdrop, 2, true)] - [InlineData(ImageType.Screenshot, 2, true)] public async void RefreshImages_PopulatedItemPopulatedProviderRemote_UpdatesImagesIfForced(ImageType imageType, int imageCount, bool forceRefresh) { var item = GetItemWithImages(imageType, imageCount, false); @@ -439,7 +435,7 @@ namespace Jellyfin.Providers.Tests.Manager [MemberData(nameof(GetImageTypesWithCount))] public async void RefreshImages_EmptyItemPopulatedProviderRemoteExtras_LimitsImages(ImageType imageType, int imageCount) { - var item = new MovieWithScreenshots(); + var item = new Video(); var libraryOptions = GetLibraryOptions(item, imageType, imageCount); @@ -528,7 +524,7 @@ namespace Jellyfin.Providers.Tests.Manager // Has to exist for querying DateModified time on file, results stored but not checked so not populating BaseItem.FileSystem ??= Mock.Of(); - var item = new MovieWithScreenshots(); + var item = new Video(); var path = validPaths ? TestDataImagePath : "invalid path {0}"; for (int i = 0; i < count; i++) @@ -599,11 +595,5 @@ namespace Jellyfin.Providers.Tests.Manager } }; } - - // Create a class that implements IHasScreenshots for testing since no BaseItem class is also IHasScreenshots - private class MovieWithScreenshots : Movie, IHasScreenshots - { - // No contents - } } } From 70b9f9bf560e4f9ff47ecb00c22561e3065a20de Mon Sep 17 00:00:00 2001 From: nextlooper42 Date: Tue, 2 Nov 2021 22:26:20 +0000 Subject: [PATCH 06/15] Translated using Weblate (Slovak) Translation: Jellyfin/Jellyfin Translate-URL: https://translate.jellyfin.org/projects/jellyfin/jellyfin-core/sk/ --- Emby.Server.Implementations/Localization/Core/sk.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Emby.Server.Implementations/Localization/Core/sk.json b/Emby.Server.Implementations/Localization/Core/sk.json index ad90bd8134..37da7d5ab3 100644 --- a/Emby.Server.Implementations/Localization/Core/sk.json +++ b/Emby.Server.Implementations/Localization/Core/sk.json @@ -39,7 +39,7 @@ "MixedContent": "Zmiešaný obsah", "Movies": "Filmy", "Music": "Hudba", - "MusicVideos": "Hudobné videá", + "MusicVideos": "Hudobné videoklipy", "NameInstallFailed": "Inštalácia {0} zlyhala", "NameSeasonNumber": "Séria {0}", "NameSeasonUnknown": "Neznáma séria", From 654bd6fff141fb53661e2a99fc6a48478c92e8dd Mon Sep 17 00:00:00 2001 From: WWWesten Date: Thu, 4 Nov 2021 08:18:21 +0000 Subject: [PATCH 07/15] Translated using Weblate (Turkish) Translation: Jellyfin/Jellyfin Translate-URL: https://translate.jellyfin.org/projects/jellyfin/jellyfin-core/tr/ --- Emby.Server.Implementations/Localization/Core/tr.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Emby.Server.Implementations/Localization/Core/tr.json b/Emby.Server.Implementations/Localization/Core/tr.json index e661299c41..8fadb88ac8 100644 --- a/Emby.Server.Implementations/Localization/Core/tr.json +++ b/Emby.Server.Implementations/Localization/Core/tr.json @@ -8,7 +8,7 @@ "CameraImageUploadedFrom": "{0} 'den yeni bir kamera resmi yüklendi", "Channels": "Kanallar", "ChapterNameValue": "Bölüm {0}", - "Collections": "Koleksiyon", + "Collections": "Koleksiyonlar", "DeviceOfflineWithName": "{0} bağlantısı kesildi", "DeviceOnlineWithName": "{0} bağlı", "FailedLoginAttemptWithUserName": "{0} adresinden giriş başarısız oldu", From 5aadf8c291df8a9f9a3bb6d4407979fc456ab6d4 Mon Sep 17 00:00:00 2001 From: WWWesten Date: Wed, 3 Nov 2021 06:33:55 +0000 Subject: [PATCH 08/15] Translated using Weblate (Esperanto) Translation: Jellyfin/Jellyfin Translate-URL: https://translate.jellyfin.org/projects/jellyfin/jellyfin-core/eo/ --- .../Localization/Core/eo.json | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Emby.Server.Implementations/Localization/Core/eo.json b/Emby.Server.Implementations/Localization/Core/eo.json index f92b5f6730..8ac466908c 100644 --- a/Emby.Server.Implementations/Localization/Core/eo.json +++ b/Emby.Server.Implementations/Localization/Core/eo.json @@ -1,5 +1,5 @@ { - "NotificationOptionInstallationFailed": "Instalada fiasko", + "NotificationOptionInstallationFailed": "Instalada malsukceso", "NotificationOptionAudioPlaybackStopped": "Ludado de sono haltis", "NotificationOptionAudioPlayback": "Ludado de sono lanĉis", "NameSeasonUnknown": "Sezono Nekonata", @@ -48,17 +48,17 @@ "Shows": "Serioj", "HeaderFavoriteShows": "Favorataj Serioj", "TvShows": "TV-serioj", - "Favorites": "Favoratoj", + "Favorites": "Favorataj", "TaskCleanLogs": "Purigi Ĵurnalan Katalogon", - "TaskRefreshLibrary": "Skanu Plurmeditekon", + "TaskRefreshLibrary": "Skani Plurmeditekon", "ValueSpecialEpisodeName": "Speciala - {0}", - "TaskOptimizeDatabase": "Optimigi datumbazon", + "TaskOptimizeDatabase": "Optimigi datenbazon", "TaskRefreshChannels": "Refreŝigi Kanalojn", "TaskUpdatePlugins": "Ĝisdatigi Kromprogramojn", "TaskRefreshPeople": "Refreŝigi Homojn", "TasksChannelsCategory": "Interretaj Kanaloj", "ProviderValue": "Provizanto: {0}", - "NotificationOptionPluginError": "Kromprograma malsukceso", + "NotificationOptionPluginError": "Kromprogramo malsukcesis", "MixedContent": "Miksita enhavo", "TasksApplicationCategory": "Aplikaĵo", "TasksMaintenanceCategory": "Prizorgado", @@ -102,9 +102,9 @@ "MessageApplicationUpdatedTo": "Jellyfin Server estis ĝisdatigita al {0}", "MessageApplicationUpdated": "Jellyfin Server estis ĝisdatigita", "TaskRefreshChannelsDescription": "Refreŝigas informon pri interretaj kanaloj.", - "TaskDownloadMissingSubtitles": "Elŝutu mankantajn subtekstojn", + "TaskDownloadMissingSubtitles": "Elŝuti mankantajn subtekstojn", "TaskCleanTranscode": "Malplenigi Transkodadan Katalogon", - "TaskRefreshChapterImages": "Eltiru Ĉapitro-Bildojn", + "TaskRefreshChapterImages": "Eltiri Ĉapitraj Bildojn", "TaskCleanCache": "Malplenigi Staplan Katalogon", "TaskCleanActivityLog": "Malplenigi Aktivecan Ĵurnalon", "PluginUpdatedWithName": "{0} estis ĝisdatigita", From c0bab5c173fbc13fc4faccbf3d231d5317b284ee Mon Sep 17 00:00:00 2001 From: cvium Date: Thu, 4 Nov 2021 11:50:46 +0100 Subject: [PATCH 09/15] Make sure ReadToDescendant was successful, #6773 --- MediaBrowser.XbmcMetadata/Parsers/BaseNfoParser.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/MediaBrowser.XbmcMetadata/Parsers/BaseNfoParser.cs b/MediaBrowser.XbmcMetadata/Parsers/BaseNfoParser.cs index 9d558b6ce7..5ce22da6a8 100644 --- a/MediaBrowser.XbmcMetadata/Parsers/BaseNfoParser.cs +++ b/MediaBrowser.XbmcMetadata/Parsers/BaseNfoParser.cs @@ -785,7 +785,11 @@ namespace MediaBrowser.XbmcMetadata.Parsers case "fanart": { var subtree = reader.ReadSubtree(); - subtree.ReadToDescendant("thumb"); + if (!subtree.ReadToDescendant("thumb")) + { + break; + } + FetchThumbNode(subtree, itemResult); break; } From f91839dd8ce9c5723b3cab42a5c5a4410f7bf7e8 Mon Sep 17 00:00:00 2001 From: Thibault Nocchi <1619359+ThibaultNocchi@users.noreply.github.com> Date: Thu, 4 Nov 2021 15:44:15 +0100 Subject: [PATCH 10/15] Fix WebVTT region to spec --- MediaBrowser.MediaEncoding/Subtitles/VttWriter.cs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/MediaBrowser.MediaEncoding/Subtitles/VttWriter.cs b/MediaBrowser.MediaEncoding/Subtitles/VttWriter.cs index 6d56dda91f..38ef57dee3 100644 --- a/MediaBrowser.MediaEncoding/Subtitles/VttWriter.cs +++ b/MediaBrowser.MediaEncoding/Subtitles/VttWriter.cs @@ -19,12 +19,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles { writer.WriteLine("WEBVTT"); writer.WriteLine(); - writer.WriteLine("REGION"); - writer.WriteLine("id:subtitle"); - writer.WriteLine("width:80%"); - writer.WriteLine("lines:3"); - writer.WriteLine("regionanchor:50%,100%"); - writer.WriteLine("viewportanchor:50%,90%"); + writer.WriteLine("Region: id:subtitle width:80% lines:3 regionanchor:50%,100% viewportanchor:50%,90%"); writer.WriteLine(); foreach (var trackEvent in info.TrackEvents) { @@ -39,7 +34,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles endTime = startTime.Add(TimeSpan.FromMilliseconds(1)); } - writer.WriteLine(@"{0:hh\:mm\:ss\.fff} --> {1:hh\:mm\:ss\.fff} region:subtitle", startTime, endTime); + writer.WriteLine(@"{0:hh\:mm\:ss\.fff} --> {1:hh\:mm\:ss\.fff} region:subtitle line:90%", startTime, endTime); var text = trackEvent.Text; From 6c76d3053890dfaf539994d01dca415daebe70f6 Mon Sep 17 00:00:00 2001 From: Joe Rogers <1337joe@gmail.com> Date: Thu, 4 Nov 2021 23:58:32 +0100 Subject: [PATCH 11/15] Add missing checkboxes --- .../Plugins/Tmdb/Configuration/config.html | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/MediaBrowser.Providers/Plugins/Tmdb/Configuration/config.html b/MediaBrowser.Providers/Plugins/Tmdb/Configuration/config.html index bce647f2ad..95d6691d9c 100644 --- a/MediaBrowser.Providers/Plugins/Tmdb/Configuration/config.html +++ b/MediaBrowser.Providers/Plugins/Tmdb/Configuration/config.html @@ -12,6 +12,14 @@ Include adult content in search results. + +
From c8eba90c178821e11a4b9cdfc7f722bc8af8aac1 Mon Sep 17 00:00:00 2001 From: Joe Rogers <1337joe@gmail.com> Date: Fri, 5 Nov 2021 00:38:50 +0100 Subject: [PATCH 12/15] Add cast limit to tmdb plugin settings --- .../Tmdb/Configuration/PluginConfiguration.cs | 5 +++++ .../Plugins/Tmdb/Configuration/config.html | 13 +++++++++++++ .../Plugins/Tmdb/Movies/TmdbMovieProvider.cs | 3 +-- .../Plugins/Tmdb/TV/TmdbEpisodeProvider.cs | 4 ++-- .../Plugins/Tmdb/TV/TmdbSeasonProvider.cs | 2 +- .../Plugins/Tmdb/TV/TmdbSeriesProvider.cs | 2 +- MediaBrowser.Providers/Plugins/Tmdb/TmdbUtils.cs | 5 ----- 7 files changed, 23 insertions(+), 11 deletions(-) diff --git a/MediaBrowser.Providers/Plugins/Tmdb/Configuration/PluginConfiguration.cs b/MediaBrowser.Providers/Plugins/Tmdb/Configuration/PluginConfiguration.cs index 9ac95f23e9..9a78a75362 100644 --- a/MediaBrowser.Providers/Plugins/Tmdb/Configuration/PluginConfiguration.cs +++ b/MediaBrowser.Providers/Plugins/Tmdb/Configuration/PluginConfiguration.cs @@ -21,5 +21,10 @@ namespace MediaBrowser.Providers.Plugins.Tmdb /// Gets or sets a value indicating whether tags should be imported for movies from TMDb. ///
public bool ExcludeTagsMovies { get; set; } + + /// + /// Gets or sets a value indicating the maximum number of cast members to fetch for an item. + /// + public int MaxCastMembers { get; set; } = 15; } } diff --git a/MediaBrowser.Providers/Plugins/Tmdb/Configuration/config.html b/MediaBrowser.Providers/Plugins/Tmdb/Configuration/config.html index 95d6691d9c..12b4c7ca4e 100644 --- a/MediaBrowser.Providers/Plugins/Tmdb/Configuration/config.html +++ b/MediaBrowser.Providers/Plugins/Tmdb/Configuration/config.html @@ -20,6 +20,10 @@ Exclude tags/keywords from metadata fetched for movies. +
+ +
The maximum number of cast members to fetch for an item.
+

@@ -39,6 +43,14 @@ document.querySelector('#includeAdult').checked = config.IncludeAdult; document.querySelector('#excludeTagsSeries').checked = config.ExcludeTagsSeries; document.querySelector('#excludeTagsMovies').checked = config.ExcludeTagsMovies; + + var maxCastMembers = document.querySelector('#maxCastMembers'); + maxCastMembers.value = config.MaxCastMembers; + maxCastMembers.dispatchEvent(new Event('change', { + bubbles: true, + cancelable: false + })); + Dashboard.hideLoadingMsg(); }); }); @@ -52,6 +64,7 @@ config.IncludeAdult = document.querySelector('#includeAdult').checked; config.ExcludeTagsSeries = document.querySelector('#excludeTagsSeries').checked; config.ExcludeTagsMovies = document.querySelector('#excludeTagsMovies').checked; + config.MaxCastMembers = document.querySelector('#maxCastMembers').value; ApiClient.updatePluginConfiguration(PluginConfig.pluginId, config).then(Dashboard.processPluginConfigurationUpdateResult); }); diff --git a/MediaBrowser.Providers/Plugins/Tmdb/Movies/TmdbMovieProvider.cs b/MediaBrowser.Providers/Plugins/Tmdb/Movies/TmdbMovieProvider.cs index 9dd0678561..fcaacc90d1 100644 --- a/MediaBrowser.Providers/Plugins/Tmdb/Movies/TmdbMovieProvider.cs +++ b/MediaBrowser.Providers/Plugins/Tmdb/Movies/TmdbMovieProvider.cs @@ -241,8 +241,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.Movies if (movieResult.Credits?.Cast != null) { - // TODO configurable - foreach (var actor in movieResult.Credits.Cast.OrderBy(a => a.Order).Take(TmdbUtils.MaxCastMembers)) + foreach (var actor in movieResult.Credits.Cast.OrderBy(a => a.Order).Take(Plugin.Instance.Configuration.MaxCastMembers)) { var personInfo = new PersonInfo { diff --git a/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbEpisodeProvider.cs b/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbEpisodeProvider.cs index 3f826843a6..8ac9d0cab1 100644 --- a/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbEpisodeProvider.cs +++ b/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbEpisodeProvider.cs @@ -154,7 +154,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV if (credits?.Cast != null) { - foreach (var actor in credits.Cast.OrderBy(a => a.Order).Take(TmdbUtils.MaxCastMembers)) + foreach (var actor in credits.Cast.OrderBy(a => a.Order).Take(Plugin.Instance.Configuration.MaxCastMembers)) { metadataResult.AddPerson(new PersonInfo { @@ -168,7 +168,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV if (credits?.GuestStars != null) { - foreach (var guest in credits.GuestStars.OrderBy(a => a.Order).Take(TmdbUtils.MaxCastMembers)) + foreach (var guest in credits.GuestStars.OrderBy(a => a.Order).Take(Plugin.Instance.Configuration.MaxCastMembers)) { metadataResult.AddPerson(new PersonInfo { diff --git a/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbSeasonProvider.cs b/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbSeasonProvider.cs index 4ac8896801..7afaddc245 100644 --- a/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbSeasonProvider.cs +++ b/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbSeasonProvider.cs @@ -67,7 +67,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV var credits = seasonResult.Credits; if (credits?.Cast != null) { - var cast = credits.Cast.OrderBy(c => c.Order).Take(TmdbUtils.MaxCastMembers).ToList(); + var cast = credits.Cast.OrderBy(c => c.Order).Take(Plugin.Instance.Configuration.MaxCastMembers).ToList(); for (var i = 0; i < cast.Count; i++) { result.AddPerson(new PersonInfo diff --git a/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbSeriesProvider.cs b/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbSeriesProvider.cs index feda15cf75..77e22ffbf0 100644 --- a/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbSeriesProvider.cs +++ b/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbSeriesProvider.cs @@ -331,7 +331,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV { if (seriesResult.Credits?.Cast != null) { - foreach (var actor in seriesResult.Credits.Cast.OrderBy(a => a.Order).Take(TmdbUtils.MaxCastMembers)) + foreach (var actor in seriesResult.Credits.Cast.OrderBy(a => a.Order).Take(Plugin.Instance.Configuration.MaxCastMembers)) { var personInfo = new PersonInfo { diff --git a/MediaBrowser.Providers/Plugins/Tmdb/TmdbUtils.cs b/MediaBrowser.Providers/Plugins/Tmdb/TmdbUtils.cs index 58ab9f5473..a3a78103ea 100644 --- a/MediaBrowser.Providers/Plugins/Tmdb/TmdbUtils.cs +++ b/MediaBrowser.Providers/Plugins/Tmdb/TmdbUtils.cs @@ -28,11 +28,6 @@ namespace MediaBrowser.Providers.Plugins.Tmdb ///
public const string ApiKey = "4219e299c89411838049ab0dab19ebd5"; - /// - /// Maximum number of cast members to pull. - /// - public const int MaxCastMembers = 15; - /// /// The crew types to keep. /// From 13668a6ecb40b4b68f1cfaebfb7bb3807e9a9cef Mon Sep 17 00:00:00 2001 From: WWWesten Date: Thu, 4 Nov 2021 10:35:48 +0000 Subject: [PATCH 13/15] Translated using Weblate (Russian) Translation: Jellyfin/Jellyfin Translate-URL: https://translate.jellyfin.org/projects/jellyfin/jellyfin-core/ru/ --- Emby.Server.Implementations/Localization/Core/ru.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Emby.Server.Implementations/Localization/Core/ru.json b/Emby.Server.Implementations/Localization/Core/ru.json index cd016b51b4..36f4e3e7c9 100644 --- a/Emby.Server.Implementations/Localization/Core/ru.json +++ b/Emby.Server.Implementations/Localization/Core/ru.json @@ -119,6 +119,6 @@ "Undefined": "Не определено", "Forced": "Форсир-ые", "Default": "По умолчанию", - "TaskOptimizeDatabaseDescription": "Сжимает базу данных и обрезает свободное место. Выполнение этой задачи после сканирования библиотеки или внесения других изменений, предполагающих модификации базы данных, может повысить производительность.", + "TaskOptimizeDatabaseDescription": "Сжимает базу данных и вырезает свободные места. Выполнение этой задачи после сканирования библиотеки или внесения других изменений, предполагающих модификации базы данных, может повысить производительность.", "TaskOptimizeDatabase": "Оптимизировать базу данных" } From 1e93c6ae3052653efbadba29657f83c660b35941 Mon Sep 17 00:00:00 2001 From: WWWesten Date: Thu, 4 Nov 2021 10:32:21 +0000 Subject: [PATCH 14/15] Translated using Weblate (Esperanto) Translation: Jellyfin/Jellyfin Translate-URL: https://translate.jellyfin.org/projects/jellyfin/jellyfin-core/eo/ --- Emby.Server.Implementations/Localization/Core/eo.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Emby.Server.Implementations/Localization/Core/eo.json b/Emby.Server.Implementations/Localization/Core/eo.json index 8ac466908c..12541a756a 100644 --- a/Emby.Server.Implementations/Localization/Core/eo.json +++ b/Emby.Server.Implementations/Localization/Core/eo.json @@ -52,7 +52,7 @@ "TaskCleanLogs": "Purigi Ĵurnalan Katalogon", "TaskRefreshLibrary": "Skani Plurmeditekon", "ValueSpecialEpisodeName": "Speciala - {0}", - "TaskOptimizeDatabase": "Optimigi datenbazon", + "TaskOptimizeDatabase": "Optimumigi datenbazon", "TaskRefreshChannels": "Refreŝigi Kanalojn", "TaskUpdatePlugins": "Ĝisdatigi Kromprogramojn", "TaskRefreshPeople": "Refreŝigi Homojn", @@ -75,7 +75,7 @@ "ServerNameNeedsToBeRestarted": "{0} devas esti relanĉita", "NotificationOptionVideoPlayback": "La videoludado lanĉis", "NotificationOptionServerRestartRequired": "Servila relanĉigo bezonata", - "TaskOptimizeDatabaseDescription": "Kompaktigas datenbazon kaj trunkas liberan lokon. Lanĉi ĉi tiun taskon post la teka skanado aŭ fari aliajn ŝanĝojn, kiuj implicas datenbazajn modifojn, povus plibonigi rendimenton.", + "TaskOptimizeDatabaseDescription": "Kompaktigas datenbazon kaj trunkas liberan lokon. Lanĉi ĉi tiun taskon post la plurmediteka skanado aŭ fari aliajn ŝanĝojn, kiuj implicas datenbazajn modifojn, povus plibonigi rendimenton.", "TaskUpdatePluginsDescription": "Elŝutas kaj instalas ĝisdatigojn por kromprogramojn, kiuj estas agorditaj por ĝisdatigi aŭtomate.", "TaskDownloadMissingSubtitlesDescription": "Serĉas en interreto mankantajn subtekstojn surbaze de metadatena agordaro.", "TaskRefreshPeopleDescription": "Ĝisdatigas metadatenojn por aktoroj kaj reĵisoroj en via plurmediteko.", From 44dc647adb35266f592191a821970359a6fb1324 Mon Sep 17 00:00:00 2001 From: Niels van Velzen Date: Fri, 5 Nov 2021 19:09:44 +0100 Subject: [PATCH 15/15] Fix OpenAPI workflow not working with pull requests from forks --- .github/workflows/openapi.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/openapi.yml b/.github/workflows/openapi.yml index 6e370819af..b81875d2c8 100644 --- a/.github/workflows/openapi.yml +++ b/.github/workflows/openapi.yml @@ -3,7 +3,7 @@ on: push: branches: - master - pull_request: + pull_request_target: jobs: openapi-head: @@ -12,6 +12,8 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v2 + with: + ref: ${{ github.head_ref }} - name: Setup .NET Core uses: actions/setup-dotnet@v1 with: @@ -53,7 +55,7 @@ jobs: openapi-diff: name: OpenAPI - Difference - if: ${{ github.event_name == 'pull_request' }} + if: ${{ github.event_name == 'pull_request_target' }} runs-on: ubuntu-latest needs: - openapi-head