mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-11 07:46:05 -07:00
Added TVMaze to the search. #21
This commit is contained in:
parent
2e8bb783d9
commit
55f296b9a4
8 changed files with 214 additions and 27 deletions
|
@ -60,6 +60,7 @@
|
||||||
<Compile Include="Sonarr\SonarrProfile.cs" />
|
<Compile Include="Sonarr\SonarrProfile.cs" />
|
||||||
<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\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" />
|
||||||
|
|
97
PlexRequests.Api.Models/Tv/TvMazeSearch.cs
Normal file
97
PlexRequests.Api.Models/Tv/TvMazeSearch.cs
Normal file
|
@ -0,0 +1,97 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace PlexRequests.Api.Models.Tv
|
||||||
|
{
|
||||||
|
public class Schedule
|
||||||
|
{
|
||||||
|
public string time { get; set; }
|
||||||
|
public List<object> days { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Rating
|
||||||
|
{
|
||||||
|
public double? average { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Country
|
||||||
|
{
|
||||||
|
public string name { get; set; }
|
||||||
|
public string code { get; set; }
|
||||||
|
public string timezone { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Network
|
||||||
|
{
|
||||||
|
public int id { get; set; }
|
||||||
|
public string name { get; set; }
|
||||||
|
public Country country { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Externals
|
||||||
|
{
|
||||||
|
public int? tvrage { get; set; }
|
||||||
|
public int? thetvdb { get; set; }
|
||||||
|
public string imdb { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Image
|
||||||
|
{
|
||||||
|
public string medium { get; set; }
|
||||||
|
public string original { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Self
|
||||||
|
{
|
||||||
|
public string href { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Previousepisode
|
||||||
|
{
|
||||||
|
public string href { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Nextepisode
|
||||||
|
{
|
||||||
|
public string href { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Links
|
||||||
|
{
|
||||||
|
public Self self { get; set; }
|
||||||
|
public Previousepisode previousepisode { get; set; }
|
||||||
|
public Nextepisode nextepisode { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Show
|
||||||
|
{
|
||||||
|
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<object> 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; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class TvMazeSearch
|
||||||
|
{
|
||||||
|
public double score { get; set; }
|
||||||
|
public Show show { get; set; }
|
||||||
|
}
|
||||||
|
}
|
|
@ -81,6 +81,8 @@
|
||||||
<Compile Include="TvBase.cs" />
|
<Compile Include="TvBase.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="TheTvDbApi.cs" />
|
<Compile Include="TheTvDbApi.cs" />
|
||||||
|
<Compile Include="TvMazeApi.cs" />
|
||||||
|
<Compile Include="TvMazeBase.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="app.config" />
|
<None Include="app.config" />
|
||||||
|
|
60
PlexRequests.Api/TvMazeApi.cs
Normal file
60
PlexRequests.Api/TvMazeApi.cs
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
#region Copyright
|
||||||
|
// /************************************************************************
|
||||||
|
// Copyright (c) 2016 Jamie Rees
|
||||||
|
// File: TvMazeApi.cs
|
||||||
|
// Created By: Jamie Rees
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
// a copy of this software and associated documentation files (the
|
||||||
|
// "Software"), to deal in the Software without restriction, including
|
||||||
|
// without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
// permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
// the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be
|
||||||
|
// included in all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
// ************************************************************************/
|
||||||
|
#endregion
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
using NLog;
|
||||||
|
|
||||||
|
using PlexRequests.Api.Models.Tv;
|
||||||
|
|
||||||
|
using RestSharp;
|
||||||
|
|
||||||
|
namespace PlexRequests.Api
|
||||||
|
{
|
||||||
|
public class TvMazeApi : TvMazeBase
|
||||||
|
{
|
||||||
|
public TvMazeApi()
|
||||||
|
{
|
||||||
|
Api = new ApiRequest();
|
||||||
|
}
|
||||||
|
private ApiRequest Api { get; }
|
||||||
|
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||||
|
public List<TvMazeSearch> Search(string searchTerm)
|
||||||
|
{
|
||||||
|
var request = new RestRequest
|
||||||
|
{
|
||||||
|
Method = Method.GET,
|
||||||
|
Resource = "search/shows?q={searchTerm}"
|
||||||
|
};
|
||||||
|
request.AddUrlSegment("searchTerm", searchTerm);
|
||||||
|
request.AddHeader("Content-Type", "application/json");
|
||||||
|
|
||||||
|
return Api.Execute<List<TvMazeSearch>>(request, new Uri(Uri));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
33
PlexRequests.Api/TvMazeBase.cs
Normal file
33
PlexRequests.Api/TvMazeBase.cs
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
#region Copyright
|
||||||
|
// /************************************************************************
|
||||||
|
// Copyright (c) 2016 Jamie Rees
|
||||||
|
// File: TvMazeBase.cs
|
||||||
|
// Created By: Jamie Rees
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
// a copy of this software and associated documentation files (the
|
||||||
|
// "Software"), to deal in the Software without restriction, including
|
||||||
|
// without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
// permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
// the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be
|
||||||
|
// included in all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
// ************************************************************************/
|
||||||
|
#endregion
|
||||||
|
namespace PlexRequests.Api
|
||||||
|
{
|
||||||
|
public class TvMazeBase
|
||||||
|
{
|
||||||
|
public string Uri = "http://api.tvmaze.com";
|
||||||
|
}
|
||||||
|
}
|
|
@ -48,8 +48,6 @@ namespace PlexRequests.UI.Models
|
||||||
public string AirsTime { get; set; }
|
public string AirsTime { get; set; }
|
||||||
public string Rating { get; set; }
|
public string Rating { get; set; }
|
||||||
public string ImdbId { get; set; }
|
public string ImdbId { get; set; }
|
||||||
public string Zap2ItId { get; set; }
|
|
||||||
public string Added { get; set; }
|
|
||||||
public int SiteRating { get; set; }
|
public int SiteRating { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -26,6 +26,9 @@
|
||||||
#endregion
|
#endregion
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
using Nancy;
|
using Nancy;
|
||||||
using Nancy.Responses.Negotiation;
|
using Nancy.Responses.Negotiation;
|
||||||
|
|
||||||
|
@ -104,41 +107,34 @@ namespace PlexRequests.UI.Modules
|
||||||
private Response SearchTvShow(string searchTerm)
|
private Response SearchTvShow(string searchTerm)
|
||||||
{
|
{
|
||||||
Log.Trace("Searching for TV Show {0}", searchTerm);
|
Log.Trace("Searching for TV Show {0}", searchTerm);
|
||||||
var tvShow = TvApi.SearchTv(searchTerm, AuthToken);
|
//var tvShow = TvApi.SearchTv(searchTerm, AuthToken);
|
||||||
|
var tvShow = new TvMazeApi().Search(searchTerm);
|
||||||
if (tvShow?.data == null)
|
if (!tvShow.Any())
|
||||||
{
|
{
|
||||||
Log.Trace("TV Show data is null");
|
Log.Trace("TV Show data is null");
|
||||||
return Response.AsJson("");
|
return Response.AsJson("");
|
||||||
}
|
}
|
||||||
var model = new List<SearchTvShowViewModel>();
|
var model = new List<SearchTvShowViewModel>();
|
||||||
|
|
||||||
foreach (var t in tvShow.data)
|
foreach (var t in tvShow)
|
||||||
{
|
{
|
||||||
model.Add(new SearchTvShowViewModel
|
model.Add(new SearchTvShowViewModel
|
||||||
{
|
{
|
||||||
Added = t.added,
|
|
||||||
AirsDayOfWeek = t.airsDayOfWeek,
|
|
||||||
AirsTime = t.airsTime,
|
|
||||||
Aliases = t.aliases,
|
|
||||||
// We are constructing the banner with the id:
|
// We are constructing the banner with the id:
|
||||||
// http://thetvdb.com/banners/_cache/posters/ID-1.jpg
|
// http://thetvdb.com/banners/_cache/posters/ID-1.jpg
|
||||||
Banner = t.id.ToString(),
|
Banner = t.show.image?.medium,
|
||||||
FirstAired = t.firstAired,
|
FirstAired = t.show.premiered,
|
||||||
Genre = t.genre,
|
Id = t.show.id,
|
||||||
Id = t.id,
|
ImdbId = t.show.externals?.imdb,
|
||||||
ImdbId = t.imdbId,
|
Network = t.show.network.name,
|
||||||
LastUpdated = t.lastUpdated,
|
NetworkId = t.show.network.id.ToString(),
|
||||||
Network = t.network,
|
Overview = t.show.summary,
|
||||||
NetworkId = t.networkId,
|
Rating = t.score.ToString(CultureInfo.CurrentUICulture),
|
||||||
Overview = t.overview,
|
Runtime = t.show.runtime.ToString(),
|
||||||
Rating = t.rating,
|
SeriesId = t.show.id,
|
||||||
Runtime = t.runtime,
|
SeriesName = t.show.name,
|
||||||
SeriesId = t.id,
|
|
||||||
SeriesName = t.seriesName,
|
Status = t.show.status,
|
||||||
SiteRating = t.siteRating,
|
|
||||||
Status = t.status,
|
|
||||||
Zap2ItId = t.zap2itId
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -69,7 +69,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}}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue