mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-10 15:32:37 -07:00
parent
b1d7a3187e
commit
f88c7d7583
9 changed files with 64 additions and 23 deletions
|
@ -61,6 +61,7 @@
|
||||||
<Compile Include="Sonarr\SystemStatus.cs" />
|
<Compile Include="Sonarr\SystemStatus.cs" />
|
||||||
<Compile Include="Tv\Authentication.cs" />
|
<Compile Include="Tv\Authentication.cs" />
|
||||||
<Compile Include="Tv\TvMazeSearch.cs" />
|
<Compile Include="Tv\TvMazeSearch.cs" />
|
||||||
|
<Compile Include="Tv\TVMazeShow.cs" />
|
||||||
<Compile Include="Tv\TvSearchResult.cs" />
|
<Compile Include="Tv\TvSearchResult.cs" />
|
||||||
<Compile Include="Tv\TvShow.cs" />
|
<Compile Include="Tv\TvShow.cs" />
|
||||||
<Compile Include="Tv\TvShowImages.cs" />
|
<Compile Include="Tv\TvShowImages.cs" />
|
||||||
|
|
27
PlexRequests.Api.Models/Tv/TVMazeShow.cs
Normal file
27
PlexRequests.Api.Models/Tv/TVMazeShow.cs
Normal file
|
@ -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));
|
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 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
|
public interface IAvailabilityChecker
|
||||||
{
|
{
|
||||||
void CheckAndUpdateAll(long check);
|
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.
|
/// Determines whether the specified search term is available.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="title">The search term.</param>
|
/// <param name="title">The search term.</param>
|
||||||
|
/// <param name="year">The year.</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
/// <exception cref="ApplicationSettingsException">The settings are not configured for Plex or Authentication</exception>
|
/// <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 plexSettings = Plex.GetSettings();
|
||||||
var authSettings = Auth.GetSettings();
|
var authSettings = Auth.GetSettings();
|
||||||
|
@ -98,8 +99,8 @@ namespace PlexRequests.Services
|
||||||
}
|
}
|
||||||
|
|
||||||
var results = PlexApi.SearchContent(authSettings.PlexAuthToken, title, plexSettings.FullUri);
|
var results = PlexApi.SearchContent(authSettings.PlexAuthToken, title, plexSettings.FullUri);
|
||||||
var result = results.Video?.FirstOrDefault(x => x.Title == title);
|
var result = results.Video?.FirstOrDefault(x => x.Title == title && x.Year == year);
|
||||||
var directoryTitle = results.Directory?.Title == title;
|
var directoryTitle = results.Directory?.Title == title && results.Directory?.Year == year;
|
||||||
return result?.Title != null || directoryTitle;
|
return result?.Title != null || directoryTitle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -114,7 +114,7 @@ namespace PlexRequests.UI.Modules
|
||||||
Status = tv.Status,
|
Status = tv.Status,
|
||||||
ImdbId = tv.ImdbId,
|
ImdbId = tv.ImdbId,
|
||||||
Id = tv.Id,
|
Id = tv.Id,
|
||||||
PosterPath = tv.ProviderId.ToString(),
|
PosterPath = tv.PosterPath,
|
||||||
ReleaseDate = tv.ReleaseDate.Humanize(),
|
ReleaseDate = tv.ReleaseDate.Humanize(),
|
||||||
RequestedDate = tv.RequestedDate.Humanize(),
|
RequestedDate = tv.RequestedDate.Humanize(),
|
||||||
Approved = tv.Approved,
|
Approved = tv.Approved,
|
||||||
|
|
|
@ -126,8 +126,8 @@ namespace PlexRequests.UI.Modules
|
||||||
FirstAired = t.show.premiered,
|
FirstAired = t.show.premiered,
|
||||||
Id = t.show.id,
|
Id = t.show.id,
|
||||||
ImdbId = t.show.externals?.imdb,
|
ImdbId = t.show.externals?.imdb,
|
||||||
Network = t.show.network.name,
|
Network = t.show.network?.name,
|
||||||
NetworkId = t.show.network.id.ToString(),
|
NetworkId = t.show.network?.id.ToString(),
|
||||||
Overview = t.show.summary,
|
Overview = t.show.summary,
|
||||||
Rating = t.score.ToString(CultureInfo.CurrentUICulture),
|
Rating = t.score.ToString(CultureInfo.CurrentUICulture),
|
||||||
Runtime = t.show.runtime.ToString(),
|
Runtime = t.show.runtime.ToString(),
|
||||||
|
@ -186,12 +186,12 @@ namespace PlexRequests.UI.Modules
|
||||||
Log.Trace("Getting movie info from TheMovieDb");
|
Log.Trace("Getting movie info from TheMovieDb");
|
||||||
Log.Trace(movieInfo.DumpJson);
|
Log.Trace(movieInfo.DumpJson);
|
||||||
|
|
||||||
#if !DEBUG
|
//#if !DEBUG
|
||||||
if (CheckIfTitleExistsInPlex(movieInfo.Title))
|
if (CheckIfTitleExistsInPlex(movieInfo.Title, movieInfo.ReleaseDate?.Year.ToString()))
|
||||||
{
|
{
|
||||||
return Response.AsJson(new JsonResponseModel { Result = false, Message = $"{movieInfo.Title} is already in Plex!" });
|
return Response.AsJson(new JsonResponseModel { Result = false, Message = $"{movieInfo.Title} is already in Plex!" });
|
||||||
}
|
}
|
||||||
#endif
|
//#endif
|
||||||
|
|
||||||
var model = new RequestedModel
|
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!" });
|
return Response.AsJson(new JsonResponseModel { Result = false, Message = "TV Show has already been requested!" });
|
||||||
}
|
}
|
||||||
|
|
||||||
var tvApi = new TheTvDbApi();
|
var tvApi = new TvMazeApi();
|
||||||
var token = GetTvDbAuthToken(tvApi);
|
|
||||||
|
|
||||||
var showInfo = tvApi.GetInformation(showId, token).data;
|
var showInfo = tvApi.ShowLookup(showId);
|
||||||
|
|
||||||
//#if !DEBUG
|
//#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
|
//#endif
|
||||||
|
|
||||||
DateTime firstAir;
|
DateTime firstAir;
|
||||||
DateTime.TryParse(showInfo.firstAired, out firstAir);
|
DateTime.TryParse(showInfo.premiered, out firstAir);
|
||||||
|
|
||||||
var model = new RequestedModel
|
var model = new RequestedModel
|
||||||
{
|
{
|
||||||
ProviderId = showInfo.id,
|
ProviderId = showInfo.id,
|
||||||
Type = RequestType.TvShow,
|
Type = RequestType.TvShow,
|
||||||
Overview = showInfo.overview,
|
Overview = showInfo.summary,
|
||||||
PosterPath = "http://image.tmdb.org/t/p/w150/" + showInfo.banner, // This is incorrect
|
PosterPath = showInfo.image?.medium,
|
||||||
Title = showInfo.seriesName,
|
Title = showInfo.name,
|
||||||
ReleaseDate = firstAir,
|
ReleaseDate = firstAir,
|
||||||
Status = showInfo.status,
|
Status = showInfo.status,
|
||||||
RequestedDate = DateTime.Now,
|
RequestedDate = DateTime.Now,
|
||||||
|
@ -320,9 +319,9 @@ namespace PlexRequests.UI.Modules
|
||||||
return Cache.GetOrSet(CacheKeys.TvDbToken, api.Authenticate, 50);
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,7 +62,7 @@
|
||||||
{{/if_eq}}
|
{{/if_eq}}
|
||||||
{{#if_eq type "tv"}}
|
{{#if_eq type "tv"}}
|
||||||
{{#if posterPath}}
|
{{#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}}
|
||||||
{{/if_eq}}
|
{{/if_eq}}
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue