Target Jellyfin 10.7

This commit is contained in:
Odd Stråbø 2020-11-27 20:23:53 +01:00
parent 8bb2c0ddd4
commit 811226904e
7 changed files with 46 additions and 83 deletions

View File

@ -1,15 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
<RootNamespace>Jellyfin.Plugin.Fanart</RootNamespace>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<FileVersion>5.0.0.0</FileVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<FileVersion>6.0.0.0</FileVersion>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Jellyfin.Controller" Version="10.*-*" />
<PackageReference Include="Microsoft.Extensions.Http" Version="5.0.0" />
</ItemGroup>
<ItemGroup>

View File

@ -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
}
/// <inheritdoc />
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
{
return _httpClient.GetResponse(new HttpRequestOptions
{
CancellationToken = cancellationToken,
Url = url
});
return _httpClientFactory.CreateClient(NamedClient.Default).GetAsync(new Uri(url), cancellationToken);
}
}
}

View File

@ -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
}
/// <inheritdoc />
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
public Task<HttpResponseMessage> 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)
{

View File

@ -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
}
/// <inheritdoc />
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
{
return _httpClient.GetResponse(new HttpRequestOptions
{
CancellationToken = cancellationToken,
Url = url
});
return _httpClientFactory.CreateClient(NamedClient.Default).GetAsync(new Uri(url), cancellationToken);
}
/// <summary>
@ -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)
{

View File

@ -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
}
/// <inheritdoc />
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
{
return _httpClient.GetResponse(new HttpRequestOptions
{
CancellationToken = cancellationToken,
Url = url
});
return _httpClientFactory.CreateClient(NamedClient.Default).GetAsync(new Uri(url), cancellationToken);
}
}
}

View File

@ -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
}
/// <inheritdoc />
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
{
return _httpClient.GetResponse(new HttpRequestOptions
{
CancellationToken = cancellationToken,
Url = url
});
return _httpClientFactory.CreateClient(NamedClient.Default).GetAsync(new Uri(url), cancellationToken);
}
/// <summary>
@ -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)
{

View File

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