You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
522 lines
19 KiB
522 lines
19 KiB
11 years ago
|
using System;
|
||
8 years ago
|
using System.Collections.Generic;
|
||
11 years ago
|
using System.Globalization;
|
||
9 years ago
|
using System.IO;
|
||
11 years ago
|
using System.Linq;
|
||
5 years ago
|
using System.Net.Http;
|
||
9 years ago
|
using System.Text;
|
||
11 years ago
|
using System.Threading;
|
||
|
using System.Threading.Tasks;
|
||
6 years ago
|
using MediaBrowser.Common;
|
||
6 years ago
|
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;
|
||
11 years ago
|
|
||
5 years ago
|
namespace MediaBrowser.Providers.Plugins.Omdb
|
||
11 years ago
|
{
|
||
|
public class OmdbProvider
|
||
|
{
|
||
|
private readonly IJsonSerializer _jsonSerializer;
|
||
9 years ago
|
private readonly IFileSystem _fileSystem;
|
||
|
private readonly IServerConfigurationManager _configurationManager;
|
||
11 years ago
|
private readonly IHttpClient _httpClient;
|
||
|
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
|
||
6 years ago
|
private readonly IApplicationHost _appHost;
|
||
11 years ago
|
|
||
6 years ago
|
public OmdbProvider(IJsonSerializer jsonSerializer, IHttpClient httpClient, IFileSystem fileSystem, IApplicationHost appHost, IServerConfigurationManager configurationManager)
|
||
11 years ago
|
{
|
||
|
_jsonSerializer = jsonSerializer;
|
||
|
_httpClient = httpClient;
|
||
9 years ago
|
_fileSystem = fileSystem;
|
||
|
_configurationManager = configurationManager;
|
||
6 years ago
|
_appHost = appHost;
|
||
11 years ago
|
}
|
||
|
|
||
8 years ago
|
public async Task Fetch<T>(MetadataResult<T> itemResult, string imdbId, string language, string country, CancellationToken cancellationToken)
|
||
8 years ago
|
where T : BaseItem
|
||
11 years ago
|
{
|
||
10 years ago
|
if (string.IsNullOrWhiteSpace(imdbId))
|
||
|
{
|
||
6 years ago
|
throw new ArgumentNullException(nameof(imdbId));
|
||
10 years ago
|
}
|
||
|
|
||
6 years ago
|
var item = itemResult.Item;
|
||
8 years ago
|
|
||
8 years ago
|
var result = await GetRootObject(imdbId, cancellationToken).ConfigureAwait(false);
|
||
11 years ago
|
|
||
8 years ago
|
// Only take the name and rating if the user's language is set to english, since Omdb has no localization
|
||
7 years ago
|
if (string.Equals(language, "en", StringComparison.OrdinalIgnoreCase) || _configurationManager.Configuration.EnableNewOmdbSupport)
|
||
8 years ago
|
{
|
||
|
item.Name = result.Title;
|
||
9 years ago
|
|
||
8 years ago
|
if (string.Equals(country, "us", StringComparison.OrdinalIgnoreCase))
|
||
|
{
|
||
|
item.OfficialRating = result.Rated;
|
||
9 years ago
|
}
|
||
8 years ago
|
}
|
||
10 years ago
|
|
||
8 years ago
|
if (!string.IsNullOrEmpty(result.Year) && result.Year.Length >= 4
|
||
6 years ago
|
&& int.TryParse(result.Year.Substring(0, 4), NumberStyles.Number, _usCulture, out var year)
|
||
8 years ago
|
&& year >= 0)
|
||
|
{
|
||
|
item.ProductionYear = year;
|
||
|
}
|
||
10 years ago
|
|
||
8 years ago
|
var tomatoScore = result.GetRottenTomatoScore();
|
||
11 years ago
|
|
||
8 years ago
|
if (tomatoScore.HasValue)
|
||
8 years ago
|
{
|
||
8 years ago
|
item.CriticRating = tomatoScore;
|
||
8 years ago
|
}
|
||
11 years ago
|
|
||
8 years ago
|
if (!string.IsNullOrEmpty(result.imdbVotes)
|
||
6 years ago
|
&& int.TryParse(result.imdbVotes, NumberStyles.Number, _usCulture, out var voteCount)
|
||
8 years ago
|
&& voteCount >= 0)
|
||
|
{
|
||
8 years ago
|
//item.VoteCount = voteCount;
|
||
8 years ago
|
}
|
||
11 years ago
|
|
||
8 years ago
|
if (!string.IsNullOrEmpty(result.imdbRating)
|
||
6 years ago
|
&& float.TryParse(result.imdbRating, NumberStyles.Any, _usCulture, out var imdbRating)
|
||
8 years ago
|
&& imdbRating >= 0)
|
||
|
{
|
||
|
item.CommunityRating = imdbRating;
|
||
|
}
|
||
11 years ago
|
|
||
6 years ago
|
//if (!string.IsNullOrEmpty(result.Website))
|
||
|
//{
|
||
|
// item.HomePageUrl = result.Website;
|
||
|
//}
|
||
11 years ago
|
|
||
8 years ago
|
if (!string.IsNullOrWhiteSpace(result.imdbID))
|
||
|
{
|
||
|
item.SetProviderId(MetadataProviders.Imdb, result.imdbID);
|
||
|
}
|
||
10 years ago
|
|
||
8 years ago
|
ParseAdditionalMetadata(itemResult, result);
|
||
9 years ago
|
}
|
||
|
|
||
8 years ago
|
public async Task<bool> FetchEpisodeData<T>(MetadataResult<T> itemResult, int episodeNumber, int seasonNumber, string episodeImdbId, string seriesImdbId, string language, string country, CancellationToken cancellationToken)
|
||
8 years ago
|
where T : BaseItem
|
||
8 years ago
|
{
|
||
8 years ago
|
if (string.IsNullOrWhiteSpace(seriesImdbId))
|
||
8 years ago
|
{
|
||
6 years ago
|
throw new ArgumentNullException(nameof(seriesImdbId));
|
||
8 years ago
|
}
|
||
|
|
||
6 years ago
|
var item = itemResult.Item;
|
||
8 years ago
|
|
||
8 years ago
|
var seasonResult = await GetSeasonRootObject(seriesImdbId, seasonNumber, cancellationToken).ConfigureAwait(false);
|
||
8 years ago
|
|
||
|
if (seasonResult == null)
|
||
|
{
|
||
|
return false;
|
||
|
}
|
||
8 years ago
|
|
||
|
RootObject result = null;
|
||
|
|
||
8 years ago
|
if (!string.IsNullOrWhiteSpace(episodeImdbId))
|
||
|
{
|
||
|
foreach (var episode in (seasonResult.Episodes ?? new RootObject[] { }))
|
||
|
{
|
||
|
if (string.Equals(episodeImdbId, episode.imdbID, StringComparison.OrdinalIgnoreCase))
|
||
|
{
|
||
|
result = episode;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// finally, search by numbers
|
||
|
if (result == null)
|
||
8 years ago
|
{
|
||
8 years ago
|
foreach (var episode in (seasonResult.Episodes ?? new RootObject[] { }))
|
||
8 years ago
|
{
|
||
8 years ago
|
if (episode.Episode == episodeNumber)
|
||
|
{
|
||
|
result = episode;
|
||
|
break;
|
||
|
}
|
||
8 years ago
|
}
|
||
|
}
|
||
|
|
||
|
if (result == null)
|
||
|
{
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
// Only take the name and rating if the user's language is set to english, since Omdb has no localization
|
||
7 years ago
|
if (string.Equals(language, "en", StringComparison.OrdinalIgnoreCase) || _configurationManager.Configuration.EnableNewOmdbSupport)
|
||
8 years ago
|
{
|
||
|
item.Name = result.Title;
|
||
|
|
||
|
if (string.Equals(country, "us", StringComparison.OrdinalIgnoreCase))
|
||
|
{
|
||
|
item.OfficialRating = result.Rated;
|
||
|
}
|
||
|
}
|
||
|
|
||
8 years ago
|
if (!string.IsNullOrEmpty(result.Year) && result.Year.Length >= 4
|
||
6 years ago
|
&& int.TryParse(result.Year.Substring(0, 4), NumberStyles.Number, _usCulture, out var year)
|
||
8 years ago
|
&& year >= 0)
|
||
|
{
|
||
|
item.ProductionYear = year;
|
||
|
}
|
||
|
|
||
8 years ago
|
var tomatoScore = result.GetRottenTomatoScore();
|
||
8 years ago
|
|
||
8 years ago
|
if (tomatoScore.HasValue)
|
||
8 years ago
|
{
|
||
8 years ago
|
item.CriticRating = tomatoScore;
|
||
8 years ago
|
}
|
||
|
|
||
|
if (!string.IsNullOrEmpty(result.imdbVotes)
|
||
6 years ago
|
&& int.TryParse(result.imdbVotes, NumberStyles.Number, _usCulture, out var voteCount)
|
||
8 years ago
|
&& voteCount >= 0)
|
||
|
{
|
||
8 years ago
|
//item.VoteCount = voteCount;
|
||
8 years ago
|
}
|
||
|
|
||
|
if (!string.IsNullOrEmpty(result.imdbRating)
|
||
6 years ago
|
&& float.TryParse(result.imdbRating, NumberStyles.Any, _usCulture, out var imdbRating)
|
||
8 years ago
|
&& imdbRating >= 0)
|
||
|
{
|
||
|
item.CommunityRating = imdbRating;
|
||
|
}
|
||
|
|
||
6 years ago
|
//if (!string.IsNullOrEmpty(result.Website))
|
||
|
//{
|
||
|
// item.HomePageUrl = result.Website;
|
||
|
//}
|
||
8 years ago
|
|
||
|
if (!string.IsNullOrWhiteSpace(result.imdbID))
|
||
|
{
|
||
|
item.SetProviderId(MetadataProviders.Imdb, result.imdbID);
|
||
|
}
|
||
|
|
||
8 years ago
|
ParseAdditionalMetadata(itemResult, result);
|
||
8 years ago
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
9 years ago
|
internal async Task<RootObject> GetRootObject(string imdbId, CancellationToken cancellationToken)
|
||
|
{
|
||
8 years ago
|
var path = await EnsureItemInfo(imdbId, cancellationToken).ConfigureAwait(false);
|
||
9 years ago
|
|
||
|
string resultString;
|
||
|
|
||
5 years ago
|
using (var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
|
||
9 years ago
|
{
|
||
|
using (var reader = new StreamReader(stream, new UTF8Encoding(false)))
|
||
|
{
|
||
|
resultString = reader.ReadToEnd();
|
||
|
resultString = resultString.Replace("\"N/A\"", "\"\"");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
var result = _jsonSerializer.DeserializeFromString<RootObject>(resultString);
|
||
|
return result;
|
||
|
}
|
||
|
|
||
8 years ago
|
internal async Task<SeasonRootObject> GetSeasonRootObject(string imdbId, int seasonId, CancellationToken cancellationToken)
|
||
|
{
|
||
8 years ago
|
var path = await EnsureSeasonInfo(imdbId, seasonId, cancellationToken).ConfigureAwait(false);
|
||
8 years ago
|
|
||
|
string resultString;
|
||
|
|
||
5 years ago
|
using (var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
|
||
8 years ago
|
{
|
||
|
using (var reader = new StreamReader(stream, new UTF8Encoding(false)))
|
||
|
{
|
||
|
resultString = reader.ReadToEnd();
|
||
|
resultString = resultString.Replace("\"N/A\"", "\"\"");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
var result = _jsonSerializer.DeserializeFromString<SeasonRootObject>(resultString);
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
internal static bool IsValidSeries(Dictionary<string, string> seriesProviderIds)
|
||
|
{
|
||
6 years ago
|
if (seriesProviderIds.TryGetValue(MetadataProviders.Imdb.ToString(), out string id) && !string.IsNullOrEmpty(id))
|
||
8 years ago
|
{
|
||
|
// This check should ideally never be necessary but we're seeing some cases of this and haven't tracked them down yet.
|
||
|
if (!string.IsNullOrWhiteSpace(id))
|
||
|
{
|
||
|
return true;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return false;
|
||
|
}
|
||
|
|
||
6 years ago
|
public static string GetOmdbUrl(string query, IApplicationHost appHost, CancellationToken cancellationToken)
|
||
8 years ago
|
{
|
||
6 years ago
|
const string url = "https://www.omdbapi.com?apikey=2c9d9507";
|
||
6 years ago
|
|
||
6 years ago
|
if (string.IsNullOrWhiteSpace(query))
|
||
6 years ago
|
{
|
||
6 years ago
|
return url;
|
||
6 years ago
|
}
|
||
6 years ago
|
return url + "&" + query;
|
||
8 years ago
|
}
|
||
|
|
||
9 years ago
|
private async Task<string> EnsureItemInfo(string imdbId, CancellationToken cancellationToken)
|
||
9 years ago
|
{
|
||
|
if (string.IsNullOrWhiteSpace(imdbId))
|
||
|
{
|
||
6 years ago
|
throw new ArgumentNullException(nameof(imdbId));
|
||
9 years ago
|
}
|
||
|
|
||
|
var imdbParam = imdbId.StartsWith("tt", StringComparison.OrdinalIgnoreCase) ? imdbId : "tt" + imdbId;
|
||
|
|
||
|
var path = GetDataFilePath(imdbParam);
|
||
|
|
||
|
var fileInfo = _fileSystem.GetFileSystemInfo(path);
|
||
|
|
||
|
if (fileInfo.Exists)
|
||
|
{
|
||
|
// If it's recent or automatic updates are enabled, don't re-download
|
||
6 years ago
|
if ((DateTime.UtcNow - _fileSystem.GetLastWriteTimeUtc(fileInfo)).TotalDays <= 1)
|
||
9 years ago
|
{
|
||
|
return path;
|
||
|
}
|
||
|
}
|
||
|
|
||
6 years ago
|
var url = GetOmdbUrl(string.Format("i={0}&plot=short&tomatoes=true&r=json", imdbParam), _appHost, cancellationToken);
|
||
9 years ago
|
|
||
7 years ago
|
using (var response = await GetOmdbResponse(_httpClient, url, cancellationToken).ConfigureAwait(false))
|
||
9 years ago
|
{
|
||
7 years ago
|
using (var stream = response.Content)
|
||
|
{
|
||
6 years ago
|
var rootObject = await _jsonSerializer.DeserializeFromStreamAsync<RootObject>(stream).ConfigureAwait(false);
|
||
6 years ago
|
Directory.CreateDirectory(Path.GetDirectoryName(path));
|
||
7 years ago
|
_jsonSerializer.SerializeToFile(rootObject, path);
|
||
|
}
|
||
9 years ago
|
}
|
||
|
|
||
|
return path;
|
||
|
}
|
||
|
|
||
8 years ago
|
private async Task<string> EnsureSeasonInfo(string seriesImdbId, int seasonId, CancellationToken cancellationToken)
|
||
|
{
|
||
|
if (string.IsNullOrWhiteSpace(seriesImdbId))
|
||
|
{
|
||
6 years ago
|
throw new ArgumentException("The series IMDb ID was null or whitespace.", nameof(seriesImdbId));
|
||
8 years ago
|
}
|
||
|
|
||
|
var imdbParam = seriesImdbId.StartsWith("tt", StringComparison.OrdinalIgnoreCase) ? seriesImdbId : "tt" + seriesImdbId;
|
||
|
|
||
|
var path = GetSeasonFilePath(imdbParam, seasonId);
|
||
|
|
||
|
var fileInfo = _fileSystem.GetFileSystemInfo(path);
|
||
|
|
||
|
if (fileInfo.Exists)
|
||
|
{
|
||
|
// If it's recent or automatic updates are enabled, don't re-download
|
||
6 years ago
|
if ((DateTime.UtcNow - _fileSystem.GetLastWriteTimeUtc(fileInfo)).TotalDays <= 1)
|
||
8 years ago
|
{
|
||
|
return path;
|
||
|
}
|
||
|
}
|
||
|
|
||
6 years ago
|
var url = GetOmdbUrl(string.Format("i={0}&season={1}&detail=full", imdbParam, seasonId), _appHost, cancellationToken);
|
||
8 years ago
|
|
||
7 years ago
|
using (var response = await GetOmdbResponse(_httpClient, url, cancellationToken).ConfigureAwait(false))
|
||
8 years ago
|
{
|
||
7 years ago
|
using (var stream = response.Content)
|
||
|
{
|
||
6 years ago
|
var rootObject = await _jsonSerializer.DeserializeFromStreamAsync<SeasonRootObject>(stream).ConfigureAwait(false);
|
||
6 years ago
|
Directory.CreateDirectory(Path.GetDirectoryName(path));
|
||
7 years ago
|
_jsonSerializer.SerializeToFile(rootObject, path);
|
||
|
}
|
||
8 years ago
|
}
|
||
|
|
||
|
return path;
|
||
|
}
|
||
|
|
||
7 years ago
|
public static Task<HttpResponseInfo> GetOmdbResponse(IHttpClient httpClient, string url, CancellationToken cancellationToken)
|
||
8 years ago
|
{
|
||
7 years ago
|
return httpClient.SendAsync(new HttpRequestOptions
|
||
8 years ago
|
{
|
||
|
Url = url,
|
||
|
CancellationToken = cancellationToken,
|
||
8 years ago
|
BufferContent = true,
|
||
|
EnableDefaultUserAgent = true
|
||
5 years ago
|
}, HttpMethod.Get);
|
||
8 years ago
|
}
|
||
|
|
||
9 years ago
|
internal string GetDataFilePath(string imdbId)
|
||
|
{
|
||
|
if (string.IsNullOrEmpty(imdbId))
|
||
|
{
|
||
6 years ago
|
throw new ArgumentNullException(nameof(imdbId));
|
||
11 years ago
|
}
|
||
9 years ago
|
|
||
|
var dataPath = Path.Combine(_configurationManager.ApplicationPaths.CachePath, "omdb");
|
||
|
|
||
|
var filename = string.Format("{0}.json", imdbId);
|
||
|
|
||
|
return Path.Combine(dataPath, filename);
|
||
11 years ago
|
}
|
||
|
|
||
8 years ago
|
internal string GetSeasonFilePath(string imdbId, int seasonId)
|
||
|
{
|
||
|
if (string.IsNullOrEmpty(imdbId))
|
||
|
{
|
||
6 years ago
|
throw new ArgumentNullException(nameof(imdbId));
|
||
8 years ago
|
}
|
||
|
|
||
|
var dataPath = Path.Combine(_configurationManager.ApplicationPaths.CachePath, "omdb");
|
||
|
|
||
|
var filename = string.Format("{0}_season_{1}.json", imdbId, seasonId);
|
||
|
|
||
|
return Path.Combine(dataPath, filename);
|
||
|
}
|
||
|
|
||
8 years ago
|
private void ParseAdditionalMetadata<T>(MetadataResult<T> itemResult, RootObject result)
|
||
|
where T : BaseItem
|
||
11 years ago
|
{
|
||
6 years ago
|
var item = itemResult.Item;
|
||
8 years ago
|
|
||
7 years ago
|
var isConfiguredForEnglish = IsConfiguredForEnglish(item) || _configurationManager.Configuration.EnableNewOmdbSupport;
|
||
8 years ago
|
|
||
11 years ago
|
// Grab series genres because imdb data is better than tvdb. Leave movies alone
|
||
|
// But only do it if english is the preferred language because this data will not be localized
|
||
8 years ago
|
if (isConfiguredForEnglish && !string.IsNullOrWhiteSpace(result.Genre))
|
||
11 years ago
|
{
|
||
6 years ago
|
item.Genres = Array.Empty<string>();
|
||
11 years ago
|
|
||
|
foreach (var genre in result.Genre
|
||
|
.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
|
||
|
.Select(i => i.Trim())
|
||
|
.Where(i => !string.IsNullOrWhiteSpace(i)))
|
||
|
{
|
||
|
item.AddGenre(genre);
|
||
|
}
|
||
|
}
|
||
|
|
||
8 years ago
|
if (isConfiguredForEnglish)
|
||
|
{
|
||
|
// Omdb is currently english only, so for other languages skip this and let secondary providers fill it in
|
||
|
item.Overview = result.Plot;
|
||
|
}
|
||
8 years ago
|
|
||
8 years ago
|
//if (!string.IsNullOrWhiteSpace(result.Director))
|
||
|
//{
|
||
|
// var person = new PersonInfo
|
||
|
// {
|
||
|
// Name = result.Director.Trim(),
|
||
|
// Type = PersonType.Director
|
||
|
// };
|
||
|
|
||
|
// itemResult.AddPerson(person);
|
||
|
//}
|
||
|
|
||
|
//if (!string.IsNullOrWhiteSpace(result.Writer))
|
||
|
//{
|
||
|
// var person = new PersonInfo
|
||
|
// {
|
||
|
// Name = result.Director.Trim(),
|
||
|
// Type = PersonType.Writer
|
||
|
// };
|
||
|
|
||
|
// itemResult.AddPerson(person);
|
||
|
//}
|
||
|
|
||
|
//if (!string.IsNullOrWhiteSpace(result.Actors))
|
||
|
//{
|
||
|
// var actorList = result.Actors.Split(',');
|
||
|
// foreach (var actor in actorList)
|
||
|
// {
|
||
|
// if (!string.IsNullOrWhiteSpace(actor))
|
||
|
// {
|
||
|
// var person = new PersonInfo
|
||
|
// {
|
||
|
// Name = actor.Trim(),
|
||
|
// Type = PersonType.Actor
|
||
|
// };
|
||
|
|
||
|
// itemResult.AddPerson(person);
|
||
|
// }
|
||
|
// }
|
||
|
//}
|
||
11 years ago
|
}
|
||
|
|
||
8 years ago
|
private bool IsConfiguredForEnglish(BaseItem item)
|
||
11 years ago
|
{
|
||
|
var lang = item.GetPreferredMetadataLanguage();
|
||
|
|
||
|
// The data isn't localized and so can only be used for english users
|
||
11 years ago
|
return string.Equals(lang, "en", StringComparison.OrdinalIgnoreCase);
|
||
11 years ago
|
}
|
||
|
|
||
8 years ago
|
internal class SeasonRootObject
|
||
|
{
|
||
|
public string Title { get; set; }
|
||
|
public string seriesID { get; set; }
|
||
|
public int Season { get; set; }
|
||
|
public int? totalSeasons { get; set; }
|
||
|
public RootObject[] Episodes { get; set; }
|
||
|
public string Response { get; set; }
|
||
|
}
|
||
|
|
||
9 years ago
|
internal class RootObject
|
||
11 years ago
|
{
|
||
|
public string Title { get; set; }
|
||
|
public string Year { get; set; }
|
||
|
public string Rated { get; set; }
|
||
|
public string Released { get; set; }
|
||
|
public string Runtime { get; set; }
|
||
|
public string Genre { get; set; }
|
||
|
public string Director { get; set; }
|
||
|
public string Writer { get; set; }
|
||
|
public string Actors { get; set; }
|
||
|
public string Plot { get; set; }
|
||
8 years ago
|
public string Language { get; set; }
|
||
|
public string Country { get; set; }
|
||
|
public string Awards { get; set; }
|
||
11 years ago
|
public string Poster { get; set; }
|
||
8 years ago
|
public List<OmdbRating> Ratings { get; set; }
|
||
|
public string Metascore { get; set; }
|
||
11 years ago
|
public string imdbRating { get; set; }
|
||
|
public string imdbVotes { get; set; }
|
||
|
public string imdbID { get; set; }
|
||
|
public string Type { get; set; }
|
||
|
public string DVD { get; set; }
|
||
|
public string BoxOffice { get; set; }
|
||
|
public string Production { get; set; }
|
||
|
public string Website { get; set; }
|
||
|
public string Response { get; set; }
|
||
8 years ago
|
public int Episode { get; set; }
|
||
11 years ago
|
|
||
8 years ago
|
public float? GetRottenTomatoScore()
|
||
|
{
|
||
|
if (Ratings != null)
|
||
|
{
|
||
|
var rating = Ratings.FirstOrDefault(i => string.Equals(i.Source, "Rotten Tomatoes", StringComparison.OrdinalIgnoreCase));
|
||
|
if (rating != null && rating.Value != null)
|
||
|
{
|
||
|
var value = rating.Value.TrimEnd('%');
|
||
6 years ago
|
if (float.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out var score))
|
||
8 years ago
|
{
|
||
|
return score;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
return null;
|
||
|
}
|
||
|
}
|
||
|
public class OmdbRating
|
||
|
{
|
||
|
public string Source { get; set; }
|
||
|
public string Value { get; set; }
|
||
11 years ago
|
}
|
||
|
}
|
||
|
}
|