mirror of https://github.com/jellyfin/jellyfin.git
Merge pull request #3925 from crobibero/httpclient
Remove IHttpClient from Providers
This commit is contained in:
commit
93fe595e5e
|
@ -331,12 +331,12 @@ namespace Jellyfin.Api.Controllers
|
||||||
/// <returns>Task.</returns>
|
/// <returns>Task.</returns>
|
||||||
private async Task DownloadImage(string providerName, string url, Guid urlHash, string pointerCachePath)
|
private async Task DownloadImage(string providerName, string url, Guid urlHash, string pointerCachePath)
|
||||||
{
|
{
|
||||||
var result = await _providerManager.GetSearchImage(providerName, url, CancellationToken.None).ConfigureAwait(false);
|
using var result = await _providerManager.GetSearchImage(providerName, url, CancellationToken.None).ConfigureAwait(false);
|
||||||
var ext = result.ContentType.Split('/').Last();
|
var ext = result.Content.Headers.ContentType.MediaType.Split('/')[^1];
|
||||||
var fullCachePath = GetFullCachePath(urlHash + "." + ext);
|
var fullCachePath = GetFullCachePath(urlHash + "." + ext);
|
||||||
|
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(fullCachePath));
|
Directory.CreateDirectory(Path.GetDirectoryName(fullCachePath));
|
||||||
await using (var stream = result.Content)
|
using (var stream = result.Content)
|
||||||
{
|
{
|
||||||
await using var fileStream = new FileStream(
|
await using var fileStream = new FileStream(
|
||||||
fullCachePath,
|
fullCachePath,
|
||||||
|
|
|
@ -1071,7 +1071,8 @@ namespace Jellyfin.Api.Controllers
|
||||||
{
|
{
|
||||||
var client = _httpClientFactory.CreateClient();
|
var client = _httpClientFactory.CreateClient();
|
||||||
// https://json.schedulesdirect.org/20141201/available/countries
|
// https://json.schedulesdirect.org/20141201/available/countries
|
||||||
using var response = await client.GetAsync("https://json.schedulesdirect.org/20141201/available/countries")
|
// Can't dispose the response as it's required up the call chain.
|
||||||
|
var response = await client.GetAsync("https://json.schedulesdirect.org/20141201/available/countries")
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
|
|
||||||
return File(await response.Content.ReadAsStreamAsync().ConfigureAwait(false), MediaTypeNames.Application.Json);
|
return File(await response.Content.ReadAsStreamAsync().ConfigureAwait(false), MediaTypeNames.Application.Json);
|
||||||
|
|
|
@ -36,7 +36,8 @@ namespace Jellyfin.Api.Helpers
|
||||||
httpClient.DefaultRequestHeaders.Add(HeaderNames.UserAgent, useragent);
|
httpClient.DefaultRequestHeaders.Add(HeaderNames.UserAgent, useragent);
|
||||||
}
|
}
|
||||||
|
|
||||||
using var response = await httpClient.GetAsync(state.MediaPath).ConfigureAwait(false);
|
// Can't dispose the response as it's required up the call chain.
|
||||||
|
var response = await httpClient.GetAsync(state.MediaPath).ConfigureAwait(false);
|
||||||
var contentType = response.Content.Headers.ContentType.ToString();
|
var contentType = response.Content.Headers.ContentType.ToString();
|
||||||
|
|
||||||
controller.Response.Headers[HeaderNames.AcceptRanges] = "none";
|
controller.Response.Headers[HeaderNames.AcceptRanges] = "none";
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Net.Http;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Jellyfin.Data.Entities;
|
using Jellyfin.Data.Entities;
|
||||||
|
@ -157,7 +158,7 @@ namespace MediaBrowser.Controller.Providers
|
||||||
/// <param name="url">The URL.</param>
|
/// <param name="url">The URL.</param>
|
||||||
/// <param name="cancellationToken">The cancellation token.</param>
|
/// <param name="cancellationToken">The cancellation token.</param>
|
||||||
/// <returns>Task{HttpResponseInfo}.</returns>
|
/// <returns>Task{HttpResponseInfo}.</returns>
|
||||||
Task<HttpResponseInfo> GetSearchImage(string providerName, string url, CancellationToken cancellationToken);
|
Task<HttpResponseMessage> GetSearchImage(string providerName, string url, CancellationToken cancellationToken);
|
||||||
|
|
||||||
Dictionary<Guid, Guid> GetRefreshQueue();
|
Dictionary<Guid, Guid> GetRefreshQueue();
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Net.Http;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using MediaBrowser.Common.Net;
|
using MediaBrowser.Common.Net;
|
||||||
|
@ -34,6 +35,6 @@ namespace MediaBrowser.Controller.Providers
|
||||||
/// <param name="url">The URL.</param>
|
/// <param name="url">The URL.</param>
|
||||||
/// <param name="cancellationToken">The cancellation token.</param>
|
/// <param name="cancellationToken">The cancellation token.</param>
|
||||||
/// <returns>Task{HttpResponseInfo}.</returns>
|
/// <returns>Task{HttpResponseInfo}.</returns>
|
||||||
Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken);
|
Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
using System.Net.Http;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using MediaBrowser.Common.Net;
|
using MediaBrowser.Common.Net;
|
||||||
|
@ -12,6 +13,6 @@ namespace MediaBrowser.Controller.Providers
|
||||||
/// <param name="url">The URL.</param>
|
/// <param name="url">The URL.</param>
|
||||||
/// <param name="cancellationToken">The cancellation token.</param>
|
/// <param name="cancellationToken">The cancellation token.</param>
|
||||||
/// <returns>Task{HttpResponseInfo}.</returns>
|
/// <returns>Task{HttpResponseInfo}.</returns>
|
||||||
Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken);
|
Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -465,9 +465,16 @@ namespace MediaBrowser.Providers.Manager
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var response = await provider.GetImageResponse(url, cancellationToken).ConfigureAwait(false);
|
using var response = await provider.GetImageResponse(url, cancellationToken).ConfigureAwait(false);
|
||||||
|
await using var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
await _providerManager.SaveImage(item, response.Content, response.ContentType, type, null, cancellationToken).ConfigureAwait(false);
|
await _providerManager.SaveImage(
|
||||||
|
item,
|
||||||
|
stream,
|
||||||
|
response.Content.Headers.ContentType.MediaType,
|
||||||
|
type,
|
||||||
|
null,
|
||||||
|
cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
result.UpdateType = result.UpdateType | ItemUpdateType.ImageUpdate;
|
result.UpdateType = result.UpdateType | ItemUpdateType.ImageUpdate;
|
||||||
return true;
|
return true;
|
||||||
|
@ -565,14 +572,14 @@ namespace MediaBrowser.Providers.Manager
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var response = await provider.GetImageResponse(url, cancellationToken).ConfigureAwait(false);
|
using var response = await provider.GetImageResponse(url, cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
// If there's already an image of the same size, skip it
|
// If there's already an image of the same size, skip it
|
||||||
if (response.ContentLength.HasValue)
|
if (response.Content.Headers.ContentLength.HasValue)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (item.GetImages(imageType).Any(i => _fileSystem.GetFileInfo(i.Path).Length == response.ContentLength.Value))
|
if (item.GetImages(imageType).Any(i => _fileSystem.GetFileInfo(i.Path).Length == response.Content.Headers.ContentLength.Value))
|
||||||
{
|
{
|
||||||
response.Content.Dispose();
|
response.Content.Dispose();
|
||||||
continue;
|
continue;
|
||||||
|
@ -584,7 +591,14 @@ namespace MediaBrowser.Providers.Manager
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await _providerManager.SaveImage(item, response.Content, response.ContentType, imageType, null, cancellationToken).ConfigureAwait(false);
|
await using var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
|
||||||
|
await _providerManager.SaveImage(
|
||||||
|
item,
|
||||||
|
stream,
|
||||||
|
response.Content.Headers.ContentType.MediaType,
|
||||||
|
imageType,
|
||||||
|
null,
|
||||||
|
cancellationToken).ConfigureAwait(false);
|
||||||
result.UpdateType = result.UpdateType | ItemUpdateType.ImageUpdate;
|
result.UpdateType = result.UpdateType | ItemUpdateType.ImageUpdate;
|
||||||
}
|
}
|
||||||
catch (HttpException ex)
|
catch (HttpException ex)
|
||||||
|
|
|
@ -5,6 +5,7 @@ using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
using System.Net.Http;
|
||||||
using System.Net.Mime;
|
using System.Net.Mime;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
@ -44,7 +45,7 @@ namespace MediaBrowser.Providers.Manager
|
||||||
{
|
{
|
||||||
private readonly object _refreshQueueLock = new object();
|
private readonly object _refreshQueueLock = new object();
|
||||||
private readonly ILogger<ProviderManager> _logger;
|
private readonly ILogger<ProviderManager> _logger;
|
||||||
private readonly IHttpClient _httpClient;
|
private readonly IHttpClientFactory _httpClientFactory;
|
||||||
private readonly ILibraryMonitor _libraryMonitor;
|
private readonly ILibraryMonitor _libraryMonitor;
|
||||||
private readonly IFileSystem _fileSystem;
|
private readonly IFileSystem _fileSystem;
|
||||||
private readonly IServerApplicationPaths _appPaths;
|
private readonly IServerApplicationPaths _appPaths;
|
||||||
|
@ -66,7 +67,7 @@ namespace MediaBrowser.Providers.Manager
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="ProviderManager"/> class.
|
/// Initializes a new instance of the <see cref="ProviderManager"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="httpClient">The Http client.</param>
|
/// <param name="httpClientFactory">The Http client factory.</param>
|
||||||
/// <param name="subtitleManager">The subtitle manager.</param>
|
/// <param name="subtitleManager">The subtitle manager.</param>
|
||||||
/// <param name="configurationManager">The configuration manager.</param>
|
/// <param name="configurationManager">The configuration manager.</param>
|
||||||
/// <param name="libraryMonitor">The library monitor.</param>
|
/// <param name="libraryMonitor">The library monitor.</param>
|
||||||
|
@ -75,7 +76,7 @@ namespace MediaBrowser.Providers.Manager
|
||||||
/// <param name="appPaths">The server application paths.</param>
|
/// <param name="appPaths">The server application paths.</param>
|
||||||
/// <param name="libraryManager">The library manager.</param>
|
/// <param name="libraryManager">The library manager.</param>
|
||||||
public ProviderManager(
|
public ProviderManager(
|
||||||
IHttpClient httpClient,
|
IHttpClientFactory httpClientFactory,
|
||||||
ISubtitleManager subtitleManager,
|
ISubtitleManager subtitleManager,
|
||||||
IServerConfigurationManager configurationManager,
|
IServerConfigurationManager configurationManager,
|
||||||
ILibraryMonitor libraryMonitor,
|
ILibraryMonitor libraryMonitor,
|
||||||
|
@ -85,7 +86,7 @@ namespace MediaBrowser.Providers.Manager
|
||||||
ILibraryManager libraryManager)
|
ILibraryManager libraryManager)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_httpClient = httpClient;
|
_httpClientFactory = httpClientFactory;
|
||||||
_configurationManager = configurationManager;
|
_configurationManager = configurationManager;
|
||||||
_libraryMonitor = libraryMonitor;
|
_libraryMonitor = libraryMonitor;
|
||||||
_fileSystem = fileSystem;
|
_fileSystem = fileSystem;
|
||||||
|
@ -155,25 +156,23 @@ namespace MediaBrowser.Providers.Manager
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public async Task SaveImage(BaseItem item, string url, ImageType type, int? imageIndex, CancellationToken cancellationToken)
|
public async Task SaveImage(BaseItem item, string url, ImageType type, int? imageIndex, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
using var response = await _httpClient.GetResponse(new HttpRequestOptions
|
var httpClient = _httpClientFactory.CreateClient();
|
||||||
{
|
using var response = await httpClient.GetAsync(url, cancellationToken).ConfigureAwait(false);
|
||||||
CancellationToken = cancellationToken,
|
|
||||||
Url = url,
|
var contentType = response.Content.Headers.ContentType.MediaType;
|
||||||
BufferContent = false
|
|
||||||
}).ConfigureAwait(false);
|
|
||||||
|
|
||||||
// Workaround for tvheadend channel icons
|
// Workaround for tvheadend channel icons
|
||||||
// TODO: Isolate this hack into the tvh plugin
|
// TODO: Isolate this hack into the tvh plugin
|
||||||
if (string.IsNullOrEmpty(response.ContentType))
|
if (string.IsNullOrEmpty(contentType))
|
||||||
{
|
{
|
||||||
if (url.IndexOf("/imagecache/", StringComparison.OrdinalIgnoreCase) != -1)
|
if (url.IndexOf("/imagecache/", StringComparison.OrdinalIgnoreCase) != -1)
|
||||||
{
|
{
|
||||||
response.ContentType = "image/png";
|
contentType = "image/png";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// thetvdb will sometimes serve a rubbish 404 html page with a 200 OK code, because reasons...
|
// thetvdb will sometimes serve a rubbish 404 html page with a 200 OK code, because reasons...
|
||||||
if (response.ContentType.Equals(MediaTypeNames.Text.Html, StringComparison.OrdinalIgnoreCase))
|
if (contentType.Equals(MediaTypeNames.Text.Html, StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
throw new HttpException("Invalid image received.")
|
throw new HttpException("Invalid image received.")
|
||||||
{
|
{
|
||||||
|
@ -181,7 +180,14 @@ namespace MediaBrowser.Providers.Manager
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
await SaveImage(item, response.Content, response.ContentType, type, imageIndex, cancellationToken).ConfigureAwait(false);
|
await using var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
|
||||||
|
await SaveImage(
|
||||||
|
item,
|
||||||
|
stream,
|
||||||
|
contentType,
|
||||||
|
type,
|
||||||
|
imageIndex,
|
||||||
|
cancellationToken).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
|
@ -888,7 +894,7 @@ namespace MediaBrowser.Providers.Manager
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public Task<HttpResponseInfo> GetSearchImage(string providerName, string url, CancellationToken cancellationToken)
|
public Task<HttpResponseMessage> GetSearchImage(string providerName, string url, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var provider = _metadataProviders.OfType<IRemoteSearchProvider>().FirstOrDefault(i => string.Equals(i.Name, providerName, StringComparison.OrdinalIgnoreCase));
|
var provider = _metadataProviders.OfType<IRemoteSearchProvider>().FirstOrDefault(i => string.Equals(i.Name, providerName, StringComparison.OrdinalIgnoreCase));
|
||||||
|
|
||||||
|
|
|
@ -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" />
|
||||||
|
@ -27,7 +28,7 @@
|
||||||
<TargetFramework>netstandard2.1</TargetFramework>
|
<TargetFramework>netstandard2.1</TargetFramework>
|
||||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||||
<TreatWarningsAsErrors Condition=" '$(Configuration)' == 'Release'" >true</TreatWarningsAsErrors>
|
<TreatWarningsAsErrors Condition=" '$(Configuration)' == 'Release'">true</TreatWarningsAsErrors>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<!-- Code Analyzers-->
|
<!-- Code Analyzers-->
|
||||||
|
|
|
@ -8,7 +8,6 @@ using MediaBrowser.Controller.Entities;
|
||||||
using MediaBrowser.Controller.Providers;
|
using MediaBrowser.Controller.Providers;
|
||||||
using MediaBrowser.Model.Entities;
|
using MediaBrowser.Model.Entities;
|
||||||
using MediaBrowser.Model.Globalization;
|
using MediaBrowser.Model.Globalization;
|
||||||
using MediaBrowser.Model.IO;
|
|
||||||
|
|
||||||
namespace MediaBrowser.Providers.MediaInfo
|
namespace MediaBrowser.Providers.MediaInfo
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
#pragma warning disable CS1591
|
#pragma warning disable CS1591
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Net.Http;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using MediaBrowser.Common.Net;
|
|
||||||
using MediaBrowser.Controller.Configuration;
|
using MediaBrowser.Controller.Configuration;
|
||||||
using MediaBrowser.Controller.Entities;
|
using MediaBrowser.Controller.Entities;
|
||||||
using MediaBrowser.Controller.Entities.Audio;
|
using MediaBrowser.Controller.Entities.Audio;
|
||||||
|
@ -17,13 +17,13 @@ namespace MediaBrowser.Providers.Plugins.AudioDb
|
||||||
public class AudioDbAlbumImageProvider : IRemoteImageProvider, IHasOrder
|
public class AudioDbAlbumImageProvider : IRemoteImageProvider, IHasOrder
|
||||||
{
|
{
|
||||||
private readonly IServerConfigurationManager _config;
|
private readonly IServerConfigurationManager _config;
|
||||||
private readonly IHttpClient _httpClient;
|
private readonly IHttpClientFactory _httpClientFactory;
|
||||||
private readonly IJsonSerializer _json;
|
private readonly IJsonSerializer _json;
|
||||||
|
|
||||||
public AudioDbAlbumImageProvider(IServerConfigurationManager config, IHttpClient httpClient, IJsonSerializer json)
|
public AudioDbAlbumImageProvider(IServerConfigurationManager config, IHttpClientFactory httpClientFactory, IJsonSerializer json)
|
||||||
{
|
{
|
||||||
_config = config;
|
_config = config;
|
||||||
_httpClient = httpClient;
|
_httpClientFactory = httpClientFactory;
|
||||||
_json = json;
|
_json = json;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,13 +94,10 @@ namespace MediaBrowser.Providers.Plugins.AudioDb
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
|
public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
return _httpClient.GetResponse(new HttpRequestOptions
|
var httpClient = _httpClientFactory.CreateClient();
|
||||||
{
|
return httpClient.GetAsync(url, cancellationToken);
|
||||||
CancellationToken = cancellationToken,
|
|
||||||
Url = url
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|
|
@ -10,7 +10,6 @@ using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using MediaBrowser.Common.Configuration;
|
using MediaBrowser.Common.Configuration;
|
||||||
using MediaBrowser.Common.Extensions;
|
using MediaBrowser.Common.Extensions;
|
||||||
using MediaBrowser.Common.Net;
|
|
||||||
using MediaBrowser.Controller.Configuration;
|
using MediaBrowser.Controller.Configuration;
|
||||||
using MediaBrowser.Controller.Entities.Audio;
|
using MediaBrowser.Controller.Entities.Audio;
|
||||||
using MediaBrowser.Controller.Providers;
|
using MediaBrowser.Controller.Providers;
|
||||||
|
@ -26,16 +25,16 @@ namespace MediaBrowser.Providers.Plugins.AudioDb
|
||||||
{
|
{
|
||||||
private readonly IServerConfigurationManager _config;
|
private readonly IServerConfigurationManager _config;
|
||||||
private readonly IFileSystem _fileSystem;
|
private readonly IFileSystem _fileSystem;
|
||||||
private readonly IHttpClient _httpClient;
|
private readonly IHttpClientFactory _httpClientFactory;
|
||||||
private readonly IJsonSerializer _json;
|
private readonly IJsonSerializer _json;
|
||||||
|
|
||||||
public static AudioDbAlbumProvider Current;
|
public static AudioDbAlbumProvider Current;
|
||||||
|
|
||||||
public AudioDbAlbumProvider(IServerConfigurationManager config, IFileSystem fileSystem, IHttpClient httpClient, IJsonSerializer json)
|
public AudioDbAlbumProvider(IServerConfigurationManager config, IFileSystem fileSystem, IHttpClientFactory httpClientFactory, IJsonSerializer json)
|
||||||
{
|
{
|
||||||
_config = config;
|
_config = config;
|
||||||
_fileSystem = fileSystem;
|
_fileSystem = fileSystem;
|
||||||
_httpClient = httpClient;
|
_httpClientFactory = httpClientFactory;
|
||||||
_json = json;
|
_json = json;
|
||||||
|
|
||||||
Current = this;
|
Current = this;
|
||||||
|
@ -174,18 +173,10 @@ namespace MediaBrowser.Providers.Plugins.AudioDb
|
||||||
|
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(path));
|
Directory.CreateDirectory(Path.GetDirectoryName(path));
|
||||||
|
|
||||||
using (var httpResponse = await _httpClient.SendAsync(
|
using var response = await _httpClientFactory.CreateClient().GetAsync(url, cancellationToken);
|
||||||
new HttpRequestOptions
|
await using var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
|
||||||
{
|
await using var xmlFileStream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read, IODefaults.FileStreamBufferSize, true);
|
||||||
Url = url,
|
await stream.CopyToAsync(xmlFileStream, cancellationToken).ConfigureAwait(false);
|
||||||
CancellationToken = cancellationToken
|
|
||||||
},
|
|
||||||
HttpMethod.Get).ConfigureAwait(false))
|
|
||||||
using (var response = httpResponse.Content)
|
|
||||||
using (var xmlFileStream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read, IODefaults.FileStreamBufferSize, true))
|
|
||||||
{
|
|
||||||
await response.CopyToAsync(xmlFileStream).ConfigureAwait(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string GetAlbumDataPath(IApplicationPaths appPaths, string musicBrainzReleaseGroupId)
|
private static string GetAlbumDataPath(IApplicationPaths appPaths, string musicBrainzReleaseGroupId)
|
||||||
|
@ -294,7 +285,7 @@ namespace MediaBrowser.Providers.Plugins.AudioDb
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
|
public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
#pragma warning disable CS1591
|
#pragma warning disable CS1591
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Net.Http;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using MediaBrowser.Common.Net;
|
|
||||||
using MediaBrowser.Controller.Configuration;
|
using MediaBrowser.Controller.Configuration;
|
||||||
using MediaBrowser.Controller.Entities;
|
using MediaBrowser.Controller.Entities;
|
||||||
using MediaBrowser.Controller.Entities.Audio;
|
using MediaBrowser.Controller.Entities.Audio;
|
||||||
|
@ -17,14 +17,14 @@ namespace MediaBrowser.Providers.Plugins.AudioDb
|
||||||
public class AudioDbArtistImageProvider : IRemoteImageProvider, IHasOrder
|
public class AudioDbArtistImageProvider : IRemoteImageProvider, IHasOrder
|
||||||
{
|
{
|
||||||
private readonly IServerConfigurationManager _config;
|
private readonly IServerConfigurationManager _config;
|
||||||
private readonly IHttpClient _httpClient;
|
private readonly IHttpClientFactory _httpClientFactory;
|
||||||
private readonly IJsonSerializer _json;
|
private readonly IJsonSerializer _json;
|
||||||
|
|
||||||
public AudioDbArtistImageProvider(IServerConfigurationManager config, IJsonSerializer json, IHttpClient httpClient)
|
public AudioDbArtistImageProvider(IServerConfigurationManager config, IJsonSerializer json, IHttpClientFactory httpClientFactory)
|
||||||
{
|
{
|
||||||
_config = config;
|
_config = config;
|
||||||
_json = json;
|
_json = json;
|
||||||
_httpClient = httpClient;
|
_httpClientFactory = httpClientFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
@ -135,13 +135,10 @@ namespace MediaBrowser.Providers.Plugins.AudioDb
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
|
public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
return _httpClient.GetResponse(new HttpRequestOptions
|
var httpClient = _httpClientFactory.CreateClient();
|
||||||
{
|
return httpClient.GetAsync(url, cancellationToken);
|
||||||
CancellationToken = cancellationToken,
|
|
||||||
Url = url
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|
|
@ -9,7 +9,6 @@ using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using MediaBrowser.Common.Configuration;
|
using MediaBrowser.Common.Configuration;
|
||||||
using MediaBrowser.Common.Extensions;
|
using MediaBrowser.Common.Extensions;
|
||||||
using MediaBrowser.Common.Net;
|
|
||||||
using MediaBrowser.Controller.Configuration;
|
using MediaBrowser.Controller.Configuration;
|
||||||
using MediaBrowser.Controller.Entities.Audio;
|
using MediaBrowser.Controller.Entities.Audio;
|
||||||
using MediaBrowser.Controller.Providers;
|
using MediaBrowser.Controller.Providers;
|
||||||
|
@ -25,7 +24,7 @@ namespace MediaBrowser.Providers.Plugins.AudioDb
|
||||||
{
|
{
|
||||||
private readonly IServerConfigurationManager _config;
|
private readonly IServerConfigurationManager _config;
|
||||||
private readonly IFileSystem _fileSystem;
|
private readonly IFileSystem _fileSystem;
|
||||||
private readonly IHttpClient _httpClient;
|
private readonly IHttpClientFactory _httpClientFactory;
|
||||||
private readonly IJsonSerializer _json;
|
private readonly IJsonSerializer _json;
|
||||||
|
|
||||||
public static AudioDbArtistProvider Current;
|
public static AudioDbArtistProvider Current;
|
||||||
|
@ -33,11 +32,11 @@ namespace MediaBrowser.Providers.Plugins.AudioDb
|
||||||
private const string ApiKey = "195003";
|
private const string ApiKey = "195003";
|
||||||
public const string BaseUrl = "https://www.theaudiodb.com/api/v1/json/" + ApiKey;
|
public const string BaseUrl = "https://www.theaudiodb.com/api/v1/json/" + ApiKey;
|
||||||
|
|
||||||
public AudioDbArtistProvider(IServerConfigurationManager config, IFileSystem fileSystem, IHttpClient httpClient, IJsonSerializer json)
|
public AudioDbArtistProvider(IServerConfigurationManager config, IFileSystem fileSystem, IHttpClientFactory httpClientFactory, IJsonSerializer json)
|
||||||
{
|
{
|
||||||
_config = config;
|
_config = config;
|
||||||
_fileSystem = fileSystem;
|
_fileSystem = fileSystem;
|
||||||
_httpClient = httpClient;
|
_httpClientFactory = httpClientFactory;
|
||||||
_json = json;
|
_json = json;
|
||||||
Current = this;
|
Current = this;
|
||||||
}
|
}
|
||||||
|
@ -155,23 +154,13 @@ namespace MediaBrowser.Providers.Plugins.AudioDb
|
||||||
|
|
||||||
var path = GetArtistInfoPath(_config.ApplicationPaths, musicBrainzId);
|
var path = GetArtistInfoPath(_config.ApplicationPaths, musicBrainzId);
|
||||||
|
|
||||||
using (var httpResponse = await _httpClient.SendAsync(
|
using var response = await _httpClientFactory.CreateClient().GetAsync(url, cancellationToken);
|
||||||
new HttpRequestOptions
|
await using var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
|
||||||
{
|
|
||||||
Url = url,
|
|
||||||
CancellationToken = cancellationToken,
|
|
||||||
BufferContent = true
|
|
||||||
},
|
|
||||||
HttpMethod.Get).ConfigureAwait(false))
|
|
||||||
using (var response = httpResponse.Content)
|
|
||||||
{
|
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(path));
|
|
||||||
|
|
||||||
using (var xmlFileStream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read, IODefaults.FileStreamBufferSize, true))
|
Directory.CreateDirectory(Path.GetDirectoryName(path));
|
||||||
{
|
|
||||||
await response.CopyToAsync(xmlFileStream).ConfigureAwait(false);
|
await using var xmlFileStream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read, IODefaults.FileStreamBufferSize, true);
|
||||||
}
|
await stream.CopyToAsync(xmlFileStream, cancellationToken).ConfigureAwait(false);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -289,7 +278,7 @@ namespace MediaBrowser.Providers.Plugins.AudioDb
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
|
public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,12 +8,12 @@ using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
|
using System.Net.Http.Headers;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
using MediaBrowser.Common;
|
using MediaBrowser.Common;
|
||||||
using MediaBrowser.Common.Net;
|
|
||||||
using MediaBrowser.Controller.Entities.Audio;
|
using MediaBrowser.Controller.Entities.Audio;
|
||||||
using MediaBrowser.Controller.Providers;
|
using MediaBrowser.Controller.Providers;
|
||||||
using MediaBrowser.Model.Entities;
|
using MediaBrowser.Model.Entities;
|
||||||
|
@ -42,7 +42,7 @@ namespace MediaBrowser.Providers.Music
|
||||||
|
|
||||||
internal static MusicBrainzAlbumProvider Current;
|
internal static MusicBrainzAlbumProvider Current;
|
||||||
|
|
||||||
private readonly IHttpClient _httpClient;
|
private readonly IHttpClientFactory _httpClientFactory;
|
||||||
private readonly IApplicationHost _appHost;
|
private readonly IApplicationHost _appHost;
|
||||||
private readonly ILogger<MusicBrainzAlbumProvider> _logger;
|
private readonly ILogger<MusicBrainzAlbumProvider> _logger;
|
||||||
|
|
||||||
|
@ -51,11 +51,11 @@ namespace MediaBrowser.Providers.Music
|
||||||
private Stopwatch _stopWatchMusicBrainz = new Stopwatch();
|
private Stopwatch _stopWatchMusicBrainz = new Stopwatch();
|
||||||
|
|
||||||
public MusicBrainzAlbumProvider(
|
public MusicBrainzAlbumProvider(
|
||||||
IHttpClient httpClient,
|
IHttpClientFactory httpClientFactory,
|
||||||
IApplicationHost appHost,
|
IApplicationHost appHost,
|
||||||
ILogger<MusicBrainzAlbumProvider> logger)
|
ILogger<MusicBrainzAlbumProvider> logger)
|
||||||
{
|
{
|
||||||
_httpClient = httpClient;
|
_httpClientFactory = httpClientFactory;
|
||||||
_appHost = appHost;
|
_appHost = appHost;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
|
||||||
|
@ -123,11 +123,9 @@ namespace MediaBrowser.Providers.Music
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(url))
|
if (!string.IsNullOrWhiteSpace(url))
|
||||||
{
|
{
|
||||||
using (var response = await GetMusicBrainzResponse(url, cancellationToken).ConfigureAwait(false))
|
using var response = await GetMusicBrainzResponse(url, cancellationToken).ConfigureAwait(false);
|
||||||
using (var stream = response.Content)
|
await using var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
|
||||||
{
|
return GetResultsFromResponse(stream);
|
||||||
return GetResultsFromResponse(stream);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Enumerable.Empty<RemoteSearchResult>();
|
return Enumerable.Empty<RemoteSearchResult>();
|
||||||
|
@ -282,23 +280,19 @@ namespace MediaBrowser.Providers.Music
|
||||||
WebUtility.UrlEncode(albumName),
|
WebUtility.UrlEncode(albumName),
|
||||||
artistId);
|
artistId);
|
||||||
|
|
||||||
using (var response = await GetMusicBrainzResponse(url, cancellationToken).ConfigureAwait(false))
|
using var response = await GetMusicBrainzResponse(url, cancellationToken).ConfigureAwait(false);
|
||||||
using (var stream = response.Content)
|
await using var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
|
||||||
using (var oReader = new StreamReader(stream, Encoding.UTF8))
|
using var oReader = new StreamReader(stream, Encoding.UTF8);
|
||||||
|
var settings = new XmlReaderSettings
|
||||||
{
|
{
|
||||||
var settings = new XmlReaderSettings()
|
ValidationType = ValidationType.None,
|
||||||
{
|
CheckCharacters = false,
|
||||||
ValidationType = ValidationType.None,
|
IgnoreProcessingInstructions = true,
|
||||||
CheckCharacters = false,
|
IgnoreComments = true
|
||||||
IgnoreProcessingInstructions = true,
|
};
|
||||||
IgnoreComments = true
|
|
||||||
};
|
|
||||||
|
|
||||||
using (var reader = XmlReader.Create(oReader, settings))
|
using var reader = XmlReader.Create(oReader, settings);
|
||||||
{
|
return ReleaseResult.Parse(reader).FirstOrDefault();
|
||||||
return ReleaseResult.Parse(reader).FirstOrDefault();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<ReleaseResult> GetReleaseResultByArtistName(string albumName, string artistName, CancellationToken cancellationToken)
|
private async Task<ReleaseResult> GetReleaseResultByArtistName(string albumName, string artistName, CancellationToken cancellationToken)
|
||||||
|
@ -309,23 +303,19 @@ namespace MediaBrowser.Providers.Music
|
||||||
WebUtility.UrlEncode(albumName),
|
WebUtility.UrlEncode(albumName),
|
||||||
WebUtility.UrlEncode(artistName));
|
WebUtility.UrlEncode(artistName));
|
||||||
|
|
||||||
using (var response = await GetMusicBrainzResponse(url, cancellationToken).ConfigureAwait(false))
|
using var response = await GetMusicBrainzResponse(url, cancellationToken).ConfigureAwait(false);
|
||||||
using (var stream = response.Content)
|
await using var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
|
||||||
using (var oReader = new StreamReader(stream, Encoding.UTF8))
|
using var oReader = new StreamReader(stream, Encoding.UTF8);
|
||||||
|
var settings = new XmlReaderSettings()
|
||||||
{
|
{
|
||||||
var settings = new XmlReaderSettings()
|
ValidationType = ValidationType.None,
|
||||||
{
|
CheckCharacters = false,
|
||||||
ValidationType = ValidationType.None,
|
IgnoreProcessingInstructions = true,
|
||||||
CheckCharacters = false,
|
IgnoreComments = true
|
||||||
IgnoreProcessingInstructions = true,
|
};
|
||||||
IgnoreComments = true
|
|
||||||
};
|
|
||||||
|
|
||||||
using (var reader = XmlReader.Create(oReader, settings))
|
using var reader = XmlReader.Create(oReader, settings);
|
||||||
{
|
return ReleaseResult.Parse(reader).FirstOrDefault();
|
||||||
return ReleaseResult.Parse(reader).FirstOrDefault();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ReleaseResult
|
private class ReleaseResult
|
||||||
|
@ -624,30 +614,21 @@ namespace MediaBrowser.Providers.Music
|
||||||
{
|
{
|
||||||
var url = "/ws/2/release?release-group=" + releaseGroupId.ToString(CultureInfo.InvariantCulture);
|
var url = "/ws/2/release?release-group=" + releaseGroupId.ToString(CultureInfo.InvariantCulture);
|
||||||
|
|
||||||
using (var response = await GetMusicBrainzResponse(url, cancellationToken).ConfigureAwait(false))
|
using var response = await GetMusicBrainzResponse(url, cancellationToken).ConfigureAwait(false);
|
||||||
using (var stream = response.Content)
|
await using var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
|
||||||
using (var oReader = new StreamReader(stream, Encoding.UTF8))
|
using var oReader = new StreamReader(stream, Encoding.UTF8);
|
||||||
|
var settings = new XmlReaderSettings
|
||||||
{
|
{
|
||||||
var settings = new XmlReaderSettings()
|
ValidationType = ValidationType.None,
|
||||||
{
|
CheckCharacters = false,
|
||||||
ValidationType = ValidationType.None,
|
IgnoreProcessingInstructions = true,
|
||||||
CheckCharacters = false,
|
IgnoreComments = true
|
||||||
IgnoreProcessingInstructions = true,
|
};
|
||||||
IgnoreComments = true
|
|
||||||
};
|
|
||||||
|
|
||||||
using (var reader = XmlReader.Create(oReader, settings))
|
using var reader = XmlReader.Create(oReader, settings);
|
||||||
{
|
var result = ReleaseResult.Parse(reader).FirstOrDefault();
|
||||||
var result = ReleaseResult.Parse(reader).FirstOrDefault();
|
|
||||||
|
|
||||||
if (result != null)
|
return result?.ReleaseId;
|
||||||
{
|
|
||||||
return result.ReleaseId;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -660,59 +641,57 @@ namespace MediaBrowser.Providers.Music
|
||||||
{
|
{
|
||||||
var url = "/ws/2/release-group/?query=reid:" + releaseEntryId.ToString(CultureInfo.InvariantCulture);
|
var url = "/ws/2/release-group/?query=reid:" + releaseEntryId.ToString(CultureInfo.InvariantCulture);
|
||||||
|
|
||||||
using (var response = await GetMusicBrainzResponse(url, cancellationToken).ConfigureAwait(false))
|
using var response = await GetMusicBrainzResponse(url, cancellationToken).ConfigureAwait(false);
|
||||||
using (var stream = response.Content)
|
await using var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
|
||||||
using (var oReader = new StreamReader(stream, Encoding.UTF8))
|
using var oReader = new StreamReader(stream, Encoding.UTF8);
|
||||||
|
var settings = new XmlReaderSettings
|
||||||
{
|
{
|
||||||
var settings = new XmlReaderSettings()
|
ValidationType = ValidationType.None,
|
||||||
{
|
CheckCharacters = false,
|
||||||
ValidationType = ValidationType.None,
|
IgnoreProcessingInstructions = true,
|
||||||
CheckCharacters = false,
|
IgnoreComments = true
|
||||||
IgnoreProcessingInstructions = true,
|
};
|
||||||
IgnoreComments = true
|
|
||||||
};
|
|
||||||
|
|
||||||
using (var reader = XmlReader.Create(oReader, settings))
|
using (var reader = XmlReader.Create(oReader, settings))
|
||||||
{
|
{
|
||||||
reader.MoveToContent();
|
reader.MoveToContent();
|
||||||
reader.Read();
|
reader.Read();
|
||||||
|
|
||||||
// Loop through each element
|
// Loop through each element
|
||||||
while (!reader.EOF && reader.ReadState == ReadState.Interactive)
|
while (!reader.EOF && reader.ReadState == ReadState.Interactive)
|
||||||
|
{
|
||||||
|
if (reader.NodeType == XmlNodeType.Element)
|
||||||
{
|
{
|
||||||
if (reader.NodeType == XmlNodeType.Element)
|
switch (reader.Name)
|
||||||
{
|
{
|
||||||
switch (reader.Name)
|
case "release-group-list":
|
||||||
{
|
{
|
||||||
case "release-group-list":
|
if (reader.IsEmptyElement)
|
||||||
{
|
{
|
||||||
if (reader.IsEmptyElement)
|
reader.Read();
|
||||||
{
|
continue;
|
||||||
reader.Read();
|
}
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
using (var subReader = reader.ReadSubtree())
|
using (var subReader = reader.ReadSubtree())
|
||||||
{
|
{
|
||||||
return GetFirstReleaseGroupId(subReader);
|
return GetFirstReleaseGroupId(subReader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
reader.Skip();
|
reader.Skip();
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
reader.Read();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
return null;
|
{
|
||||||
|
reader.Read();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -755,23 +734,19 @@ namespace MediaBrowser.Providers.Music
|
||||||
/// A number of retries shall be made in order to try and satisfy the request before
|
/// A number of retries shall be made in order to try and satisfy the request before
|
||||||
/// giving up and returning null.
|
/// giving up and returning null.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal async Task<HttpResponseInfo> GetMusicBrainzResponse(string url, CancellationToken cancellationToken)
|
internal async Task<HttpResponseMessage> GetMusicBrainzResponse(string url, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var options = new HttpRequestOptions
|
using var options = new HttpRequestMessage(HttpMethod.Get, _musicBrainzBaseUrl.TrimEnd('/') + url);
|
||||||
{
|
|
||||||
Url = _musicBrainzBaseUrl.TrimEnd('/') + url,
|
|
||||||
CancellationToken = cancellationToken,
|
|
||||||
// MusicBrainz request a contact email address is supplied, as comment, in user agent field:
|
|
||||||
// https://musicbrainz.org/doc/XML_Web_Service/Rate_Limiting#User-Agent
|
|
||||||
UserAgent = string.Format(
|
|
||||||
CultureInfo.InvariantCulture,
|
|
||||||
"{0} ( {1} )",
|
|
||||||
_appHost.ApplicationUserAgent,
|
|
||||||
_appHost.ApplicationUserAgentAddress),
|
|
||||||
BufferContent = false
|
|
||||||
};
|
|
||||||
|
|
||||||
HttpResponseInfo response;
|
// MusicBrainz request a contact email address is supplied, as comment, in user agent field:
|
||||||
|
// https://musicbrainz.org/doc/XML_Web_Service/Rate_Limiting#User-Agent
|
||||||
|
options.Headers.UserAgent.Add(new ProductInfoHeaderValue(string.Format(
|
||||||
|
CultureInfo.InvariantCulture,
|
||||||
|
"{0} ( {1} )",
|
||||||
|
_appHost.ApplicationUserAgent,
|
||||||
|
_appHost.ApplicationUserAgentAddress)));
|
||||||
|
|
||||||
|
HttpResponseMessage response;
|
||||||
var attempts = 0u;
|
var attempts = 0u;
|
||||||
|
|
||||||
do
|
do
|
||||||
|
@ -790,7 +765,7 @@ namespace MediaBrowser.Providers.Music
|
||||||
_logger.LogDebug("GetMusicBrainzResponse: Time since previous request: {0} ms", _stopWatchMusicBrainz.ElapsedMilliseconds);
|
_logger.LogDebug("GetMusicBrainzResponse: Time since previous request: {0} ms", _stopWatchMusicBrainz.ElapsedMilliseconds);
|
||||||
_stopWatchMusicBrainz.Restart();
|
_stopWatchMusicBrainz.Restart();
|
||||||
|
|
||||||
response = await _httpClient.SendAsync(options, HttpMethod.Get).ConfigureAwait(false);
|
response = await _httpClientFactory.CreateClient().SendAsync(options).ConfigureAwait(false);
|
||||||
|
|
||||||
// We retry a finite number of times, and only whilst MB is indicating 503 (throttling)
|
// We retry a finite number of times, and only whilst MB is indicating 503 (throttling)
|
||||||
}
|
}
|
||||||
|
@ -799,14 +774,14 @@ namespace MediaBrowser.Providers.Music
|
||||||
// Log error if unable to query MB database due to throttling
|
// Log error if unable to query MB database due to throttling
|
||||||
if (attempts == MusicBrainzQueryAttempts && response.StatusCode == HttpStatusCode.ServiceUnavailable)
|
if (attempts == MusicBrainzQueryAttempts && response.StatusCode == HttpStatusCode.ServiceUnavailable)
|
||||||
{
|
{
|
||||||
_logger.LogError("GetMusicBrainzResponse: 503 Service Unavailable (throttled) response received {0} times whilst requesting {1}", attempts, options.Url);
|
_logger.LogError("GetMusicBrainzResponse: 503 Service Unavailable (throttled) response received {0} times whilst requesting {1}", attempts, options.RequestUri);
|
||||||
}
|
}
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
|
public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,11 +6,11 @@ using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
using System.Net.Http;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
using MediaBrowser.Common.Net;
|
|
||||||
using MediaBrowser.Controller.Entities.Audio;
|
using MediaBrowser.Controller.Entities.Audio;
|
||||||
using MediaBrowser.Controller.Extensions;
|
using MediaBrowser.Controller.Extensions;
|
||||||
using MediaBrowser.Controller.Providers;
|
using MediaBrowser.Controller.Providers;
|
||||||
|
@ -37,11 +37,9 @@ namespace MediaBrowser.Providers.Music
|
||||||
{
|
{
|
||||||
var url = "/ws/2/artist/?query=arid:{0}" + musicBrainzId.ToString(CultureInfo.InvariantCulture);
|
var url = "/ws/2/artist/?query=arid:{0}" + musicBrainzId.ToString(CultureInfo.InvariantCulture);
|
||||||
|
|
||||||
using (var response = await MusicBrainzAlbumProvider.Current.GetMusicBrainzResponse(url, cancellationToken).ConfigureAwait(false))
|
using var response = await MusicBrainzAlbumProvider.Current.GetMusicBrainzResponse(url, cancellationToken).ConfigureAwait(false);
|
||||||
using (var stream = response.Content)
|
await using var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
|
||||||
{
|
return GetResultsFromResponse(stream);
|
||||||
return GetResultsFromResponse(stream);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -51,7 +49,7 @@ namespace MediaBrowser.Providers.Music
|
||||||
var url = string.Format("/ws/2/artist/?query=\"{0}\"&dismax=true", UrlEncode(nameToSearch));
|
var url = string.Format("/ws/2/artist/?query=\"{0}\"&dismax=true", UrlEncode(nameToSearch));
|
||||||
|
|
||||||
using (var response = await MusicBrainzAlbumProvider.Current.GetMusicBrainzResponse(url, cancellationToken).ConfigureAwait(false))
|
using (var response = await MusicBrainzAlbumProvider.Current.GetMusicBrainzResponse(url, cancellationToken).ConfigureAwait(false))
|
||||||
using (var stream = response.Content)
|
await using (var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false))
|
||||||
{
|
{
|
||||||
var results = GetResultsFromResponse(stream).ToList();
|
var results = GetResultsFromResponse(stream).ToList();
|
||||||
|
|
||||||
|
@ -66,13 +64,9 @@ namespace MediaBrowser.Providers.Music
|
||||||
// Try again using the search with accent characters url
|
// Try again using the search with accent characters url
|
||||||
url = string.Format("/ws/2/artist/?query=artistaccent:\"{0}\"", UrlEncode(nameToSearch));
|
url = string.Format("/ws/2/artist/?query=artistaccent:\"{0}\"", UrlEncode(nameToSearch));
|
||||||
|
|
||||||
using (var response = await MusicBrainzAlbumProvider.Current.GetMusicBrainzResponse(url, cancellationToken).ConfigureAwait(false))
|
using var response = await MusicBrainzAlbumProvider.Current.GetMusicBrainzResponse(url, cancellationToken).ConfigureAwait(false);
|
||||||
{
|
await using var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
|
||||||
using (var stream = response.Content)
|
return GetResultsFromResponse(stream);
|
||||||
{
|
|
||||||
return GetResultsFromResponse(stream);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -298,7 +292,7 @@ namespace MediaBrowser.Providers.Music
|
||||||
|
|
||||||
public string Name => "MusicBrainz";
|
public string Name => "MusicBrainz";
|
||||||
|
|
||||||
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
|
public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
#pragma warning disable CS1591
|
#pragma warning disable CS1591
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Net.Http;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using MediaBrowser.Common;
|
using MediaBrowser.Common;
|
||||||
using MediaBrowser.Common.Net;
|
|
||||||
using MediaBrowser.Controller.Configuration;
|
using MediaBrowser.Controller.Configuration;
|
||||||
using MediaBrowser.Controller.Entities.TV;
|
using MediaBrowser.Controller.Entities.TV;
|
||||||
using MediaBrowser.Controller.Library;
|
using MediaBrowser.Controller.Library;
|
||||||
|
@ -19,7 +19,7 @@ namespace MediaBrowser.Providers.Plugins.Omdb
|
||||||
public class OmdbEpisodeProvider : IRemoteMetadataProvider<Episode, EpisodeInfo>, IHasOrder
|
public class OmdbEpisodeProvider : IRemoteMetadataProvider<Episode, EpisodeInfo>, IHasOrder
|
||||||
{
|
{
|
||||||
private readonly IJsonSerializer _jsonSerializer;
|
private readonly IJsonSerializer _jsonSerializer;
|
||||||
private readonly IHttpClient _httpClient;
|
private readonly IHttpClientFactory _httpClientFactory;
|
||||||
private readonly OmdbItemProvider _itemProvider;
|
private readonly OmdbItemProvider _itemProvider;
|
||||||
private readonly IFileSystem _fileSystem;
|
private readonly IFileSystem _fileSystem;
|
||||||
private readonly IServerConfigurationManager _configurationManager;
|
private readonly IServerConfigurationManager _configurationManager;
|
||||||
|
@ -28,17 +28,17 @@ namespace MediaBrowser.Providers.Plugins.Omdb
|
||||||
public OmdbEpisodeProvider(
|
public OmdbEpisodeProvider(
|
||||||
IJsonSerializer jsonSerializer,
|
IJsonSerializer jsonSerializer,
|
||||||
IApplicationHost appHost,
|
IApplicationHost appHost,
|
||||||
IHttpClient httpClient,
|
IHttpClientFactory httpClientFactory,
|
||||||
ILibraryManager libraryManager,
|
ILibraryManager libraryManager,
|
||||||
IFileSystem fileSystem,
|
IFileSystem fileSystem,
|
||||||
IServerConfigurationManager configurationManager)
|
IServerConfigurationManager configurationManager)
|
||||||
{
|
{
|
||||||
_jsonSerializer = jsonSerializer;
|
_jsonSerializer = jsonSerializer;
|
||||||
_httpClient = httpClient;
|
_httpClientFactory = httpClientFactory;
|
||||||
_fileSystem = fileSystem;
|
_fileSystem = fileSystem;
|
||||||
_configurationManager = configurationManager;
|
_configurationManager = configurationManager;
|
||||||
_appHost = appHost;
|
_appHost = appHost;
|
||||||
_itemProvider = new OmdbItemProvider(jsonSerializer, _appHost, httpClient, libraryManager, fileSystem, configurationManager);
|
_itemProvider = new OmdbItemProvider(jsonSerializer, _appHost, httpClientFactory, libraryManager, fileSystem, configurationManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
// After TheTvDb
|
// After TheTvDb
|
||||||
|
@ -69,7 +69,7 @@ namespace MediaBrowser.Providers.Plugins.Omdb
|
||||||
{
|
{
|
||||||
if (info.IndexNumber.HasValue && info.ParentIndexNumber.HasValue)
|
if (info.IndexNumber.HasValue && info.ParentIndexNumber.HasValue)
|
||||||
{
|
{
|
||||||
result.HasMetadata = await new OmdbProvider(_jsonSerializer, _httpClient, _fileSystem, _appHost, _configurationManager)
|
result.HasMetadata = await new OmdbProvider(_jsonSerializer, _httpClientFactory, _fileSystem, _appHost, _configurationManager)
|
||||||
.FetchEpisodeData(result, info.IndexNumber.Value, info.ParentIndexNumber.Value, info.GetProviderId(MetadataProvider.Imdb), seriesImdbId, info.MetadataLanguage, info.MetadataCountryCode, cancellationToken).ConfigureAwait(false);
|
.FetchEpisodeData(result, info.IndexNumber.Value, info.ParentIndexNumber.Value, info.GetProviderId(MetadataProvider.Imdb), seriesImdbId, info.MetadataLanguage, info.MetadataCountryCode, cancellationToken).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -77,7 +77,7 @@ namespace MediaBrowser.Providers.Plugins.Omdb
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
|
public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
return _itemProvider.GetImageResponse(url, cancellationToken);
|
return _itemProvider.GetImageResponse(url, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
#pragma warning disable CS1591
|
#pragma warning disable CS1591
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Net.Http;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using MediaBrowser.Common;
|
using MediaBrowser.Common;
|
||||||
using MediaBrowser.Common.Net;
|
|
||||||
using MediaBrowser.Controller.Configuration;
|
using MediaBrowser.Controller.Configuration;
|
||||||
using MediaBrowser.Controller.Entities;
|
using MediaBrowser.Controller.Entities;
|
||||||
using MediaBrowser.Controller.Entities.Movies;
|
using MediaBrowser.Controller.Entities.Movies;
|
||||||
|
@ -19,16 +19,16 @@ namespace MediaBrowser.Providers.Plugins.Omdb
|
||||||
{
|
{
|
||||||
public class OmdbImageProvider : IRemoteImageProvider, IHasOrder
|
public class OmdbImageProvider : IRemoteImageProvider, IHasOrder
|
||||||
{
|
{
|
||||||
private readonly IHttpClient _httpClient;
|
private readonly IHttpClientFactory _httpClientFactory;
|
||||||
private readonly IJsonSerializer _jsonSerializer;
|
private readonly IJsonSerializer _jsonSerializer;
|
||||||
private readonly IFileSystem _fileSystem;
|
private readonly IFileSystem _fileSystem;
|
||||||
private readonly IServerConfigurationManager _configurationManager;
|
private readonly IServerConfigurationManager _configurationManager;
|
||||||
private readonly IApplicationHost _appHost;
|
private readonly IApplicationHost _appHost;
|
||||||
|
|
||||||
public OmdbImageProvider(IJsonSerializer jsonSerializer, IApplicationHost appHost, IHttpClient httpClient, IFileSystem fileSystem, IServerConfigurationManager configurationManager)
|
public OmdbImageProvider(IJsonSerializer jsonSerializer, IApplicationHost appHost, IHttpClientFactory httpClientFactory, IFileSystem fileSystem, IServerConfigurationManager configurationManager)
|
||||||
{
|
{
|
||||||
_jsonSerializer = jsonSerializer;
|
_jsonSerializer = jsonSerializer;
|
||||||
_httpClient = httpClient;
|
_httpClientFactory = httpClientFactory;
|
||||||
_fileSystem = fileSystem;
|
_fileSystem = fileSystem;
|
||||||
_configurationManager = configurationManager;
|
_configurationManager = configurationManager;
|
||||||
_appHost = appHost;
|
_appHost = appHost;
|
||||||
|
@ -48,7 +48,7 @@ namespace MediaBrowser.Providers.Plugins.Omdb
|
||||||
|
|
||||||
var list = new List<RemoteImageInfo>();
|
var list = new List<RemoteImageInfo>();
|
||||||
|
|
||||||
var provider = new OmdbProvider(_jsonSerializer, _httpClient, _fileSystem, _appHost, _configurationManager);
|
var provider = new OmdbProvider(_jsonSerializer, _httpClientFactory, _fileSystem, _appHost, _configurationManager);
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(imdbId))
|
if (!string.IsNullOrWhiteSpace(imdbId))
|
||||||
{
|
{
|
||||||
|
@ -79,13 +79,9 @@ namespace MediaBrowser.Providers.Plugins.Omdb
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
|
public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
return _httpClient.GetResponse(new HttpRequestOptions
|
return _httpClientFactory.CreateClient().GetAsync(url, cancellationToken);
|
||||||
{
|
|
||||||
CancellationToken = cancellationToken,
|
|
||||||
Url = url
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Name => "The Open Movie Database";
|
public string Name => "The Open Movie Database";
|
||||||
|
|
|
@ -5,10 +5,10 @@ using System.Collections.Generic;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
using System.Net.Http;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using MediaBrowser.Common;
|
using MediaBrowser.Common;
|
||||||
using MediaBrowser.Common.Net;
|
|
||||||
using MediaBrowser.Controller.Configuration;
|
using MediaBrowser.Controller.Configuration;
|
||||||
using MediaBrowser.Controller.Entities;
|
using MediaBrowser.Controller.Entities;
|
||||||
using MediaBrowser.Controller.Entities.Movies;
|
using MediaBrowser.Controller.Entities.Movies;
|
||||||
|
@ -26,7 +26,7 @@ namespace MediaBrowser.Providers.Plugins.Omdb
|
||||||
IRemoteMetadataProvider<Movie, MovieInfo>, IRemoteMetadataProvider<Trailer, TrailerInfo>, IHasOrder
|
IRemoteMetadataProvider<Movie, MovieInfo>, IRemoteMetadataProvider<Trailer, TrailerInfo>, IHasOrder
|
||||||
{
|
{
|
||||||
private readonly IJsonSerializer _jsonSerializer;
|
private readonly IJsonSerializer _jsonSerializer;
|
||||||
private readonly IHttpClient _httpClient;
|
private readonly IHttpClientFactory _httpClientFactory;
|
||||||
private readonly ILibraryManager _libraryManager;
|
private readonly ILibraryManager _libraryManager;
|
||||||
private readonly IFileSystem _fileSystem;
|
private readonly IFileSystem _fileSystem;
|
||||||
private readonly IServerConfigurationManager _configurationManager;
|
private readonly IServerConfigurationManager _configurationManager;
|
||||||
|
@ -35,13 +35,13 @@ namespace MediaBrowser.Providers.Plugins.Omdb
|
||||||
public OmdbItemProvider(
|
public OmdbItemProvider(
|
||||||
IJsonSerializer jsonSerializer,
|
IJsonSerializer jsonSerializer,
|
||||||
IApplicationHost appHost,
|
IApplicationHost appHost,
|
||||||
IHttpClient httpClient,
|
IHttpClientFactory httpClientFactory,
|
||||||
ILibraryManager libraryManager,
|
ILibraryManager libraryManager,
|
||||||
IFileSystem fileSystem,
|
IFileSystem fileSystem,
|
||||||
IServerConfigurationManager configurationManager)
|
IServerConfigurationManager configurationManager)
|
||||||
{
|
{
|
||||||
_jsonSerializer = jsonSerializer;
|
_jsonSerializer = jsonSerializer;
|
||||||
_httpClient = httpClient;
|
_httpClientFactory = httpClientFactory;
|
||||||
_libraryManager = libraryManager;
|
_libraryManager = libraryManager;
|
||||||
_fileSystem = fileSystem;
|
_fileSystem = fileSystem;
|
||||||
_configurationManager = configurationManager;
|
_configurationManager = configurationManager;
|
||||||
|
@ -129,67 +129,63 @@ namespace MediaBrowser.Providers.Plugins.Omdb
|
||||||
|
|
||||||
var url = OmdbProvider.GetOmdbUrl(urlQuery, _appHost, cancellationToken);
|
var url = OmdbProvider.GetOmdbUrl(urlQuery, _appHost, cancellationToken);
|
||||||
|
|
||||||
using (var response = await OmdbProvider.GetOmdbResponse(_httpClient, url, cancellationToken).ConfigureAwait(false))
|
using var response = await OmdbProvider.GetOmdbResponse(_httpClientFactory.CreateClient(), url, cancellationToken).ConfigureAwait(false);
|
||||||
|
await using var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
|
||||||
|
var resultList = new List<SearchResult>();
|
||||||
|
|
||||||
|
if (isSearch)
|
||||||
{
|
{
|
||||||
using (var stream = response.Content)
|
var searchResultList = await _jsonSerializer.DeserializeFromStreamAsync<SearchResultList>(stream).ConfigureAwait(false);
|
||||||
|
if (searchResultList != null && searchResultList.Search != null)
|
||||||
{
|
{
|
||||||
var resultList = new List<SearchResult>();
|
resultList.AddRange(searchResultList.Search);
|
||||||
|
|
||||||
if (isSearch)
|
|
||||||
{
|
|
||||||
var searchResultList = await _jsonSerializer.DeserializeFromStreamAsync<SearchResultList>(stream).ConfigureAwait(false);
|
|
||||||
if (searchResultList != null && searchResultList.Search != null)
|
|
||||||
{
|
|
||||||
resultList.AddRange(searchResultList.Search);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var result = await _jsonSerializer.DeserializeFromStreamAsync<SearchResult>(stream).ConfigureAwait(false);
|
|
||||||
if (string.Equals(result.Response, "true", StringComparison.OrdinalIgnoreCase))
|
|
||||||
{
|
|
||||||
resultList.Add(result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return resultList.Select(result =>
|
|
||||||
{
|
|
||||||
var item = new RemoteSearchResult
|
|
||||||
{
|
|
||||||
IndexNumber = searchInfo.IndexNumber,
|
|
||||||
Name = result.Title,
|
|
||||||
ParentIndexNumber = searchInfo.ParentIndexNumber,
|
|
||||||
SearchProviderName = Name
|
|
||||||
};
|
|
||||||
|
|
||||||
if (episodeSearchInfo != null && episodeSearchInfo.IndexNumberEnd.HasValue)
|
|
||||||
{
|
|
||||||
item.IndexNumberEnd = episodeSearchInfo.IndexNumberEnd.Value;
|
|
||||||
}
|
|
||||||
|
|
||||||
item.SetProviderId(MetadataProvider.Imdb, result.imdbID);
|
|
||||||
|
|
||||||
if (result.Year.Length > 0
|
|
||||||
&& int.TryParse(result.Year.AsSpan().Slice(0, Math.Min(result.Year.Length, 4)), NumberStyles.Integer, CultureInfo.InvariantCulture, out var parsedYear))
|
|
||||||
{
|
|
||||||
item.ProductionYear = parsedYear;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(result.Released)
|
|
||||||
&& DateTime.TryParse(result.Released, CultureInfo.InvariantCulture, DateTimeStyles.AllowWhiteSpaces, out var released))
|
|
||||||
{
|
|
||||||
item.PremiereDate = released;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(result.Poster) && !string.Equals(result.Poster, "N/A", StringComparison.OrdinalIgnoreCase))
|
|
||||||
{
|
|
||||||
item.ImageUrl = result.Poster;
|
|
||||||
}
|
|
||||||
|
|
||||||
return item;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var result = await _jsonSerializer.DeserializeFromStreamAsync<SearchResult>(stream).ConfigureAwait(false);
|
||||||
|
if (string.Equals(result.Response, "true", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
resultList.Add(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return resultList.Select(result =>
|
||||||
|
{
|
||||||
|
var item = new RemoteSearchResult
|
||||||
|
{
|
||||||
|
IndexNumber = searchInfo.IndexNumber,
|
||||||
|
Name = result.Title,
|
||||||
|
ParentIndexNumber = searchInfo.ParentIndexNumber,
|
||||||
|
SearchProviderName = Name
|
||||||
|
};
|
||||||
|
|
||||||
|
if (episodeSearchInfo != null && episodeSearchInfo.IndexNumberEnd.HasValue)
|
||||||
|
{
|
||||||
|
item.IndexNumberEnd = episodeSearchInfo.IndexNumberEnd.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
item.SetProviderId(MetadataProvider.Imdb, result.imdbID);
|
||||||
|
|
||||||
|
if (result.Year.Length > 0
|
||||||
|
&& int.TryParse(result.Year.AsSpan().Slice(0, Math.Min(result.Year.Length, 4)), NumberStyles.Integer, CultureInfo.InvariantCulture, out var parsedYear))
|
||||||
|
{
|
||||||
|
item.ProductionYear = parsedYear;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(result.Released)
|
||||||
|
&& DateTime.TryParse(result.Released, CultureInfo.InvariantCulture, DateTimeStyles.AllowWhiteSpaces, out var released))
|
||||||
|
{
|
||||||
|
item.PremiereDate = released;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(result.Poster) && !string.Equals(result.Poster, "N/A", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
item.ImageUrl = result.Poster;
|
||||||
|
}
|
||||||
|
|
||||||
|
return item;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<MetadataResult<Trailer>> GetMetadata(TrailerInfo info, CancellationToken cancellationToken)
|
public Task<MetadataResult<Trailer>> GetMetadata(TrailerInfo info, CancellationToken cancellationToken)
|
||||||
|
@ -224,7 +220,7 @@ namespace MediaBrowser.Providers.Plugins.Omdb
|
||||||
result.Item.SetProviderId(MetadataProvider.Imdb, imdbId);
|
result.Item.SetProviderId(MetadataProvider.Imdb, imdbId);
|
||||||
result.HasMetadata = true;
|
result.HasMetadata = true;
|
||||||
|
|
||||||
await new OmdbProvider(_jsonSerializer, _httpClient, _fileSystem, _appHost, _configurationManager).Fetch(result, imdbId, info.MetadataLanguage, info.MetadataCountryCode, cancellationToken).ConfigureAwait(false);
|
await new OmdbProvider(_jsonSerializer, _httpClientFactory, _fileSystem, _appHost, _configurationManager).Fetch(result, imdbId, info.MetadataLanguage, info.MetadataCountryCode, cancellationToken).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -256,7 +252,7 @@ namespace MediaBrowser.Providers.Plugins.Omdb
|
||||||
result.Item.SetProviderId(MetadataProvider.Imdb, imdbId);
|
result.Item.SetProviderId(MetadataProvider.Imdb, imdbId);
|
||||||
result.HasMetadata = true;
|
result.HasMetadata = true;
|
||||||
|
|
||||||
await new OmdbProvider(_jsonSerializer, _httpClient, _fileSystem, _appHost, _configurationManager).Fetch(result, imdbId, info.MetadataLanguage, info.MetadataCountryCode, cancellationToken).ConfigureAwait(false);
|
await new OmdbProvider(_jsonSerializer, _httpClientFactory, _fileSystem, _appHost, _configurationManager).Fetch(result, imdbId, info.MetadataLanguage, info.MetadataCountryCode, cancellationToken).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -276,13 +272,9 @@ namespace MediaBrowser.Providers.Plugins.Omdb
|
||||||
return first == null ? null : first.GetProviderId(MetadataProvider.Imdb);
|
return first == null ? null : first.GetProviderId(MetadataProvider.Imdb);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
|
public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
return _httpClient.GetResponse(new HttpRequestOptions
|
return _httpClientFactory.CreateClient().GetAsync(url, cancellationToken);
|
||||||
{
|
|
||||||
CancellationToken = cancellationToken,
|
|
||||||
Url = url
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class SearchResult
|
class SearchResult
|
||||||
|
|
|
@ -10,7 +10,6 @@ using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using MediaBrowser.Common;
|
using MediaBrowser.Common;
|
||||||
using MediaBrowser.Common.Net;
|
|
||||||
using MediaBrowser.Controller.Configuration;
|
using MediaBrowser.Controller.Configuration;
|
||||||
using MediaBrowser.Controller.Entities;
|
using MediaBrowser.Controller.Entities;
|
||||||
using MediaBrowser.Controller.Providers;
|
using MediaBrowser.Controller.Providers;
|
||||||
|
@ -25,14 +24,14 @@ namespace MediaBrowser.Providers.Plugins.Omdb
|
||||||
private readonly IJsonSerializer _jsonSerializer;
|
private readonly IJsonSerializer _jsonSerializer;
|
||||||
private readonly IFileSystem _fileSystem;
|
private readonly IFileSystem _fileSystem;
|
||||||
private readonly IServerConfigurationManager _configurationManager;
|
private readonly IServerConfigurationManager _configurationManager;
|
||||||
private readonly IHttpClient _httpClient;
|
private readonly IHttpClientFactory _httpClientFactory;
|
||||||
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
|
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
|
||||||
private readonly IApplicationHost _appHost;
|
private readonly IApplicationHost _appHost;
|
||||||
|
|
||||||
public OmdbProvider(IJsonSerializer jsonSerializer, IHttpClient httpClient, IFileSystem fileSystem, IApplicationHost appHost, IServerConfigurationManager configurationManager)
|
public OmdbProvider(IJsonSerializer jsonSerializer, IHttpClientFactory httpClientFactory, IFileSystem fileSystem, IApplicationHost appHost, IServerConfigurationManager configurationManager)
|
||||||
{
|
{
|
||||||
_jsonSerializer = jsonSerializer;
|
_jsonSerializer = jsonSerializer;
|
||||||
_httpClient = httpClient;
|
_httpClientFactory = httpClientFactory;
|
||||||
_fileSystem = fileSystem;
|
_fileSystem = fileSystem;
|
||||||
_configurationManager = configurationManager;
|
_configurationManager = configurationManager;
|
||||||
_appHost = appHost;
|
_appHost = appHost;
|
||||||
|
@ -293,15 +292,11 @@ namespace MediaBrowser.Providers.Plugins.Omdb
|
||||||
|
|
||||||
var url = GetOmdbUrl(string.Format("i={0}&plot=short&tomatoes=true&r=json", imdbParam), _appHost, cancellationToken);
|
var url = GetOmdbUrl(string.Format("i={0}&plot=short&tomatoes=true&r=json", imdbParam), _appHost, cancellationToken);
|
||||||
|
|
||||||
using (var response = await GetOmdbResponse(_httpClient, url, cancellationToken).ConfigureAwait(false))
|
using var response = await GetOmdbResponse(_httpClientFactory.CreateClient(), url, cancellationToken).ConfigureAwait(false);
|
||||||
{
|
await using var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
|
||||||
using (var stream = response.Content)
|
var rootObject = await _jsonSerializer.DeserializeFromStreamAsync<RootObject>(stream).ConfigureAwait(false);
|
||||||
{
|
Directory.CreateDirectory(Path.GetDirectoryName(path));
|
||||||
var rootObject = await _jsonSerializer.DeserializeFromStreamAsync<RootObject>(stream).ConfigureAwait(false);
|
_jsonSerializer.SerializeToFile(rootObject, path);
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(path));
|
|
||||||
_jsonSerializer.SerializeToFile(rootObject, path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
@ -330,28 +325,18 @@ namespace MediaBrowser.Providers.Plugins.Omdb
|
||||||
|
|
||||||
var url = GetOmdbUrl(string.Format("i={0}&season={1}&detail=full", imdbParam, seasonId), _appHost, cancellationToken);
|
var url = GetOmdbUrl(string.Format("i={0}&season={1}&detail=full", imdbParam, seasonId), _appHost, cancellationToken);
|
||||||
|
|
||||||
using (var response = await GetOmdbResponse(_httpClient, url, cancellationToken).ConfigureAwait(false))
|
using var response = await GetOmdbResponse(_httpClientFactory.CreateClient(), url, cancellationToken).ConfigureAwait(false);
|
||||||
{
|
await using var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
|
||||||
using (var stream = response.Content)
|
var rootObject = await _jsonSerializer.DeserializeFromStreamAsync<SeasonRootObject>(stream).ConfigureAwait(false);
|
||||||
{
|
Directory.CreateDirectory(Path.GetDirectoryName(path));
|
||||||
var rootObject = await _jsonSerializer.DeserializeFromStreamAsync<SeasonRootObject>(stream).ConfigureAwait(false);
|
_jsonSerializer.SerializeToFile(rootObject, path);
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(path));
|
|
||||||
_jsonSerializer.SerializeToFile(rootObject, path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Task<HttpResponseInfo> GetOmdbResponse(IHttpClient httpClient, string url, CancellationToken cancellationToken)
|
public static Task<HttpResponseMessage> GetOmdbResponse(HttpClient httpClient, string url, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
return httpClient.SendAsync(new HttpRequestOptions
|
return httpClient.GetAsync(url, cancellationToken);
|
||||||
{
|
|
||||||
Url = url,
|
|
||||||
CancellationToken = cancellationToken,
|
|
||||||
BufferContent = true,
|
|
||||||
EnableDefaultUserAgent = true
|
|
||||||
}, HttpMethod.Get);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal string GetDataFilePath(string imdbId)
|
internal string GetDataFilePath(string imdbId)
|
||||||
|
|
|
@ -2,9 +2,9 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Net.Http;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using MediaBrowser.Common.Net;
|
|
||||||
using MediaBrowser.Controller.Entities;
|
using MediaBrowser.Controller.Entities;
|
||||||
using MediaBrowser.Controller.Entities.TV;
|
using MediaBrowser.Controller.Entities.TV;
|
||||||
using MediaBrowser.Controller.Providers;
|
using MediaBrowser.Controller.Providers;
|
||||||
|
@ -18,13 +18,13 @@ namespace MediaBrowser.Providers.Plugins.TheTvdb
|
||||||
{
|
{
|
||||||
public class TvdbEpisodeImageProvider : IRemoteImageProvider
|
public class TvdbEpisodeImageProvider : IRemoteImageProvider
|
||||||
{
|
{
|
||||||
private readonly IHttpClient _httpClient;
|
private readonly IHttpClientFactory _httpClientFactory;
|
||||||
private readonly ILogger<TvdbEpisodeImageProvider> _logger;
|
private readonly ILogger<TvdbEpisodeImageProvider> _logger;
|
||||||
private readonly TvdbClientManager _tvdbClientManager;
|
private readonly TvdbClientManager _tvdbClientManager;
|
||||||
|
|
||||||
public TvdbEpisodeImageProvider(IHttpClient httpClient, ILogger<TvdbEpisodeImageProvider> logger, TvdbClientManager tvdbClientManager)
|
public TvdbEpisodeImageProvider(IHttpClientFactory httpClientFactory, ILogger<TvdbEpisodeImageProvider> logger, TvdbClientManager tvdbClientManager)
|
||||||
{
|
{
|
||||||
_httpClient = httpClient;
|
_httpClientFactory = httpClientFactory;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_tvdbClientManager = tvdbClientManager;
|
_tvdbClientManager = tvdbClientManager;
|
||||||
}
|
}
|
||||||
|
@ -113,13 +113,9 @@ namespace MediaBrowser.Providers.Plugins.TheTvdb
|
||||||
|
|
||||||
public int Order => 0;
|
public int Order => 0;
|
||||||
|
|
||||||
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
|
public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
return _httpClient.GetResponse(new HttpRequestOptions
|
return _httpClientFactory.CreateClient().GetAsync(url, cancellationToken);
|
||||||
{
|
|
||||||
CancellationToken = cancellationToken,
|
|
||||||
Url = url
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,9 +2,9 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Net.Http;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using MediaBrowser.Common.Net;
|
|
||||||
using MediaBrowser.Controller.Entities;
|
using MediaBrowser.Controller.Entities;
|
||||||
using MediaBrowser.Controller.Entities.TV;
|
using MediaBrowser.Controller.Entities.TV;
|
||||||
using MediaBrowser.Controller.Providers;
|
using MediaBrowser.Controller.Providers;
|
||||||
|
@ -21,13 +21,13 @@ namespace MediaBrowser.Providers.Plugins.TheTvdb
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class TvdbEpisodeProvider : IRemoteMetadataProvider<Episode, EpisodeInfo>, IHasOrder
|
public class TvdbEpisodeProvider : IRemoteMetadataProvider<Episode, EpisodeInfo>, IHasOrder
|
||||||
{
|
{
|
||||||
private readonly IHttpClient _httpClient;
|
private readonly IHttpClientFactory _httpClientFactory;
|
||||||
private readonly ILogger<TvdbEpisodeProvider> _logger;
|
private readonly ILogger<TvdbEpisodeProvider> _logger;
|
||||||
private readonly TvdbClientManager _tvdbClientManager;
|
private readonly TvdbClientManager _tvdbClientManager;
|
||||||
|
|
||||||
public TvdbEpisodeProvider(IHttpClient httpClient, ILogger<TvdbEpisodeProvider> logger, TvdbClientManager tvdbClientManager)
|
public TvdbEpisodeProvider(IHttpClientFactory httpClientFactory, ILogger<TvdbEpisodeProvider> logger, TvdbClientManager tvdbClientManager)
|
||||||
{
|
{
|
||||||
_httpClient = httpClient;
|
_httpClientFactory = httpClientFactory;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_tvdbClientManager = tvdbClientManager;
|
_tvdbClientManager = tvdbClientManager;
|
||||||
}
|
}
|
||||||
|
@ -242,13 +242,9 @@ namespace MediaBrowser.Providers.Plugins.TheTvdb
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
|
public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
return _httpClient.GetResponse(new HttpRequestOptions
|
return _httpClientFactory.CreateClient().GetAsync(url, cancellationToken);
|
||||||
{
|
|
||||||
CancellationToken = cancellationToken,
|
|
||||||
Url = url
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Order => 0;
|
public int Order => 0;
|
||||||
|
|
|
@ -3,9 +3,9 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Net.Http;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using MediaBrowser.Common.Net;
|
|
||||||
using MediaBrowser.Controller.Dto;
|
using MediaBrowser.Controller.Dto;
|
||||||
using MediaBrowser.Controller.Entities;
|
using MediaBrowser.Controller.Entities;
|
||||||
using MediaBrowser.Controller.Entities.TV;
|
using MediaBrowser.Controller.Entities.TV;
|
||||||
|
@ -20,15 +20,15 @@ namespace MediaBrowser.Providers.Plugins.TheTvdb
|
||||||
{
|
{
|
||||||
public class TvdbPersonImageProvider : IRemoteImageProvider, IHasOrder
|
public class TvdbPersonImageProvider : IRemoteImageProvider, IHasOrder
|
||||||
{
|
{
|
||||||
private readonly IHttpClient _httpClient;
|
private readonly IHttpClientFactory _httpClientFactory;
|
||||||
private readonly ILogger<TvdbPersonImageProvider> _logger;
|
private readonly ILogger<TvdbPersonImageProvider> _logger;
|
||||||
private readonly ILibraryManager _libraryManager;
|
private readonly ILibraryManager _libraryManager;
|
||||||
private readonly TvdbClientManager _tvdbClientManager;
|
private readonly TvdbClientManager _tvdbClientManager;
|
||||||
|
|
||||||
public TvdbPersonImageProvider(ILibraryManager libraryManager, IHttpClient httpClient, ILogger<TvdbPersonImageProvider> logger, TvdbClientManager tvdbClientManager)
|
public TvdbPersonImageProvider(ILibraryManager libraryManager, IHttpClientFactory httpClientFactory, ILogger<TvdbPersonImageProvider> logger, TvdbClientManager tvdbClientManager)
|
||||||
{
|
{
|
||||||
_libraryManager = libraryManager;
|
_libraryManager = libraryManager;
|
||||||
_httpClient = httpClient;
|
_httpClientFactory = httpClientFactory;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_tvdbClientManager = tvdbClientManager;
|
_tvdbClientManager = tvdbClientManager;
|
||||||
}
|
}
|
||||||
|
@ -104,13 +104,9 @@ namespace MediaBrowser.Providers.Plugins.TheTvdb
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
|
public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
return _httpClient.GetResponse(new HttpRequestOptions
|
return _httpClientFactory.CreateClient().GetAsync(url, cancellationToken);
|
||||||
{
|
|
||||||
CancellationToken = cancellationToken,
|
|
||||||
Url = url
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,9 +3,9 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Net.Http;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using MediaBrowser.Common.Net;
|
|
||||||
using MediaBrowser.Controller.Entities;
|
using MediaBrowser.Controller.Entities;
|
||||||
using MediaBrowser.Controller.Entities.TV;
|
using MediaBrowser.Controller.Entities.TV;
|
||||||
using MediaBrowser.Controller.Providers;
|
using MediaBrowser.Controller.Providers;
|
||||||
|
@ -20,13 +20,13 @@ namespace MediaBrowser.Providers.Plugins.TheTvdb
|
||||||
{
|
{
|
||||||
public class TvdbSeasonImageProvider : IRemoteImageProvider, IHasOrder
|
public class TvdbSeasonImageProvider : IRemoteImageProvider, IHasOrder
|
||||||
{
|
{
|
||||||
private readonly IHttpClient _httpClient;
|
private readonly IHttpClientFactory _httpClientFactory;
|
||||||
private readonly ILogger<TvdbSeasonImageProvider> _logger;
|
private readonly ILogger<TvdbSeasonImageProvider> _logger;
|
||||||
private readonly TvdbClientManager _tvdbClientManager;
|
private readonly TvdbClientManager _tvdbClientManager;
|
||||||
|
|
||||||
public TvdbSeasonImageProvider(IHttpClient httpClient, ILogger<TvdbSeasonImageProvider> logger, TvdbClientManager tvdbClientManager)
|
public TvdbSeasonImageProvider(IHttpClientFactory httpClientFactory, ILogger<TvdbSeasonImageProvider> logger, TvdbClientManager tvdbClientManager)
|
||||||
{
|
{
|
||||||
_httpClient = httpClient;
|
_httpClientFactory = httpClientFactory;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_tvdbClientManager = tvdbClientManager;
|
_tvdbClientManager = tvdbClientManager;
|
||||||
}
|
}
|
||||||
|
@ -146,13 +146,9 @@ namespace MediaBrowser.Providers.Plugins.TheTvdb
|
||||||
|
|
||||||
public int Order => 0;
|
public int Order => 0;
|
||||||
|
|
||||||
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
|
public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
return _httpClient.GetResponse(new HttpRequestOptions
|
return _httpClientFactory.CreateClient().GetAsync(url, cancellationToken);
|
||||||
{
|
|
||||||
CancellationToken = cancellationToken,
|
|
||||||
Url = url
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,9 +3,9 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Net.Http;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using MediaBrowser.Common.Net;
|
|
||||||
using MediaBrowser.Controller.Entities;
|
using MediaBrowser.Controller.Entities;
|
||||||
using MediaBrowser.Controller.Providers;
|
using MediaBrowser.Controller.Providers;
|
||||||
using MediaBrowser.Model.Entities;
|
using MediaBrowser.Model.Entities;
|
||||||
|
@ -20,13 +20,13 @@ namespace MediaBrowser.Providers.Plugins.TheTvdb
|
||||||
{
|
{
|
||||||
public class TvdbSeriesImageProvider : IRemoteImageProvider, IHasOrder
|
public class TvdbSeriesImageProvider : IRemoteImageProvider, IHasOrder
|
||||||
{
|
{
|
||||||
private readonly IHttpClient _httpClient;
|
private readonly IHttpClientFactory _httpClientFactory;
|
||||||
private readonly ILogger<TvdbSeriesImageProvider> _logger;
|
private readonly ILogger<TvdbSeriesImageProvider> _logger;
|
||||||
private readonly TvdbClientManager _tvdbClientManager;
|
private readonly TvdbClientManager _tvdbClientManager;
|
||||||
|
|
||||||
public TvdbSeriesImageProvider(IHttpClient httpClient, ILogger<TvdbSeriesImageProvider> logger, TvdbClientManager tvdbClientManager)
|
public TvdbSeriesImageProvider(IHttpClientFactory httpClientFactory, ILogger<TvdbSeriesImageProvider> logger, TvdbClientManager tvdbClientManager)
|
||||||
{
|
{
|
||||||
_httpClient = httpClient;
|
_httpClientFactory = httpClientFactory;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_tvdbClientManager = tvdbClientManager;
|
_tvdbClientManager = tvdbClientManager;
|
||||||
}
|
}
|
||||||
|
@ -144,13 +144,9 @@ namespace MediaBrowser.Providers.Plugins.TheTvdb
|
||||||
|
|
||||||
public int Order => 0;
|
public int Order => 0;
|
||||||
|
|
||||||
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
|
public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
return _httpClient.GetResponse(new HttpRequestOptions
|
return _httpClientFactory.CreateClient().GetAsync(url, cancellationToken);
|
||||||
{
|
|
||||||
CancellationToken = cancellationToken,
|
|
||||||
Url = url
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,11 +3,11 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Net.Http;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using MediaBrowser.Common.Net;
|
|
||||||
using MediaBrowser.Controller.Entities;
|
using MediaBrowser.Controller.Entities;
|
||||||
using MediaBrowser.Controller.Library;
|
using MediaBrowser.Controller.Library;
|
||||||
using MediaBrowser.Controller.Providers;
|
using MediaBrowser.Controller.Providers;
|
||||||
|
@ -25,15 +25,15 @@ namespace MediaBrowser.Providers.Plugins.TheTvdb
|
||||||
{
|
{
|
||||||
internal static TvdbSeriesProvider Current { get; private set; }
|
internal static TvdbSeriesProvider Current { get; private set; }
|
||||||
|
|
||||||
private readonly IHttpClient _httpClient;
|
private readonly IHttpClientFactory _httpClientFactory;
|
||||||
private readonly ILogger<TvdbSeriesProvider> _logger;
|
private readonly ILogger<TvdbSeriesProvider> _logger;
|
||||||
private readonly ILibraryManager _libraryManager;
|
private readonly ILibraryManager _libraryManager;
|
||||||
private readonly ILocalizationManager _localizationManager;
|
private readonly ILocalizationManager _localizationManager;
|
||||||
private readonly TvdbClientManager _tvdbClientManager;
|
private readonly TvdbClientManager _tvdbClientManager;
|
||||||
|
|
||||||
public TvdbSeriesProvider(IHttpClient httpClient, ILogger<TvdbSeriesProvider> logger, ILibraryManager libraryManager, ILocalizationManager localizationManager, TvdbClientManager tvdbClientManager)
|
public TvdbSeriesProvider(IHttpClientFactory httpClientFactory, ILogger<TvdbSeriesProvider> logger, ILibraryManager libraryManager, ILocalizationManager localizationManager, TvdbClientManager tvdbClientManager)
|
||||||
{
|
{
|
||||||
_httpClient = httpClient;
|
_httpClientFactory = httpClientFactory;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_libraryManager = libraryManager;
|
_libraryManager = libraryManager;
|
||||||
_localizationManager = localizationManager;
|
_localizationManager = localizationManager;
|
||||||
|
@ -408,14 +408,9 @@ namespace MediaBrowser.Providers.Plugins.TheTvdb
|
||||||
|
|
||||||
public int Order => 0;
|
public int Order => 0;
|
||||||
|
|
||||||
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
|
public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
return _httpClient.GetResponse(new HttpRequestOptions
|
return _httpClientFactory.CreateClient().GetAsync(url, cancellationToken);
|
||||||
{
|
|
||||||
CancellationToken = cancellationToken,
|
|
||||||
Url = url,
|
|
||||||
BufferContent = false
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,9 +3,9 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Net.Http;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using MediaBrowser.Common.Net;
|
|
||||||
using MediaBrowser.Controller.Entities;
|
using MediaBrowser.Controller.Entities;
|
||||||
using MediaBrowser.Controller.Entities.Movies;
|
using MediaBrowser.Controller.Entities.Movies;
|
||||||
using MediaBrowser.Controller.Providers;
|
using MediaBrowser.Controller.Providers;
|
||||||
|
@ -20,11 +20,11 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.BoxSets
|
||||||
{
|
{
|
||||||
public class TmdbBoxSetImageProvider : IRemoteImageProvider, IHasOrder
|
public class TmdbBoxSetImageProvider : IRemoteImageProvider, IHasOrder
|
||||||
{
|
{
|
||||||
private readonly IHttpClient _httpClient;
|
private readonly IHttpClientFactory _httpClientFactory;
|
||||||
|
|
||||||
public TmdbBoxSetImageProvider(IHttpClient httpClient)
|
public TmdbBoxSetImageProvider(IHttpClientFactory httpClientFactory)
|
||||||
{
|
{
|
||||||
_httpClient = httpClient;
|
_httpClientFactory = httpClientFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Name => ProviderName;
|
public string Name => ProviderName;
|
||||||
|
@ -153,13 +153,9 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.BoxSets
|
||||||
|
|
||||||
public int Order => 0;
|
public int Order => 0;
|
||||||
|
|
||||||
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
|
public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
return _httpClient.GetResponse(new HttpRequestOptions
|
return _httpClientFactory.CreateClient().GetAsync(url, cancellationToken);
|
||||||
{
|
|
||||||
CancellationToken = cancellationToken,
|
|
||||||
Url = url
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,10 +5,11 @@ using System.Collections.Generic;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Net.Http.Headers;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using MediaBrowser.Common.Configuration;
|
using MediaBrowser.Common.Configuration;
|
||||||
using MediaBrowser.Common.Net;
|
|
||||||
using MediaBrowser.Controller.Configuration;
|
using MediaBrowser.Controller.Configuration;
|
||||||
using MediaBrowser.Controller.Entities.Movies;
|
using MediaBrowser.Controller.Entities.Movies;
|
||||||
using MediaBrowser.Controller.Library;
|
using MediaBrowser.Controller.Library;
|
||||||
|
@ -36,7 +37,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.BoxSets
|
||||||
private readonly IServerConfigurationManager _config;
|
private readonly IServerConfigurationManager _config;
|
||||||
private readonly IFileSystem _fileSystem;
|
private readonly IFileSystem _fileSystem;
|
||||||
private readonly ILocalizationManager _localization;
|
private readonly ILocalizationManager _localization;
|
||||||
private readonly IHttpClient _httpClient;
|
private readonly IHttpClientFactory _httpClientFactory;
|
||||||
private readonly ILibraryManager _libraryManager;
|
private readonly ILibraryManager _libraryManager;
|
||||||
|
|
||||||
public TmdbBoxSetProvider(
|
public TmdbBoxSetProvider(
|
||||||
|
@ -45,7 +46,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.BoxSets
|
||||||
IServerConfigurationManager config,
|
IServerConfigurationManager config,
|
||||||
IFileSystem fileSystem,
|
IFileSystem fileSystem,
|
||||||
ILocalizationManager localization,
|
ILocalizationManager localization,
|
||||||
IHttpClient httpClient,
|
IHttpClientFactory httpClientFactory,
|
||||||
ILibraryManager libraryManager)
|
ILibraryManager libraryManager)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
@ -53,7 +54,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.BoxSets
|
||||||
_config = config;
|
_config = config;
|
||||||
_fileSystem = fileSystem;
|
_fileSystem = fileSystem;
|
||||||
_localization = localization;
|
_localization = localization;
|
||||||
_httpClient = httpClient;
|
_httpClientFactory = httpClientFactory;
|
||||||
_libraryManager = libraryManager;
|
_libraryManager = libraryManager;
|
||||||
Current = this;
|
Current = this;
|
||||||
}
|
}
|
||||||
|
@ -187,21 +188,16 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.BoxSets
|
||||||
|
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
|
|
||||||
CollectionResult mainResult;
|
using var requestMessage = new HttpRequestMessage(HttpMethod.Get, url);
|
||||||
|
foreach (var header in TmdbUtils.AcceptHeaders)
|
||||||
using (var response = await TmdbMovieProvider.Current.GetMovieDbResponse(new HttpRequestOptions
|
|
||||||
{
|
{
|
||||||
Url = url,
|
requestMessage.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(header));
|
||||||
CancellationToken = cancellationToken,
|
|
||||||
AcceptHeader = TmdbUtils.AcceptHeader
|
|
||||||
}).ConfigureAwait(false))
|
|
||||||
{
|
|
||||||
using (var json = response.Content)
|
|
||||||
{
|
|
||||||
mainResult = await _json.DeserializeFromStreamAsync<CollectionResult>(json).ConfigureAwait(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
using var mainResponse = await TmdbMovieProvider.Current.GetMovieDbResponse(requestMessage);
|
||||||
|
await using var stream = await mainResponse.Content.ReadAsStreamAsync().ConfigureAwait(false);
|
||||||
|
var mainResult = await _json.DeserializeFromStreamAsync<CollectionResult>(stream).ConfigureAwait(false);
|
||||||
|
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
|
|
||||||
if (mainResult != null && string.IsNullOrEmpty(mainResult.Name))
|
if (mainResult != null && string.IsNullOrEmpty(mainResult.Name))
|
||||||
|
@ -216,18 +212,14 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.BoxSets
|
||||||
url += "&include_image_language=" + TmdbMovieProvider.GetImageLanguagesParam(language);
|
url += "&include_image_language=" + TmdbMovieProvider.GetImageLanguagesParam(language);
|
||||||
}
|
}
|
||||||
|
|
||||||
using (var response = await TmdbMovieProvider.Current.GetMovieDbResponse(new HttpRequestOptions
|
using var langRequestMessage = new HttpRequestMessage(HttpMethod.Get, url);
|
||||||
|
foreach (var header in TmdbUtils.AcceptHeaders)
|
||||||
{
|
{
|
||||||
Url = url,
|
langRequestMessage.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(header));
|
||||||
CancellationToken = cancellationToken,
|
|
||||||
AcceptHeader = TmdbUtils.AcceptHeader
|
|
||||||
}).ConfigureAwait(false))
|
|
||||||
{
|
|
||||||
using (var json = response.Content)
|
|
||||||
{
|
|
||||||
mainResult = await _json.DeserializeFromStreamAsync<CollectionResult>(json).ConfigureAwait(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await using var langStream = await mainResponse.Content.ReadAsStreamAsync().ConfigureAwait(false);
|
||||||
|
mainResult = await _json.DeserializeFromStreamAsync<CollectionResult>(langStream).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -277,13 +269,9 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.BoxSets
|
||||||
return dataPath;
|
return dataPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
|
public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
return _httpClient.GetResponse(new HttpRequestOptions
|
return _httpClientFactory.CreateClient().GetAsync(url, cancellationToken);
|
||||||
{
|
|
||||||
CancellationToken = cancellationToken,
|
|
||||||
Url = url
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,9 +4,9 @@ using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Net.Http;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using MediaBrowser.Common.Net;
|
|
||||||
using MediaBrowser.Controller.Entities;
|
using MediaBrowser.Controller.Entities;
|
||||||
using MediaBrowser.Controller.Entities.Movies;
|
using MediaBrowser.Controller.Entities.Movies;
|
||||||
using MediaBrowser.Controller.Providers;
|
using MediaBrowser.Controller.Providers;
|
||||||
|
@ -23,13 +23,13 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.Movies
|
||||||
public class TmdbImageProvider : IRemoteImageProvider, IHasOrder
|
public class TmdbImageProvider : IRemoteImageProvider, IHasOrder
|
||||||
{
|
{
|
||||||
private readonly IJsonSerializer _jsonSerializer;
|
private readonly IJsonSerializer _jsonSerializer;
|
||||||
private readonly IHttpClient _httpClient;
|
private readonly IHttpClientFactory _httpClientFactory;
|
||||||
private readonly IFileSystem _fileSystem;
|
private readonly IFileSystem _fileSystem;
|
||||||
|
|
||||||
public TmdbImageProvider(IJsonSerializer jsonSerializer, IHttpClient httpClient, IFileSystem fileSystem)
|
public TmdbImageProvider(IJsonSerializer jsonSerializer, IHttpClientFactory httpClientFactory, IFileSystem fileSystem)
|
||||||
{
|
{
|
||||||
_jsonSerializer = jsonSerializer;
|
_jsonSerializer = jsonSerializer;
|
||||||
_httpClient = httpClient;
|
_httpClientFactory = httpClientFactory;
|
||||||
_fileSystem = fileSystem;
|
_fileSystem = fileSystem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,13 +202,9 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.Movies
|
||||||
|
|
||||||
public int Order => 0;
|
public int Order => 0;
|
||||||
|
|
||||||
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
|
public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
return _httpClient.GetResponse(new HttpRequestOptions
|
return _httpClientFactory.CreateClient().GetAsync(url, cancellationToken);
|
||||||
{
|
|
||||||
CancellationToken = cancellationToken,
|
|
||||||
Url = url
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,11 +6,11 @@ using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
|
using System.Net.Http.Headers;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using MediaBrowser.Common;
|
using MediaBrowser.Common;
|
||||||
using MediaBrowser.Common.Configuration;
|
using MediaBrowser.Common.Configuration;
|
||||||
using MediaBrowser.Common.Net;
|
|
||||||
using MediaBrowser.Controller.Configuration;
|
using MediaBrowser.Controller.Configuration;
|
||||||
using MediaBrowser.Controller.Entities;
|
using MediaBrowser.Controller.Entities;
|
||||||
using MediaBrowser.Controller.Entities.Movies;
|
using MediaBrowser.Controller.Entities.Movies;
|
||||||
|
@ -18,7 +18,6 @@ using MediaBrowser.Controller.Library;
|
||||||
using MediaBrowser.Controller.Providers;
|
using MediaBrowser.Controller.Providers;
|
||||||
using MediaBrowser.Model.Entities;
|
using MediaBrowser.Model.Entities;
|
||||||
using MediaBrowser.Model.IO;
|
using MediaBrowser.Model.IO;
|
||||||
using MediaBrowser.Model.Net;
|
|
||||||
using MediaBrowser.Model.Providers;
|
using MediaBrowser.Model.Providers;
|
||||||
using MediaBrowser.Model.Serialization;
|
using MediaBrowser.Model.Serialization;
|
||||||
using MediaBrowser.Providers.Plugins.Tmdb.Models.Movies;
|
using MediaBrowser.Providers.Plugins.Tmdb.Models.Movies;
|
||||||
|
@ -34,7 +33,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.Movies
|
||||||
internal static TmdbMovieProvider Current { get; private set; }
|
internal static TmdbMovieProvider Current { get; private set; }
|
||||||
|
|
||||||
private readonly IJsonSerializer _jsonSerializer;
|
private readonly IJsonSerializer _jsonSerializer;
|
||||||
private readonly IHttpClient _httpClient;
|
private readonly IHttpClientFactory _httpClientFactory;
|
||||||
private readonly IFileSystem _fileSystem;
|
private readonly IFileSystem _fileSystem;
|
||||||
private readonly IServerConfigurationManager _configurationManager;
|
private readonly IServerConfigurationManager _configurationManager;
|
||||||
private readonly ILogger<TmdbMovieProvider> _logger;
|
private readonly ILogger<TmdbMovieProvider> _logger;
|
||||||
|
@ -45,7 +44,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.Movies
|
||||||
|
|
||||||
public TmdbMovieProvider(
|
public TmdbMovieProvider(
|
||||||
IJsonSerializer jsonSerializer,
|
IJsonSerializer jsonSerializer,
|
||||||
IHttpClient httpClient,
|
IHttpClientFactory httpClientFactory,
|
||||||
IFileSystem fileSystem,
|
IFileSystem fileSystem,
|
||||||
IServerConfigurationManager configurationManager,
|
IServerConfigurationManager configurationManager,
|
||||||
ILogger<TmdbMovieProvider> logger,
|
ILogger<TmdbMovieProvider> logger,
|
||||||
|
@ -53,7 +52,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.Movies
|
||||||
IApplicationHost appHost)
|
IApplicationHost appHost)
|
||||||
{
|
{
|
||||||
_jsonSerializer = jsonSerializer;
|
_jsonSerializer = jsonSerializer;
|
||||||
_httpClient = httpClient;
|
_httpClientFactory = httpClientFactory;
|
||||||
_fileSystem = fileSystem;
|
_fileSystem = fileSystem;
|
||||||
_configurationManager = configurationManager;
|
_configurationManager = configurationManager;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
@ -146,20 +145,16 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.Movies
|
||||||
return _tmdbSettings;
|
return _tmdbSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
using (HttpResponseInfo response = await GetMovieDbResponse(new HttpRequestOptions
|
using var requestMessage = new HttpRequestMessage(HttpMethod.Get, string.Format(CultureInfo.InvariantCulture, TmdbConfigUrl, TmdbUtils.ApiKey));
|
||||||
|
foreach (var header in TmdbUtils.AcceptHeaders)
|
||||||
{
|
{
|
||||||
Url = string.Format(CultureInfo.InvariantCulture, TmdbConfigUrl, TmdbUtils.ApiKey),
|
requestMessage.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(header));
|
||||||
CancellationToken = cancellationToken,
|
|
||||||
AcceptHeader = TmdbUtils.AcceptHeader
|
|
||||||
}).ConfigureAwait(false))
|
|
||||||
{
|
|
||||||
using (Stream json = response.Content)
|
|
||||||
{
|
|
||||||
_tmdbSettings = await _jsonSerializer.DeserializeFromStreamAsync<TmdbSettingsResult>(json).ConfigureAwait(false);
|
|
||||||
|
|
||||||
return _tmdbSettings;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
using var response = await GetMovieDbResponse(requestMessage).ConfigureAwait(false);
|
||||||
|
await using var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
|
||||||
|
_tmdbSettings = await _jsonSerializer.DeserializeFromStreamAsync<TmdbSettingsResult>(stream).ConfigureAwait(false);
|
||||||
|
return _tmdbSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
private const string TmdbConfigUrl = TmdbUtils.BaseTmdbApiUrl + "3/configuration?api_key={0}";
|
private const string TmdbConfigUrl = TmdbUtils.BaseTmdbApiUrl + "3/configuration?api_key={0}";
|
||||||
|
@ -331,42 +326,23 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.Movies
|
||||||
url += "&include_image_language=" + GetImageLanguagesParam(language);
|
url += "&include_image_language=" + GetImageLanguagesParam(language);
|
||||||
}
|
}
|
||||||
|
|
||||||
MovieResult mainResult;
|
|
||||||
|
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
|
|
||||||
// Cache if not using a tmdbId because we won't have the tmdb cache directory structure. So use the lower level cache.
|
using var requestMessage = new HttpRequestMessage(HttpMethod.Get, url);
|
||||||
var cacheMode = isTmdbId ? CacheMode.None : CacheMode.Unconditional;
|
foreach (var header in TmdbUtils.AcceptHeaders)
|
||||||
var cacheLength = TimeSpan.FromDays(3);
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
using (var response = await GetMovieDbResponse(new HttpRequestOptions
|
requestMessage.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(header));
|
||||||
{
|
|
||||||
Url = url,
|
|
||||||
CancellationToken = cancellationToken,
|
|
||||||
AcceptHeader = TmdbUtils.AcceptHeader,
|
|
||||||
CacheMode = cacheMode,
|
|
||||||
CacheLength = cacheLength
|
|
||||||
}).ConfigureAwait(false))
|
|
||||||
{
|
|
||||||
using (var json = response.Content)
|
|
||||||
{
|
|
||||||
mainResult = await _jsonSerializer.DeserializeFromStreamAsync<MovieResult>(json).ConfigureAwait(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (HttpException ex)
|
|
||||||
{
|
|
||||||
// Return null so that callers know there is no metadata for this id
|
|
||||||
if (ex.StatusCode.HasValue && ex.StatusCode.Value == HttpStatusCode.NotFound)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw;
|
using var mainResponse = await GetMovieDbResponse(requestMessage);
|
||||||
|
if (mainResponse.StatusCode == HttpStatusCode.NotFound)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await using var stream = await mainResponse.Content.ReadAsStreamAsync().ConfigureAwait(false);
|
||||||
|
var mainResult = await _jsonSerializer.DeserializeFromStreamAsync<MovieResult>(stream).ConfigureAwait(false);
|
||||||
|
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
|
|
||||||
// If the language preference isn't english, then have the overview fallback to english if it's blank
|
// If the language preference isn't english, then have the overview fallback to english if it's blank
|
||||||
|
@ -385,22 +361,17 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.Movies
|
||||||
url += "&include_image_language=" + GetImageLanguagesParam(language);
|
url += "&include_image_language=" + GetImageLanguagesParam(language);
|
||||||
}
|
}
|
||||||
|
|
||||||
using (var response = await GetMovieDbResponse(new HttpRequestOptions
|
using var langRequestMessage = new HttpRequestMessage(HttpMethod.Get, url);
|
||||||
|
foreach (var header in TmdbUtils.AcceptHeaders)
|
||||||
{
|
{
|
||||||
Url = url,
|
langRequestMessage.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(header));
|
||||||
CancellationToken = cancellationToken,
|
|
||||||
AcceptHeader = TmdbUtils.AcceptHeader,
|
|
||||||
CacheMode = cacheMode,
|
|
||||||
CacheLength = cacheLength
|
|
||||||
}).ConfigureAwait(false))
|
|
||||||
{
|
|
||||||
using (var json = response.Content)
|
|
||||||
{
|
|
||||||
var englishResult = await _jsonSerializer.DeserializeFromStreamAsync<MovieResult>(json).ConfigureAwait(false);
|
|
||||||
|
|
||||||
mainResult.Overview = englishResult.Overview;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
using var langResponse = await GetMovieDbResponse(langRequestMessage);
|
||||||
|
|
||||||
|
await using var langStream = await langResponse.Content.ReadAsStreamAsync().ConfigureAwait(false);
|
||||||
|
var langResult = await _jsonSerializer.DeserializeFromStreamAsync<MovieResult>(stream).ConfigureAwait(false);
|
||||||
|
mainResult.Overview = langResult.Overview;
|
||||||
}
|
}
|
||||||
|
|
||||||
return mainResult;
|
return mainResult;
|
||||||
|
@ -409,25 +380,19 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.Movies
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the movie db response.
|
/// Gets the movie db response.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal async Task<HttpResponseInfo> GetMovieDbResponse(HttpRequestOptions options)
|
internal async Task<HttpResponseMessage> GetMovieDbResponse(HttpRequestMessage message)
|
||||||
{
|
{
|
||||||
options.BufferContent = true;
|
message.Headers.UserAgent.Add(new ProductInfoHeaderValue(_appHost.ApplicationUserAgent));
|
||||||
options.UserAgent = _appHost.ApplicationUserAgent;
|
return await _httpClientFactory.CreateClient().SendAsync(message);
|
||||||
|
|
||||||
return await _httpClient.SendAsync(options, HttpMethod.Get).ConfigureAwait(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public int Order => 1;
|
public int Order => 1;
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
|
public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
return _httpClient.GetResponse(new HttpRequestOptions
|
return _httpClientFactory.CreateClient().GetAsync(url, cancellationToken);
|
||||||
{
|
|
||||||
CancellationToken = cancellationToken,
|
|
||||||
Url = url
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,10 +5,11 @@ using System.Collections.Generic;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Net.Http.Headers;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using MediaBrowser.Common.Net;
|
|
||||||
using MediaBrowser.Controller.Library;
|
using MediaBrowser.Controller.Library;
|
||||||
using MediaBrowser.Controller.Providers;
|
using MediaBrowser.Controller.Providers;
|
||||||
using MediaBrowser.Model.Entities;
|
using MediaBrowser.Model.Entities;
|
||||||
|
@ -168,47 +169,38 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.Movies
|
||||||
|
|
||||||
var url3 = string.Format(_searchURL, WebUtility.UrlEncode(name), TmdbUtils.ApiKey, language, type);
|
var url3 = string.Format(_searchURL, WebUtility.UrlEncode(name), TmdbUtils.ApiKey, language, type);
|
||||||
|
|
||||||
using (var response = await TmdbMovieProvider.Current.GetMovieDbResponse(new HttpRequestOptions
|
var requestMessage = new HttpRequestMessage(HttpMethod.Get, url3);
|
||||||
|
foreach (var header in TmdbUtils.AcceptHeaders)
|
||||||
{
|
{
|
||||||
Url = url3,
|
requestMessage.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(header));
|
||||||
CancellationToken = cancellationToken,
|
|
||||||
AcceptHeader = TmdbUtils.AcceptHeader
|
|
||||||
|
|
||||||
}).ConfigureAwait(false))
|
|
||||||
{
|
|
||||||
using (var json = response.Content)
|
|
||||||
{
|
|
||||||
var searchResults = await _json.DeserializeFromStreamAsync<TmdbSearchResult<MovieResult>>(json).ConfigureAwait(false);
|
|
||||||
|
|
||||||
var results = searchResults.Results ?? new List<MovieResult>();
|
|
||||||
|
|
||||||
return results
|
|
||||||
.Select(i =>
|
|
||||||
{
|
|
||||||
var remoteResult = new RemoteSearchResult
|
|
||||||
{
|
|
||||||
SearchProviderName = TmdbMovieProvider.Current.Name,
|
|
||||||
Name = i.Title ?? i.Name ?? i.Original_Title,
|
|
||||||
ImageUrl = string.IsNullOrWhiteSpace(i.Poster_Path) ? null : baseImageUrl + i.Poster_Path
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(i.Release_Date))
|
|
||||||
{
|
|
||||||
// These dates are always in this exact format
|
|
||||||
if (DateTime.TryParseExact(i.Release_Date, "yyyy-MM-dd", _usCulture, DateTimeStyles.None, out var r))
|
|
||||||
{
|
|
||||||
remoteResult.PremiereDate = r.ToUniversalTime();
|
|
||||||
remoteResult.ProductionYear = remoteResult.PremiereDate.Value.Year;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
remoteResult.SetProviderId(MetadataProvider.Tmdb, i.Id.ToString(_usCulture));
|
|
||||||
|
|
||||||
return remoteResult;
|
|
||||||
})
|
|
||||||
.ToList();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
using var response = await TmdbMovieProvider.Current.GetMovieDbResponse(requestMessage).ConfigureAwait(false);
|
||||||
|
await using var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
|
||||||
|
var searchResults = await _json.DeserializeFromStreamAsync<TmdbSearchResult<MovieResult>>(stream).ConfigureAwait(false);
|
||||||
|
|
||||||
|
var results = searchResults.Results ?? new List<MovieResult>();
|
||||||
|
|
||||||
|
return results
|
||||||
|
.Select(i =>
|
||||||
|
{
|
||||||
|
var remoteResult = new RemoteSearchResult {SearchProviderName = TmdbMovieProvider.Current.Name, Name = i.Title ?? i.Name ?? i.Original_Title, ImageUrl = string.IsNullOrWhiteSpace(i.Poster_Path) ? null : baseImageUrl + i.Poster_Path};
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(i.Release_Date))
|
||||||
|
{
|
||||||
|
// These dates are always in this exact format
|
||||||
|
if (DateTime.TryParseExact(i.Release_Date, "yyyy-MM-dd", _usCulture, DateTimeStyles.None, out var r))
|
||||||
|
{
|
||||||
|
remoteResult.PremiereDate = r.ToUniversalTime();
|
||||||
|
remoteResult.ProductionYear = remoteResult.PremiereDate.Value.Year;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
remoteResult.SetProviderId(MetadataProvider.Tmdb, i.Id.ToString(_usCulture));
|
||||||
|
|
||||||
|
return remoteResult;
|
||||||
|
})
|
||||||
|
.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<List<RemoteSearchResult>> GetSearchResultsTv(string name, int? year, string language, string baseImageUrl, CancellationToken cancellationToken)
|
private async Task<List<RemoteSearchResult>> GetSearchResultsTv(string name, int? year, string language, string baseImageUrl, CancellationToken cancellationToken)
|
||||||
|
@ -220,46 +212,38 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.Movies
|
||||||
|
|
||||||
var url3 = string.Format(_searchURL, WebUtility.UrlEncode(name), TmdbUtils.ApiKey, language, "tv");
|
var url3 = string.Format(_searchURL, WebUtility.UrlEncode(name), TmdbUtils.ApiKey, language, "tv");
|
||||||
|
|
||||||
using (var response = await TmdbMovieProvider.Current.GetMovieDbResponse(new HttpRequestOptions
|
var requestMessage = new HttpRequestMessage(HttpMethod.Get, url3);
|
||||||
|
foreach (var header in TmdbUtils.AcceptHeaders)
|
||||||
{
|
{
|
||||||
Url = url3,
|
requestMessage.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(header));
|
||||||
CancellationToken = cancellationToken,
|
|
||||||
AcceptHeader = TmdbUtils.AcceptHeader
|
|
||||||
}).ConfigureAwait(false))
|
|
||||||
{
|
|
||||||
using (var json = response.Content)
|
|
||||||
{
|
|
||||||
var searchResults = await _json.DeserializeFromStreamAsync<TmdbSearchResult<TvResult>>(json).ConfigureAwait(false);
|
|
||||||
|
|
||||||
var results = searchResults.Results ?? new List<TvResult>();
|
|
||||||
|
|
||||||
return results
|
|
||||||
.Select(i =>
|
|
||||||
{
|
|
||||||
var remoteResult = new RemoteSearchResult
|
|
||||||
{
|
|
||||||
SearchProviderName = TmdbMovieProvider.Current.Name,
|
|
||||||
Name = i.Name ?? i.Original_Name,
|
|
||||||
ImageUrl = string.IsNullOrWhiteSpace(i.Poster_Path) ? null : baseImageUrl + i.Poster_Path
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(i.First_Air_Date))
|
|
||||||
{
|
|
||||||
// These dates are always in this exact format
|
|
||||||
if (DateTime.TryParseExact(i.First_Air_Date, "yyyy-MM-dd", _usCulture, DateTimeStyles.None, out var r))
|
|
||||||
{
|
|
||||||
remoteResult.PremiereDate = r.ToUniversalTime();
|
|
||||||
remoteResult.ProductionYear = remoteResult.PremiereDate.Value.Year;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
remoteResult.SetProviderId(MetadataProvider.Tmdb, i.Id.ToString(_usCulture));
|
|
||||||
|
|
||||||
return remoteResult;
|
|
||||||
})
|
|
||||||
.ToList();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
using var response = await TmdbMovieProvider.Current.GetMovieDbResponse(requestMessage).ConfigureAwait(false);
|
||||||
|
await using var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
|
||||||
|
var searchResults = await _json.DeserializeFromStreamAsync<TmdbSearchResult<TvResult>>(stream).ConfigureAwait(false);
|
||||||
|
|
||||||
|
var results = searchResults.Results ?? new List<TvResult>();
|
||||||
|
|
||||||
|
return results
|
||||||
|
.Select(i =>
|
||||||
|
{
|
||||||
|
var remoteResult = new RemoteSearchResult {SearchProviderName = TmdbMovieProvider.Current.Name, Name = i.Name ?? i.Original_Name, ImageUrl = string.IsNullOrWhiteSpace(i.Poster_Path) ? null : baseImageUrl + i.Poster_Path};
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(i.First_Air_Date))
|
||||||
|
{
|
||||||
|
// These dates are always in this exact format
|
||||||
|
if (DateTime.TryParseExact(i.First_Air_Date, "yyyy-MM-dd", _usCulture, DateTimeStyles.None, out var r))
|
||||||
|
{
|
||||||
|
remoteResult.PremiereDate = r.ToUniversalTime();
|
||||||
|
remoteResult.ProductionYear = remoteResult.PremiereDate.Value.Year;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
remoteResult.SetProviderId(MetadataProvider.Tmdb, i.Id.ToString(_usCulture));
|
||||||
|
|
||||||
|
return remoteResult;
|
||||||
|
})
|
||||||
|
.ToList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,9 +2,9 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Net.Http;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using MediaBrowser.Common.Net;
|
|
||||||
using MediaBrowser.Controller.Entities;
|
using MediaBrowser.Controller.Entities;
|
||||||
using MediaBrowser.Controller.Providers;
|
using MediaBrowser.Controller.Providers;
|
||||||
using MediaBrowser.Model.Providers;
|
using MediaBrowser.Model.Providers;
|
||||||
|
@ -26,7 +26,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.Music
|
||||||
|
|
||||||
public string Name => TmdbMovieProvider.Current.Name;
|
public string Name => TmdbMovieProvider.Current.Name;
|
||||||
|
|
||||||
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
|
public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,9 +3,9 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Net.Http;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using MediaBrowser.Common.Net;
|
|
||||||
using MediaBrowser.Controller.Configuration;
|
using MediaBrowser.Controller.Configuration;
|
||||||
using MediaBrowser.Controller.Entities;
|
using MediaBrowser.Controller.Entities;
|
||||||
using MediaBrowser.Controller.Providers;
|
using MediaBrowser.Controller.Providers;
|
||||||
|
@ -22,13 +22,13 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.People
|
||||||
{
|
{
|
||||||
private readonly IServerConfigurationManager _config;
|
private readonly IServerConfigurationManager _config;
|
||||||
private readonly IJsonSerializer _jsonSerializer;
|
private readonly IJsonSerializer _jsonSerializer;
|
||||||
private readonly IHttpClient _httpClient;
|
private readonly IHttpClientFactory _httpClientFactory;
|
||||||
|
|
||||||
public TmdbPersonImageProvider(IServerConfigurationManager config, IJsonSerializer jsonSerializer, IHttpClient httpClient)
|
public TmdbPersonImageProvider(IServerConfigurationManager config, IJsonSerializer jsonSerializer, IHttpClientFactory httpClientFactory)
|
||||||
{
|
{
|
||||||
_config = config;
|
_config = config;
|
||||||
_jsonSerializer = jsonSerializer;
|
_jsonSerializer = jsonSerializer;
|
||||||
_httpClient = httpClient;
|
_httpClientFactory = httpClientFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Name => ProviderName;
|
public string Name => ProviderName;
|
||||||
|
@ -127,13 +127,9 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.People
|
||||||
|
|
||||||
public int Order => 0;
|
public int Order => 0;
|
||||||
|
|
||||||
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
|
public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
return _httpClient.GetResponse(new HttpRequestOptions
|
return _httpClientFactory.CreateClient().GetAsync(url, cancellationToken);
|
||||||
{
|
|
||||||
CancellationToken = cancellationToken,
|
|
||||||
Url = url
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,11 +6,12 @@ using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Net.Http.Headers;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using MediaBrowser.Common.Configuration;
|
using MediaBrowser.Common.Configuration;
|
||||||
using MediaBrowser.Common.Extensions;
|
using MediaBrowser.Common.Extensions;
|
||||||
using MediaBrowser.Common.Net;
|
|
||||||
using MediaBrowser.Controller.Configuration;
|
using MediaBrowser.Controller.Configuration;
|
||||||
using MediaBrowser.Controller.Entities;
|
using MediaBrowser.Controller.Entities;
|
||||||
using MediaBrowser.Controller.Providers;
|
using MediaBrowser.Controller.Providers;
|
||||||
|
@ -36,20 +37,20 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.People
|
||||||
private readonly IJsonSerializer _jsonSerializer;
|
private readonly IJsonSerializer _jsonSerializer;
|
||||||
private readonly IFileSystem _fileSystem;
|
private readonly IFileSystem _fileSystem;
|
||||||
private readonly IServerConfigurationManager _configurationManager;
|
private readonly IServerConfigurationManager _configurationManager;
|
||||||
private readonly IHttpClient _httpClient;
|
private readonly IHttpClientFactory _httpClientFactory;
|
||||||
private readonly ILogger<TmdbPersonProvider> _logger;
|
private readonly ILogger<TmdbPersonProvider> _logger;
|
||||||
|
|
||||||
public TmdbPersonProvider(
|
public TmdbPersonProvider(
|
||||||
IFileSystem fileSystem,
|
IFileSystem fileSystem,
|
||||||
IServerConfigurationManager configurationManager,
|
IServerConfigurationManager configurationManager,
|
||||||
IJsonSerializer jsonSerializer,
|
IJsonSerializer jsonSerializer,
|
||||||
IHttpClient httpClient,
|
IHttpClientFactory httpClientFactory,
|
||||||
ILogger<TmdbPersonProvider> logger)
|
ILogger<TmdbPersonProvider> logger)
|
||||||
{
|
{
|
||||||
_fileSystem = fileSystem;
|
_fileSystem = fileSystem;
|
||||||
_configurationManager = configurationManager;
|
_configurationManager = configurationManager;
|
||||||
_jsonSerializer = jsonSerializer;
|
_jsonSerializer = jsonSerializer;
|
||||||
_httpClient = httpClient;
|
_httpClientFactory = httpClientFactory;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
Current = this;
|
Current = this;
|
||||||
}
|
}
|
||||||
|
@ -96,22 +97,19 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.People
|
||||||
|
|
||||||
var url = string.Format(TmdbUtils.BaseTmdbApiUrl + @"3/search/person?api_key={1}&query={0}", WebUtility.UrlEncode(searchInfo.Name), TmdbUtils.ApiKey);
|
var url = string.Format(TmdbUtils.BaseTmdbApiUrl + @"3/search/person?api_key={1}&query={0}", WebUtility.UrlEncode(searchInfo.Name), TmdbUtils.ApiKey);
|
||||||
|
|
||||||
using (var response = await TmdbMovieProvider.Current.GetMovieDbResponse(new HttpRequestOptions
|
using var requestMessage = new HttpRequestMessage(HttpMethod.Get, url);
|
||||||
|
foreach (var header in TmdbUtils.AcceptHeaders)
|
||||||
{
|
{
|
||||||
Url = url,
|
requestMessage.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(header));
|
||||||
CancellationToken = cancellationToken,
|
|
||||||
AcceptHeader = TmdbUtils.AcceptHeader
|
|
||||||
|
|
||||||
}).ConfigureAwait(false))
|
|
||||||
{
|
|
||||||
using (var json = response.Content)
|
|
||||||
{
|
|
||||||
var result = await _jsonSerializer.DeserializeFromStreamAsync<TmdbSearchResult<PersonSearchResult>>(json).ConfigureAwait(false) ??
|
|
||||||
new TmdbSearchResult<PersonSearchResult>();
|
|
||||||
|
|
||||||
return result.Results.Select(i => GetSearchResult(i, tmdbImageUrl));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var response = await TmdbMovieProvider.Current.GetMovieDbResponse(requestMessage).ConfigureAwait(false);
|
||||||
|
await using var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
|
var result2 = await _jsonSerializer.DeserializeFromStreamAsync<TmdbSearchResult<PersonSearchResult>>(stream).ConfigureAwait(false)
|
||||||
|
?? new TmdbSearchResult<PersonSearchResult>();
|
||||||
|
|
||||||
|
return result2.Results.Select(i => GetSearchResult(i, tmdbImageUrl));
|
||||||
}
|
}
|
||||||
|
|
||||||
private RemoteSearchResult GetSearchResult(PersonSearchResult i, string baseImageUrl)
|
private RemoteSearchResult GetSearchResult(PersonSearchResult i, string baseImageUrl)
|
||||||
|
@ -230,23 +228,16 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.People
|
||||||
|
|
||||||
var url = string.Format(TmdbUtils.BaseTmdbApiUrl + @"3/person/{1}?api_key={0}&append_to_response=credits,images,external_ids", TmdbUtils.ApiKey, id);
|
var url = string.Format(TmdbUtils.BaseTmdbApiUrl + @"3/person/{1}?api_key={0}&append_to_response=credits,images,external_ids", TmdbUtils.ApiKey, id);
|
||||||
|
|
||||||
using (var response = await TmdbMovieProvider.Current.GetMovieDbResponse(new HttpRequestOptions
|
using var requestMessage = new HttpRequestMessage(HttpMethod.Get, url);
|
||||||
|
foreach (var header in TmdbUtils.AcceptHeaders)
|
||||||
{
|
{
|
||||||
Url = url,
|
requestMessage.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(header));
|
||||||
CancellationToken = cancellationToken,
|
|
||||||
AcceptHeader = TmdbUtils.AcceptHeader
|
|
||||||
}).ConfigureAwait(false))
|
|
||||||
{
|
|
||||||
using (var json = response.Content)
|
|
||||||
{
|
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(dataFilePath));
|
|
||||||
|
|
||||||
using (var fs = new FileStream(dataFilePath, FileMode.Create, FileAccess.Write, FileShare.Read, IODefaults.FileStreamBufferSize, true))
|
|
||||||
{
|
|
||||||
await json.CopyToAsync(fs).ConfigureAwait(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
using var response = await TmdbMovieProvider.Current.GetMovieDbResponse(requestMessage).ConfigureAwait(false);
|
||||||
|
Directory.CreateDirectory(Path.GetDirectoryName(dataFilePath));
|
||||||
|
await using var fs = new FileStream(dataFilePath, FileMode.Create, FileAccess.Write, FileShare.Read, IODefaults.FileStreamBufferSize, true);
|
||||||
|
await response.Content.CopyToAsync(fs).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string GetPersonDataPath(IApplicationPaths appPaths, string tmdbId)
|
private static string GetPersonDataPath(IApplicationPaths appPaths, string tmdbId)
|
||||||
|
@ -266,13 +257,9 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.People
|
||||||
return Path.Combine(appPaths.CachePath, "tmdb-people");
|
return Path.Combine(appPaths.CachePath, "tmdb-people");
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
|
public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
return _httpClient.GetResponse(new HttpRequestOptions
|
return _httpClientFactory.CreateClient().GetAsync(url, cancellationToken);
|
||||||
{
|
|
||||||
CancellationToken = cancellationToken,
|
|
||||||
Url = url
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,9 +3,9 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Net.Http;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using MediaBrowser.Common.Net;
|
|
||||||
using MediaBrowser.Controller.Configuration;
|
using MediaBrowser.Controller.Configuration;
|
||||||
using MediaBrowser.Controller.Entities;
|
using MediaBrowser.Controller.Entities;
|
||||||
using MediaBrowser.Controller.Providers;
|
using MediaBrowser.Controller.Providers;
|
||||||
|
@ -26,8 +26,8 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV
|
||||||
IRemoteImageProvider,
|
IRemoteImageProvider,
|
||||||
IHasOrder
|
IHasOrder
|
||||||
{
|
{
|
||||||
public TmdbEpisodeImageProvider(IHttpClient httpClient, IServerConfigurationManager configurationManager, IJsonSerializer jsonSerializer, IFileSystem fileSystem, ILocalizationManager localization, ILoggerFactory loggerFactory)
|
public TmdbEpisodeImageProvider(IHttpClientFactory httpClientFactory, IServerConfigurationManager configurationManager, IJsonSerializer jsonSerializer, IFileSystem fileSystem, ILocalizationManager localization, ILoggerFactory loggerFactory)
|
||||||
: base(httpClient, configurationManager, jsonSerializer, fileSystem, localization, loggerFactory)
|
: base(httpClientFactory, configurationManager, jsonSerializer, fileSystem, localization, loggerFactory)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
public IEnumerable<ImageType> GetSupportedImages(BaseItem item)
|
public IEnumerable<ImageType> GetSupportedImages(BaseItem item)
|
||||||
|
@ -115,7 +115,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV
|
||||||
return images.Stills ?? new List<Still>();
|
return images.Stills ?? new List<Still>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
|
public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
return GetResponse(url, cancellationToken);
|
return GetResponse(url, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,9 +5,9 @@ using System.Collections.Generic;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
using System.Net.Http;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using MediaBrowser.Common.Net;
|
|
||||||
using MediaBrowser.Controller.Configuration;
|
using MediaBrowser.Controller.Configuration;
|
||||||
using MediaBrowser.Controller.Entities;
|
using MediaBrowser.Controller.Entities;
|
||||||
using MediaBrowser.Controller.Entities.TV;
|
using MediaBrowser.Controller.Entities.TV;
|
||||||
|
@ -27,8 +27,8 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV
|
||||||
IRemoteMetadataProvider<Episode, EpisodeInfo>,
|
IRemoteMetadataProvider<Episode, EpisodeInfo>,
|
||||||
IHasOrder
|
IHasOrder
|
||||||
{
|
{
|
||||||
public TmdbEpisodeProvider(IHttpClient httpClient, IServerConfigurationManager configurationManager, IJsonSerializer jsonSerializer, IFileSystem fileSystem, ILocalizationManager localization, ILoggerFactory loggerFactory)
|
public TmdbEpisodeProvider(IHttpClientFactory httpClientFactory, IServerConfigurationManager configurationManager, IJsonSerializer jsonSerializer, IFileSystem fileSystem, ILocalizationManager localization, ILoggerFactory loggerFactory)
|
||||||
: base(httpClient, configurationManager, jsonSerializer, fileSystem, localization, loggerFactory)
|
: base(httpClientFactory, configurationManager, jsonSerializer, fileSystem, localization, loggerFactory)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
public async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(EpisodeInfo searchInfo, CancellationToken cancellationToken)
|
public async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(EpisodeInfo searchInfo, CancellationToken cancellationToken)
|
||||||
|
@ -201,7 +201,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
|
public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
return GetResponse(url, cancellationToken);
|
return GetResponse(url, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,9 +3,10 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Net.Http.Headers;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using MediaBrowser.Common.Net;
|
|
||||||
using MediaBrowser.Controller.Configuration;
|
using MediaBrowser.Controller.Configuration;
|
||||||
using MediaBrowser.Model.Globalization;
|
using MediaBrowser.Model.Globalization;
|
||||||
using MediaBrowser.Model.IO;
|
using MediaBrowser.Model.IO;
|
||||||
|
@ -19,16 +20,16 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV
|
||||||
public abstract class TmdbEpisodeProviderBase
|
public abstract class TmdbEpisodeProviderBase
|
||||||
{
|
{
|
||||||
private const string EpisodeUrlPattern = TmdbUtils.BaseTmdbApiUrl + @"3/tv/{0}/season/{1}/episode/{2}?api_key={3}&append_to_response=images,external_ids,credits,videos";
|
private const string EpisodeUrlPattern = TmdbUtils.BaseTmdbApiUrl + @"3/tv/{0}/season/{1}/episode/{2}?api_key={3}&append_to_response=images,external_ids,credits,videos";
|
||||||
private readonly IHttpClient _httpClient;
|
private readonly IHttpClientFactory _httpClientFactory;
|
||||||
private readonly IServerConfigurationManager _configurationManager;
|
private readonly IServerConfigurationManager _configurationManager;
|
||||||
private readonly IJsonSerializer _jsonSerializer;
|
private readonly IJsonSerializer _jsonSerializer;
|
||||||
private readonly IFileSystem _fileSystem;
|
private readonly IFileSystem _fileSystem;
|
||||||
private readonly ILocalizationManager _localization;
|
private readonly ILocalizationManager _localization;
|
||||||
private readonly ILogger<TmdbEpisodeProviderBase> _logger;
|
private readonly ILogger<TmdbEpisodeProviderBase> _logger;
|
||||||
|
|
||||||
protected TmdbEpisodeProviderBase(IHttpClient httpClient, IServerConfigurationManager configurationManager, IJsonSerializer jsonSerializer, IFileSystem fileSystem, ILocalizationManager localization, ILoggerFactory loggerFactory)
|
protected TmdbEpisodeProviderBase(IHttpClientFactory httpClientFactory, IServerConfigurationManager configurationManager, IJsonSerializer jsonSerializer, IFileSystem fileSystem, ILocalizationManager localization, ILoggerFactory loggerFactory)
|
||||||
{
|
{
|
||||||
_httpClient = httpClient;
|
_httpClientFactory = httpClientFactory;
|
||||||
_configurationManager = configurationManager;
|
_configurationManager = configurationManager;
|
||||||
_jsonSerializer = jsonSerializer;
|
_jsonSerializer = jsonSerializer;
|
||||||
_fileSystem = fileSystem;
|
_fileSystem = fileSystem;
|
||||||
|
@ -124,27 +125,20 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV
|
||||||
|
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
|
|
||||||
using (var response = await TmdbMovieProvider.Current.GetMovieDbResponse(new HttpRequestOptions
|
using var requestMessage = new HttpRequestMessage(HttpMethod.Get, url);
|
||||||
|
foreach (var header in TmdbUtils.AcceptHeaders)
|
||||||
{
|
{
|
||||||
Url = url,
|
requestMessage.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(header));
|
||||||
CancellationToken = cancellationToken,
|
|
||||||
AcceptHeader = TmdbUtils.AcceptHeader
|
|
||||||
}).ConfigureAwait(false))
|
|
||||||
{
|
|
||||||
using (var json = response.Content)
|
|
||||||
{
|
|
||||||
return await _jsonSerializer.DeserializeFromStreamAsync<EpisodeResult>(json).ConfigureAwait(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
using var response = await TmdbMovieProvider.Current.GetMovieDbResponse(requestMessage);
|
||||||
|
await using var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
|
||||||
|
return await _jsonSerializer.DeserializeFromStreamAsync<EpisodeResult>(stream).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Task<HttpResponseInfo> GetResponse(string url, CancellationToken cancellationToken)
|
protected Task<HttpResponseMessage> GetResponse(string url, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
return _httpClient.GetResponse(new HttpRequestOptions
|
return _httpClientFactory.CreateClient().GetAsync(url, cancellationToken);
|
||||||
{
|
|
||||||
CancellationToken = cancellationToken,
|
|
||||||
Url = url
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,9 +4,9 @@ using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Net.Http;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using MediaBrowser.Common.Net;
|
|
||||||
using MediaBrowser.Controller.Entities;
|
using MediaBrowser.Controller.Entities;
|
||||||
using MediaBrowser.Controller.Entities.TV;
|
using MediaBrowser.Controller.Entities.TV;
|
||||||
using MediaBrowser.Controller.Providers;
|
using MediaBrowser.Controller.Providers;
|
||||||
|
@ -22,12 +22,12 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV
|
||||||
public class TmdbSeasonImageProvider : IRemoteImageProvider, IHasOrder
|
public class TmdbSeasonImageProvider : IRemoteImageProvider, IHasOrder
|
||||||
{
|
{
|
||||||
private readonly IJsonSerializer _jsonSerializer;
|
private readonly IJsonSerializer _jsonSerializer;
|
||||||
private readonly IHttpClient _httpClient;
|
private readonly IHttpClientFactory _httpClientFactory;
|
||||||
|
|
||||||
public TmdbSeasonImageProvider(IJsonSerializer jsonSerializer, IHttpClient httpClient)
|
public TmdbSeasonImageProvider(IJsonSerializer jsonSerializer, IHttpClientFactory httpClientFactory)
|
||||||
{
|
{
|
||||||
_jsonSerializer = jsonSerializer;
|
_jsonSerializer = jsonSerializer;
|
||||||
_httpClient = httpClient;
|
_httpClientFactory = httpClientFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Order => 1;
|
public int Order => 1;
|
||||||
|
@ -36,13 +36,9 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV
|
||||||
|
|
||||||
public static string ProviderName => TmdbUtils.ProviderName;
|
public static string ProviderName => TmdbUtils.ProviderName;
|
||||||
|
|
||||||
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
|
public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
return _httpClient.GetResponse(new HttpRequestOptions
|
return _httpClientFactory.CreateClient().GetAsync(url, cancellationToken);
|
||||||
{
|
|
||||||
CancellationToken = cancellationToken,
|
|
||||||
Url = url
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, CancellationToken cancellationToken)
|
public async Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, CancellationToken cancellationToken)
|
||||||
|
|
|
@ -5,9 +5,10 @@ using System.Collections.Generic;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Net.Http.Headers;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using MediaBrowser.Common.Net;
|
|
||||||
using MediaBrowser.Controller.Configuration;
|
using MediaBrowser.Controller.Configuration;
|
||||||
using MediaBrowser.Controller.Providers;
|
using MediaBrowser.Controller.Providers;
|
||||||
using MediaBrowser.Model.Entities;
|
using MediaBrowser.Model.Entities;
|
||||||
|
@ -26,7 +27,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV
|
||||||
public class TmdbSeasonProvider : IRemoteMetadataProvider<Season, SeasonInfo>
|
public class TmdbSeasonProvider : IRemoteMetadataProvider<Season, SeasonInfo>
|
||||||
{
|
{
|
||||||
private const string GetTvInfo3 = TmdbUtils.BaseTmdbApiUrl + @"3/tv/{0}/season/{1}?api_key={2}&append_to_response=images,keywords,external_ids,credits,videos";
|
private const string GetTvInfo3 = TmdbUtils.BaseTmdbApiUrl + @"3/tv/{0}/season/{1}?api_key={2}&append_to_response=images,keywords,external_ids,credits,videos";
|
||||||
private readonly IHttpClient _httpClient;
|
private readonly IHttpClientFactory _httpClientFactory;
|
||||||
private readonly IServerConfigurationManager _configurationManager;
|
private readonly IServerConfigurationManager _configurationManager;
|
||||||
private readonly IJsonSerializer _jsonSerializer;
|
private readonly IJsonSerializer _jsonSerializer;
|
||||||
private readonly IFileSystem _fileSystem;
|
private readonly IFileSystem _fileSystem;
|
||||||
|
@ -35,9 +36,9 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV
|
||||||
|
|
||||||
internal static TmdbSeasonProvider Current { get; private set; }
|
internal static TmdbSeasonProvider Current { get; private set; }
|
||||||
|
|
||||||
public TmdbSeasonProvider(IHttpClient httpClient, IServerConfigurationManager configurationManager, IFileSystem fileSystem, ILocalizationManager localization, IJsonSerializer jsonSerializer, ILogger<TmdbSeasonProvider> logger)
|
public TmdbSeasonProvider(IHttpClientFactory httpClientFactory, IServerConfigurationManager configurationManager, IFileSystem fileSystem, ILocalizationManager localization, IJsonSerializer jsonSerializer, ILogger<TmdbSeasonProvider> logger)
|
||||||
{
|
{
|
||||||
_httpClient = httpClient;
|
_httpClientFactory = httpClientFactory;
|
||||||
_configurationManager = configurationManager;
|
_configurationManager = configurationManager;
|
||||||
_fileSystem = fileSystem;
|
_fileSystem = fileSystem;
|
||||||
_localization = localization;
|
_localization = localization;
|
||||||
|
@ -121,13 +122,9 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV
|
||||||
return Task.FromResult<IEnumerable<RemoteSearchResult>>(new List<RemoteSearchResult>());
|
return Task.FromResult<IEnumerable<RemoteSearchResult>>(new List<RemoteSearchResult>());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
|
public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
return _httpClient.GetResponse(new HttpRequestOptions
|
return _httpClientFactory.CreateClient().GetAsync(url, cancellationToken);
|
||||||
{
|
|
||||||
CancellationToken = cancellationToken,
|
|
||||||
Url = url
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<SeasonResult> GetSeasonInfo(string seriesTmdbId, int season, string preferredMetadataLanguage,
|
private async Task<SeasonResult> GetSeasonInfo(string seriesTmdbId, int season, string preferredMetadataLanguage,
|
||||||
|
@ -215,18 +212,15 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV
|
||||||
|
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
|
|
||||||
using (var response = await TmdbMovieProvider.Current.GetMovieDbResponse(new HttpRequestOptions
|
using var requestMessage = new HttpRequestMessage(HttpMethod.Get, url);
|
||||||
|
foreach (var header in TmdbUtils.AcceptHeaders)
|
||||||
{
|
{
|
||||||
Url = url,
|
requestMessage.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(header));
|
||||||
CancellationToken = cancellationToken,
|
|
||||||
AcceptHeader = TmdbUtils.AcceptHeader
|
|
||||||
}).ConfigureAwait(false))
|
|
||||||
{
|
|
||||||
using (var json = response.Content)
|
|
||||||
{
|
|
||||||
return await _jsonSerializer.DeserializeFromStreamAsync<SeasonResult>(json).ConfigureAwait(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
using var response = await TmdbMovieProvider.Current.GetMovieDbResponse(requestMessage).ConfigureAwait(false);
|
||||||
|
await using var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
|
||||||
|
return await _jsonSerializer.DeserializeFromStreamAsync<SeasonResult>(stream).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,9 +3,9 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Net.Http;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using MediaBrowser.Common.Net;
|
|
||||||
using MediaBrowser.Controller.Entities;
|
using MediaBrowser.Controller.Entities;
|
||||||
using MediaBrowser.Controller.Entities.TV;
|
using MediaBrowser.Controller.Entities.TV;
|
||||||
using MediaBrowser.Controller.Providers;
|
using MediaBrowser.Controller.Providers;
|
||||||
|
@ -23,13 +23,13 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV
|
||||||
public class TmdbSeriesImageProvider : IRemoteImageProvider, IHasOrder
|
public class TmdbSeriesImageProvider : IRemoteImageProvider, IHasOrder
|
||||||
{
|
{
|
||||||
private readonly IJsonSerializer _jsonSerializer;
|
private readonly IJsonSerializer _jsonSerializer;
|
||||||
private readonly IHttpClient _httpClient;
|
private readonly IHttpClientFactory _httpClientFactory;
|
||||||
private readonly IFileSystem _fileSystem;
|
private readonly IFileSystem _fileSystem;
|
||||||
|
|
||||||
public TmdbSeriesImageProvider(IJsonSerializer jsonSerializer, IHttpClient httpClient, IFileSystem fileSystem)
|
public TmdbSeriesImageProvider(IJsonSerializer jsonSerializer, IHttpClientFactory httpClientFactory, IFileSystem fileSystem)
|
||||||
{
|
{
|
||||||
_jsonSerializer = jsonSerializer;
|
_jsonSerializer = jsonSerializer;
|
||||||
_httpClient = httpClient;
|
_httpClientFactory = httpClientFactory;
|
||||||
_fileSystem = fileSystem;
|
_fileSystem = fileSystem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,13 +180,9 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV
|
||||||
// After tvdb and fanart
|
// After tvdb and fanart
|
||||||
public int Order => 2;
|
public int Order => 2;
|
||||||
|
|
||||||
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
|
public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
return _httpClient.GetResponse(new HttpRequestOptions
|
return _httpClientFactory.CreateClient().GetAsync(url, cancellationToken);
|
||||||
{
|
|
||||||
CancellationToken = cancellationToken,
|
|
||||||
Url = url
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,10 +5,11 @@ using System.Collections.Generic;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Net.Http.Headers;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using MediaBrowser.Common.Configuration;
|
using MediaBrowser.Common.Configuration;
|
||||||
using MediaBrowser.Common.Net;
|
|
||||||
using MediaBrowser.Controller.Configuration;
|
using MediaBrowser.Controller.Configuration;
|
||||||
using MediaBrowser.Controller.Entities;
|
using MediaBrowser.Controller.Entities;
|
||||||
using MediaBrowser.Controller.Entities.TV;
|
using MediaBrowser.Controller.Entities.TV;
|
||||||
|
@ -35,7 +36,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV
|
||||||
private readonly IServerConfigurationManager _configurationManager;
|
private readonly IServerConfigurationManager _configurationManager;
|
||||||
private readonly ILogger<TmdbSeriesProvider> _logger;
|
private readonly ILogger<TmdbSeriesProvider> _logger;
|
||||||
private readonly ILocalizationManager _localization;
|
private readonly ILocalizationManager _localization;
|
||||||
private readonly IHttpClient _httpClient;
|
private readonly IHttpClientFactory _httpClientFactory;
|
||||||
private readonly ILibraryManager _libraryManager;
|
private readonly ILibraryManager _libraryManager;
|
||||||
|
|
||||||
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
|
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
|
||||||
|
@ -48,7 +49,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV
|
||||||
IServerConfigurationManager configurationManager,
|
IServerConfigurationManager configurationManager,
|
||||||
ILogger<TmdbSeriesProvider> logger,
|
ILogger<TmdbSeriesProvider> logger,
|
||||||
ILocalizationManager localization,
|
ILocalizationManager localization,
|
||||||
IHttpClient httpClient,
|
IHttpClientFactory httpClientFactory,
|
||||||
ILibraryManager libraryManager)
|
ILibraryManager libraryManager)
|
||||||
{
|
{
|
||||||
_jsonSerializer = jsonSerializer;
|
_jsonSerializer = jsonSerializer;
|
||||||
|
@ -56,7 +57,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV
|
||||||
_configurationManager = configurationManager;
|
_configurationManager = configurationManager;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_localization = localization;
|
_localization = localization;
|
||||||
_httpClient = httpClient;
|
_httpClientFactory = httpClientFactory;
|
||||||
_libraryManager = libraryManager;
|
_libraryManager = libraryManager;
|
||||||
Current = this;
|
Current = this;
|
||||||
}
|
}
|
||||||
|
@ -413,24 +414,19 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV
|
||||||
|
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
|
|
||||||
SeriesResult mainResult;
|
using var mainRequestMessage = new HttpRequestMessage(HttpMethod.Get, url);
|
||||||
|
foreach (var header in TmdbUtils.AcceptHeaders)
|
||||||
using (var response = await TmdbMovieProvider.Current.GetMovieDbResponse(new HttpRequestOptions
|
|
||||||
{
|
{
|
||||||
Url = url,
|
mainRequestMessage.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(header));
|
||||||
CancellationToken = cancellationToken,
|
}
|
||||||
AcceptHeader = TmdbUtils.AcceptHeader
|
|
||||||
}).ConfigureAwait(false))
|
|
||||||
{
|
|
||||||
using (var json = response.Content)
|
|
||||||
{
|
|
||||||
mainResult = await _jsonSerializer.DeserializeFromStreamAsync<SeriesResult>(json).ConfigureAwait(false);
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(language))
|
using var mainResponse = await TmdbMovieProvider.Current.GetMovieDbResponse(mainRequestMessage);
|
||||||
{
|
await using var mainStream = await mainResponse.Content.ReadAsStreamAsync().ConfigureAwait(false);
|
||||||
mainResult.ResultLanguage = language;
|
var mainResult = await _jsonSerializer.DeserializeFromStreamAsync<SeriesResult>(mainStream).ConfigureAwait(false);
|
||||||
}
|
|
||||||
}
|
if (!string.IsNullOrEmpty(language))
|
||||||
|
{
|
||||||
|
mainResult.ResultLanguage = language;
|
||||||
}
|
}
|
||||||
|
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
|
@ -451,21 +447,18 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV
|
||||||
url += "&include_image_language=" + TmdbMovieProvider.GetImageLanguagesParam(language);
|
url += "&include_image_language=" + TmdbMovieProvider.GetImageLanguagesParam(language);
|
||||||
}
|
}
|
||||||
|
|
||||||
using (var response = await TmdbMovieProvider.Current.GetMovieDbResponse(new HttpRequestOptions
|
using var requestMessage = new HttpRequestMessage(HttpMethod.Get, url);
|
||||||
|
foreach (var header in TmdbUtils.AcceptHeaders)
|
||||||
{
|
{
|
||||||
Url = url,
|
mainRequestMessage.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(header));
|
||||||
CancellationToken = cancellationToken,
|
|
||||||
AcceptHeader = TmdbUtils.AcceptHeader
|
|
||||||
}).ConfigureAwait(false))
|
|
||||||
{
|
|
||||||
using (var json = response.Content)
|
|
||||||
{
|
|
||||||
var englishResult = await _jsonSerializer.DeserializeFromStreamAsync<SeriesResult>(json).ConfigureAwait(false);
|
|
||||||
|
|
||||||
mainResult.Overview = englishResult.Overview;
|
|
||||||
mainResult.ResultLanguage = "en";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
using var response = await TmdbMovieProvider.Current.GetMovieDbResponse(requestMessage);
|
||||||
|
await using var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
|
||||||
|
var englishResult = await _jsonSerializer.DeserializeFromStreamAsync<SeriesResult>(stream).ConfigureAwait(false);
|
||||||
|
|
||||||
|
mainResult.Overview = englishResult.Overview;
|
||||||
|
mainResult.ResultLanguage = "en";
|
||||||
}
|
}
|
||||||
|
|
||||||
return mainResult;
|
return mainResult;
|
||||||
|
@ -515,38 +508,38 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV
|
||||||
TmdbUtils.ApiKey,
|
TmdbUtils.ApiKey,
|
||||||
externalSource);
|
externalSource);
|
||||||
|
|
||||||
using (var response = await TmdbMovieProvider.Current.GetMovieDbResponse(new HttpRequestOptions
|
using var requestMessage = new HttpRequestMessage(HttpMethod.Get, url);
|
||||||
|
foreach (var header in TmdbUtils.AcceptHeaders)
|
||||||
{
|
{
|
||||||
Url = url,
|
requestMessage.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(header));
|
||||||
CancellationToken = cancellationToken,
|
}
|
||||||
AcceptHeader = TmdbUtils.AcceptHeader
|
|
||||||
}).ConfigureAwait(false))
|
using var response = await TmdbMovieProvider.Current.GetMovieDbResponse(requestMessage);
|
||||||
|
await using var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
|
var result = await _jsonSerializer.DeserializeFromStreamAsync<ExternalIdLookupResult>(stream).ConfigureAwait(false);
|
||||||
|
|
||||||
|
if (result != null && result.Tv_Results != null)
|
||||||
{
|
{
|
||||||
using (var json = response.Content)
|
var tv = result.Tv_Results.FirstOrDefault();
|
||||||
|
|
||||||
|
if (tv != null)
|
||||||
{
|
{
|
||||||
var result = await _jsonSerializer.DeserializeFromStreamAsync<ExternalIdLookupResult>(json).ConfigureAwait(false);
|
var tmdbSettings = await TmdbMovieProvider.Current.GetTmdbSettings(cancellationToken).ConfigureAwait(false);
|
||||||
|
var tmdbImageUrl = tmdbSettings.images.GetImageUrl("original");
|
||||||
|
|
||||||
if (result != null && result.Tv_Results != null)
|
var remoteResult = new RemoteSearchResult
|
||||||
{
|
{
|
||||||
var tv = result.Tv_Results.FirstOrDefault();
|
Name = tv.Name,
|
||||||
|
SearchProviderName = Name,
|
||||||
|
ImageUrl = string.IsNullOrWhiteSpace(tv.Poster_Path)
|
||||||
|
? null
|
||||||
|
: tmdbImageUrl + tv.Poster_Path
|
||||||
|
};
|
||||||
|
|
||||||
if (tv != null)
|
remoteResult.SetProviderId(MetadataProvider.Tmdb, tv.Id.ToString(_usCulture));
|
||||||
{
|
|
||||||
var tmdbSettings = await TmdbMovieProvider.Current.GetTmdbSettings(cancellationToken).ConfigureAwait(false);
|
|
||||||
var tmdbImageUrl = tmdbSettings.images.GetImageUrl("original");
|
|
||||||
|
|
||||||
var remoteResult = new RemoteSearchResult
|
return remoteResult;
|
||||||
{
|
|
||||||
Name = tv.Name,
|
|
||||||
SearchProviderName = Name,
|
|
||||||
ImageUrl = string.IsNullOrWhiteSpace(tv.Poster_Path) ? null : tmdbImageUrl + tv.Poster_Path
|
|
||||||
};
|
|
||||||
|
|
||||||
remoteResult.SetProviderId(MetadataProvider.Tmdb, tv.Id.ToString(_usCulture));
|
|
||||||
|
|
||||||
return remoteResult;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -556,13 +549,9 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV
|
||||||
// After TheTVDB
|
// After TheTVDB
|
||||||
public int Order => 1;
|
public int Order => 1;
|
||||||
|
|
||||||
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
|
public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
return _httpClient.GetResponse(new HttpRequestOptions
|
return _httpClientFactory.CreateClient().GetAsync(url, cancellationToken);
|
||||||
{
|
|
||||||
CancellationToken = cancellationToken,
|
|
||||||
Url = url
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Net.Mime;
|
||||||
using MediaBrowser.Model.Entities;
|
using MediaBrowser.Model.Entities;
|
||||||
using MediaBrowser.Providers.Plugins.Tmdb.Models.General;
|
using MediaBrowser.Providers.Plugins.Tmdb.Models.General;
|
||||||
|
|
||||||
|
@ -32,7 +33,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Value of the Accept header for requests to the provider.
|
/// Value of the Accept header for requests to the provider.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public const string AcceptHeader = "application/json,image/*";
|
public static readonly string[] AcceptHeaders = { MediaTypeNames.Application.Json, "image/*" };
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Maps the TMDB provided roles for crew members to Jellyfin roles.
|
/// Maps the TMDB provided roles for crew members to Jellyfin roles.
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
#pragma warning disable CS1591
|
#pragma warning disable CS1591
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Net.Http;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using MediaBrowser.Common.Net;
|
|
||||||
using MediaBrowser.Controller.Entities;
|
using MediaBrowser.Controller.Entities;
|
||||||
using MediaBrowser.Controller.Providers;
|
using MediaBrowser.Controller.Providers;
|
||||||
using MediaBrowser.Model.Providers;
|
using MediaBrowser.Model.Providers;
|
||||||
|
@ -13,11 +13,11 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.Trailers
|
||||||
{
|
{
|
||||||
public class TmdbTrailerProvider : IHasOrder, IRemoteMetadataProvider<Trailer, TrailerInfo>
|
public class TmdbTrailerProvider : IHasOrder, IRemoteMetadataProvider<Trailer, TrailerInfo>
|
||||||
{
|
{
|
||||||
private readonly IHttpClient _httpClient;
|
private readonly IHttpClientFactory _httpClientFactory;
|
||||||
|
|
||||||
public TmdbTrailerProvider(IHttpClient httpClient)
|
public TmdbTrailerProvider(IHttpClientFactory httpClientFactory)
|
||||||
{
|
{
|
||||||
_httpClient = httpClient;
|
_httpClientFactory = httpClientFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<IEnumerable<RemoteSearchResult>> GetSearchResults(TrailerInfo searchInfo, CancellationToken cancellationToken)
|
public Task<IEnumerable<RemoteSearchResult>> GetSearchResults(TrailerInfo searchInfo, CancellationToken cancellationToken)
|
||||||
|
@ -34,13 +34,9 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.Trailers
|
||||||
|
|
||||||
public int Order => 0;
|
public int Order => 0;
|
||||||
|
|
||||||
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
|
public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
return _httpClient.GetResponse(new HttpRequestOptions
|
return _httpClientFactory.CreateClient().GetAsync(url, cancellationToken);
|
||||||
{
|
|
||||||
CancellationToken = cancellationToken,
|
|
||||||
Url = url
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,6 @@ using System.Linq;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using MediaBrowser.Common.Net;
|
|
||||||
using MediaBrowser.Controller.Configuration;
|
using MediaBrowser.Controller.Configuration;
|
||||||
using MediaBrowser.Controller.Entities;
|
using MediaBrowser.Controller.Entities;
|
||||||
using MediaBrowser.Controller.Providers;
|
using MediaBrowser.Controller.Providers;
|
||||||
|
@ -20,13 +19,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,26 +107,22 @@ 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;
|
||||||
|
|
||||||
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
|
public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
return _httpClient.GetResponse(new HttpRequestOptions
|
var httpClient = _httpClientFactory.CreateClient();
|
||||||
{
|
return httpClient.GetAsync(url, cancellationToken);
|
||||||
CancellationToken = cancellationToken,
|
|
||||||
Url = url,
|
|
||||||
BufferContent = false
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -135,30 +130,21 @@ namespace MediaBrowser.Providers.Studios
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="url">The URL.</param>
|
/// <param name="url">The URL.</param>
|
||||||
/// <param name="file">The file.</param>
|
/// <param name="file">The file.</param>
|
||||||
/// <param name="httpClient">The HTTP client.</param>
|
|
||||||
/// <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