mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-20 21:33:15 -07:00
Added Rotten Tomatoes ratings to the detail pages
This commit is contained in:
parent
fde93d2445
commit
cb127f3858
40 changed files with 312 additions and 95 deletions
14
src/Ombi.Api.RottenTomatoes/IRottenTomatoesApi.cs
Normal file
14
src/Ombi.Api.RottenTomatoes/IRottenTomatoesApi.cs
Normal file
|
@ -0,0 +1,14 @@
|
|||
using Ombi.Api.RottenTomatoes.Models;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ombi.Api.RottenTomatoes
|
||||
{
|
||||
public interface IRottenTomatoesApi
|
||||
{
|
||||
Task<MovieRatings> GetMovieRatings(string movieName, int movieYear);
|
||||
Task<TvRatings> GetTvRatings(string showName, int showYear);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace Ombi.Api.RottenTomatoes.Models
|
||||
{
|
||||
public class RottenTomatoesMovieResponse
|
||||
{
|
||||
public int total { get; set; }
|
||||
public List<Movie> movies { get; set; }
|
||||
}
|
||||
|
||||
public class Movie
|
||||
{
|
||||
public string id { get; set; }
|
||||
public string title { get; set; }
|
||||
public int year { get; set; }
|
||||
public string mpaa_rating { get; set; }
|
||||
public object runtime { get; set; }
|
||||
public string critics_consensus { get; set; }
|
||||
public MovieRatings ratings { get; set; }
|
||||
public Links links { get; set; }
|
||||
}
|
||||
|
||||
public class MovieRatings
|
||||
{
|
||||
public string critics_rating { get; set; }
|
||||
public int critics_score { get; set; }
|
||||
public string audience_rating { get; set; }
|
||||
public int audience_score { get; set; }
|
||||
}
|
||||
|
||||
public class Links
|
||||
{
|
||||
public string alternate { get; set; }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
namespace Ombi.Api.RottenTomatoes.Models
|
||||
{
|
||||
public class RottenTomatoesTvResponse
|
||||
{
|
||||
public int tvCount { get; set; }
|
||||
public TvSeries[] tvSeries { get; set; }
|
||||
}
|
||||
|
||||
public class TvSeries
|
||||
{
|
||||
public string title { get; set; }
|
||||
public int startYear { get; set; }
|
||||
public int endYear { get; set; }
|
||||
public string url { get; set; }
|
||||
public string meterClass { get; set; }
|
||||
public int meterScore { get; set; }
|
||||
public string image { get; set; }
|
||||
}
|
||||
|
||||
}
|
8
src/Ombi.Api.RottenTomatoes/Models/TvRatings.cs
Normal file
8
src/Ombi.Api.RottenTomatoes/Models/TvRatings.cs
Normal file
|
@ -0,0 +1,8 @@
|
|||
namespace Ombi.Api.RottenTomatoes.Models
|
||||
{
|
||||
public class TvRatings
|
||||
{
|
||||
public string Class { get; set; }
|
||||
public int Score { get; set; }
|
||||
}
|
||||
}
|
12
src/Ombi.Api.RottenTomatoes/Ombi.Api.RottenTomatoes.csproj
Normal file
12
src/Ombi.Api.RottenTomatoes/Ombi.Api.RottenTomatoes.csproj
Normal file
|
@ -0,0 +1,12 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<LangVersion>8.0</LangVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Ombi.Api\Ombi.Api.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
56
src/Ombi.Api.RottenTomatoes/RottenTomatoesApi.cs
Normal file
56
src/Ombi.Api.RottenTomatoes/RottenTomatoesApi.cs
Normal file
|
@ -0,0 +1,56 @@
|
|||
using Ombi.Api.RottenTomatoes.Models;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ombi.Api.RottenTomatoes
|
||||
{
|
||||
public class RottenTomatoesApi : IRottenTomatoesApi
|
||||
{
|
||||
public RottenTomatoesApi(IApi api)
|
||||
{
|
||||
_api = api;
|
||||
}
|
||||
|
||||
private string Endpoint => "https://www.rottentomatoes.com/api/private";
|
||||
private IApi _api { get; }
|
||||
|
||||
public async Task<MovieRatings> GetMovieRatings(string movieName, int movieYear)
|
||||
{
|
||||
var request = new Request("/v1.0/movies", Endpoint, HttpMethod.Get);
|
||||
request.AddHeader("Accept", "application/json");
|
||||
request.AddQueryString("q", movieName);
|
||||
var result = await _api.Request<RottenTomatoesMovieResponse>(request);
|
||||
|
||||
var movieFound = result.movies.FirstOrDefault(x => x.year == movieYear);
|
||||
if (movieFound == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return movieFound.ratings;
|
||||
}
|
||||
|
||||
public async Task<TvRatings> GetTvRatings(string showName, int showYear)
|
||||
{
|
||||
var request = new Request("/v2.0/search/", Endpoint, HttpMethod.Get);
|
||||
request.AddHeader("Accept", "application/json");
|
||||
request.AddQueryString("q", showName);
|
||||
request.AddQueryString("limit", 10.ToString());
|
||||
var result = await _api.Request<RottenTomatoesTvResponse>(request);
|
||||
|
||||
var showFound = result.tvSeries.FirstOrDefault(x => x.startYear == showYear);
|
||||
if (showFound == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new TvRatings
|
||||
{
|
||||
Class = showFound.meterClass,
|
||||
Score = showFound.meterScore
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue