mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-08 06:00:50 -07:00
Wow, that was a lot of work.
- So, I have now finished #40. - Fixed a bug where we was not choosing the correct tv series (Because of TVMaze) - Fixed a bug when checking for plex titles - Fixed a bug where the wrong issue would clean on the UI (DB was correct) - Refactored how we send tv shows - And too many small changes to count.
This commit is contained in:
parent
803b12da0f
commit
9402d1409e
21 changed files with 510 additions and 122 deletions
|
@ -42,6 +42,7 @@ using PlexRequests.Helpers;
|
|||
using PlexRequests.Services.Interfaces;
|
||||
using PlexRequests.Services.Notification;
|
||||
using PlexRequests.Store;
|
||||
using PlexRequests.UI.Helpers;
|
||||
using PlexRequests.UI.Models;
|
||||
|
||||
namespace PlexRequests.UI.Modules
|
||||
|
@ -51,7 +52,7 @@ namespace PlexRequests.UI.Modules
|
|||
public SearchModule(ICacheProvider cache, ISettingsService<CouchPotatoSettings> cpSettings,
|
||||
ISettingsService<PlexRequestSettings> prSettings, IAvailabilityChecker checker,
|
||||
IRequestService request, ISonarrApi sonarrApi, ISettingsService<SonarrSettings> sonarrSettings,
|
||||
ICouchPotatoApi cpApi) : base("search")
|
||||
ISettingsService<SickRageSettings> sickRageService, ICouchPotatoApi cpApi, ISickRageApi srApi) : base("search")
|
||||
{
|
||||
CpService = cpSettings;
|
||||
PrService = prSettings;
|
||||
|
@ -63,6 +64,8 @@ namespace PlexRequests.UI.Modules
|
|||
SonarrApi = sonarrApi;
|
||||
SonarrService = sonarrSettings;
|
||||
CouchPotatoApi = cpApi;
|
||||
SickRageService = sickRageService;
|
||||
SickrageApi = srApi;
|
||||
|
||||
Get["/"] = parameters => RequestLoad();
|
||||
|
||||
|
@ -79,11 +82,13 @@ namespace PlexRequests.UI.Modules
|
|||
private ICouchPotatoApi CouchPotatoApi { get; }
|
||||
private ISonarrApi SonarrApi { get; }
|
||||
private TheTvDbApi TvApi { get; }
|
||||
private ISickRageApi SickrageApi { get; }
|
||||
private IRequestService RequestService { get; }
|
||||
private ICacheProvider Cache { get; }
|
||||
private ISettingsService<CouchPotatoSettings> CpService { get; }
|
||||
private ISettingsService<PlexRequestSettings> PrService { get; }
|
||||
private ISettingsService<SonarrSettings> SonarrService { get; }
|
||||
private ISettingsService<SickRageSettings> SickRageService { get; }
|
||||
private IAvailabilityChecker Checker { get; }
|
||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||
private string AuthToken => Cache.GetOrSet(CacheKeys.TvDbToken, TvApi.Authenticate, 50);
|
||||
|
@ -124,7 +129,7 @@ namespace PlexRequests.UI.Modules
|
|||
// http://thetvdb.com/banners/_cache/posters/ID-1.jpg
|
||||
Banner = t.show.image?.medium,
|
||||
FirstAired = t.show.premiered,
|
||||
Id = t.show.id,
|
||||
Id = t.show.externals?.thetvdb ?? 0,
|
||||
ImdbId = t.show.externals?.imdb,
|
||||
Network = t.show.network?.name,
|
||||
NetworkId = t.show.network?.id.ToString(),
|
||||
|
@ -133,7 +138,7 @@ namespace PlexRequests.UI.Modules
|
|||
Runtime = t.show.runtime.ToString(),
|
||||
SeriesId = t.show.id,
|
||||
SeriesName = t.show.name,
|
||||
|
||||
|
||||
Status = t.show.status,
|
||||
});
|
||||
}
|
||||
|
@ -186,12 +191,12 @@ namespace PlexRequests.UI.Modules
|
|||
Log.Trace("Getting movie info from TheMovieDb");
|
||||
Log.Trace(movieInfo.DumpJson);
|
||||
|
||||
//#if !DEBUG
|
||||
//#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
|
||||
{
|
||||
|
@ -215,7 +220,7 @@ namespace PlexRequests.UI.Modules
|
|||
if (!settings.RequireApproval)
|
||||
{
|
||||
Log.Info("Adding movie to CP (No approval required)");
|
||||
var result = CouchPotatoApi.AddMovie(model.ImdbId, cpSettings.ApiKey, model.Title, cpSettings.FullUri,cpSettings.ProfileId);
|
||||
var result = CouchPotatoApi.AddMovie(model.ImdbId, cpSettings.ApiKey, model.Title, cpSettings.FullUri, cpSettings.ProfileId);
|
||||
Log.Debug("Adding movie to CP result {0}", result);
|
||||
if (result)
|
||||
{
|
||||
|
@ -260,21 +265,21 @@ namespace PlexRequests.UI.Modules
|
|||
|
||||
var tvApi = new TvMazeApi();
|
||||
|
||||
var showInfo = tvApi.ShowLookup(showId);
|
||||
var showInfo = tvApi.ShowLookupByTheTvDbId(showId);
|
||||
|
||||
//#if !DEBUG
|
||||
if (CheckIfTitleExistsInPlex(showInfo.name, showInfo.premiered.Substring(0,4))) // Take only the year Format = 2014-01-01
|
||||
//#if !DEBUG
|
||||
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.name} is already in Plex!" });
|
||||
}
|
||||
//#endif
|
||||
//#endif
|
||||
|
||||
DateTime firstAir;
|
||||
DateTime.TryParse(showInfo.premiered, out firstAir);
|
||||
|
||||
var model = new RequestedModel
|
||||
{
|
||||
ProviderId = showInfo.id,
|
||||
ProviderId = showInfo.externals?.thetvdb ?? 0,
|
||||
Type = RequestType.TvShow,
|
||||
Overview = showInfo.summary.RemoveHtml(),
|
||||
PosterPath = showInfo.image?.medium,
|
||||
|
@ -293,20 +298,39 @@ namespace PlexRequests.UI.Modules
|
|||
if (!settings.RequireApproval)
|
||||
{
|
||||
var sonarrSettings = SonarrService.GetSettings();
|
||||
int qualityProfile;
|
||||
int.TryParse(sonarrSettings.QualityProfile, out qualityProfile);
|
||||
var result = SonarrApi.AddSeries(model.ProviderId, model.Title, qualityProfile,
|
||||
sonarrSettings.SeasonFolders, sonarrSettings.RootPath, model.LatestTv, sonarrSettings.ApiKey,
|
||||
sonarrSettings.FullUri);
|
||||
if (result != null)
|
||||
var sender = new TvSender(SonarrApi, SickrageApi);
|
||||
if (sonarrSettings.Enabled)
|
||||
{
|
||||
model.Approved = true;
|
||||
Log.Debug("Adding tv to database requests (No approval required)");
|
||||
RequestService.AddRequest(model);
|
||||
var result = sender.SendToSonarr(sonarrSettings, model);
|
||||
if (result != null)
|
||||
{
|
||||
model.Approved = true;
|
||||
Log.Debug("Adding tv to database requests (No approval required & Sonarr)");
|
||||
RequestService.AddRequest(model);
|
||||
|
||||
return Response.AsJson(new JsonResponseModel { Result = true });
|
||||
}
|
||||
return Response.AsJson(new JsonResponseModel { Result = false, Message = "Something went wrong adding the movie to Sonarr! Please check your settings." });
|
||||
|
||||
return Response.AsJson(new JsonResponseModel { Result = true });
|
||||
}
|
||||
return Response.AsJson(new JsonResponseModel { Result = false, Message = "Something went wrong adding the movie to CouchPotato! Please check your settings." });
|
||||
|
||||
var srSettings = SickRageService.GetSettings();
|
||||
if (srSettings.Enabled)
|
||||
{
|
||||
var result = sender.SendToSickRage(srSettings, model);
|
||||
if (result?.result == "success")
|
||||
{
|
||||
model.Approved = true;
|
||||
Log.Debug("Adding tv to database requests (No approval required & SickRage)");
|
||||
RequestService.AddRequest(model);
|
||||
|
||||
return Response.AsJson(new JsonResponseModel { Result = true });
|
||||
}
|
||||
return Response.AsJson(new JsonResponseModel { Result = false, Message = result?.message != null ? "<b>Message From SickRage: </b>" + result.message : "Something went wrong adding the movie to SickRage! Please check your settings." });
|
||||
}
|
||||
|
||||
return Response.AsJson("The request of TV Shows is not correctly set up. Please contact your admin.");
|
||||
|
||||
}
|
||||
|
||||
RequestService.AddRequest(model);
|
||||
|
@ -314,15 +338,30 @@ namespace PlexRequests.UI.Modules
|
|||
|
||||
return Response.AsJson(new { Result = true });
|
||||
}
|
||||
private string GetTvDbAuthToken(TheTvDbApi api)
|
||||
{
|
||||
return Cache.GetOrSet(CacheKeys.TvDbToken, api.Authenticate, 50);
|
||||
}
|
||||
|
||||
private bool CheckIfTitleExistsInPlex(string title, string year)
|
||||
{
|
||||
var result = Checker.IsAvailable(title, year);
|
||||
return result;
|
||||
}
|
||||
|
||||
private Response SendToSickRage(SickRageSettings sickRageSettings, RequestedModel model)
|
||||
{
|
||||
var result = SickrageApi.AddSeries(model.ProviderId, model.LatestTv, sickRageSettings.QualityProfile,
|
||||
sickRageSettings.ApiKey, sickRageSettings.FullUri);
|
||||
|
||||
Log.Trace("SickRage Result: ");
|
||||
Log.Trace(result.DumpJson());
|
||||
|
||||
if (result?.result == "success")
|
||||
{
|
||||
model.Approved = true;
|
||||
Log.Debug("Adding tv to database requests (No approval required & SickRage)");
|
||||
RequestService.AddRequest(model);
|
||||
|
||||
return Response.AsJson(new JsonResponseModel { Result = true });
|
||||
}
|
||||
return Response.AsJson(new JsonResponseModel { Result = false, Message = "Something went wrong adding the movie to SickRage! Please check your settings." });
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue