Almost fully integrated TVMaze #21 and also improved the fix for #31

pull/39/head
Jamie Rees 8 years ago
parent b1d7a3187e
commit f88c7d7583

@ -61,6 +61,7 @@
<Compile Include="Sonarr\SystemStatus.cs" />
<Compile Include="Tv\Authentication.cs" />
<Compile Include="Tv\TvMazeSearch.cs" />
<Compile Include="Tv\TVMazeShow.cs" />
<Compile Include="Tv\TvSearchResult.cs" />
<Compile Include="Tv\TvShow.cs" />
<Compile Include="Tv\TvShowImages.cs" />

@ -0,0 +1,27 @@
using System.Collections.Generic;
namespace PlexRequests.Api.Models.Tv
{
public class TvMazeShow
{
public int id { get; set; }
public string url { get; set; }
public string name { get; set; }
public string type { get; set; }
public string language { get; set; }
public List<string> genres { get; set; }
public string status { get; set; }
public int runtime { get; set; }
public string premiered { get; set; }
public Schedule schedule { get; set; }
public Rating rating { get; set; }
public int weight { get; set; }
public Network network { get; set; }
public object webChannel { get; set; }
public Externals externals { get; set; }
public Image image { get; set; }
public string summary { get; set; }
public int updated { get; set; }
public Links _links { get; set; }
}
}

@ -56,5 +56,18 @@ namespace PlexRequests.Api
return Api.Execute<List<TvMazeSearch>>(request, new Uri(Uri));
}
public TvMazeShow ShowLookup(int showId)
{
var request = new RestRequest
{
Method = Method.GET,
Resource = "shows/{id}"
};
request.AddUrlSegment("id", showId.ToString());
request.AddHeader("Content-Type", "application/json");
return Api.Execute<TvMazeShow>(request, new Uri(Uri));
}
}
}

@ -28,6 +28,6 @@ namespace PlexRequests.Api
{
public class TvMazeBase
{
public string Uri = "http://api.tvmaze.com";
protected string Uri = "http://api.tvmaze.com";
}
}

@ -29,6 +29,6 @@ namespace PlexRequests.Services.Interfaces
public interface IAvailabilityChecker
{
void CheckAndUpdateAll(long check);
bool IsAvailable(string title);
bool IsAvailable(string title, string year);
}
}

@ -85,9 +85,10 @@ namespace PlexRequests.Services
/// Determines whether the specified search term is available.
/// </summary>
/// <param name="title">The search term.</param>
/// <param name="year">The year.</param>
/// <returns></returns>
/// <exception cref="ApplicationSettingsException">The settings are not configured for Plex or Authentication</exception>
public bool IsAvailable(string title)
public bool IsAvailable(string title, string year)
{
var plexSettings = Plex.GetSettings();
var authSettings = Auth.GetSettings();
@ -98,8 +99,8 @@ namespace PlexRequests.Services
}
var results = PlexApi.SearchContent(authSettings.PlexAuthToken, title, plexSettings.FullUri);
var result = results.Video?.FirstOrDefault(x => x.Title == title);
var directoryTitle = results.Directory?.Title == title;
var result = results.Video?.FirstOrDefault(x => x.Title == title && x.Year == year);
var directoryTitle = results.Directory?.Title == title && results.Directory?.Year == year;
return result?.Title != null || directoryTitle;
}

@ -114,7 +114,7 @@ namespace PlexRequests.UI.Modules
Status = tv.Status,
ImdbId = tv.ImdbId,
Id = tv.Id,
PosterPath = tv.ProviderId.ToString(),
PosterPath = tv.PosterPath,
ReleaseDate = tv.ReleaseDate.Humanize(),
RequestedDate = tv.RequestedDate.Humanize(),
Approved = tv.Approved,

@ -126,8 +126,8 @@ namespace PlexRequests.UI.Modules
FirstAired = t.show.premiered,
Id = t.show.id,
ImdbId = t.show.externals?.imdb,
Network = t.show.network.name,
NetworkId = t.show.network.id.ToString(),
Network = t.show.network?.name,
NetworkId = t.show.network?.id.ToString(),
Overview = t.show.summary,
Rating = t.score.ToString(CultureInfo.CurrentUICulture),
Runtime = t.show.runtime.ToString(),
@ -186,12 +186,12 @@ namespace PlexRequests.UI.Modules
Log.Trace("Getting movie info from TheMovieDb");
Log.Trace(movieInfo.DumpJson);
#if !DEBUG
if (CheckIfTitleExistsInPlex(movieInfo.Title))
//#if !DEBUG
if (CheckIfTitleExistsInPlex(movieInfo.Title, movieInfo.ReleaseDate?.Year.ToString()))
{
return Response.AsJson(new JsonResponseModel { Result = false, Message = $"{movieInfo.Title} is already in Plex!" });
}
#endif
//#endif
var model = new RequestedModel
{
@ -258,28 +258,27 @@ namespace PlexRequests.UI.Modules
return Response.AsJson(new JsonResponseModel { Result = false, Message = "TV Show has already been requested!" });
}
var tvApi = new TheTvDbApi();
var token = GetTvDbAuthToken(tvApi);
var tvApi = new TvMazeApi();
var showInfo = tvApi.GetInformation(showId, token).data;
var showInfo = tvApi.ShowLookup(showId);
//#if !DEBUG
if (CheckIfTitleExistsInPlex(showInfo.seriesName))
if (CheckIfTitleExistsInPlex(showInfo.name, showInfo.premiered.Substring(0,4))) // Take only the year Format = 2014-01-01
{
return Response.AsJson(new JsonResponseModel { Result = false, Message = $"{showInfo.seriesName} is already in Plex!" });
return Response.AsJson(new JsonResponseModel { Result = false, Message = $"{showInfo.name} is already in Plex!" });
}
//#endif
DateTime firstAir;
DateTime.TryParse(showInfo.firstAired, out firstAir);
DateTime.TryParse(showInfo.premiered, out firstAir);
var model = new RequestedModel
{
ProviderId = showInfo.id,
Type = RequestType.TvShow,
Overview = showInfo.overview,
PosterPath = "http://image.tmdb.org/t/p/w150/" + showInfo.banner, // This is incorrect
Title = showInfo.seriesName,
Overview = showInfo.summary,
PosterPath = showInfo.image?.medium,
Title = showInfo.name,
ReleaseDate = firstAir,
Status = showInfo.status,
RequestedDate = DateTime.Now,
@ -320,9 +319,9 @@ namespace PlexRequests.UI.Modules
return Cache.GetOrSet(CacheKeys.TvDbToken, api.Authenticate, 50);
}
private bool CheckIfTitleExistsInPlex(string title)
private bool CheckIfTitleExistsInPlex(string title, string year)
{
var result = Checker.IsAvailable(title);
var result = Checker.IsAvailable(title, year);
return result;
}
}

@ -62,7 +62,7 @@
{{/if_eq}}
{{#if_eq type "tv"}}
{{#if posterPath}}
<img class="img-responsive" width="150" src="http://thetvdb.com/banners/_cache/posters/{{posterPath}}-1.jpg" alt="poster">
<img class="img-responsive" width="150" src="{{posterPath}}" alt="poster">
{{/if}}
{{/if_eq}}
</div>

Loading…
Cancel
Save