Remove IHttpClient from StudiosImageProvider
This commit is contained in:
parent
d0f49b3994
commit
aee72aefb0
|
@ -18,6 +18,7 @@
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="3.1.6" />
|
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="3.1.6" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="3.1.6" />
|
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="3.1.6" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Http" Version="3.1.6" />
|
||||||
<PackageReference Include="OptimizedPriorityQueue" Version="4.2.0" />
|
<PackageReference Include="OptimizedPriorityQueue" Version="4.2.0" />
|
||||||
<PackageReference Include="PlaylistsNET" Version="1.1.2" />
|
<PackageReference Include="PlaylistsNET" Version="1.1.2" />
|
||||||
<PackageReference Include="TvDbSharper" Version="3.2.1" />
|
<PackageReference Include="TvDbSharper" Version="3.2.1" />
|
||||||
|
|
|
@ -20,13 +20,13 @@ namespace MediaBrowser.Providers.Studios
|
||||||
public class StudiosImageProvider : IRemoteImageProvider
|
public class StudiosImageProvider : IRemoteImageProvider
|
||||||
{
|
{
|
||||||
private readonly IServerConfigurationManager _config;
|
private readonly IServerConfigurationManager _config;
|
||||||
private readonly IHttpClient _httpClient;
|
private readonly IHttpClientFactory _httpClientFactory;
|
||||||
private readonly IFileSystem _fileSystem;
|
private readonly IFileSystem _fileSystem;
|
||||||
|
|
||||||
public StudiosImageProvider(IServerConfigurationManager config, IHttpClient httpClient, IFileSystem fileSystem)
|
public StudiosImageProvider(IServerConfigurationManager config, IHttpClientFactory httpClientFactory, IFileSystem fileSystem)
|
||||||
{
|
{
|
||||||
_config = config;
|
_config = config;
|
||||||
_httpClient = httpClient;
|
_httpClientFactory = httpClientFactory;
|
||||||
_fileSystem = fileSystem;
|
_fileSystem = fileSystem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,14 +108,14 @@ namespace MediaBrowser.Providers.Studios
|
||||||
{
|
{
|
||||||
const string url = "https://raw.github.com/MediaBrowser/MediaBrowser.Resources/master/images/imagesbyname/studiothumbs.txt";
|
const string url = "https://raw.github.com/MediaBrowser/MediaBrowser.Resources/master/images/imagesbyname/studiothumbs.txt";
|
||||||
|
|
||||||
return EnsureList(url, file, _httpClient, _fileSystem, cancellationToken);
|
return EnsureList(url, file, _fileSystem, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Task<string> EnsurePosterList(string file, CancellationToken cancellationToken)
|
private Task<string> EnsurePosterList(string file, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
const string url = "https://raw.github.com/MediaBrowser/MediaBrowser.Resources/master/images/imagesbyname/studioposters.txt";
|
const string url = "https://raw.github.com/MediaBrowser/MediaBrowser.Resources/master/images/imagesbyname/studioposters.txt";
|
||||||
|
|
||||||
return EnsureList(url, file, _httpClient, _fileSystem, cancellationToken);
|
return EnsureList(url, file, _fileSystem, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Order => 0;
|
public int Order => 0;
|
||||||
|
@ -139,26 +139,18 @@ namespace MediaBrowser.Providers.Studios
|
||||||
/// <param name="fileSystem">The file system.</param>
|
/// <param name="fileSystem">The file system.</param>
|
||||||
/// <param name="cancellationToken">The cancellation token.</param>
|
/// <param name="cancellationToken">The cancellation token.</param>
|
||||||
/// <returns>Task.</returns>
|
/// <returns>Task.</returns>
|
||||||
public async Task<string> EnsureList(string url, string file, IHttpClient httpClient, IFileSystem fileSystem, CancellationToken cancellationToken)
|
public async Task<string> EnsureList(string url, string file, IFileSystem fileSystem, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var fileInfo = fileSystem.GetFileInfo(file);
|
var fileInfo = fileSystem.GetFileInfo(file);
|
||||||
|
|
||||||
if (!fileInfo.Exists || (DateTime.UtcNow - fileSystem.GetLastWriteTimeUtc(fileInfo)).TotalDays > 1)
|
if (!fileInfo.Exists || (DateTime.UtcNow - fileSystem.GetLastWriteTimeUtc(fileInfo)).TotalDays > 1)
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(file));
|
var httpClient = _httpClientFactory.CreateClient();
|
||||||
|
|
||||||
using (var res = await httpClient.SendAsync(
|
Directory.CreateDirectory(Path.GetDirectoryName(file));
|
||||||
new HttpRequestOptions
|
await using var response = await httpClient.GetStreamAsync(url).ConfigureAwait(false);
|
||||||
{
|
await using var fileStream = new FileStream(file, FileMode.Create);
|
||||||
CancellationToken = cancellationToken,
|
await response.CopyToAsync(fileStream, cancellationToken).ConfigureAwait(false);
|
||||||
Url = url
|
|
||||||
},
|
|
||||||
HttpMethod.Get).ConfigureAwait(false))
|
|
||||||
using (var content = res.Content)
|
|
||||||
using (var fileStream = new FileStream(file, FileMode.Create))
|
|
||||||
{
|
|
||||||
await content.CopyToAsync(fileStream).ConfigureAwait(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return file;
|
return file;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user