From 811226904ec6a2480983db0ec24efd6e76c110dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Odd=20Str=C3=A5b=C3=B8?= Date: Fri, 27 Nov 2020 20:23:53 +0100 Subject: [PATCH] Target Jellyfin 10.7 --- .../Jellyfin.Plugin.Fanart.csproj | 7 +++-- .../Providers/AlbumProvider.cs | 15 ++++------ .../Providers/ArtistProvider.cs | 27 +++++------------ .../Providers/MovieProvider.cs | 29 ++++++------------- .../Providers/SeasonProvider.cs | 17 +++++------ .../Providers/SeriesProvider.cs | 29 ++++++------------- build.yaml | 5 ++-- 7 files changed, 46 insertions(+), 83 deletions(-) diff --git a/Jellyfin.Plugin.Fanart/Jellyfin.Plugin.Fanart.csproj b/Jellyfin.Plugin.Fanart/Jellyfin.Plugin.Fanart.csproj index a5464fc..0e73902 100644 --- a/Jellyfin.Plugin.Fanart/Jellyfin.Plugin.Fanart.csproj +++ b/Jellyfin.Plugin.Fanart/Jellyfin.Plugin.Fanart.csproj @@ -1,15 +1,16 @@ - netstandard2.1 + net5.0 Jellyfin.Plugin.Fanart - 5.0.0.0 - 5.0.0.0 + 6.0.0.0 + 6.0.0.0 true + diff --git a/Jellyfin.Plugin.Fanart/Providers/AlbumProvider.cs b/Jellyfin.Plugin.Fanart/Providers/AlbumProvider.cs index f6f53f8..572354e 100644 --- a/Jellyfin.Plugin.Fanart/Providers/AlbumProvider.cs +++ b/Jellyfin.Plugin.Fanart/Providers/AlbumProvider.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; +using System.Net.Http; using System.Threading; using System.Threading.Tasks; using MediaBrowser.Common.Net; @@ -21,13 +22,13 @@ namespace Jellyfin.Plugin.Fanart.Providers public class AlbumProvider : IRemoteImageProvider, IHasOrder { private readonly IServerConfigurationManager _config; - private readonly IHttpClient _httpClient; + private readonly IHttpClientFactory _httpClientFactory; private readonly IJsonSerializer _jsonSerializer; - public AlbumProvider(IServerConfigurationManager config, IHttpClient httpClient, IJsonSerializer jsonSerializer) + public AlbumProvider(IServerConfigurationManager config, IHttpClientFactory httpClientFactory, IJsonSerializer jsonSerializer) { _config = config; - _httpClient = httpClient; + _httpClientFactory = httpClientFactory; _jsonSerializer = jsonSerializer; } @@ -192,13 +193,9 @@ namespace Jellyfin.Plugin.Fanart.Providers } /// - public Task GetImageResponse(string url, CancellationToken cancellationToken) + public Task GetImageResponse(string url, CancellationToken cancellationToken) { - return _httpClient.GetResponse(new HttpRequestOptions - { - CancellationToken = cancellationToken, - Url = url - }); + return _httpClientFactory.CreateClient(NamedClient.Default).GetAsync(new Uri(url), cancellationToken); } } } diff --git a/Jellyfin.Plugin.Fanart/Providers/ArtistProvider.cs b/Jellyfin.Plugin.Fanart/Providers/ArtistProvider.cs index b38387b..532bfbc 100644 --- a/Jellyfin.Plugin.Fanart/Providers/ArtistProvider.cs +++ b/Jellyfin.Plugin.Fanart/Providers/ArtistProvider.cs @@ -27,14 +27,14 @@ namespace Jellyfin.Plugin.Fanart.Providers public class ArtistProvider : IRemoteImageProvider, IHasOrder { private readonly IServerConfigurationManager _config; - private readonly IHttpClient _httpClient; + private readonly IHttpClientFactory _httpClientFactory; private readonly IFileSystem _fileSystem; private readonly IJsonSerializer _jsonSerializer; - public ArtistProvider(IServerConfigurationManager config, IHttpClient httpClient, IFileSystem fileSystem, IJsonSerializer jsonSerializer) + public ArtistProvider(IServerConfigurationManager config, IHttpClientFactory httpClientFactory, IFileSystem fileSystem, IJsonSerializer jsonSerializer) { _config = config; - _httpClient = httpClient; + _httpClientFactory = httpClientFactory; _fileSystem = fileSystem; _jsonSerializer = jsonSerializer; @@ -191,13 +191,9 @@ namespace Jellyfin.Plugin.Fanart.Providers } /// - public Task GetImageResponse(string url, CancellationToken cancellationToken) + public Task GetImageResponse(string url, CancellationToken cancellationToken) { - return _httpClient.GetResponse(new HttpRequestOptions - { - CancellationToken = cancellationToken, - Url = url - }); + return _httpClientFactory.CreateClient(NamedClient.Default).GetAsync(new Uri(url), cancellationToken); } internal Task EnsureArtistJson(string musicBrainzId, CancellationToken cancellationToken) @@ -244,22 +240,15 @@ namespace Jellyfin.Plugin.Fanart.Providers try { - using (var httpResponse = await _httpClient.SendAsync( - new HttpRequestOptions - { - Url = url, - CancellationToken = cancellationToken, - BufferContent = true - - }, - HttpMethod.Get).ConfigureAwait(false)) + var httpClient = _httpClientFactory.CreateClient(NamedClient.Default); + using (var httpResponse = await httpClient.GetAsync(new Uri(url), cancellationToken).ConfigureAwait(false)) using (var response = httpResponse.Content) using (var saveFileStream = new FileStream(jsonPath, FileMode.Create, FileAccess.Write, FileShare.Read, IODefaults.FileStreamBufferSize, FileOptions.Asynchronous)) { await response.CopyToAsync(saveFileStream, CancellationToken.None).ConfigureAwait(false); } } - catch (HttpException ex) + catch (HttpRequestException ex) { if (ex.StatusCode.HasValue && ex.StatusCode.Value == HttpStatusCode.NotFound) { diff --git a/Jellyfin.Plugin.Fanart/Providers/MovieProvider.cs b/Jellyfin.Plugin.Fanart/Providers/MovieProvider.cs index 7166239..63a13ca 100644 --- a/Jellyfin.Plugin.Fanart/Providers/MovieProvider.cs +++ b/Jellyfin.Plugin.Fanart/Providers/MovieProvider.cs @@ -26,14 +26,14 @@ namespace Jellyfin.Plugin.Fanart.Providers public class MovieProvider : IRemoteImageProvider, IHasOrder { private readonly IServerConfigurationManager _config; - private readonly IHttpClient _httpClient; + private readonly IHttpClientFactory _httpClientFactory; private readonly IFileSystem _fileSystem; private readonly IJsonSerializer _json; - public MovieProvider(IServerConfigurationManager config, IHttpClient httpClient, IFileSystem fileSystem, IJsonSerializer json) + public MovieProvider(IServerConfigurationManager config, IHttpClientFactory httpClientFactory, IFileSystem fileSystem, IJsonSerializer json) { _config = config; - _httpClient = httpClient; + _httpClientFactory = httpClientFactory; _fileSystem = fileSystem; _json = json; } @@ -78,7 +78,7 @@ namespace Jellyfin.Plugin.Fanart.Providers { await EnsureMovieJson(movieId, cancellationToken).ConfigureAwait(false); } - catch (HttpException ex) + catch (HttpRequestException ex) { if (!ex.StatusCode.HasValue || ex.StatusCode.Value != HttpStatusCode.NotFound) { @@ -193,13 +193,9 @@ namespace Jellyfin.Plugin.Fanart.Providers } /// - public Task GetImageResponse(string url, CancellationToken cancellationToken) + public Task GetImageResponse(string url, CancellationToken cancellationToken) { - return _httpClient.GetResponse(new HttpRequestOptions - { - CancellationToken = cancellationToken, - Url = url - }); + return _httpClientFactory.CreateClient(NamedClient.Default).GetAsync(new Uri(url), cancellationToken); } /// @@ -262,22 +258,15 @@ namespace Jellyfin.Plugin.Fanart.Providers try { - using (var httpResponse = await _httpClient.SendAsync( - new HttpRequestOptions - { - Url = url, - CancellationToken = cancellationToken, - BufferContent = true - - }, - HttpMethod.Get).ConfigureAwait(false)) + var httpClient = _httpClientFactory.CreateClient(NamedClient.Default); + using (var httpResponse = await httpClient.GetAsync(new Uri(url), cancellationToken).ConfigureAwait(false)) using (var response = httpResponse.Content) using (var fileStream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read, IODefaults.FileStreamBufferSize, FileOptions.Asynchronous)) { await response.CopyToAsync(fileStream, CancellationToken.None).ConfigureAwait(false); } } - catch (HttpException exception) + catch (HttpRequestException exception) { if (exception.StatusCode.HasValue && exception.StatusCode.Value == HttpStatusCode.NotFound) { diff --git a/Jellyfin.Plugin.Fanart/Providers/SeasonProvider.cs b/Jellyfin.Plugin.Fanart/Providers/SeasonProvider.cs index 76d0ba7..2b663b7 100644 --- a/Jellyfin.Plugin.Fanart/Providers/SeasonProvider.cs +++ b/Jellyfin.Plugin.Fanart/Providers/SeasonProvider.cs @@ -4,6 +4,7 @@ using System.Globalization; using System.IO; using System.Linq; using System.Net; +using System.Net.Http; using System.Threading; using System.Threading.Tasks; using MediaBrowser.Common.Net; @@ -21,12 +22,12 @@ namespace Jellyfin.Plugin.Fanart.Providers { public class SeasonProvider : IRemoteImageProvider, IHasOrder { - private readonly IHttpClient _httpClient; + private readonly IHttpClientFactory _httpClientFactory; private readonly IJsonSerializer _json; - public SeasonProvider(IHttpClient httpClient, IJsonSerializer json) + public SeasonProvider(IHttpClientFactory httpClientFactory, IJsonSerializer json) { - _httpClient = httpClient; + _httpClientFactory = httpClientFactory; _json = json; } @@ -71,7 +72,7 @@ namespace Jellyfin.Plugin.Fanart.Providers { await SeriesProvider.Current.EnsureSeriesJson(id, cancellationToken).ConfigureAwait(false); } - catch (HttpException ex) + catch (HttpRequestException ex) { if (!ex.StatusCode.HasValue || ex.StatusCode.Value != HttpStatusCode.NotFound) { @@ -193,13 +194,9 @@ namespace Jellyfin.Plugin.Fanart.Providers } /// - public Task GetImageResponse(string url, CancellationToken cancellationToken) + public Task GetImageResponse(string url, CancellationToken cancellationToken) { - return _httpClient.GetResponse(new HttpRequestOptions - { - CancellationToken = cancellationToken, - Url = url - }); + return _httpClientFactory.CreateClient(NamedClient.Default).GetAsync(new Uri(url), cancellationToken); } } } diff --git a/Jellyfin.Plugin.Fanart/Providers/SeriesProvider.cs b/Jellyfin.Plugin.Fanart/Providers/SeriesProvider.cs index fc4e74f..6d0e92e 100644 --- a/Jellyfin.Plugin.Fanart/Providers/SeriesProvider.cs +++ b/Jellyfin.Plugin.Fanart/Providers/SeriesProvider.cs @@ -27,16 +27,16 @@ namespace Jellyfin.Plugin.Fanart.Providers public class SeriesProvider : IRemoteImageProvider, IHasOrder { private readonly IServerConfigurationManager _config; - private readonly IHttpClient _httpClient; + private readonly IHttpClientFactory _httpClientFactory; private readonly IFileSystem _fileSystem; private readonly IJsonSerializer _json; private readonly SemaphoreSlim _ensureSemaphore = new SemaphoreSlim(1, 1); - public SeriesProvider(IServerConfigurationManager config, IHttpClient httpClient, IFileSystem fileSystem, IJsonSerializer json) + public SeriesProvider(IServerConfigurationManager config, IHttpClientFactory httpClientFactory, IFileSystem fileSystem, IJsonSerializer json) { _config = config; - _httpClient = httpClient; + _httpClientFactory = httpClientFactory; _fileSystem = fileSystem; _json = json; @@ -85,7 +85,7 @@ namespace Jellyfin.Plugin.Fanart.Providers { await EnsureSeriesJson(id, cancellationToken).ConfigureAwait(false); } - catch (HttpException ex) + catch (HttpRequestException ex) { if (!ex.StatusCode.HasValue || ex.StatusCode.Value != HttpStatusCode.NotFound) { @@ -211,13 +211,9 @@ namespace Jellyfin.Plugin.Fanart.Providers } /// - public Task GetImageResponse(string url, CancellationToken cancellationToken) + public Task GetImageResponse(string url, CancellationToken cancellationToken) { - return _httpClient.GetResponse(new HttpRequestOptions - { - CancellationToken = cancellationToken, - Url = url - }); + return _httpClientFactory.CreateClient(NamedClient.Default).GetAsync(new Uri(url), cancellationToken); } /// @@ -307,22 +303,15 @@ namespace Jellyfin.Plugin.Fanart.Providers try { - using (var httpResponse = await _httpClient.SendAsync( - new HttpRequestOptions - { - Url = url, - CancellationToken = cancellationToken, - BufferContent = true - - }, - HttpMethod.Get).ConfigureAwait(false)) + var httpClient = _httpClientFactory.CreateClient(NamedClient.Default); + using (var httpResponse = await httpClient.GetAsync(new Uri(url), cancellationToken).ConfigureAwait(false)) using (var response = httpResponse.Content) using (var fileStream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read, IODefaults.FileStreamBufferSize, FileOptions.Asynchronous)) { await response.CopyToAsync(fileStream, CancellationToken.None).ConfigureAwait(false); } } - catch (HttpException exception) + catch (HttpRequestException exception) { if (exception.StatusCode.HasValue && exception.StatusCode.Value == HttpStatusCode.NotFound) { diff --git a/build.yaml b/build.yaml index 8208475..ccbf283 100644 --- a/build.yaml +++ b/build.yaml @@ -1,8 +1,9 @@ --- name: "Fanart" guid: "170a157f-ac6c-437a-abdd-ca9c25cebd39" -version: "5.0.0.0" -targetAbi: "10.6.0.0" +version: "6.0.0.0" +targetAbi: "10.7.0.0" +framework: "net5.0" overview: "Scrape poster images from Fanart" description: "Scrape poster images for movies, shows, and artists in your library." category: "Metadata"