Fully switched the TV shows over to use the other provider.

pull/13/head
Jamie Rees 9 years ago
parent 46dc9d95f1
commit 7677831bbc

@ -34,7 +34,7 @@ namespace PlexRequests.Api.Models.Tv
public string seriesName { get; set; }
public List<string> aliases { get; set; }
public string banner { get; set; }
public int seriesId { get; set; }
public string seriesId { get; set; }
public string status { get; set; }
public string firstAired { get; set; }
public string network { get; set; }
@ -49,7 +49,13 @@ namespace PlexRequests.Api.Models.Tv
public string imdbId { get; set; }
public string zap2itId { get; set; }
public string added { get; set; }
public int addedBy { get; set; }
public int siteRating { get; set; }
}
public class TvShowInformation
{
public TvShow data { get; set; }
}
}

@ -0,0 +1,54 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: TvShowImages.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.Collections.Generic;
namespace PlexRequests.Api.Models.Tv
{
public class RatingsInfo
{
public double average { get; set; }
}
public class Datum
{
public int id { get; set; }
public string keyType { get; set; }
public string subKey { get; set; }
public string fileName { get; set; }
public string resolution { get; set; }
public RatingsInfo ratingsInfo { get; set; }
public string thumbnail { get; set; }
}
public class TvShowImages
{
public List<Datum> data { get; set; }
public object errors { get; set; }
}
}

@ -67,6 +67,7 @@
<Compile Include="Models\Tv\Authentication.cs" />
<Compile Include="Models\Tv\TvSearchResult.cs" />
<Compile Include="Models\Tv\TvShow.cs" />
<Compile Include="Models\Tv\TvShowImages.cs" />
<Compile Include="MovieBase.cs" />
<Compile Include="PlexApi.cs" />
<Compile Include="TheMovieDbApi.cs" />

@ -97,6 +97,26 @@ namespace PlexRequests.Api
return Api.Execute<TvSearchResult>(request, Url);
}
/// <summary>
/// Gets the tv images.
/// </summary>
/// <param name="seriesId">The series identifier.</param>
/// <param name="token">The token.</param>
/// <returns></returns>
public TvShowImages GetTvImages(int seriesId, string token)
{
var request = new RestRequest
{
Method = Method.GET,
Resource = "/series/{id}/images/query?keyType=poster"
};
request.AddUrlSegment("id", seriesId.ToString());
request.AddHeader("Authorization", $"Bearer {token}");
request.AddHeader("Content-Type", "application/json");
return Api.Execute<TvShowImages>(request, Url);
}
/// <summary>
/// Gets the information for a TV Series.
@ -104,18 +124,18 @@ namespace PlexRequests.Api
/// <param name="tvdbId">The TVDB identifier.</param>
/// <param name="token">The token.</param>
/// <returns></returns>
public TvShow GetInformation(int tvdbId, string token)
public TvShowInformation GetInformation(int tvdbId, string token)
{
var request = new RestRequest
{
Method = Method.GET,
Resource = "search/{id}"
Resource = "series/{id}"
};
request.AddUrlSegment("id", tvdbId.ToString());
request.AddHeader("Authorization", $"Bearer {token}");
request.AddHeader("Content-Type", "application/json");
return Api.Execute<TvShow>(request, Url);
return Api.Execute<TvShowInformation>(request, Url);
}
}
}

@ -37,9 +37,14 @@ namespace PlexRequests.Core
{
public class SettingsService
{
public SettingsService(ICacheProvider cache)
{
Cache = cache;
}
public SettingsModel GetSettings(ICacheProvider cache)
public SettingsModel GetSettings()
{
var db = new DbConfiguration(new SqliteFactory());
var repo = new GenericRepository<SettingsModel>(db);
@ -77,7 +82,7 @@ namespace PlexRequests.Core
var tvApi = new TheTvDbApi();
var token = GetAuthToken(tvApi);
var showInfo = tvApi.GetInformation(providerId, token);
var showInfo = tvApi.GetInformation(providerId, token).data;
DateTime firstAir;
DateTime.TryParse(showInfo.firstAired, out firstAir);

@ -85,12 +85,14 @@ function movieSearch() {
var query = $("#movieSearchContent").val();
$.ajax("/search/movie/" + query).success(function (results) {
results.forEach(function (result) {
var context = buildMovieContext(result);
if (results.length > 0) {
results.forEach(function(result) {
var context = buildMovieContext(result);
var html = searchTemplate(context);
$("#movieList").append(html);
});
var html = searchTemplate(context);
$("#movieList").append(html);
});
}
});
};
@ -99,12 +101,13 @@ function tvSearch() {
var query = $("#tvSearchContent").val();
$.ajax("/search/tv/" + query).success(function (results) {
results.data.forEach(function (result) {
var context = buildTvShowContext(result);
var html = searchTemplate(context);
$("#tvList").append(html);
});
if (results.length > 0) {
results.forEach(function(result) {
var context = buildTvShowContext(result);
var html = searchTemplate(context);
$("#tvList").append(html);
});
}
});
};

@ -30,12 +30,10 @@ function buildTvShowContext(result) {
var date = new Date(result.firstAired);
var year = date.getFullYear();
var context = {
posterPath: result.posterPath,
posterPath: result.banner,
id: result.id,
title: result.name,
title: result.seriesName,
overview: result.overview,
voteCount: result.voteCount,
voteAverage: result.voteAverage,
year: year,
type: "tv"
};

@ -31,7 +31,7 @@ namespace PlexRequests.UI.Models
public class RequestViewModel
{
public int Id { get; set; }
public int Tmdbid { get; set; }
public int ProviderId { get; set; }
public string ImdbId { get; set; }
public string Overview { get; set; }
public string Title { get; set; }

@ -0,0 +1,55 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: SearchTvShowViewModel.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.Collections.Generic;
namespace PlexRequests.UI.Models
{
public class SearchTvShowViewModel
{
public int Id { get; set; }
public string SeriesName { get; set; }
public List<string> Aliases { get; set; }
public string Banner { get; set; }
public int SeriesId { get; set; }
public string Status { get; set; }
public string FirstAired { get; set; }
public string Network { get; set; }
public string NetworkId { get; set; }
public string Runtime { get; set; }
public List<string> Genre { get; set; }
public string Overview { get; set; }
public int LastUpdated { get; set; }
public string AirsDayOfWeek { get; set; }
public string AirsTime { get; set; }
public string Rating { get; set; }
public string ImdbId { get; set; }
public string Zap2ItId { get; set; }
public string Added { get; set; }
public int SiteRating { get; set; }
}
}

@ -64,7 +64,7 @@ namespace PlexRequests.UI.Modules
var dbMovies = Service.GetAll().Where(x => x.Type == RequestType.Movie);
var viewModel = dbMovies.Select(tv => new RequestViewModel
{
Tmdbid = tv.ProviderId,
ProviderId = tv.ProviderId,
Type = tv.Type,
Status = tv.Status,
ImdbId = tv.ImdbId,
@ -87,12 +87,12 @@ namespace PlexRequests.UI.Modules
var dbTv = Service.GetAll().Where(x => x.Type == RequestType.TvShow);
var viewModel = dbTv.Select(tv => new RequestViewModel
{
Tmdbid = tv.ProviderId,
ProviderId = tv.ProviderId,
Type = tv.Type,
Status = tv.Status,
ImdbId = tv.ImdbId,
Id = tv.Id,
PosterPath = tv.PosterPath,
PosterPath = tv.ProviderId.ToString(),
ReleaseDate = tv.ReleaseDate.Humanize(),
RequestedDate = tv.RequestedDate.Humanize(),
Approved = tv.Approved,

@ -24,6 +24,9 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ************************************************************************/
#endregion
using System.Collections.Generic;
using System.Linq;
using Nancy;
using Nancy.Responses.Negotiation;
@ -31,6 +34,7 @@ using PlexRequests.Api;
using PlexRequests.Core;
using PlexRequests.Helpers;
using PlexRequests.Store;
using PlexRequests.UI.Models;
namespace PlexRequests.UI.Modules
{
@ -73,7 +77,42 @@ namespace PlexRequests.UI.Modules
private Response SearchTvShow(string searchTerm)
{
var tvShow = TvApi.SearchTv(searchTerm, AuthToken);
return Response.AsJson(tvShow);
if (tvShow?.data == null)
{
return Response.AsJson("");
}
var model = new List<SearchTvShowViewModel>();
foreach (var t in tvShow.data)
{
model.Add(new SearchTvShowViewModel
{
Added = t.added,
AirsDayOfWeek = t.airsDayOfWeek,
AirsTime = t.airsTime,
Aliases = t.aliases,
// We are constructing the banner with the id:
// http://thetvdb.com/banners/_cache/posters/ID-1.jpg
Banner = t.id.ToString(),
FirstAired = t.firstAired,
Genre = t.genre,
Id = t.id,
ImdbId = t.imdbId,
LastUpdated = t.lastUpdated,
Network = t.network,
NetworkId = t.networkId,
Overview = t.overview,
Rating = t.rating,
Runtime = t.runtime,
SeriesId = t.id,
SeriesName = t.seriesName,
SiteRating = t.siteRating,
Status = t.status,
Zap2ItId = t.zap2itId
});
}
return Response.AsJson(model);
}
private Response UpcomingMovies()
@ -92,7 +131,7 @@ namespace PlexRequests.UI.Modules
private Response RequestMovie(int movieId)
{
var s = new SettingsService();
var s = new SettingsService(Cache);
if (s.CheckRequest(movieId))
{
return Response.AsJson(new { Result = false, Message = "Movie has already been requested!" });
@ -111,7 +150,7 @@ namespace PlexRequests.UI.Modules
private Response RequestTvShow(int showId, bool latest)
{
// Latest send to Sonarr and no need to store in DB
var s = new SettingsService();
var s = new SettingsService(Cache);
if (s.CheckRequest(showId))
{
return Response.AsJson(new { Result = false, Message = "TV Show has already been requested!" });

@ -142,6 +142,7 @@
</Content>
<Compile Include="Models\PlexAuth.cs" />
<Compile Include="Models\RequestViewModel.cs" />
<Compile Include="Models\SearchTvShowViewModel.cs" />
<Compile Include="Models\SessionKeys.cs" />
<Compile Include="Modules\AdminModule.cs" />
<Compile Include="Modules\IndexModule.cs" />

@ -37,9 +37,16 @@
<div id="{{id}}Template">
<div class="row">
<div class="col-sm-2">
{{#if_eq type "movie"}}
{{#if posterPath}}
<img src="http://image.tmdb.org/t/p/w150/{{posterPath}}" alt="poster">
{{/if}}
{{/if_eq}}
{{#if_eq type "tv"}}
{{#if posterPath}}
<img width="150" src="http://thetvdb.com/banners/_cache/posters/{{posterPath}}-1.jpg" alt="poster">
{{/if}}
{{/if_eq}}
</div>
<div class="col-sm-5 ">
<div>

@ -48,9 +48,18 @@
<script id="search-template" type="text/x-handlebars-template">
<div class="row">
<div class="col-sm-2">
{{#if_eq type "movie"}}
{{#if posterPath}}
<img src="http://image.tmdb.org/t/p/w150/{{posterPath}}" alt="poster">
{{/if}}
{{/if_eq}}
{{#if_eq type "tv"}}
{{#if posterPath}}
<img width="150" src="http://thetvdb.com/banners/_cache/posters/{{posterPath}}-1.jpg" alt="poster">
{{/if}}
{{/if_eq}}
</div>
<div class="col-sm-5 ">
<div>
@ -68,7 +77,7 @@
{{/if_eq}}
{{#if_eq type "tv"}}
<div class="dropdown">
<button id="{{id}}" class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
<button id="{{id}}" class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
<i class="fa fa-plus"></i> Request
<span class="caret"></span>
</button>
@ -81,8 +90,11 @@
<br />
<br />
<br />
{{#if voteAverage}}
<small class="row">Vote Average: {{voteAverage}}</small>
<small class="row">Vote Count: {{voteCount}}</small>
{{/if}}
</form>
</div>

Loading…
Cancel
Save