mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-07-17 11:43:44 +01:00
Put json serializer options in private field
This commit is contained in:
@@ -22,6 +22,7 @@ namespace MediaBrowser.Providers.Plugins.AudioDb
|
||||
{
|
||||
private readonly IServerConfigurationManager _config;
|
||||
private readonly IHttpClientFactory _httpClientFactory;
|
||||
private readonly JsonSerializerOptions _jsonOptions = JsonDefaults.GetOptions();
|
||||
|
||||
public AudioDbAlbumImageProvider(IServerConfigurationManager config, IHttpClientFactory httpClientFactory)
|
||||
{
|
||||
@@ -58,7 +59,7 @@ namespace MediaBrowser.Providers.Plugins.AudioDb
|
||||
var path = AudioDbAlbumProvider.GetAlbumInfoPath(_config.ApplicationPaths, id);
|
||||
|
||||
await using FileStream jsonStream = File.OpenRead(path);
|
||||
var obj = await JsonSerializer.DeserializeAsync<AudioDbAlbumProvider.RootObject>(jsonStream, JsonDefaults.GetOptions(), cancellationToken).ConfigureAwait(false);
|
||||
var obj = await JsonSerializer.DeserializeAsync<AudioDbAlbumProvider.RootObject>(jsonStream, _jsonOptions, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (obj != null && obj.album != null && obj.album.Count > 0)
|
||||
{
|
||||
|
||||
@@ -29,6 +29,7 @@ namespace MediaBrowser.Providers.Plugins.AudioDb
|
||||
private readonly IServerConfigurationManager _config;
|
||||
private readonly IFileSystem _fileSystem;
|
||||
private readonly IHttpClientFactory _httpClientFactory;
|
||||
private readonly JsonSerializerOptions _jsonOptions = JsonDefaults.GetOptions();
|
||||
|
||||
public static AudioDbAlbumProvider Current;
|
||||
|
||||
@@ -65,7 +66,7 @@ namespace MediaBrowser.Providers.Plugins.AudioDb
|
||||
var path = GetAlbumInfoPath(_config.ApplicationPaths, id);
|
||||
|
||||
await using FileStream jsonStream = File.OpenRead(path);
|
||||
var obj = await JsonSerializer.DeserializeAsync<RootObject>(jsonStream, JsonDefaults.GetOptions(), cancellationToken).ConfigureAwait(false);
|
||||
var obj = await JsonSerializer.DeserializeAsync<RootObject>(jsonStream, _jsonOptions, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (obj != null && obj.album != null && obj.album.Count > 0)
|
||||
{
|
||||
|
||||
@@ -22,6 +22,7 @@ namespace MediaBrowser.Providers.Plugins.AudioDb
|
||||
{
|
||||
private readonly IServerConfigurationManager _config;
|
||||
private readonly IHttpClientFactory _httpClientFactory;
|
||||
private readonly JsonSerializerOptions _jsonOptions = JsonDefaults.GetOptions();
|
||||
|
||||
public AudioDbArtistImageProvider(IServerConfigurationManager config, IHttpClientFactory httpClientFactory)
|
||||
{
|
||||
@@ -60,7 +61,7 @@ namespace MediaBrowser.Providers.Plugins.AudioDb
|
||||
var path = AudioDbArtistProvider.GetArtistInfoPath(_config.ApplicationPaths, id);
|
||||
|
||||
await using FileStream jsonStream = File.OpenRead(path);
|
||||
var obj = await JsonSerializer.DeserializeAsync<AudioDbArtistProvider.RootObject>(jsonStream, JsonDefaults.GetOptions(), cancellationToken).ConfigureAwait(false);
|
||||
var obj = await JsonSerializer.DeserializeAsync<AudioDbArtistProvider.RootObject>(jsonStream, _jsonOptions, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (obj != null && obj.artists != null && obj.artists.Count > 0)
|
||||
{
|
||||
|
||||
@@ -31,6 +31,7 @@ namespace MediaBrowser.Providers.Plugins.AudioDb
|
||||
private readonly IServerConfigurationManager _config;
|
||||
private readonly IFileSystem _fileSystem;
|
||||
private readonly IHttpClientFactory _httpClientFactory;
|
||||
private readonly JsonSerializerOptions _jsonOptions = JsonDefaults.GetOptions();
|
||||
|
||||
public AudioDbArtistProvider(IServerConfigurationManager config, IFileSystem fileSystem, IHttpClientFactory httpClientFactory)
|
||||
{
|
||||
@@ -66,7 +67,7 @@ namespace MediaBrowser.Providers.Plugins.AudioDb
|
||||
var path = GetArtistInfoPath(_config.ApplicationPaths, id);
|
||||
|
||||
await using FileStream jsonStream = File.OpenRead(path);
|
||||
var obj = await JsonSerializer.DeserializeAsync<RootObject>(jsonStream, JsonDefaults.GetOptions(), cancellationToken).ConfigureAwait(false);
|
||||
var obj = await JsonSerializer.DeserializeAsync<RootObject>(jsonStream, _jsonOptions, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (obj != null && obj.artists != null && obj.artists.Count > 0)
|
||||
{
|
||||
|
||||
@@ -32,6 +32,7 @@ namespace MediaBrowser.Providers.Plugins.Omdb
|
||||
private readonly IFileSystem _fileSystem;
|
||||
private readonly IServerConfigurationManager _configurationManager;
|
||||
private readonly IApplicationHost _appHost;
|
||||
private readonly JsonSerializerOptions _jsonOptions = JsonDefaults.GetOptions();
|
||||
|
||||
public OmdbItemProvider(
|
||||
IApplicationHost appHost,
|
||||
@@ -136,7 +137,7 @@ namespace MediaBrowser.Providers.Plugins.Omdb
|
||||
|
||||
if (isSearch)
|
||||
{
|
||||
var searchResultList = await JsonSerializer.DeserializeAsync<SearchResultList>(stream, JsonDefaults.GetOptions(), cancellationToken).ConfigureAwait(false);
|
||||
var searchResultList = await JsonSerializer.DeserializeAsync<SearchResultList>(stream, _jsonOptions, cancellationToken).ConfigureAwait(false);
|
||||
if (searchResultList != null && searchResultList.Search != null)
|
||||
{
|
||||
resultList.AddRange(searchResultList.Search);
|
||||
@@ -144,7 +145,7 @@ namespace MediaBrowser.Providers.Plugins.Omdb
|
||||
}
|
||||
else
|
||||
{
|
||||
var result = await JsonSerializer.DeserializeAsync<SearchResult>(stream, JsonDefaults.GetOptions(), cancellationToken).ConfigureAwait(false);
|
||||
var result = await JsonSerializer.DeserializeAsync<SearchResult>(stream, _jsonOptions, cancellationToken).ConfigureAwait(false);
|
||||
if (string.Equals(result.Response, "true", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
resultList.Add(result);
|
||||
|
||||
@@ -28,6 +28,7 @@ namespace MediaBrowser.Providers.Plugins.Omdb
|
||||
private readonly IHttpClientFactory _httpClientFactory;
|
||||
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
|
||||
private readonly IApplicationHost _appHost;
|
||||
private static readonly JsonSerializerOptions _jsonOptions = JsonDefaults.GetOptions();
|
||||
|
||||
public OmdbProvider(IHttpClientFactory httpClientFactory, IFileSystem fileSystem, IApplicationHost appHost, IServerConfigurationManager configurationManager)
|
||||
{
|
||||
@@ -219,7 +220,7 @@ namespace MediaBrowser.Providers.Plugins.Omdb
|
||||
}
|
||||
}
|
||||
|
||||
var result = JsonSerializer.Deserialize<RootObject>(resultString, JsonDefaults.GetOptions());
|
||||
var result = JsonSerializer.Deserialize<RootObject>(resultString, _jsonOptions);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -238,7 +239,7 @@ namespace MediaBrowser.Providers.Plugins.Omdb
|
||||
}
|
||||
}
|
||||
|
||||
var result = JsonSerializer.Deserialize<SeasonRootObject>(resultString, JsonDefaults.GetOptions());
|
||||
var result = JsonSerializer.Deserialize<SeasonRootObject>(resultString, _jsonOptions);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -296,11 +297,10 @@ namespace MediaBrowser.Providers.Plugins.Omdb
|
||||
"i={0}&plot=short&tomatoes=true&r=json",
|
||||
imdbParam));
|
||||
|
||||
var jsonOptions = JsonDefaults.GetOptions();
|
||||
var rootObject = await GetDeserializedOmdbResponse<RootObject>(_httpClientFactory.CreateClient(NamedClient.Default), url, jsonOptions, cancellationToken).ConfigureAwait(false);
|
||||
var rootObject = await GetDeserializedOmdbResponse<RootObject>(_httpClientFactory.CreateClient(NamedClient.Default), url, cancellationToken).ConfigureAwait(false);
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(path));
|
||||
await using FileStream jsonFileStream = File.OpenWrite(path);
|
||||
await JsonSerializer.SerializeAsync(jsonFileStream, rootObject, jsonOptions, cancellationToken).ConfigureAwait(false);
|
||||
await JsonSerializer.SerializeAsync(jsonFileStream, rootObject, _jsonOptions, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
return path;
|
||||
}
|
||||
@@ -334,23 +334,22 @@ namespace MediaBrowser.Providers.Plugins.Omdb
|
||||
imdbParam,
|
||||
seasonId));
|
||||
|
||||
var jsonOptions = JsonDefaults.GetOptions();
|
||||
var rootObject = await GetDeserializedOmdbResponse<SeasonRootObject>(_httpClientFactory.CreateClient(NamedClient.Default), url, jsonOptions, cancellationToken).ConfigureAwait(false);
|
||||
var rootObject = await GetDeserializedOmdbResponse<SeasonRootObject>(_httpClientFactory.CreateClient(NamedClient.Default), url, cancellationToken).ConfigureAwait(false);
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(path));
|
||||
await using FileStream jsonFileStream = File.OpenWrite(path);
|
||||
await JsonSerializer.SerializeAsync(jsonFileStream, rootObject, jsonOptions, cancellationToken).ConfigureAwait(false);
|
||||
await JsonSerializer.SerializeAsync(jsonFileStream, rootObject, _jsonOptions, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
public static async Task<T> GetDeserializedOmdbResponse<T>(HttpClient httpClient, string url, JsonSerializerOptions jsonOptions, CancellationToken cancellationToken)
|
||||
public static async Task<T> GetDeserializedOmdbResponse<T>(HttpClient httpClient, string url, CancellationToken cancellationToken)
|
||||
{
|
||||
using var response = await GetOmdbResponse(httpClient, url, cancellationToken).ConfigureAwait(false);
|
||||
var content = await response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
|
||||
|
||||
// OMDb is sending "N/A" for no empty number fields
|
||||
content = content.Replace("\"N/A\"", "\"\"", StringComparison.InvariantCulture);
|
||||
return JsonSerializer.Deserialize<T>(content, jsonOptions);
|
||||
return JsonSerializer.Deserialize<T>(content, _jsonOptions);
|
||||
}
|
||||
|
||||
public static Task<HttpResponseMessage> GetOmdbResponse(HttpClient httpClient, string url, CancellationToken cancellationToken)
|
||||
|
||||
Reference in New Issue
Block a user