Remove attributes

This commit is contained in:
David 2020-12-25 19:37:38 +01:00
parent dfd5a118ca
commit e0499f8769
3 changed files with 13 additions and 34 deletions

View File

@ -11,6 +11,7 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using MediaBrowser.Common; using MediaBrowser.Common;
using MediaBrowser.Common.Json; using MediaBrowser.Common.Json;
using MediaBrowser.Common.Json.Converters;
using MediaBrowser.Common.Net; using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
@ -32,7 +33,7 @@ namespace MediaBrowser.Providers.Plugins.Omdb
private readonly IFileSystem _fileSystem; private readonly IFileSystem _fileSystem;
private readonly IServerConfigurationManager _configurationManager; private readonly IServerConfigurationManager _configurationManager;
private readonly IApplicationHost _appHost; private readonly IApplicationHost _appHost;
private readonly JsonSerializerOptions _jsonOptions = JsonDefaults.GetOptions(); private readonly JsonSerializerOptions _jsonOptions;
public OmdbItemProvider( public OmdbItemProvider(
IApplicationHost appHost, IApplicationHost appHost,
@ -46,6 +47,10 @@ namespace MediaBrowser.Providers.Plugins.Omdb
_fileSystem = fileSystem; _fileSystem = fileSystem;
_configurationManager = configurationManager; _configurationManager = configurationManager;
_appHost = appHost; _appHost = appHost;
_jsonOptions = new JsonSerializerOptions(JsonDefaults.GetOptions());
_jsonOptions.Converters.Add(new JsonOmdbNotAvailableStringConverter());
_jsonOptions.Converters.Add(new JsonOmdbNotAvailableStructConverter<int>());
} }
public string Name => "The Open Movie Database"; public string Name => "The Open Movie Database";

View File

@ -30,7 +30,7 @@ namespace MediaBrowser.Providers.Plugins.Omdb
private readonly IHttpClientFactory _httpClientFactory; 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;
private static readonly JsonSerializerOptions _jsonOptions = JsonDefaults.GetOptions(); private readonly JsonSerializerOptions _jsonOptions;
public OmdbProvider(IHttpClientFactory httpClientFactory, IFileSystem fileSystem, IApplicationHost appHost, IServerConfigurationManager configurationManager) public OmdbProvider(IHttpClientFactory httpClientFactory, IFileSystem fileSystem, IApplicationHost appHost, IServerConfigurationManager configurationManager)
{ {
@ -38,6 +38,10 @@ namespace MediaBrowser.Providers.Plugins.Omdb
_fileSystem = fileSystem; _fileSystem = fileSystem;
_configurationManager = configurationManager; _configurationManager = configurationManager;
_appHost = appHost; _appHost = appHost;
_jsonOptions = new JsonSerializerOptions(JsonDefaults.GetOptions());
_jsonOptions.Converters.Add(new JsonOmdbNotAvailableStringConverter());
_jsonOptions.Converters.Add(new JsonOmdbNotAvailableStructConverter<int>());
} }
public async Task Fetch<T>(MetadataResult<T> itemResult, string imdbId, string language, string country, CancellationToken cancellationToken) public async Task Fetch<T>(MetadataResult<T> itemResult, string imdbId, string language, string country, CancellationToken cancellationToken)
@ -344,7 +348,7 @@ namespace MediaBrowser.Providers.Plugins.Omdb
return path; return path;
} }
public static async Task<T> GetDeserializedOmdbResponse<T>(HttpClient httpClient, string url, CancellationToken cancellationToken) public async Task<T> GetDeserializedOmdbResponse<T>(HttpClient httpClient, string url, CancellationToken cancellationToken)
{ {
using var response = await GetOmdbResponse(httpClient, url, cancellationToken).ConfigureAwait(false); using var response = await GetOmdbResponse(httpClient, url, cancellationToken).ConfigureAwait(false);
var content = await response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); var content = await response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
@ -471,101 +475,71 @@ namespace MediaBrowser.Providers.Plugins.Omdb
public class SeasonRootObject public class SeasonRootObject
{ {
[JsonConverter(typeof(JsonOmdbNotAvailableStringConverter))]
public string Title { get; set; } public string Title { get; set; }
[JsonConverter(typeof(JsonOmdbNotAvailableStringConverter))]
public string seriesID { get; set; } public string seriesID { get; set; }
[JsonConverter(typeof(JsonOmdbNotAvailableStructConverter<int>))]
public int? Season { get; set; } public int? Season { get; set; }
[JsonConverter(typeof(JsonOmdbNotAvailableStructConverter<int>))]
public int? totalSeasons { get; set; } public int? totalSeasons { get; set; }
public RootObject[] Episodes { get; set; } public RootObject[] Episodes { get; set; }
[JsonConverter(typeof(JsonOmdbNotAvailableStringConverter))]
public string Response { get; set; } public string Response { get; set; }
} }
public class RootObject public class RootObject
{ {
[JsonConverter(typeof(JsonOmdbNotAvailableStringConverter))]
public string Title { get; set; } public string Title { get; set; }
[JsonConverter(typeof(JsonOmdbNotAvailableStringConverter))]
public string Year { get; set; } public string Year { get; set; }
[JsonConverter(typeof(JsonOmdbNotAvailableStringConverter))]
public string Rated { get; set; } public string Rated { get; set; }
[JsonConverter(typeof(JsonOmdbNotAvailableStringConverter))]
public string Released { get; set; } public string Released { get; set; }
[JsonConverter(typeof(JsonOmdbNotAvailableStringConverter))]
public string Runtime { get; set; } public string Runtime { get; set; }
[JsonConverter(typeof(JsonOmdbNotAvailableStringConverter))]
public string Genre { get; set; } public string Genre { get; set; }
[JsonConverter(typeof(JsonOmdbNotAvailableStringConverter))]
public string Director { get; set; } public string Director { get; set; }
[JsonConverter(typeof(JsonOmdbNotAvailableStringConverter))]
public string Writer { get; set; } public string Writer { get; set; }
[JsonConverter(typeof(JsonOmdbNotAvailableStringConverter))]
public string Actors { get; set; } public string Actors { get; set; }
[JsonConverter(typeof(JsonOmdbNotAvailableStringConverter))]
public string Plot { get; set; } public string Plot { get; set; }
[JsonConverter(typeof(JsonOmdbNotAvailableStringConverter))]
public string Language { get; set; } public string Language { get; set; }
[JsonConverter(typeof(JsonOmdbNotAvailableStringConverter))]
public string Country { get; set; } public string Country { get; set; }
[JsonConverter(typeof(JsonOmdbNotAvailableStringConverter))]
public string Awards { get; set; } public string Awards { get; set; }
[JsonConverter(typeof(JsonOmdbNotAvailableStringConverter))]
public string Poster { get; set; } public string Poster { get; set; }
public List<OmdbRating> Ratings { get; set; } public List<OmdbRating> Ratings { get; set; }
[JsonConverter(typeof(JsonOmdbNotAvailableStringConverter))]
public string Metascore { get; set; } public string Metascore { get; set; }
[JsonConverter(typeof(JsonOmdbNotAvailableStringConverter))]
public string imdbRating { get; set; } public string imdbRating { get; set; }
[JsonConverter(typeof(JsonOmdbNotAvailableStringConverter))]
public string imdbVotes { get; set; } public string imdbVotes { get; set; }
[JsonConverter(typeof(JsonOmdbNotAvailableStringConverter))]
public string imdbID { get; set; } public string imdbID { get; set; }
[JsonConverter(typeof(JsonOmdbNotAvailableStringConverter))]
public string Type { get; set; } public string Type { get; set; }
[JsonConverter(typeof(JsonOmdbNotAvailableStringConverter))]
public string DVD { get; set; } public string DVD { get; set; }
[JsonConverter(typeof(JsonOmdbNotAvailableStringConverter))]
public string BoxOffice { get; set; } public string BoxOffice { get; set; }
[JsonConverter(typeof(JsonOmdbNotAvailableStringConverter))]
public string Production { get; set; } public string Production { get; set; }
[JsonConverter(typeof(JsonOmdbNotAvailableStringConverter))]
public string Website { get; set; } public string Website { get; set; }
[JsonConverter(typeof(JsonOmdbNotAvailableStringConverter))]
public string Response { get; set; } public string Response { get; set; }
[JsonConverter(typeof(JsonOmdbNotAvailableStructConverter<int>))]
public int? Episode { get; set; } public int? Episode { get; set; }
public float? GetRottenTomatoScore() public float? GetRottenTomatoScore()

View File

@ -23,7 +23,7 @@ namespace Jellyfin.Common.Tests.Json
public void Deserialize_Omdb_Response_Not_Available_Success() public void Deserialize_Omdb_Response_Not_Available_Success()
{ {
const string Input = "{\"Title\":\"Chapter 1\",\"Year\":\"2013\",\"Rated\":\"TV-MA\",\"Released\":\"01 Feb 2013\",\"Season\":\"N/A\",\"Episode\":\"N/A\",\"Runtime\":\"55 min\",\"Genre\":\"Drama\",\"Director\":\"David Fincher\",\"Writer\":\"Michael Dobbs (based on the novels by), Andrew Davies (based on the mini-series by), Beau Willimon (created for television by), Beau Willimon, Sam Forman (staff writer)\",\"Actors\":\"Kevin Spacey, Robin Wright, Kate Mara, Corey Stoll\",\"Plot\":\"Congressman Francis Underwood has been declined the chair for Secretary of State. He's now gathering his own team to plot his revenge. Zoe Barnes, a reporter for the Washington Herald, will do anything to get her big break.\",\"Language\":\"English\",\"Country\":\"USA\",\"Awards\":\"N/A\",\"Poster\":\"https://m.media-amazon.com/images/M/MV5BMTY5MTU4NDQzNV5BMl5BanBnXkFtZTgwMzk2ODcxMzE@._V1_SX300.jpg\",\"Ratings\":[{\"Source\":\"Internet Movie Database\",\"Value\":\"8.7/10\"}],\"Metascore\":\"N/A\",\"imdbRating\":\"8.7\",\"imdbVotes\":\"6736\",\"imdbID\":\"tt2161930\",\"seriesID\":\"N/A\",\"Type\":\"episode\",\"Response\":\"True\"}"; const string Input = "{\"Title\":\"Chapter 1\",\"Year\":\"2013\",\"Rated\":\"TV-MA\",\"Released\":\"01 Feb 2013\",\"Season\":\"N/A\",\"Episode\":\"N/A\",\"Runtime\":\"55 min\",\"Genre\":\"Drama\",\"Director\":\"David Fincher\",\"Writer\":\"Michael Dobbs (based on the novels by), Andrew Davies (based on the mini-series by), Beau Willimon (created for television by), Beau Willimon, Sam Forman (staff writer)\",\"Actors\":\"Kevin Spacey, Robin Wright, Kate Mara, Corey Stoll\",\"Plot\":\"Congressman Francis Underwood has been declined the chair for Secretary of State. He's now gathering his own team to plot his revenge. Zoe Barnes, a reporter for the Washington Herald, will do anything to get her big break.\",\"Language\":\"English\",\"Country\":\"USA\",\"Awards\":\"N/A\",\"Poster\":\"https://m.media-amazon.com/images/M/MV5BMTY5MTU4NDQzNV5BMl5BanBnXkFtZTgwMzk2ODcxMzE@._V1_SX300.jpg\",\"Ratings\":[{\"Source\":\"Internet Movie Database\",\"Value\":\"8.7/10\"}],\"Metascore\":\"N/A\",\"imdbRating\":\"8.7\",\"imdbVotes\":\"6736\",\"imdbID\":\"tt2161930\",\"seriesID\":\"N/A\",\"Type\":\"episode\",\"Response\":\"True\"}";
var seasonRootObject = JsonSerializer.Deserialize<OmdbProvider.RootObject>(Input, JsonDefaults.GetOptions()); var seasonRootObject = JsonSerializer.Deserialize<OmdbProvider.RootObject>(Input, _options);
Assert.NotNull(seasonRootObject); Assert.NotNull(seasonRootObject);
Assert.Null(seasonRootObject?.Awards); Assert.Null(seasonRootObject?.Awards);
Assert.Null(seasonRootObject?.Episode); Assert.Null(seasonRootObject?.Episode);