Remove custom Json serializer from Providers
This commit is contained in:
parent
bfdd4727b5
commit
e09d3ba9ef
|
@ -1,9 +1,12 @@
|
|||
#pragma warning disable CS1591
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Common.Json;
|
||||
using MediaBrowser.Common.Net;
|
||||
using MediaBrowser.Controller.Configuration;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
|
@ -19,13 +22,11 @@ namespace MediaBrowser.Providers.Plugins.AudioDb
|
|||
{
|
||||
private readonly IServerConfigurationManager _config;
|
||||
private readonly IHttpClientFactory _httpClientFactory;
|
||||
private readonly IJsonSerializer _json;
|
||||
|
||||
public AudioDbAlbumImageProvider(IServerConfigurationManager config, IHttpClientFactory httpClientFactory, IJsonSerializer json)
|
||||
public AudioDbAlbumImageProvider(IServerConfigurationManager config, IHttpClientFactory httpClientFactory)
|
||||
{
|
||||
_config = config;
|
||||
_httpClientFactory = httpClientFactory;
|
||||
_json = json;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
@ -56,7 +57,8 @@ namespace MediaBrowser.Providers.Plugins.AudioDb
|
|||
|
||||
var path = AudioDbAlbumProvider.GetAlbumInfoPath(_config.ApplicationPaths, id);
|
||||
|
||||
var obj = _json.DeserializeFromFile<AudioDbAlbumProvider.RootObject>(path);
|
||||
var jsonString = await File.ReadAllTextAsync(path, cancellationToken).ConfigureAwait(false);
|
||||
var obj = JsonSerializer.Deserialize<AudioDbAlbumProvider.RootObject>(jsonString, JsonDefaults.GetOptions());
|
||||
|
||||
if (obj != null && obj.album != null && obj.album.Count > 0)
|
||||
{
|
||||
|
|
|
@ -6,10 +6,12 @@ using System.Globalization;
|
|||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Common.Configuration;
|
||||
using MediaBrowser.Common.Extensions;
|
||||
using MediaBrowser.Common.Json;
|
||||
using MediaBrowser.Common.Net;
|
||||
using MediaBrowser.Controller.Configuration;
|
||||
using MediaBrowser.Controller.Entities.Audio;
|
||||
|
@ -27,16 +29,14 @@ namespace MediaBrowser.Providers.Plugins.AudioDb
|
|||
private readonly IServerConfigurationManager _config;
|
||||
private readonly IFileSystem _fileSystem;
|
||||
private readonly IHttpClientFactory _httpClientFactory;
|
||||
private readonly IJsonSerializer _json;
|
||||
|
||||
public static AudioDbAlbumProvider Current;
|
||||
|
||||
public AudioDbAlbumProvider(IServerConfigurationManager config, IFileSystem fileSystem, IHttpClientFactory httpClientFactory, IJsonSerializer json)
|
||||
public AudioDbAlbumProvider(IServerConfigurationManager config, IFileSystem fileSystem, IHttpClientFactory httpClientFactory)
|
||||
{
|
||||
_config = config;
|
||||
_fileSystem = fileSystem;
|
||||
_httpClientFactory = httpClientFactory;
|
||||
_json = json;
|
||||
|
||||
Current = this;
|
||||
}
|
||||
|
@ -64,7 +64,8 @@ namespace MediaBrowser.Providers.Plugins.AudioDb
|
|||
|
||||
var path = GetAlbumInfoPath(_config.ApplicationPaths, id);
|
||||
|
||||
var obj = _json.DeserializeFromFile<RootObject>(path);
|
||||
var jsonString = await File.ReadAllTextAsync(path, cancellationToken).ConfigureAwait(false);
|
||||
var obj = JsonSerializer.Deserialize<RootObject>(jsonString, JsonDefaults.GetOptions());
|
||||
|
||||
if (obj != null && obj.album != null && obj.album.Count > 0)
|
||||
{
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
#pragma warning disable CS1591
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Common.Json;
|
||||
using MediaBrowser.Common.Net;
|
||||
using MediaBrowser.Controller.Configuration;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
|
@ -19,12 +22,10 @@ namespace MediaBrowser.Providers.Plugins.AudioDb
|
|||
{
|
||||
private readonly IServerConfigurationManager _config;
|
||||
private readonly IHttpClientFactory _httpClientFactory;
|
||||
private readonly IJsonSerializer _json;
|
||||
|
||||
public AudioDbArtistImageProvider(IServerConfigurationManager config, IJsonSerializer json, IHttpClientFactory httpClientFactory)
|
||||
public AudioDbArtistImageProvider(IServerConfigurationManager config, IHttpClientFactory httpClientFactory)
|
||||
{
|
||||
_config = config;
|
||||
_json = json;
|
||||
_httpClientFactory = httpClientFactory;
|
||||
}
|
||||
|
||||
|
@ -58,7 +59,8 @@ namespace MediaBrowser.Providers.Plugins.AudioDb
|
|||
|
||||
var path = AudioDbArtistProvider.GetArtistInfoPath(_config.ApplicationPaths, id);
|
||||
|
||||
var obj = _json.DeserializeFromFile<AudioDbArtistProvider.RootObject>(path);
|
||||
var jsonString = await File.ReadAllTextAsync(path, cancellationToken).ConfigureAwait(false);
|
||||
var obj = JsonSerializer.Deserialize<AudioDbArtistProvider.RootObject>(jsonString, JsonDefaults.GetOptions());
|
||||
|
||||
if (obj != null && obj.artists != null && obj.artists.Count > 0)
|
||||
{
|
||||
|
|
|
@ -5,10 +5,12 @@ using System.Collections.Generic;
|
|||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Common.Configuration;
|
||||
using MediaBrowser.Common.Extensions;
|
||||
using MediaBrowser.Common.Json;
|
||||
using MediaBrowser.Common.Net;
|
||||
using MediaBrowser.Controller.Configuration;
|
||||
using MediaBrowser.Controller.Entities.Audio;
|
||||
|
@ -29,14 +31,12 @@ namespace MediaBrowser.Providers.Plugins.AudioDb
|
|||
private readonly IServerConfigurationManager _config;
|
||||
private readonly IFileSystem _fileSystem;
|
||||
private readonly IHttpClientFactory _httpClientFactory;
|
||||
private readonly IJsonSerializer _json;
|
||||
|
||||
public AudioDbArtistProvider(IServerConfigurationManager config, IFileSystem fileSystem, IHttpClientFactory httpClientFactory, IJsonSerializer json)
|
||||
public AudioDbArtistProvider(IServerConfigurationManager config, IFileSystem fileSystem, IHttpClientFactory httpClientFactory)
|
||||
{
|
||||
_config = config;
|
||||
_fileSystem = fileSystem;
|
||||
_httpClientFactory = httpClientFactory;
|
||||
_json = json;
|
||||
Current = this;
|
||||
}
|
||||
|
||||
|
@ -65,7 +65,8 @@ namespace MediaBrowser.Providers.Plugins.AudioDb
|
|||
|
||||
var path = GetArtistInfoPath(_config.ApplicationPaths, id);
|
||||
|
||||
var obj = _json.DeserializeFromFile<RootObject>(path);
|
||||
var jsonString = await File.ReadAllTextAsync(path, cancellationToken).ConfigureAwait(false);
|
||||
var obj = JsonSerializer.Deserialize<RootObject>(jsonString, JsonDefaults.GetOptions());
|
||||
|
||||
if (obj != null && obj.artists != null && obj.artists.Count > 0)
|
||||
{
|
||||
|
|
|
@ -12,13 +12,11 @@ using MediaBrowser.Controller.Providers;
|
|||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.IO;
|
||||
using MediaBrowser.Model.Providers;
|
||||
using MediaBrowser.Model.Serialization;
|
||||
|
||||
namespace MediaBrowser.Providers.Plugins.Omdb
|
||||
{
|
||||
public class OmdbEpisodeProvider : IRemoteMetadataProvider<Episode, EpisodeInfo>, IHasOrder
|
||||
{
|
||||
private readonly IJsonSerializer _jsonSerializer;
|
||||
private readonly IHttpClientFactory _httpClientFactory;
|
||||
private readonly OmdbItemProvider _itemProvider;
|
||||
private readonly IFileSystem _fileSystem;
|
||||
|
@ -26,19 +24,17 @@ namespace MediaBrowser.Providers.Plugins.Omdb
|
|||
private readonly IApplicationHost _appHost;
|
||||
|
||||
public OmdbEpisodeProvider(
|
||||
IJsonSerializer jsonSerializer,
|
||||
IApplicationHost appHost,
|
||||
IHttpClientFactory httpClientFactory,
|
||||
ILibraryManager libraryManager,
|
||||
IFileSystem fileSystem,
|
||||
IServerConfigurationManager configurationManager)
|
||||
{
|
||||
_jsonSerializer = jsonSerializer;
|
||||
_httpClientFactory = httpClientFactory;
|
||||
_fileSystem = fileSystem;
|
||||
_configurationManager = configurationManager;
|
||||
_appHost = appHost;
|
||||
_itemProvider = new OmdbItemProvider(jsonSerializer, _appHost, httpClientFactory, libraryManager, fileSystem, configurationManager);
|
||||
_itemProvider = new OmdbItemProvider(_appHost, httpClientFactory, libraryManager, fileSystem, configurationManager);
|
||||
}
|
||||
|
||||
// After TheTvDb
|
||||
|
@ -69,7 +65,7 @@ namespace MediaBrowser.Providers.Plugins.Omdb
|
|||
{
|
||||
if (info.IndexNumber.HasValue && info.ParentIndexNumber.HasValue)
|
||||
{
|
||||
result.HasMetadata = await new OmdbProvider(_jsonSerializer, _httpClientFactory, _fileSystem, _appHost, _configurationManager)
|
||||
result.HasMetadata = await new OmdbProvider(_httpClientFactory, _fileSystem, _appHost, _configurationManager)
|
||||
.FetchEpisodeData(result, info.IndexNumber.Value, info.ParentIndexNumber.Value, info.GetProviderId(MetadataProvider.Imdb), seriesImdbId, info.MetadataLanguage, info.MetadataCountryCode, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#pragma warning disable CS1591
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
using System.Globalization;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Common;
|
||||
|
@ -15,21 +15,18 @@ using MediaBrowser.Controller.Providers;
|
|||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.IO;
|
||||
using MediaBrowser.Model.Providers;
|
||||
using MediaBrowser.Model.Serialization;
|
||||
|
||||
namespace MediaBrowser.Providers.Plugins.Omdb
|
||||
{
|
||||
public class OmdbImageProvider : IRemoteImageProvider, IHasOrder
|
||||
{
|
||||
private readonly IHttpClientFactory _httpClientFactory;
|
||||
private readonly IJsonSerializer _jsonSerializer;
|
||||
private readonly IFileSystem _fileSystem;
|
||||
private readonly IServerConfigurationManager _configurationManager;
|
||||
private readonly IApplicationHost _appHost;
|
||||
|
||||
public OmdbImageProvider(IJsonSerializer jsonSerializer, IApplicationHost appHost, IHttpClientFactory httpClientFactory, IFileSystem fileSystem, IServerConfigurationManager configurationManager)
|
||||
public OmdbImageProvider(IApplicationHost appHost, IHttpClientFactory httpClientFactory, IFileSystem fileSystem, IServerConfigurationManager configurationManager)
|
||||
{
|
||||
_jsonSerializer = jsonSerializer;
|
||||
_httpClientFactory = httpClientFactory;
|
||||
_fileSystem = fileSystem;
|
||||
_configurationManager = configurationManager;
|
||||
|
@ -56,7 +53,7 @@ namespace MediaBrowser.Providers.Plugins.Omdb
|
|||
|
||||
var list = new List<RemoteImageInfo>();
|
||||
|
||||
var provider = new OmdbProvider(_jsonSerializer, _httpClientFactory, _fileSystem, _appHost, _configurationManager);
|
||||
var provider = new OmdbProvider(_httpClientFactory, _fileSystem, _appHost, _configurationManager);
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(imdbId))
|
||||
{
|
||||
|
|
|
@ -6,9 +6,11 @@ using System.Globalization;
|
|||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Common;
|
||||
using MediaBrowser.Common.Json;
|
||||
using MediaBrowser.Common.Net;
|
||||
using MediaBrowser.Controller.Configuration;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
|
@ -19,14 +21,12 @@ using MediaBrowser.Controller.Providers;
|
|||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.IO;
|
||||
using MediaBrowser.Model.Providers;
|
||||
using MediaBrowser.Model.Serialization;
|
||||
|
||||
namespace MediaBrowser.Providers.Plugins.Omdb
|
||||
{
|
||||
public class OmdbItemProvider : IRemoteMetadataProvider<Series, SeriesInfo>,
|
||||
IRemoteMetadataProvider<Movie, MovieInfo>, IRemoteMetadataProvider<Trailer, TrailerInfo>, IHasOrder
|
||||
{
|
||||
private readonly IJsonSerializer _jsonSerializer;
|
||||
private readonly IHttpClientFactory _httpClientFactory;
|
||||
private readonly ILibraryManager _libraryManager;
|
||||
private readonly IFileSystem _fileSystem;
|
||||
|
@ -34,14 +34,12 @@ namespace MediaBrowser.Providers.Plugins.Omdb
|
|||
private readonly IApplicationHost _appHost;
|
||||
|
||||
public OmdbItemProvider(
|
||||
IJsonSerializer jsonSerializer,
|
||||
IApplicationHost appHost,
|
||||
IHttpClientFactory httpClientFactory,
|
||||
ILibraryManager libraryManager,
|
||||
IFileSystem fileSystem,
|
||||
IServerConfigurationManager configurationManager)
|
||||
{
|
||||
_jsonSerializer = jsonSerializer;
|
||||
_httpClientFactory = httpClientFactory;
|
||||
_libraryManager = libraryManager;
|
||||
_fileSystem = fileSystem;
|
||||
|
@ -138,7 +136,7 @@ namespace MediaBrowser.Providers.Plugins.Omdb
|
|||
|
||||
if (isSearch)
|
||||
{
|
||||
var searchResultList = await _jsonSerializer.DeserializeFromStreamAsync<SearchResultList>(stream).ConfigureAwait(false);
|
||||
var searchResultList = await JsonSerializer.DeserializeAsync<SearchResultList>(stream, JsonDefaults.GetOptions(), cancellationToken).ConfigureAwait(false);
|
||||
if (searchResultList != null && searchResultList.Search != null)
|
||||
{
|
||||
resultList.AddRange(searchResultList.Search);
|
||||
|
@ -146,7 +144,7 @@ namespace MediaBrowser.Providers.Plugins.Omdb
|
|||
}
|
||||
else
|
||||
{
|
||||
var result = await _jsonSerializer.DeserializeFromStreamAsync<SearchResult>(stream).ConfigureAwait(false);
|
||||
var result = await JsonSerializer.DeserializeAsync<SearchResult>(stream, JsonDefaults.GetOptions(), cancellationToken).ConfigureAwait(false);
|
||||
if (string.Equals(result.Response, "true", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
resultList.Add(result);
|
||||
|
@ -221,7 +219,7 @@ namespace MediaBrowser.Providers.Plugins.Omdb
|
|||
result.Item.SetProviderId(MetadataProvider.Imdb, imdbId);
|
||||
result.HasMetadata = true;
|
||||
|
||||
await new OmdbProvider(_jsonSerializer, _httpClientFactory, _fileSystem, _appHost, _configurationManager).Fetch(result, imdbId, info.MetadataLanguage, info.MetadataCountryCode, cancellationToken).ConfigureAwait(false);
|
||||
await new OmdbProvider(_httpClientFactory, _fileSystem, _appHost, _configurationManager).Fetch(result, imdbId, info.MetadataLanguage, info.MetadataCountryCode, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@ -253,7 +251,7 @@ namespace MediaBrowser.Providers.Plugins.Omdb
|
|||
result.Item.SetProviderId(MetadataProvider.Imdb, imdbId);
|
||||
result.HasMetadata = true;
|
||||
|
||||
await new OmdbProvider(_jsonSerializer, _httpClientFactory, _fileSystem, _appHost, _configurationManager).Fetch(result, imdbId, info.MetadataLanguage, info.MetadataCountryCode, cancellationToken).ConfigureAwait(false);
|
||||
await new OmdbProvider(_httpClientFactory, _fileSystem, _appHost, _configurationManager).Fetch(result, imdbId, info.MetadataLanguage, info.MetadataCountryCode, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
|
@ -7,31 +7,30 @@ using System.IO;
|
|||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Common;
|
||||
using MediaBrowser.Common.Json;
|
||||
using MediaBrowser.Common.Net;
|
||||
using MediaBrowser.Controller.Configuration;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.IO;
|
||||
using MediaBrowser.Model.Serialization;
|
||||
|
||||
namespace MediaBrowser.Providers.Plugins.Omdb
|
||||
{
|
||||
public class OmdbProvider
|
||||
{
|
||||
private readonly IJsonSerializer _jsonSerializer;
|
||||
private readonly IFileSystem _fileSystem;
|
||||
private readonly IServerConfigurationManager _configurationManager;
|
||||
private readonly IHttpClientFactory _httpClientFactory;
|
||||
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
|
||||
private readonly IApplicationHost _appHost;
|
||||
|
||||
public OmdbProvider(IJsonSerializer jsonSerializer, IHttpClientFactory httpClientFactory, IFileSystem fileSystem, IApplicationHost appHost, IServerConfigurationManager configurationManager)
|
||||
public OmdbProvider(IHttpClientFactory httpClientFactory, IFileSystem fileSystem, IApplicationHost appHost, IServerConfigurationManager configurationManager)
|
||||
{
|
||||
_jsonSerializer = jsonSerializer;
|
||||
_httpClientFactory = httpClientFactory;
|
||||
_fileSystem = fileSystem;
|
||||
_configurationManager = configurationManager;
|
||||
|
@ -220,7 +219,7 @@ namespace MediaBrowser.Providers.Plugins.Omdb
|
|||
}
|
||||
}
|
||||
|
||||
var result = _jsonSerializer.DeserializeFromString<RootObject>(resultString);
|
||||
var result = JsonSerializer.Deserialize<RootObject>(resultString, JsonDefaults.GetOptions());
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -239,7 +238,7 @@ namespace MediaBrowser.Providers.Plugins.Omdb
|
|||
}
|
||||
}
|
||||
|
||||
var result = _jsonSerializer.DeserializeFromString<SeasonRootObject>(resultString);
|
||||
var result = JsonSerializer.Deserialize<SeasonRootObject>(resultString, JsonDefaults.GetOptions());
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -299,9 +298,10 @@ namespace MediaBrowser.Providers.Plugins.Omdb
|
|||
|
||||
using var response = await GetOmdbResponse(_httpClientFactory.CreateClient(NamedClient.Default), url, cancellationToken).ConfigureAwait(false);
|
||||
await using var stream = await response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
|
||||
var rootObject = await _jsonSerializer.DeserializeFromStreamAsync<RootObject>(stream).ConfigureAwait(false);
|
||||
var rootObject = await JsonSerializer.DeserializeAsync<RootObject>(stream, cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(path));
|
||||
_jsonSerializer.SerializeToFile(rootObject, path);
|
||||
await using FileStream jsonFileStream = File.Create(path);
|
||||
await JsonSerializer.SerializeAsync(jsonFileStream, rootObject, JsonDefaults.GetOptions(), cancellationToken).ConfigureAwait(false);
|
||||
|
||||
return path;
|
||||
}
|
||||
|
@ -337,9 +337,10 @@ namespace MediaBrowser.Providers.Plugins.Omdb
|
|||
|
||||
using var response = await GetOmdbResponse(_httpClientFactory.CreateClient(NamedClient.Default), url, cancellationToken).ConfigureAwait(false);
|
||||
await using var stream = await response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
|
||||
var rootObject = await _jsonSerializer.DeserializeFromStreamAsync<SeasonRootObject>(stream).ConfigureAwait(false);
|
||||
var rootObject = await JsonSerializer.DeserializeAsync<SeasonRootObject>(stream, cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(path));
|
||||
_jsonSerializer.SerializeToFile(rootObject, path);
|
||||
await using FileStream jsonFileStream = File.Create(path);
|
||||
await JsonSerializer.SerializeAsync(jsonFileStream, rootObject, JsonDefaults.GetOptions(), cancellationToken).ConfigureAwait(false);
|
||||
|
||||
return path;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user