Fix OMDb converter

This commit is contained in:
crobibero 2021-01-03 09:35:22 -07:00
parent d1da1aa407
commit a3a31952f4
2 changed files with 8 additions and 28 deletions

View File

@ -1,4 +1,5 @@
using System;
using System.ComponentModel;
using System.Text.Json;
using System.Text.Json.Serialization;
@ -21,6 +22,9 @@ namespace MediaBrowser.Common.Json.Converters
{
return null;
}
var converter = TypeDescriptor.GetConverter(typeToConvert);
return (T?)converter.ConvertFromString(str);
}
return JsonSerializer.Deserialize<T>(ref reader, options);

View File

@ -214,39 +214,15 @@ namespace MediaBrowser.Providers.Plugins.Omdb
internal async Task<RootObject> GetRootObject(string imdbId, CancellationToken cancellationToken)
{
var path = await EnsureItemInfo(imdbId, cancellationToken).ConfigureAwait(false);
string resultString;
using (var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
{
using (var reader = new StreamReader(stream, new UTF8Encoding(false)))
{
resultString = reader.ReadToEnd();
resultString = resultString.Replace("\"N/A\"", "\"\"");
}
}
var result = JsonSerializer.Deserialize<RootObject>(resultString, _jsonOptions);
return result;
await using var stream = File.OpenRead(path);
return await JsonSerializer.DeserializeAsync<RootObject>(stream, _jsonOptions, cancellationToken);
}
internal async Task<SeasonRootObject> GetSeasonRootObject(string imdbId, int seasonId, CancellationToken cancellationToken)
{
var path = await EnsureSeasonInfo(imdbId, seasonId, cancellationToken).ConfigureAwait(false);
string resultString;
using (var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
{
using (var reader = new StreamReader(stream, new UTF8Encoding(false)))
{
resultString = reader.ReadToEnd();
resultString = resultString.Replace("\"N/A\"", "\"\"");
}
}
var result = JsonSerializer.Deserialize<SeasonRootObject>(resultString, _jsonOptions);
return result;
await using var stream = File.OpenRead(path);
return await JsonSerializer.DeserializeAsync<SeasonRootObject>(stream, _jsonOptions, cancellationToken);
}
internal static bool IsValidSeries(Dictionary<string, string> seriesProviderIds)