mirror of https://github.com/Ombi-app/Ombi
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1946 lines
84 KiB
1946 lines
84 KiB
9 years ago
|
#region Copyright
|
||
8 years ago
|
|
||
9 years ago
|
// /************************************************************************
|
||
|
// Copyright (c) 2016 Jamie Rees
|
||
|
// File: SearchModule.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.
|
||
|
// ************************************************************************/
|
||
8 years ago
|
|
||
9 years ago
|
#endregion
|
||
8 years ago
|
|
||
9 years ago
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Globalization;
|
||
|
using System.Linq;
|
||
8 years ago
|
using System.Threading.Tasks;
|
||
9 years ago
|
using Nancy;
|
||
8 years ago
|
using Nancy.Extensions;
|
||
9 years ago
|
using Nancy.Responses.Negotiation;
|
||
8 years ago
|
using Newtonsoft.Json;
|
||
9 years ago
|
using NLog;
|
||
8 years ago
|
using Ombi.Api;
|
||
|
using Ombi.Api.Interfaces;
|
||
|
using Ombi.Api.Models.Music;
|
||
|
using Ombi.Api.Models.Sonarr;
|
||
|
using Ombi.Api.Models.Tv;
|
||
|
using Ombi.Core;
|
||
|
using Ombi.Core.Models;
|
||
|
using Ombi.Core.Queue;
|
||
|
using Ombi.Core.SettingModels;
|
||
8 years ago
|
using Ombi.Core.Tv;
|
||
8 years ago
|
using Ombi.Helpers;
|
||
|
using Ombi.Helpers.Analytics;
|
||
|
using Ombi.Helpers.Permissions;
|
||
|
using Ombi.Services.Interfaces;
|
||
8 years ago
|
using Ombi.Services.Jobs;
|
||
8 years ago
|
using Ombi.Services.Notification;
|
||
|
using Ombi.Store;
|
||
|
using Ombi.Store.Models;
|
||
8 years ago
|
using Ombi.Store.Models.Emby;
|
||
8 years ago
|
using Ombi.Store.Models.Plex;
|
||
|
using Ombi.Store.Repository;
|
||
|
using Ombi.UI.Helpers;
|
||
|
using Ombi.UI.Models;
|
||
9 years ago
|
using TMDbLib.Objects.General;
|
||
8 years ago
|
using TraktApiSharp.Objects.Get.Shows;
|
||
8 years ago
|
using Action = Ombi.Helpers.Analytics.Action;
|
||
|
using EpisodesModel = Ombi.Store.EpisodesModel;
|
||
|
using ISecurityExtensions = Ombi.Core.ISecurityExtensions;
|
||
9 years ago
|
|
||
8 years ago
|
namespace Ombi.UI.Modules
|
||
9 years ago
|
{
|
||
|
public class SearchModule : BaseAuthModule
|
||
|
{
|
||
8 years ago
|
public SearchModule(ICacheProvider cache,
|
||
|
ISettingsService<PlexRequestSettings> prSettings, IAvailabilityChecker plexChecker,
|
||
9 years ago
|
IRequestService request, ISonarrApi sonarrApi, ISettingsService<SonarrSettings> sonarrSettings,
|
||
8 years ago
|
ISettingsService<SickRageSettings> sickRageService, ISickRageApi srApi,
|
||
8 years ago
|
INotificationService notify, IMusicBrainzApi mbApi, IHeadphonesApi hpApi,
|
||
|
ISettingsService<HeadphonesSettings> hpService,
|
||
8 years ago
|
ICouchPotatoCacher cpCacher, IWatcherCacher watcherCacher, ISonarrCacher sonarrCacher, ISickRageCacher sickRageCacher, IPlexApi plexApi,
|
||
8 years ago
|
ISettingsService<PlexSettings> plexService, ISettingsService<AuthenticationSettings> auth,
|
||
|
IRepository<UsersToNotify> u, ISettingsService<EmailNotificationSettings> email,
|
||
8 years ago
|
IIssueService issue, IAnalytics a, IRepository<RequestLimit> rl, ITransientFaultQueue tfQueue, IRepository<PlexContent> content,
|
||
8 years ago
|
ISecurityExtensions security, IMovieSender movieSender, IRadarrCacher radarrCacher, ITraktApi traktApi, ISettingsService<CustomizationSettings> cus,
|
||
|
IEmbyAvailabilityChecker embyChecker, IRepository<EmbyContent> embyContent, ISettingsService<EmbySettings> embySettings)
|
||
8 years ago
|
: base("search", prSettings, security)
|
||
9 years ago
|
{
|
||
|
Auth = auth;
|
||
|
PlexService = plexService;
|
||
|
PlexApi = plexApi;
|
||
|
PrService = prSettings;
|
||
|
MovieApi = new TheMovieDbApi();
|
||
|
Cache = cache;
|
||
8 years ago
|
PlexChecker = plexChecker;
|
||
9 years ago
|
CpCacher = cpCacher;
|
||
|
SonarrCacher = sonarrCacher;
|
||
|
SickRageCacher = sickRageCacher;
|
||
|
RequestService = request;
|
||
|
SonarrApi = sonarrApi;
|
||
|
SonarrService = sonarrSettings;
|
||
|
SickRageService = sickRageService;
|
||
|
SickrageApi = srApi;
|
||
|
NotificationService = notify;
|
||
|
MusicBrainzApi = mbApi;
|
||
|
HeadphonesApi = hpApi;
|
||
|
HeadphonesService = hpService;
|
||
|
UsersToNotifyRepo = u;
|
||
|
EmailNotificationSettings = email;
|
||
|
IssueService = issue;
|
||
9 years ago
|
Analytics = a;
|
||
9 years ago
|
RequestLimitRepo = rl;
|
||
8 years ago
|
FaultQueue = tfQueue;
|
||
8 years ago
|
TvApi = new TvMazeApi();
|
||
8 years ago
|
PlexContentRepository = content;
|
||
8 years ago
|
MovieSender = movieSender;
|
||
|
WatcherCacher = watcherCacher;
|
||
8 years ago
|
RadarrCacher = radarrCacher;
|
||
8 years ago
|
TraktApi = traktApi;
|
||
8 years ago
|
CustomizationSettings = cus;
|
||
8 years ago
|
EmbyChecker = embyChecker;
|
||
|
EmbyContentRepository = embyContent;
|
||
|
EmbySettings = embySettings;
|
||
9 years ago
|
|
||
8 years ago
|
Get["SearchIndex", "/", true] = async (x, ct) => await RequestLoad();
|
||
9 years ago
|
|
||
8 years ago
|
Get["actor/{searchTerm}", true] = async (x, ct) => await SearchPerson((string)x.searchTerm);
|
||
|
Get["actor/new/{searchTerm}", true] = async (x, ct) => await SearchPerson((string)x.searchTerm, true);
|
||
9 years ago
|
Get["movie/{searchTerm}", true] = async (x, ct) => await SearchMovie((string)x.searchTerm);
|
||
|
Get["tv/{searchTerm}", true] = async (x, ct) => await SearchTvShow((string)x.searchTerm);
|
||
8 years ago
|
Get["music/{searchTerm}", true] = async (x, ct) => await SearchAlbum((string)x.searchTerm);
|
||
9 years ago
|
Get["music/coverArt/{id}"] = p => GetMusicBrainzCoverArt((string)p.id);
|
||
|
|
||
|
Get["movie/upcoming", true] = async (x, ct) => await UpcomingMovies();
|
||
|
Get["movie/playing", true] = async (x, ct) => await CurrentlyPlayingMovies();
|
||
|
|
||
8 years ago
|
Get["tv/popular", true] = async (x, ct) => await ProcessShows(ShowSearchType.Popular);
|
||
|
Get["tv/trending", true] = async (x, ct) => await ProcessShows(ShowSearchType.Trending);
|
||
|
Get["tv/mostwatched", true] = async (x, ct) => await ProcessShows(ShowSearchType.MostWatched);
|
||
|
Get["tv/anticipated", true] = async (x, ct) => await ProcessShows(ShowSearchType.Anticipated);
|
||
|
|
||
|
Get["tv/poster/{id}"] = p => GetTvPoster((int)p.id);
|
||
|
|
||
9 years ago
|
Post["request/movie", true] = async (x, ct) => await RequestMovie((int)Request.Form.movieId);
|
||
8 years ago
|
Post["request/tv", true] =
|
||
|
async (x, ct) => await RequestTvShow((int)Request.Form.tvId, (string)Request.Form.seasons);
|
||
8 years ago
|
Post["request/tvEpisodes", true] = async (x, ct) => await RequestTvShow(0, "episode");
|
||
9 years ago
|
Post["request/album", true] = async (x, ct) => await RequestAlbum((string)Request.Form.albumId);
|
||
8 years ago
|
|
||
9 years ago
|
Get["/seasons"] = x => GetSeasons();
|
||
8 years ago
|
Get["/episodes", true] = async (x, ct) => await GetEpisodes();
|
||
9 years ago
|
}
|
||
8 years ago
|
private ITraktApi TraktApi { get; }
|
||
8 years ago
|
private IWatcherCacher WatcherCacher { get; }
|
||
|
private IMovieSender MovieSender { get; }
|
||
8 years ago
|
private IRepository<PlexContent> PlexContentRepository { get; }
|
||
8 years ago
|
private IRepository<EmbyContent> EmbyContentRepository { get; }
|
||
8 years ago
|
private TvMazeApi TvApi { get; }
|
||
9 years ago
|
private IPlexApi PlexApi { get; }
|
||
|
private TheMovieDbApi MovieApi { get; }
|
||
|
private INotificationService NotificationService { get; }
|
||
|
private ISonarrApi SonarrApi { get; }
|
||
|
private ISickRageApi SickrageApi { get; }
|
||
|
private IRequestService RequestService { get; }
|
||
|
private ICacheProvider Cache { get; }
|
||
|
private ISettingsService<AuthenticationSettings> Auth { get; }
|
||
8 years ago
|
private ISettingsService<EmbySettings> EmbySettings { get; }
|
||
9 years ago
|
private ISettingsService<PlexSettings> PlexService { get; }
|
||
|
private ISettingsService<PlexRequestSettings> PrService { get; }
|
||
|
private ISettingsService<SonarrSettings> SonarrService { get; }
|
||
|
private ISettingsService<SickRageSettings> SickRageService { get; }
|
||
|
private ISettingsService<HeadphonesSettings> HeadphonesService { get; }
|
||
|
private ISettingsService<EmailNotificationSettings> EmailNotificationSettings { get; }
|
||
8 years ago
|
private IAvailabilityChecker PlexChecker { get; }
|
||
|
private IEmbyAvailabilityChecker EmbyChecker { get; }
|
||
9 years ago
|
private ICouchPotatoCacher CpCacher { get; }
|
||
|
private ISonarrCacher SonarrCacher { get; }
|
||
|
private ISickRageCacher SickRageCacher { get; }
|
||
|
private IMusicBrainzApi MusicBrainzApi { get; }
|
||
|
private IHeadphonesApi HeadphonesApi { get; }
|
||
|
private IRepository<UsersToNotify> UsersToNotifyRepo { get; }
|
||
|
private IIssueService IssueService { get; }
|
||
9 years ago
|
private IAnalytics Analytics { get; }
|
||
8 years ago
|
private ITransientFaultQueue FaultQueue { get; }
|
||
9 years ago
|
private IRepository<RequestLimit> RequestLimitRepo { get; }
|
||
8 years ago
|
private IRadarrCacher RadarrCacher { get; }
|
||
8 years ago
|
private ISettingsService<CustomizationSettings> CustomizationSettings { get; }
|
||
9 years ago
|
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||
8 years ago
|
|
||
|
private long _plexMovieCacheTime = 0;
|
||
8 years ago
|
private IEnumerable<PlexContent> _plexMovies;
|
||
8 years ago
|
|
||
8 years ago
|
private long _embyMovieCacheTime = 0;
|
||
8 years ago
|
private IEnumerable<EmbyContent> _embyMovies;
|
||
8 years ago
|
|
||
8 years ago
|
private long _dbMovieCacheTime = 0;
|
||
8 years ago
|
private Dictionary<int, RequestedModel> _dbMovies;
|
||
9 years ago
|
|
||
|
private async Task<Negotiator> RequestLoad()
|
||
|
{
|
||
|
var settings = await PrService.GetSettingsAsync();
|
||
8 years ago
|
var custom = await CustomizationSettings.GetSettingsAsync();
|
||
8 years ago
|
var emby = await EmbySettings.GetSettingsAsync();
|
||
|
var plex = await PlexService.GetSettingsAsync();
|
||
8 years ago
|
var searchViewModel = new SearchLoadViewModel
|
||
|
{
|
||
|
Settings = settings,
|
||
8 years ago
|
CustomizationSettings = custom,
|
||
|
Emby = emby.Enable,
|
||
|
Plex = plex.Enable
|
||
8 years ago
|
};
|
||
9 years ago
|
|
||
8 years ago
|
|
||
|
return View["Search/Index", searchViewModel];
|
||
9 years ago
|
}
|
||
|
|
||
|
private async Task<Response> UpcomingMovies()
|
||
|
{
|
||
8 years ago
|
Analytics.TrackEventAsync(Category.Search, Action.Movie, "Upcoming", Username,
|
||
|
CookieHelper.GetAnalyticClientId(Cookies));
|
||
9 years ago
|
return await ProcessMovies(MovieSearchType.Upcoming, string.Empty);
|
||
|
}
|
||
|
|
||
|
private async Task<Response> CurrentlyPlayingMovies()
|
||
|
{
|
||
8 years ago
|
Analytics.TrackEventAsync(Category.Search, Action.Movie, "CurrentlyPlaying", Username,
|
||
|
CookieHelper.GetAnalyticClientId(Cookies));
|
||
9 years ago
|
return await ProcessMovies(MovieSearchType.CurrentlyPlaying, string.Empty);
|
||
|
}
|
||
|
|
||
|
private async Task<Response> SearchMovie(string searchTerm)
|
||
|
{
|
||
8 years ago
|
Analytics.TrackEventAsync(Category.Search, Action.Movie, searchTerm, Username,
|
||
|
CookieHelper.GetAnalyticClientId(Cookies));
|
||
9 years ago
|
return await ProcessMovies(MovieSearchType.Search, searchTerm);
|
||
|
}
|
||
|
|
||
8 years ago
|
private async Task<Response> SearchPerson(string searchTerm)
|
||
8 years ago
|
{
|
||
8 years ago
|
var movies = TransformMovieListToMovieResultList(await MovieApi.SearchPerson(searchTerm));
|
||
8 years ago
|
return await TransformMovieResultsToResponse(movies);
|
||
|
}
|
||
|
|
||
8 years ago
|
private async Task<Response> SearchPerson(string searchTerm, bool filterExisting)
|
||
8 years ago
|
{
|
||
8 years ago
|
var movies = TransformMovieListToMovieResultList(await MovieApi.SearchPerson(searchTerm, AlreadyAvailable));
|
||
8 years ago
|
return await TransformMovieResultsToResponse(movies);
|
||
|
}
|
||
|
|
||
|
private async Task<bool> AlreadyAvailable(int id, string title, string year)
|
||
|
{
|
||
8 years ago
|
var plexSettings = await PlexService.GetSettingsAsync();
|
||
|
var embySettings = await EmbySettings.GetSettingsAsync();
|
||
|
|
||
|
return IsMovieInCache(id, String.Empty) ||
|
||
|
(plexSettings.Enable && PlexChecker.IsMovieAvailable(PlexMovies(), title, year)) ||
|
||
|
(embySettings.Enable && EmbyChecker.IsMovieAvailable(EmbyMovies(), title, year, String.Empty));
|
||
8 years ago
|
}
|
||
|
|
||
8 years ago
|
private IEnumerable<PlexContent> PlexMovies()
|
||
8 years ago
|
{ long now = DateTime.Now.Ticks;
|
||
|
if(_plexMovies == null || (now - _plexMovieCacheTime) > 10000)
|
||
8 years ago
|
{
|
||
|
var content = PlexContentRepository.GetAll();
|
||
8 years ago
|
_plexMovies = PlexChecker.GetPlexMovies(content);
|
||
8 years ago
|
_plexMovieCacheTime = now;
|
||
8 years ago
|
}
|
||
|
|
||
|
return _plexMovies;
|
||
|
}
|
||
|
|
||
8 years ago
|
private IEnumerable<EmbyContent> EmbyMovies()
|
||
|
{
|
||
|
long now = DateTime.Now.Ticks;
|
||
|
if (_embyMovies == null || (now - _embyMovieCacheTime) > 10000)
|
||
|
{
|
||
|
var content = EmbyContentRepository.GetAll();
|
||
|
_embyMovies = EmbyChecker.GetEmbyMovies(content);
|
||
|
_embyMovieCacheTime = now;
|
||
|
}
|
||
|
|
||
|
return _embyMovies;
|
||
|
}
|
||
|
|
||
8 years ago
|
private Response GetTvPoster(int theTvDbId)
|
||
|
{
|
||
|
var result = TvApi.ShowLookupByTheTvDbId(theTvDbId);
|
||
|
|
||
|
var banner = result.image?.medium;
|
||
|
if (!string.IsNullOrEmpty(banner))
|
||
|
{
|
||
|
banner = banner.Replace("http", "https"); // Always use the Https banners
|
||
|
}
|
||
|
return banner;
|
||
|
}
|
||
9 years ago
|
|
||
8 years ago
|
private List<MovieResult> TransformSearchMovieListToMovieResultList(List<TMDbLib.Objects.Search.SearchMovie> searchMovies)
|
||
|
{
|
||
|
return searchMovies.Select(x =>
|
||
8 years ago
|
new MovieResult
|
||
|
{
|
||
|
Adult = x.Adult,
|
||
|
BackdropPath = x.BackdropPath,
|
||
|
GenreIds = x.GenreIds,
|
||
|
Id = x.Id,
|
||
|
OriginalLanguage = x.OriginalLanguage,
|
||
|
OriginalTitle = x.OriginalTitle,
|
||
|
Overview = x.Overview,
|
||
|
Popularity = x.Popularity,
|
||
|
PosterPath = x.PosterPath,
|
||
|
ReleaseDate = x.ReleaseDate,
|
||
|
Title = x.Title,
|
||
|
Video = x.Video,
|
||
|
VoteAverage = x.VoteAverage,
|
||
|
VoteCount = x.VoteCount
|
||
|
})
|
||
|
.ToList();
|
||
8 years ago
|
}
|
||
|
|
||
|
private List<MovieResult> TransformMovieListToMovieResultList(List<TMDbLib.Objects.Movies.Movie> movies)
|
||
|
{
|
||
|
return movies.Select(x =>
|
||
|
new MovieResult
|
||
|
{
|
||
|
Adult = x.Adult,
|
||
|
BackdropPath = x.BackdropPath,
|
||
|
GenreIds = x.Genres.Select(y => y.Id).ToList(),
|
||
|
Id = x.Id,
|
||
|
OriginalLanguage = x.OriginalLanguage,
|
||
|
OriginalTitle = x.OriginalTitle,
|
||
|
Overview = x.Overview,
|
||
|
Popularity = x.Popularity,
|
||
|
PosterPath = x.PosterPath,
|
||
|
ReleaseDate = x.ReleaseDate,
|
||
|
Title = x.Title,
|
||
|
Video = x.Video,
|
||
|
VoteAverage = x.VoteAverage,
|
||
|
VoteCount = x.VoteCount
|
||
|
})
|
||
|
.ToList();
|
||
|
}
|
||
|
private async Task<Response> ProcessMovies(MovieSearchType searchType, string searchTerm)
|
||
|
{
|
||
|
List<MovieResult> apiMovies;
|
||
|
|
||
|
switch (searchType)
|
||
|
{
|
||
|
case MovieSearchType.Search:
|
||
|
var movies = await MovieApi.SearchMovie(searchTerm).ConfigureAwait(false);
|
||
|
apiMovies = TransformSearchMovieListToMovieResultList(movies);
|
||
8 years ago
|
break;
|
||
|
case MovieSearchType.CurrentlyPlaying:
|
||
|
apiMovies = await MovieApi.GetCurrentPlayingMovies();
|
||
|
break;
|
||
|
case MovieSearchType.Upcoming:
|
||
|
apiMovies = await MovieApi.GetUpcomingMovies();
|
||
|
break;
|
||
|
default:
|
||
8 years ago
|
apiMovies = new List<MovieResult>();
|
||
8 years ago
|
break;
|
||
|
}
|
||
8 years ago
|
|
||
8 years ago
|
return await TransformMovieResultsToResponse(apiMovies);
|
||
|
}
|
||
|
|
||
8 years ago
|
private async Task<Dictionary<int, RequestedModel>> RequestedMovies()
|
||
8 years ago
|
{
|
||
8 years ago
|
long now = DateTime.Now.Ticks;
|
||
|
if (_dbMovies == null || (now - _dbMovieCacheTime) > 10000)
|
||
8 years ago
|
{
|
||
|
var allResults = await RequestService.GetAllAsync();
|
||
|
allResults = allResults.Where(x => x.Type == RequestType.Movie);
|
||
9 years ago
|
|
||
8 years ago
|
var distinctResults = allResults.DistinctBy(x => x.ProviderId);
|
||
|
_dbMovies = distinctResults.ToDictionary(x => x.ProviderId);
|
||
8 years ago
|
_dbMovieCacheTime = now;
|
||
8 years ago
|
}
|
||
|
return _dbMovies;
|
||
|
}
|
||
9 years ago
|
|
||
8 years ago
|
private async Task<Response> TransformMovieResultsToResponse(List<MovieResult> movies)
|
||
|
{
|
||
|
await Task.Yield();
|
||
9 years ago
|
var viewMovies = new List<SearchMovieViewModel>();
|
||
8 years ago
|
var counter = 0;
|
||
8 years ago
|
Dictionary<int, RequestedModel> dbMovies = await RequestedMovies();
|
||
8 years ago
|
foreach (var movie in movies)
|
||
9 years ago
|
{
|
||
|
var viewMovie = new SearchMovieViewModel
|
||
|
{
|
||
|
Adult = movie.Adult,
|
||
|
BackdropPath = movie.BackdropPath,
|
||
|
GenreIds = movie.GenreIds,
|
||
|
Id = movie.Id,
|
||
|
OriginalLanguage = movie.OriginalLanguage,
|
||
|
OriginalTitle = movie.OriginalTitle,
|
||
|
Overview = movie.Overview,
|
||
|
Popularity = movie.Popularity,
|
||
|
PosterPath = movie.PosterPath,
|
||
|
ReleaseDate = movie.ReleaseDate,
|
||
|
Title = movie.Title,
|
||
|
Video = movie.Video,
|
||
|
VoteAverage = movie.VoteAverage,
|
||
|
VoteCount = movie.VoteCount
|
||
|
};
|
||
8 years ago
|
|
||
|
if (counter <= 5) // Let's only do it for the first 5 items
|
||
|
{
|
||
|
var movieInfo = MovieApi.GetMovieInformationWithVideos(movie.Id);
|
||
8 years ago
|
|
||
8 years ago
|
// TODO needs to be careful about this, it's adding extra time to search...
|
||
|
// https://www.themoviedb.org/talk/5807f4cdc3a36812160041f2
|
||
|
viewMovie.ImdbId = movieInfo?.imdb_id;
|
||
|
viewMovie.Homepage = movieInfo?.homepage;
|
||
|
var videoId = movieInfo?.video ?? false
|
||
|
? movieInfo?.videos?.results?.FirstOrDefault()?.key
|
||
|
: string.Empty;
|
||
|
|
||
|
viewMovie.Trailer = string.IsNullOrEmpty(videoId)
|
||
|
? string.Empty
|
||
|
: $"https://www.youtube.com/watch?v={videoId}";
|
||
|
|
||
|
counter++;
|
||
|
}
|
||
|
|
||
8 years ago
|
var canSee = CanUserSeeThisRequest(viewMovie.Id, Security.HasPermissions(User, Permissions.UsersCanViewOnlyOwnRequests), dbMovies);
|
||
|
|
||
|
var plexSettings = await PlexService.GetSettingsAsync();
|
||
|
var embySettings = await EmbySettings.GetSettingsAsync();
|
||
|
if (plexSettings.Enable)
|
||
9 years ago
|
{
|
||
8 years ago
|
var content = PlexContentRepository.GetAll();
|
||
|
var plexMovies = PlexChecker.GetPlexMovies(content);
|
||
|
|
||
|
var plexMovie = PlexChecker.GetMovie(plexMovies.ToArray(), movie.Title,
|
||
|
movie.ReleaseDate?.Year.ToString(),
|
||
|
viewMovie.ImdbId);
|
||
|
if (plexMovie != null)
|
||
|
{
|
||
|
viewMovie.Available = true;
|
||
|
viewMovie.PlexUrl = plexMovie.Url;
|
||
|
}
|
||
|
}
|
||
|
if (embySettings.Enable)
|
||
|
{
|
||
|
var embyContent = EmbyContentRepository.GetAll();
|
||
|
var embyMovies = EmbyChecker.GetEmbyMovies(embyContent);
|
||
|
|
||
|
var embyMovie = EmbyChecker.GetMovie(embyMovies.ToArray(), movie.Title,
|
||
|
movie.ReleaseDate?.Year.ToString(), viewMovie.ImdbId);
|
||
|
if (embyMovie != null)
|
||
|
{
|
||
|
viewMovie.Available = true;
|
||
|
}
|
||
9 years ago
|
}
|
||
8 years ago
|
if (dbMovies.ContainsKey(movie.Id) && canSee) // compare to the requests db
|
||
9 years ago
|
{
|
||
|
var dbm = dbMovies[movie.Id];
|
||
|
|
||
|
viewMovie.Requested = true;
|
||
|
viewMovie.Approved = dbm.Approved;
|
||
|
viewMovie.Available = dbm.Available;
|
||
|
}
|
||
8 years ago
|
else if (canSee)
|
||
8 years ago
|
{
|
||
8 years ago
|
bool exists = IsMovieInCache(movie, viewMovie.ImdbId);
|
||
8 years ago
|
viewMovie.Approved = exists;
|
||
|
viewMovie.Requested = exists;
|
||
8 years ago
|
}
|
||
9 years ago
|
viewMovies.Add(viewMovie);
|
||
|
}
|
||
|
|
||
|
return Response.AsJson(viewMovies);
|
||
8 years ago
|
}
|
||
|
|
||
|
private bool IsMovieInCache(MovieResult movie, string imdbId)
|
||
|
{ int id = movie.Id;
|
||
|
return IsMovieInCache(id, imdbId);
|
||
|
}
|
||
|
|
||
|
private bool IsMovieInCache(int id, string imdbId)
|
||
|
{ var cpCached = CpCacher.QueuedIds();
|
||
|
var watcherCached = WatcherCacher.QueuedIds();
|
||
|
var radarrCached = RadarrCacher.QueuedIds();
|
||
8 years ago
|
|
||
8 years ago
|
return cpCached.Contains(id) || watcherCached.Contains(imdbId) || radarrCached.Contains(id);
|
||
9 years ago
|
}
|
||
|
|
||
8 years ago
|
private bool CanUserSeeThisRequest(int movieId, bool usersCanViewOnlyOwnRequests,
|
||
|
Dictionary<int, RequestedModel> moviesInDb)
|
||
9 years ago
|
{
|
||
|
if (usersCanViewOnlyOwnRequests)
|
||
|
{
|
||
|
var result = moviesInDb.FirstOrDefault(x => x.Value.ProviderId == movieId);
|
||
|
return result.Value == null || result.Value.UserHasRequested(Username);
|
||
|
}
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
8 years ago
|
private async Task<Response> ProcessShows(ShowSearchType type)
|
||
|
{
|
||
|
var shows = new List<SearchTvShowViewModel>();
|
||
|
var prSettings = await PrService.GetSettingsAsync();
|
||
|
switch (type)
|
||
|
{
|
||
|
case ShowSearchType.Popular:
|
||
|
Analytics.TrackEventAsync(Category.Search, Action.TvShow, "Popular", Username, CookieHelper.GetAnalyticClientId(Cookies));
|
||
|
var popularShows = await TraktApi.GetPopularShows();
|
||
8 years ago
|
|
||
8 years ago
|
foreach (var popularShow in popularShows)
|
||
|
{
|
||
|
var theTvDbId = int.Parse(popularShow.Ids.Tvdb.ToString());
|
||
8 years ago
|
|
||
8 years ago
|
var model = new SearchTvShowViewModel
|
||
|
{
|
||
|
FirstAired = popularShow.FirstAired?.ToString("yyyy-MM-ddTHH:mm:ss"),
|
||
|
Id = theTvDbId,
|
||
|
ImdbId = popularShow.Ids.Imdb,
|
||
|
Network = popularShow.Network,
|
||
|
Overview = popularShow.Overview.RemoveHtml(),
|
||
|
Rating = popularShow.Rating.ToString(),
|
||
|
Runtime = popularShow.Runtime.ToString(),
|
||
|
SeriesName = popularShow.Title,
|
||
|
Status = popularShow.Status.DisplayName,
|
||
|
DisableTvRequestsByEpisode = prSettings.DisableTvRequestsByEpisode,
|
||
|
DisableTvRequestsBySeason = prSettings.DisableTvRequestsBySeason,
|
||
|
EnableTvRequestsForOnlySeries = (prSettings.DisableTvRequestsByEpisode && prSettings.DisableTvRequestsBySeason),
|
||
|
Trailer = popularShow.Trailer,
|
||
|
Homepage = popularShow.Homepage
|
||
|
};
|
||
|
shows.Add(model);
|
||
|
}
|
||
|
shows = await MapToTvModel(shows, prSettings);
|
||
|
break;
|
||
|
case ShowSearchType.Anticipated:
|
||
|
Analytics.TrackEventAsync(Category.Search, Action.TvShow, "Anticipated", Username, CookieHelper.GetAnalyticClientId(Cookies));
|
||
|
var anticipated = await TraktApi.GetAnticipatedShows();
|
||
|
foreach (var anticipatedShow in anticipated)
|
||
|
{
|
||
|
var show = anticipatedShow.Show;
|
||
|
var theTvDbId = int.Parse(show.Ids.Tvdb.ToString());
|
||
8 years ago
|
var result = TvApi.ShowLookupByTheTvDbId(theTvDbId);
|
||
|
if (result == null)
|
||
|
{
|
||
|
continue;
|
||
|
}
|
||
8 years ago
|
|
||
|
var model = new SearchTvShowViewModel
|
||
|
{
|
||
|
FirstAired = show.FirstAired?.ToString("yyyy-MM-ddTHH:mm:ss"),
|
||
|
Id = theTvDbId,
|
||
|
ImdbId = show.Ids.Imdb,
|
||
|
Network = show.Network ?? string.Empty,
|
||
|
Overview = show.Overview?.RemoveHtml() ?? string.Empty,
|
||
|
Rating = show.Rating.ToString(),
|
||
|
Runtime = show.Runtime.ToString(),
|
||
|
SeriesName = show.Title,
|
||
|
Status = show.Status?.DisplayName ?? string.Empty,
|
||
|
DisableTvRequestsByEpisode = prSettings.DisableTvRequestsByEpisode,
|
||
|
DisableTvRequestsBySeason = prSettings.DisableTvRequestsBySeason,
|
||
|
EnableTvRequestsForOnlySeries = (prSettings.DisableTvRequestsByEpisode && prSettings.DisableTvRequestsBySeason),
|
||
|
Trailer = show.Trailer,
|
||
|
Homepage = show.Homepage
|
||
|
};
|
||
|
shows.Add(model);
|
||
|
}
|
||
|
shows = await MapToTvModel(shows, prSettings);
|
||
|
break;
|
||
|
case ShowSearchType.MostWatched:
|
||
|
Analytics.TrackEventAsync(Category.Search, Action.TvShow, "MostWatched", Username, CookieHelper.GetAnalyticClientId(Cookies));
|
||
|
var mostWatched = await TraktApi.GetMostWatchesShows();
|
||
|
foreach (var watched in mostWatched)
|
||
|
{
|
||
|
var show = watched.Show;
|
||
|
var theTvDbId = int.Parse(show.Ids.Tvdb.ToString());
|
||
8 years ago
|
var result = TvApi.ShowLookupByTheTvDbId(theTvDbId);
|
||
|
if (result == null)
|
||
|
{
|
||
|
continue;
|
||
|
}
|
||
|
|
||
8 years ago
|
var model = new SearchTvShowViewModel
|
||
|
{
|
||
|
FirstAired = show.FirstAired?.ToString("yyyy-MM-ddTHH:mm:ss"),
|
||
|
Id = theTvDbId,
|
||
|
ImdbId = show.Ids.Imdb,
|
||
|
Network = show.Network,
|
||
|
Overview = show.Overview.RemoveHtml(),
|
||
|
Rating = show.Rating.ToString(),
|
||
|
Runtime = show.Runtime.ToString(),
|
||
|
SeriesName = show.Title,
|
||
|
Status = show.Status.DisplayName,
|
||
|
DisableTvRequestsByEpisode = prSettings.DisableTvRequestsByEpisode,
|
||
|
DisableTvRequestsBySeason = prSettings.DisableTvRequestsBySeason,
|
||
|
EnableTvRequestsForOnlySeries = (prSettings.DisableTvRequestsByEpisode && prSettings.DisableTvRequestsBySeason),
|
||
|
Trailer = show.Trailer,
|
||
|
Homepage = show.Homepage
|
||
|
};
|
||
|
shows.Add(model);
|
||
|
}
|
||
|
shows = await MapToTvModel(shows, prSettings);
|
||
|
break;
|
||
|
case ShowSearchType.Trending:
|
||
|
Analytics.TrackEventAsync(Category.Search, Action.TvShow, "Trending", Username, CookieHelper.GetAnalyticClientId(Cookies));
|
||
|
var trending = await TraktApi.GetTrendingShows();
|
||
|
foreach (var watched in trending)
|
||
|
{
|
||
|
var show = watched.Show;
|
||
|
var theTvDbId = int.Parse(show.Ids.Tvdb.ToString());
|
||
8 years ago
|
var result = TvApi.ShowLookupByTheTvDbId(theTvDbId);
|
||
|
if (result == null)
|
||
|
{
|
||
|
continue;
|
||
|
}
|
||
|
|
||
8 years ago
|
var model = new SearchTvShowViewModel
|
||
|
{
|
||
|
FirstAired = show.FirstAired?.ToString("yyyy-MM-ddTHH:mm:ss"),
|
||
|
Id = theTvDbId,
|
||
|
ImdbId = show.Ids.Imdb,
|
||
|
Network = show.Network,
|
||
|
Overview = show.Overview.RemoveHtml(),
|
||
|
Rating = show.Rating.ToString(),
|
||
|
Runtime = show.Runtime.ToString(),
|
||
|
SeriesName = show.Title,
|
||
|
Status = show.Status.DisplayName,
|
||
|
DisableTvRequestsByEpisode = prSettings.DisableTvRequestsByEpisode,
|
||
|
DisableTvRequestsBySeason = prSettings.DisableTvRequestsBySeason,
|
||
|
EnableTvRequestsForOnlySeries = (prSettings.DisableTvRequestsByEpisode && prSettings.DisableTvRequestsBySeason),
|
||
|
Trailer = show.Trailer,
|
||
|
Homepage = show.Homepage
|
||
|
};
|
||
|
shows.Add(model);
|
||
|
}
|
||
|
shows = await MapToTvModel(shows, prSettings);
|
||
|
break;
|
||
|
default:
|
||
|
throw new ArgumentOutOfRangeException(nameof(type), type, null);
|
||
|
}
|
||
|
|
||
|
|
||
|
return Response.AsJson(shows);
|
||
|
}
|
||
|
|
||
|
private async Task<List<SearchTvShowViewModel>> MapToTvModel(List<SearchTvShowViewModel> shows, PlexRequestSettings prSettings)
|
||
|
{
|
||
|
var plexSettings = await PlexService.GetSettingsAsync();
|
||
8 years ago
|
var embySettings = await EmbySettings.GetSettingsAsync();
|
||
8 years ago
|
|
||
|
// Get the requests
|
||
|
var allResults = await RequestService.GetAllAsync();
|
||
|
allResults = allResults.Where(x => x.Type == RequestType.TvShow);
|
||
|
var distinctResults = allResults.DistinctBy(x => x.ProviderId);
|
||
8 years ago
|
var dbTv = distinctResults.ToDictionary(x => x.ImdbId);
|
||
|
|
||
8 years ago
|
var content = PlexContentRepository.GetAll();
|
||
8 years ago
|
var plexTvShows = PlexChecker.GetPlexTvShows(content);
|
||
|
var embyContent = EmbyContentRepository.GetAll();
|
||
|
var embyCached = EmbyChecker.GetEmbyTvShows(embyContent).ToList();
|
||
8 years ago
|
|
||
|
foreach (var show in shows)
|
||
|
{
|
||
8 years ago
|
|
||
|
var providerId = show.Id.ToString();
|
||
|
|
||
|
if (embySettings.Enable)
|
||
8 years ago
|
{
|
||
8 years ago
|
var embyShow = EmbyChecker.GetTvShow(embyCached.ToArray(), show.SeriesName, show.FirstAired?.Substring(0, 4), providerId);
|
||
|
if (embyShow != null)
|
||
|
{
|
||
|
show.Available = true;
|
||
|
}
|
||
8 years ago
|
}
|
||
8 years ago
|
if (plexSettings.Enable)
|
||
8 years ago
|
{
|
||
8 years ago
|
var plexShow = PlexChecker.GetTvShow(plexTvShows.ToArray(), show.SeriesName, show.FirstAired?.Substring(0, 4),
|
||
|
providerId);
|
||
|
if (plexShow != null)
|
||
|
{
|
||
|
show.Available = true;
|
||
|
show.PlexUrl = plexShow.Url;
|
||
|
}
|
||
8 years ago
|
}
|
||
8 years ago
|
|
||
|
if (show.ImdbId != null && !show.Available)
|
||
8 years ago
|
{
|
||
8 years ago
|
var imdbId = show.ImdbId;
|
||
|
if (dbTv.ContainsKey(imdbId))
|
||
8 years ago
|
{
|
||
8 years ago
|
var dbt = dbTv[imdbId];
|
||
8 years ago
|
|
||
|
show.Requested = true;
|
||
|
show.Episodes = dbt.Episodes.ToList();
|
||
|
show.Approved = dbt.Approved;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
return shows;
|
||
|
}
|
||
|
|
||
9 years ago
|
private async Task<Response> SearchTvShow(string searchTerm)
|
||
|
{
|
||
8 years ago
|
|
||
8 years ago
|
Analytics.TrackEventAsync(Category.Search, Action.TvShow, searchTerm, Username,
|
||
|
CookieHelper.GetAnalyticClientId(Cookies));
|
||
9 years ago
|
var plexSettings = await PlexService.GetSettingsAsync();
|
||
8 years ago
|
var embySettings = await EmbySettings.GetSettingsAsync();
|
||
8 years ago
|
var prSettings = await PrService.GetSettingsAsync();
|
||
8 years ago
|
var providerId = string.Empty;
|
||
9 years ago
|
|
||
|
var apiTv = new List<TvMazeSearch>();
|
||
|
await Task.Factory.StartNew(() => new TvMazeApi().Search(searchTerm)).ContinueWith((t) =>
|
||
|
{
|
||
|
apiTv = t.Result;
|
||
|
});
|
||
|
|
||
|
var allResults = await RequestService.GetAllAsync();
|
||
|
allResults = allResults.Where(x => x.Type == RequestType.TvShow);
|
||
8 years ago
|
var distinctResults = allResults.DistinctBy(x => x.ProviderId);
|
||
|
var dbTv = distinctResults.ToDictionary(x => x.ProviderId);
|
||
9 years ago
|
|
||
|
if (!apiTv.Any())
|
||
|
{
|
||
|
return Response.AsJson("");
|
||
|
}
|
||
|
|
||
|
var sonarrCached = SonarrCacher.QueuedIds();
|
||
|
var sickRageCache = SickRageCacher.QueuedIds(); // consider just merging sonarr/sickrage arrays
|
||
8 years ago
|
var content = PlexContentRepository.GetAll();
|
||
8 years ago
|
var plexTvShows = PlexChecker.GetPlexTvShows(content);
|
||
|
var embyContent = EmbyContentRepository.GetAll();
|
||
|
var embyCached = EmbyChecker.GetEmbyTvShows(embyContent);
|
||
9 years ago
|
|
||
|
var viewTv = new List<SearchTvShowViewModel>();
|
||
|
foreach (var t in apiTv)
|
||
|
{
|
||
8 years ago
|
if (!(t.show.externals?.thetvdb.HasValue) ?? false)
|
||
|
{
|
||
|
continue;
|
||
|
}
|
||
9 years ago
|
var banner = t.show.image?.medium;
|
||
|
if (!string.IsNullOrEmpty(banner))
|
||
|
{
|
||
8 years ago
|
banner = banner.Replace("http", "https"); // Always use the Https banners
|
||
9 years ago
|
}
|
||
|
|
||
|
var viewT = new SearchTvShowViewModel
|
||
|
{
|
||
|
Banner = banner,
|
||
|
FirstAired = t.show.premiered,
|
||
|
Id = t.show.externals?.thetvdb ?? 0,
|
||
|
ImdbId = t.show.externals?.imdb,
|
||
|
Network = t.show.network?.name,
|
||
|
NetworkId = t.show.network?.id.ToString(),
|
||
|
Overview = t.show.summary.RemoveHtml(),
|
||
|
Rating = t.score.ToString(CultureInfo.CurrentUICulture),
|
||
|
Runtime = t.show.runtime.ToString(),
|
||
|
SeriesId = t.show.id,
|
||
|
SeriesName = t.show.name,
|
||
8 years ago
|
Status = t.show.status,
|
||
|
DisableTvRequestsByEpisode = prSettings.DisableTvRequestsByEpisode,
|
||
8 years ago
|
DisableTvRequestsBySeason = prSettings.DisableTvRequestsBySeason,
|
||
|
EnableTvRequestsForOnlySeries = (prSettings.DisableTvRequestsByEpisode && prSettings.DisableTvRequestsBySeason)
|
||
9 years ago
|
};
|
||
8 years ago
|
|
||
8 years ago
|
providerId = viewT.Id.ToString();
|
||
9 years ago
|
|
||
8 years ago
|
if (embySettings.Enable)
|
||
9 years ago
|
{
|
||
8 years ago
|
var embyShow = EmbyChecker.GetTvShow(embyCached.ToArray(), t.show.name, t.show.premiered?.Substring(0, 4), providerId);
|
||
|
if (embyShow != null)
|
||
|
{
|
||
|
viewT.Available = true;
|
||
|
}
|
||
9 years ago
|
}
|
||
8 years ago
|
if (plexSettings.Enable)
|
||
9 years ago
|
{
|
||
8 years ago
|
var plexShow = PlexChecker.GetTvShow(plexTvShows.ToArray(), t.show.name, t.show.premiered?.Substring(0, 4),
|
||
|
providerId);
|
||
|
if (plexShow != null)
|
||
|
{
|
||
|
viewT.Available = true;
|
||
|
viewT.PlexUrl = plexShow.Url;
|
||
|
}
|
||
9 years ago
|
}
|
||
8 years ago
|
|
||
|
if (t.show?.externals?.thetvdb != null && !viewT.Available)
|
||
9 years ago
|
{
|
||
8 years ago
|
var tvdbid = (int)t.show.externals.thetvdb;
|
||
9 years ago
|
if (dbTv.ContainsKey(tvdbid))
|
||
|
{
|
||
|
var dbt = dbTv[tvdbid];
|
||
|
|
||
|
viewT.Requested = true;
|
||
8 years ago
|
viewT.Episodes = dbt.Episodes.ToList();
|
||
9 years ago
|
viewT.Approved = dbt.Approved;
|
||
|
}
|
||
8 years ago
|
if (sonarrCached.Select(x => x.TvdbId).Contains(tvdbid) || sickRageCache.Contains(tvdbid))
|
||
|
// compare to the sonarr/sickrage db
|
||
9 years ago
|
{
|
||
|
viewT.Requested = true;
|
||
|
}
|
||
|
}
|
||
8 years ago
|
|
||
9 years ago
|
viewTv.Add(viewT);
|
||
|
}
|
||
|
|
||
|
return Response.AsJson(viewTv);
|
||
|
}
|
||
|
|
||
8 years ago
|
private async Task<Response> SearchAlbum(string searchTerm)
|
||
9 years ago
|
{
|
||
8 years ago
|
Analytics.TrackEventAsync(Category.Search, Action.Album, searchTerm, Username,
|
||
|
CookieHelper.GetAnalyticClientId(Cookies));
|
||
9 years ago
|
var apiAlbums = new List<Release>();
|
||
|
await Task.Run(() => MusicBrainzApi.SearchAlbum(searchTerm)).ContinueWith((t) =>
|
||
|
{
|
||
|
apiAlbums = t.Result.releases ?? new List<Release>();
|
||
|
});
|
||
|
|
||
|
var allResults = await RequestService.GetAllAsync();
|
||
|
allResults = allResults.Where(x => x.Type == RequestType.Album);
|
||
|
|
||
|
var dbAlbum = allResults.ToDictionary(x => x.MusicBrainzId);
|
||
|
|
||
8 years ago
|
var content = PlexContentRepository.GetAll();
|
||
8 years ago
|
var plexAlbums = PlexChecker.GetPlexAlbums(content);
|
||
9 years ago
|
|
||
|
var viewAlbum = new List<SearchMusicViewModel>();
|
||
|
foreach (var a in apiAlbums)
|
||
|
{
|
||
|
var viewA = new SearchMusicViewModel
|
||
|
{
|
||
|
Title = a.title,
|
||
|
Id = a.id,
|
||
|
Artist = a.ArtistCredit?.Select(x => x.artist?.name).FirstOrDefault(),
|
||
|
Overview = a.disambiguation,
|
||
|
ReleaseDate = a.date,
|
||
|
TrackCount = a.TrackCount,
|
||
|
ReleaseType = a.status,
|
||
|
Country = a.country
|
||
|
};
|
||
|
|
||
|
DateTime release;
|
||
|
DateTimeHelper.CustomParse(a.ReleaseEvents?.FirstOrDefault()?.date, out release);
|
||
|
var artist = a.ArtistCredit?.FirstOrDefault()?.artist;
|
||
8 years ago
|
var plexAlbum = PlexChecker.GetAlbum(plexAlbums.ToArray(), a.title, release.ToString("yyyy"), artist?.name);
|
||
8 years ago
|
if (plexAlbum != null)
|
||
9 years ago
|
{
|
||
|
viewA.Available = true;
|
||
8 years ago
|
viewA.PlexUrl = plexAlbum.Url;
|
||
9 years ago
|
}
|
||
|
if (!string.IsNullOrEmpty(a.id) && dbAlbum.ContainsKey(a.id))
|
||
|
{
|
||
|
var dba = dbAlbum[a.id];
|
||
|
|
||
|
viewA.Requested = true;
|
||
|
viewA.Approved = dba.Approved;
|
||
|
viewA.Available = dba.Available;
|
||
|
}
|
||
|
|
||
|
viewAlbum.Add(viewA);
|
||
|
}
|
||
|
return Response.AsJson(viewAlbum);
|
||
|
}
|
||
|
|
||
|
private async Task<Response> RequestMovie(int movieId)
|
||
|
{
|
||
8 years ago
|
if(string.IsNullOrEmpty(Username))
|
||
|
{
|
||
|
return Response.AsJson(new JsonResponseModel
|
||
|
{
|
||
|
Result = false,
|
||
|
Message = "Your session has expired, please refresh the page"
|
||
|
});
|
||
|
}
|
||
8 years ago
|
if (Security.HasPermissions(User, Permissions.ReadOnlyUser) || !Security.HasPermissions(User, Permissions.RequestMovie))
|
||
8 years ago
|
{
|
||
|
return
|
||
8 years ago
|
Response.AsJson(new JsonResponseModel
|
||
8 years ago
|
{
|
||
|
Result = false,
|
||
|
Message = "Sorry, you do not have the correct permissions to request a movie!"
|
||
|
});
|
||
|
}
|
||
9 years ago
|
var settings = await PrService.GetSettingsAsync();
|
||
|
if (!await CheckRequestLimit(settings, RequestType.Movie))
|
||
|
{
|
||
8 years ago
|
return
|
||
|
Response.AsJson(new JsonResponseModel
|
||
|
{
|
||
|
Result = false,
|
||
|
Message = "You have reached your weekly request limit for Movies! Please contact your admin."
|
||
|
});
|
||
9 years ago
|
}
|
||
8 years ago
|
var embySettings = await EmbySettings.GetSettingsAsync();
|
||
8 years ago
|
Analytics.TrackEventAsync(Category.Search, Action.Request, "Movie", Username,
|
||
|
CookieHelper.GetAnalyticClientId(Cookies));
|
||
8 years ago
|
var movieInfo = await MovieApi.GetMovieInformation(movieId);
|
||
8 years ago
|
if (movieInfo == null)
|
||
|
{
|
||
|
return
|
||
|
Response.AsJson(new JsonResponseModel
|
||
|
{
|
||
|
Result = false,
|
||
|
Message = "There was an issue adding this movie!"
|
||
|
});
|
||
|
}
|
||
8 years ago
|
var fullMovieName =
|
||
|
$"{movieInfo.Title}{(movieInfo.ReleaseDate.HasValue ? $" ({movieInfo.ReleaseDate.Value.Year})" : string.Empty)}";
|
||
8 years ago
|
|
||
9 years ago
|
var existingRequest = await RequestService.CheckRequestAsync(movieId);
|
||
|
if (existingRequest != null)
|
||
|
{
|
||
|
// check if the current user is already marked as a requester for this movie, if not, add them
|
||
|
if (!existingRequest.UserHasRequested(Username))
|
||
|
{
|
||
|
existingRequest.RequestedUsers.Add(Username);
|
||
|
await RequestService.UpdateRequestAsync(existingRequest);
|
||
|
}
|
||
|
|
||
8 years ago
|
return
|
||
|
Response.AsJson(new JsonResponseModel
|
||
|
{
|
||
|
Result = true,
|
||
|
Message =
|
||
8 years ago
|
Security.HasPermissions(User, Permissions.UsersCanViewOnlyOwnRequests)
|
||
8 years ago
|
? $"{fullMovieName} {Ombi.UI.Resources.UI.Search_SuccessfullyAdded}"
|
||
8 years ago
|
: $"{fullMovieName} {Resources.UI.Search_AlreadyRequested}"
|
||
|
});
|
||
9 years ago
|
}
|
||
8 years ago
|
|
||
9 years ago
|
try
|
||
|
{
|
||
8 years ago
|
|
||
|
var content = PlexContentRepository.GetAll();
|
||
8 years ago
|
var movies = PlexChecker.GetPlexMovies(content);
|
||
|
if (PlexChecker.IsMovieAvailable(movies.ToArray(), movieInfo.Title, movieInfo.ReleaseDate?.Year.ToString()))
|
||
9 years ago
|
{
|
||
8 years ago
|
return
|
||
|
Response.AsJson(new JsonResponseModel
|
||
|
{
|
||
|
Result = false,
|
||
|
Message = $"{fullMovieName} is already in Plex!"
|
||
|
});
|
||
9 years ago
|
}
|
||
|
}
|
||
|
catch (Exception e)
|
||
|
{
|
||
|
Log.Error(e);
|
||
8 years ago
|
return
|
||
|
Response.AsJson(new JsonResponseModel
|
||
|
{
|
||
|
Result = false,
|
||
8 years ago
|
Message = string.Format(Resources.UI.Search_CouldNotCheckPlex, fullMovieName,GetMediaServerName())
|
||
8 years ago
|
});
|
||
9 years ago
|
}
|
||
|
//#endif
|
||
|
|
||
|
var model = new RequestedModel
|
||
|
{
|
||
|
ProviderId = movieInfo.Id,
|
||
|
Type = RequestType.Movie,
|
||
|
Overview = movieInfo.Overview,
|
||
|
ImdbId = movieInfo.ImdbId,
|
||
8 years ago
|
PosterPath = movieInfo.PosterPath,
|
||
9 years ago
|
Title = movieInfo.Title,
|
||
|
ReleaseDate = movieInfo.ReleaseDate ?? DateTime.MinValue,
|
||
|
Status = movieInfo.Status,
|
||
|
RequestedDate = DateTime.UtcNow,
|
||
|
Approved = false,
|
||
|
RequestedUsers = new List<string> { Username },
|
||
|
Issues = IssueState.None,
|
||
|
|
||
|
};
|
||
8 years ago
|
try
|
||
9 years ago
|
{
|
||
8 years ago
|
if (ShouldAutoApprove(RequestType.Movie))
|
||
9 years ago
|
{
|
||
8 years ago
|
model.Approved = true;
|
||
8 years ago
|
|
||
|
var result = await MovieSender.Send(model);
|
||
|
if (result.Result)
|
||
|
{
|
||
|
return await AddRequest(model, settings,
|
||
8 years ago
|
$"{fullMovieName} {Resources.UI.Search_SuccessfullyAdded}");
|
||
|
}
|
||
|
if (result.Error)
|
||
|
|
||
|
{
|
||
|
return
|
||
|
Response.AsJson(new JsonResponseModel
|
||
|
{
|
||
8 years ago
|
Message = "Could not add movie, please contact your administrator",
|
||
8 years ago
|
Result = false
|
||
|
});
|
||
8 years ago
|
}
|
||
|
if (!result.MovieSendingEnabled)
|
||
9 years ago
|
{
|
||
8 years ago
|
|
||
8 years ago
|
return await AddRequest(model, settings, $"{fullMovieName} {Resources.UI.Search_SuccessfullyAdded}");
|
||
8 years ago
|
}
|
||
8 years ago
|
|
||
|
return Response.AsJson(new JsonResponseModel
|
||
|
{
|
||
|
Result = false,
|
||
|
Message = Resources.UI.Search_CouchPotatoError
|
||
|
});
|
||
9 years ago
|
}
|
||
|
|
||
8 years ago
|
|
||
9 years ago
|
return await AddRequest(model, settings, $"{fullMovieName} {Resources.UI.Search_SuccessfullyAdded}");
|
||
9 years ago
|
}
|
||
|
catch (Exception e)
|
||
|
{
|
||
|
Log.Fatal(e);
|
||
8 years ago
|
await FaultQueue.QueueItemAsync(model, movieInfo.Id.ToString(), RequestType.Movie, FaultType.RequestFault, e.Message);
|
||
8 years ago
|
|
||
|
await NotificationService.Publish(new NotificationModel
|
||
|
{
|
||
|
DateTime = DateTime.Now,
|
||
|
User = Username,
|
||
|
RequestType = RequestType.Movie,
|
||
|
Title = model.Title,
|
||
|
NotificationType = NotificationType.ItemAddedToFaultQueue
|
||
|
});
|
||
9 years ago
|
|
||
8 years ago
|
return Response.AsJson(new JsonResponseModel
|
||
|
{
|
||
|
Result = true,
|
||
|
Message = $"{fullMovieName} {Resources.UI.Search_SuccessfullyAdded}"
|
||
|
});
|
||
9 years ago
|
}
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// Requests the tv show.
|
||
|
/// </summary>
|
||
|
/// <param name="showId">The show identifier.</param>
|
||
|
/// <param name="seasons">The seasons.</param>
|
||
|
/// <returns></returns>
|
||
|
private async Task<Response> RequestTvShow(int showId, string seasons)
|
||
|
{
|
||
8 years ago
|
if (string.IsNullOrEmpty(Username))
|
||
|
{
|
||
|
return Response.AsJson(new JsonResponseModel
|
||
|
{
|
||
|
Result = false,
|
||
|
Message = "Your session has expired, please refresh the page"
|
||
|
});
|
||
|
}
|
||
8 years ago
|
if (Security.HasPermissions(User, Permissions.ReadOnlyUser) || !Security.HasPermissions(User, Permissions.RequestTvShow))
|
||
8 years ago
|
{
|
||
|
return
|
||
|
Response.AsJson(new JsonResponseModel()
|
||
|
{
|
||
|
Result = false,
|
||
|
Message = "Sorry, you do not have the correct permissions to request a TV Show!"
|
||
|
});
|
||
|
}
|
||
8 years ago
|
// Get the JSON from the request
|
||
|
var req = (Dictionary<string, object>.ValueCollection)Request.Form.Values;
|
||
8 years ago
|
EpisodeRequestModel episodeModel = null;
|
||
|
if (req.Count == 1)
|
||
|
{
|
||
|
var json = req.FirstOrDefault()?.ToString();
|
||
|
episodeModel = JsonConvert.DeserializeObject<EpisodeRequestModel>(json); // Convert it into the object
|
||
|
}
|
||
8 years ago
|
var episodeRequest = false;
|
||
|
|
||
9 years ago
|
var settings = await PrService.GetSettingsAsync();
|
||
|
if (!await CheckRequestLimit(settings, RequestType.TvShow))
|
||
|
{
|
||
8 years ago
|
return
|
||
|
Response.AsJson(new JsonResponseModel
|
||
|
{
|
||
|
Result = false,
|
||
|
Message = Resources.UI.Search_WeeklyRequestLimitTVShow
|
||
|
});
|
||
9 years ago
|
}
|
||
8 years ago
|
Analytics.TrackEventAsync(Category.Search, Action.Request, "TvShow", Username,
|
||
|
CookieHelper.GetAnalyticClientId(Cookies));
|
||
9 years ago
|
|
||
8 years ago
|
var sonarrSettings = SonarrService.GetSettingsAsync();
|
||
|
|
||
8 years ago
|
// This means we are requesting an episode rather than a whole series or season
|
||
|
if (episodeModel != null)
|
||
|
{
|
||
|
episodeRequest = true;
|
||
8 years ago
|
showId = episodeModel.ShowId;
|
||
8 years ago
|
var s = await sonarrSettings;
|
||
|
if (!s.Enabled)
|
||
8 years ago
|
{
|
||
8 years ago
|
return
|
||
|
Response.AsJson(new JsonResponseModel
|
||
|
{
|
||
|
Message =
|
||
|
"This is currently only supported with Sonarr, Please enable Sonarr for this feature",
|
||
|
Result = false
|
||
|
});
|
||
8 years ago
|
}
|
||
|
}
|
||
8 years ago
|
var embySettings = await EmbySettings.GetSettingsAsync();
|
||
8 years ago
|
var showInfo = TvApi.ShowLookupByTheTvDbId(showId);
|
||
9 years ago
|
DateTime firstAir;
|
||
|
DateTime.TryParse(showInfo.premiered, out firstAir);
|
||
|
string fullShowName = $"{showInfo.name} ({firstAir.Year})";
|
||
|
|
||
8 years ago
|
// For some reason the poster path is always http
|
||
|
var posterPath = showInfo.image?.medium.Replace("http:", "https:");
|
||
9 years ago
|
var model = new RequestedModel
|
||
|
{
|
||
|
Type = RequestType.TvShow,
|
||
|
Overview = showInfo.summary.RemoveHtml(),
|
||
8 years ago
|
PosterPath = posterPath,
|
||
9 years ago
|
Title = showInfo.name,
|
||
|
ReleaseDate = firstAir,
|
||
|
Status = showInfo.status,
|
||
|
RequestedDate = DateTime.UtcNow,
|
||
|
Approved = false,
|
||
|
RequestedUsers = new List<string> { Username },
|
||
|
Issues = IssueState.None,
|
||
|
ImdbId = showInfo.externals?.imdb ?? string.Empty,
|
||
8 years ago
|
TvDbId = showId.ToString(),
|
||
|
ProviderId = showId
|
||
9 years ago
|
};
|
||
|
|
||
8 years ago
|
var totalSeasons = showInfo.Season.GroupBy(x => x.SeasonNumber);
|
||
|
model.SeasonCount = totalSeasons.Count();
|
||
9 years ago
|
var seasonsList = new List<int>();
|
||
|
switch (seasons)
|
||
|
{
|
||
|
case "first":
|
||
|
seasonsList.Add(1);
|
||
|
model.SeasonsRequested = "First";
|
||
|
break;
|
||
|
case "latest":
|
||
|
seasonsList.Add(model.SeasonCount);
|
||
|
model.SeasonsRequested = "Latest";
|
||
|
break;
|
||
|
case "all":
|
||
|
model.SeasonsRequested = "All";
|
||
|
break;
|
||
8 years ago
|
case "episode":
|
||
8 years ago
|
model.Episodes = new List<EpisodesModel>();
|
||
8 years ago
|
|
||
8 years ago
|
foreach (var ep in episodeModel?.Episodes ?? new Models.EpisodesModel[0])
|
||
8 years ago
|
{
|
||
8 years ago
|
model.Episodes.Add(new EpisodesModel
|
||
|
{
|
||
|
EpisodeNumber = ep.EpisodeNumber,
|
||
|
SeasonNumber = ep.SeasonNumber
|
||
|
});
|
||
8 years ago
|
}
|
||
8 years ago
|
Analytics.TrackEventAsync(Category.Requests, Action.TvShow, $"Episode request for {model.Title}",
|
||
|
Username, CookieHelper.GetAnalyticClientId(Cookies));
|
||
8 years ago
|
break;
|
||
9 years ago
|
default:
|
||
|
model.SeasonsRequested = seasons;
|
||
|
var split = seasons.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
||
|
var seasonsCount = new int[split.Length];
|
||
|
for (var i = 0; i < split.Length; i++)
|
||
|
{
|
||
|
int tryInt;
|
||
|
int.TryParse(split[i], out tryInt);
|
||
|
seasonsCount[i] = tryInt;
|
||
|
}
|
||
|
seasonsList.AddRange(seasonsCount);
|
||
|
break;
|
||
|
}
|
||
|
|
||
|
model.SeasonList = seasonsList.ToArray();
|
||
|
|
||
8 years ago
|
// check if the show/episodes have already been requested
|
||
|
var existingRequest = await RequestService.CheckRequestAsync(showId);
|
||
|
var difference = new List<EpisodesModel>();
|
||
|
if (existingRequest != null)
|
||
|
{
|
||
|
if (episodeRequest)
|
||
|
{
|
||
|
// Make sure we are not somehow adding dupes
|
||
|
difference = GetListDifferences(existingRequest.Episodes, episodeModel.Episodes).ToList();
|
||
|
if (difference.Any())
|
||
|
{
|
||
|
// Convert the request into the correct shape
|
||
|
var newEpisodes = episodeModel.Episodes?.Select(x => new EpisodesModel
|
||
|
{
|
||
|
SeasonNumber = x.SeasonNumber,
|
||
|
EpisodeNumber = x.EpisodeNumber
|
||
|
});
|
||
|
|
||
|
// Add it to the existing requests
|
||
|
existingRequest.Episodes.AddRange(newEpisodes ?? Enumerable.Empty<EpisodesModel>());
|
||
|
|
||
|
// It's technically a new request now, so set the status to not approved.
|
||
8 years ago
|
var autoApprove = ShouldAutoApprove(RequestType.TvShow);
|
||
|
if (autoApprove)
|
||
|
{
|
||
|
return await SendTv(model, sonarrSettings, existingRequest, fullShowName, settings);
|
||
|
}
|
||
8 years ago
|
existingRequest.Approved = false;
|
||
|
|
||
8 years ago
|
return await AddUserToRequest(existingRequest, settings, fullShowName, true);
|
||
8 years ago
|
}
|
||
8 years ago
|
else
|
||
|
{
|
||
|
// We no episodes to approve
|
||
8 years ago
|
return
|
||
|
Response.AsJson(new JsonResponseModel
|
||
|
{
|
||
|
Result = false,
|
||
8 years ago
|
Message = $"{fullShowName} {string.Format(Resources.UI.Search_AlreadyInPlex,embySettings.Enable ? "Emby" : "Plex")}"
|
||
8 years ago
|
});
|
||
8 years ago
|
}
|
||
8 years ago
|
}
|
||
|
else if (model.SeasonList.Except(existingRequest.SeasonList).Any())
|
||
|
{
|
||
|
// This is a season being requested that we do not yet have
|
||
|
// Let's just continue
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
return await AddUserToRequest(existingRequest, settings, fullShowName);
|
||
|
}
|
||
|
}
|
||
|
|
||
8 years ago
|
try
|
||
|
{
|
||
8 years ago
|
|
||
8 years ago
|
var plexSettings = await PlexService.GetSettingsAsync();
|
||
8 years ago
|
if (plexSettings.Enable)
|
||
8 years ago
|
{
|
||
8 years ago
|
var content = PlexContentRepository.GetAll();
|
||
|
var shows = PlexChecker.GetPlexTvShows(content);
|
||
|
|
||
|
var providerId = string.Empty;
|
||
|
if (plexSettings.AdvancedSearch)
|
||
|
{
|
||
|
providerId = showId.ToString();
|
||
|
}
|
||
|
if (episodeRequest)
|
||
8 years ago
|
{
|
||
8 years ago
|
var cachedEpisodesTask = await PlexChecker.GetEpisodes();
|
||
|
var cachedEpisodes = cachedEpisodesTask.ToList();
|
||
|
foreach (var d in difference) // difference is from an existing request
|
||
|
{
|
||
|
if (
|
||
|
cachedEpisodes.Any(
|
||
|
x =>
|
||
|
x.SeasonNumber == d.SeasonNumber && x.EpisodeNumber == d.EpisodeNumber &&
|
||
|
x.ProviderId == providerId))
|
||
|
{
|
||
|
return
|
||
|
Response.AsJson(new JsonResponseModel
|
||
|
{
|
||
|
Result = false,
|
||
|
Message =
|
||
|
$"{fullShowName} {d.SeasonNumber} - {d.EpisodeNumber} {string.Format(Resources.UI.Search_AlreadyInPlex,GetMediaServerName())}"
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
|
||
|
var diff = await GetEpisodeRequestDifference(showId, model);
|
||
|
model.Episodes = diff.ToList();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
if (plexSettings.EnableTvEpisodeSearching)
|
||
|
{
|
||
|
foreach (var s in showInfo.Season)
|
||
|
{
|
||
|
var result = PlexChecker.IsEpisodeAvailable(showId.ToString(), s.SeasonNumber,
|
||
|
s.EpisodeNumber);
|
||
|
if (result)
|
||
|
{
|
||
|
return
|
||
|
Response.AsJson(new JsonResponseModel
|
||
|
{
|
||
|
Result = false,
|
||
|
Message = $"{fullShowName} {string.Format(Resources.UI.Search_AlreadyInPlex,GetMediaServerName())}"
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
else if (PlexChecker.IsTvShowAvailable(shows.ToArray(), showInfo.name,
|
||
|
showInfo.premiered?.Substring(0, 4),
|
||
|
providerId, model.SeasonList))
|
||
8 years ago
|
{
|
||
8 years ago
|
return
|
||
|
Response.AsJson(new JsonResponseModel
|
||
|
{
|
||
|
Result = false,
|
||
8 years ago
|
Message = $"{fullShowName} {string.Format(Resources.UI.Search_AlreadyInPlex,GetMediaServerName())}"
|
||
8 years ago
|
});
|
||
8 years ago
|
}
|
||
|
}
|
||
|
}
|
||
8 years ago
|
if (embySettings.Enable)
|
||
8 years ago
|
{
|
||
8 years ago
|
var embyContent = EmbyContentRepository.GetAll();
|
||
|
var embyMovies = EmbyChecker.GetEmbyTvShows(embyContent);
|
||
|
var providerId = showId.ToString();
|
||
|
if (episodeRequest)
|
||
8 years ago
|
{
|
||
8 years ago
|
var cachedEpisodesTask = await EmbyChecker.GetEpisodes();
|
||
|
var cachedEpisodes = cachedEpisodesTask.ToList();
|
||
|
foreach (var d in difference) // difference is from an existing request
|
||
8 years ago
|
{
|
||
8 years ago
|
if (
|
||
|
cachedEpisodes.Any(
|
||
|
x =>
|
||
|
x.SeasonNumber == d.SeasonNumber && x.EpisodeNumber == d.EpisodeNumber &&
|
||
|
x.ProviderId == providerId))
|
||
8 years ago
|
{
|
||
8 years ago
|
return
|
||
|
Response.AsJson(new JsonResponseModel
|
||
|
{
|
||
|
Result = false,
|
||
8 years ago
|
Message =
|
||
|
$"{fullShowName} {d.SeasonNumber} - {d.EpisodeNumber} {string.Format(Resources.UI.Search_AlreadyInPlex,GetMediaServerName())}"
|
||
8 years ago
|
});
|
||
8 years ago
|
}
|
||
|
}
|
||
8 years ago
|
|
||
|
var diff = await GetEpisodeRequestDifference(showId, model);
|
||
|
model.Episodes = diff.ToList();
|
||
8 years ago
|
}
|
||
8 years ago
|
else
|
||
8 years ago
|
{
|
||
8 years ago
|
if (embySettings.EnableEpisodeSearching)
|
||
|
{
|
||
|
foreach (var s in showInfo.Season)
|
||
8 years ago
|
{
|
||
8 years ago
|
var result = EmbyChecker.IsEpisodeAvailable(showId.ToString(), s.SeasonNumber,
|
||
|
s.EpisodeNumber);
|
||
|
if (result)
|
||
|
{
|
||
|
return
|
||
|
Response.AsJson(new JsonResponseModel
|
||
|
{
|
||
|
Result = false,
|
||
|
Message = $"{fullShowName} is already in Emby!"
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
else if (EmbyChecker.IsTvShowAvailable(embyMovies.ToArray(), showInfo.name,
|
||
|
showInfo.premiered?.Substring(0, 4),
|
||
|
providerId, model.SeasonList))
|
||
|
{
|
||
|
return
|
||
|
Response.AsJson(new JsonResponseModel
|
||
|
{
|
||
|
Result = false,
|
||
|
Message = $"{fullShowName} is already in Emby!"
|
||
|
});
|
||
|
}
|
||
8 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
catch (Exception)
|
||
|
{
|
||
8 years ago
|
return
|
||
|
Response.AsJson(new JsonResponseModel
|
||
|
{
|
||
|
Result = false,
|
||
8 years ago
|
Message = string.Format(Resources.UI.Search_CouldNotCheckPlex, fullShowName,GetMediaServerName())
|
||
8 years ago
|
});
|
||
8 years ago
|
}
|
||
|
|
||
8 years ago
|
if (showInfo.externals?.thetvdb == null)
|
||
|
{
|
||
8 years ago
|
await FaultQueue.QueueItemAsync(model, showInfo.id.ToString(), RequestType.TvShow, FaultType.MissingInformation, "We do not have a TheTVDBId from TVMaze");
|
||
8 years ago
|
await NotificationService.Publish(new NotificationModel
|
||
|
{
|
||
|
DateTime = DateTime.Now,
|
||
|
User = Username,
|
||
|
RequestType = RequestType.TvShow,
|
||
|
Title = model.Title,
|
||
|
NotificationType = NotificationType.ItemAddedToFaultQueue
|
||
|
});
|
||
|
return Response.AsJson(new JsonResponseModel
|
||
|
{
|
||
|
Result = true,
|
||
|
Message = $"{fullShowName} {Resources.UI.Search_SuccessfullyAdded}"
|
||
|
});
|
||
|
}
|
||
|
|
||
|
model.ProviderId = showInfo.externals?.thetvdb ?? 0;
|
||
|
|
||
8 years ago
|
try
|
||
9 years ago
|
{
|
||
8 years ago
|
if (ShouldAutoApprove(RequestType.TvShow))
|
||
9 years ago
|
{
|
||
8 years ago
|
return await SendTv(model, sonarrSettings, existingRequest, fullShowName, settings);
|
||
8 years ago
|
}
|
||
|
return await AddRequest(model, settings, $"{fullShowName} {Resources.UI.Search_SuccessfullyAdded}");
|
||
|
}
|
||
|
catch (Exception e)
|
||
|
{
|
||
8 years ago
|
await FaultQueue.QueueItemAsync(model, showInfo.id.ToString(), RequestType.TvShow, FaultType.RequestFault, e.Message);
|
||
8 years ago
|
await NotificationService.Publish(new NotificationModel
|
||
|
{
|
||
|
DateTime = DateTime.Now,
|
||
|
User = Username,
|
||
|
RequestType = RequestType.TvShow,
|
||
|
Title = model.Title,
|
||
|
NotificationType = NotificationType.ItemAddedToFaultQueue
|
||
|
});
|
||
|
Log.Error(e);
|
||
|
return
|
||
|
Response.AsJson(new JsonResponseModel
|
||
|
{
|
||
|
Result = true,
|
||
|
Message = $"{fullShowName} {Resources.UI.Search_SuccessfullyAdded}"
|
||
|
});
|
||
9 years ago
|
}
|
||
|
}
|
||
|
|
||
8 years ago
|
private async Task<Response> AddUserToRequest(RequestedModel existingRequest, PlexRequestSettings settings,
|
||
|
string fullShowName, bool episodeReq = false)
|
||
8 years ago
|
{
|
||
|
// check if the current user is already marked as a requester for this show, if not, add them
|
||
8 years ago
|
if (!existingRequest.UserHasRequested(Username))
|
||
8 years ago
|
{
|
||
|
existingRequest.RequestedUsers.Add(Username);
|
||
|
}
|
||
8 years ago
|
if (Security.HasPermissions(User, Permissions.UsersCanViewOnlyOwnRequests) || episodeReq)
|
||
8 years ago
|
{
|
||
|
return
|
||
|
await
|
||
|
UpdateRequest(existingRequest, settings,
|
||
|
$"{fullShowName} {Resources.UI.Search_SuccessfullyAdded}");
|
||
|
}
|
||
8 years ago
|
|
||
8 years ago
|
return
|
||
|
await UpdateRequest(existingRequest, settings, $"{fullShowName} {Resources.UI.Search_AlreadyRequested}");
|
||
8 years ago
|
}
|
||
|
|
||
9 years ago
|
private bool ShouldSendNotification(RequestType type, PlexRequestSettings prSettings)
|
||
9 years ago
|
{
|
||
8 years ago
|
var sendNotification = !ShouldAutoApprove(type) || !prSettings.IgnoreNotifyForAutoApprovedRequests;
|
||
8 years ago
|
|
||
8 years ago
|
if (IsAdmin)
|
||
9 years ago
|
{
|
||
8 years ago
|
sendNotification = false; // Don't bother sending a notification if the user is an admin
|
||
|
|
||
9 years ago
|
}
|
||
|
return sendNotification;
|
||
|
}
|
||
|
|
||
|
|
||
|
private async Task<Response> RequestAlbum(string releaseId)
|
||
|
{
|
||
8 years ago
|
if (Security.HasPermissions(User, Permissions.ReadOnlyUser) || !Security.HasPermissions(User, Permissions.RequestMusic))
|
||
|
{
|
||
|
return
|
||
|
Response.AsJson(new JsonResponseModel
|
||
|
{
|
||
|
Result = false,
|
||
|
Message = "Sorry, you do not have the correct permissions to request music!"
|
||
|
});
|
||
|
}
|
||
|
|
||
9 years ago
|
var settings = await PrService.GetSettingsAsync();
|
||
9 years ago
|
if (!await CheckRequestLimit(settings, RequestType.Album))
|
||
|
{
|
||
8 years ago
|
return
|
||
|
Response.AsJson(new JsonResponseModel
|
||
|
{
|
||
|
Result = false,
|
||
|
Message = Resources.UI.Search_WeeklyRequestLimitAlbums
|
||
|
});
|
||
9 years ago
|
}
|
||
8 years ago
|
Analytics.TrackEventAsync(Category.Search, Action.Request, "Album", Username,
|
||
|
CookieHelper.GetAnalyticClientId(Cookies));
|
||
9 years ago
|
var existingRequest = await RequestService.CheckRequestAsync(releaseId);
|
||
8 years ago
|
|
||
9 years ago
|
if (existingRequest != null)
|
||
|
{
|
||
|
if (!existingRequest.UserHasRequested(Username))
|
||
|
{
|
||
|
existingRequest.RequestedUsers.Add(Username);
|
||
|
await RequestService.UpdateRequestAsync(existingRequest);
|
||
|
}
|
||
8 years ago
|
return
|
||
|
Response.AsJson(new JsonResponseModel
|
||
|
{
|
||
|
Result = true,
|
||
|
Message =
|
||
8 years ago
|
Security.HasPermissions(User, Permissions.UsersCanViewOnlyOwnRequests)
|
||
8 years ago
|
? $"{existingRequest.Title} {Resources.UI.Search_SuccessfullyAdded}"
|
||
|
: $"{existingRequest.Title} {Resources.UI.Search_AlreadyRequested}"
|
||
|
});
|
||
9 years ago
|
}
|
||
8 years ago
|
|
||
9 years ago
|
var albumInfo = MusicBrainzApi.GetAlbum(releaseId);
|
||
|
DateTime release;
|
||
|
DateTimeHelper.CustomParse(albumInfo.ReleaseEvents?.FirstOrDefault()?.date, out release);
|
||
|
|
||
|
var artist = albumInfo.ArtistCredits?.FirstOrDefault()?.artist;
|
||
|
if (artist == null)
|
||
|
{
|
||
8 years ago
|
return
|
||
|
Response.AsJson(new JsonResponseModel
|
||
|
{
|
||
|
Result = false,
|
||
|
Message = Resources.UI.Search_MusicBrainzError
|
||
|
});
|
||
9 years ago
|
}
|
||
|
|
||
8 years ago
|
|
||
|
var content = PlexContentRepository.GetAll();
|
||
8 years ago
|
var albums = PlexChecker.GetPlexAlbums(content);
|
||
|
var alreadyInPlex = PlexChecker.IsAlbumAvailable(albums.ToArray(), albumInfo.title, release.ToString("yyyy"),
|
||
8 years ago
|
artist.name);
|
||
9 years ago
|
|
||
|
if (alreadyInPlex)
|
||
|
{
|
||
|
return Response.AsJson(new JsonResponseModel
|
||
|
{
|
||
|
Result = false,
|
||
9 years ago
|
Message = $"{albumInfo.title} {Resources.UI.Search_AlreadyInPlex}"
|
||
9 years ago
|
});
|
||
|
}
|
||
|
|
||
|
var img = GetMusicBrainzCoverArt(albumInfo.id);
|
||
|
|
||
|
var model = new RequestedModel
|
||
|
{
|
||
|
Title = albumInfo.title,
|
||
|
MusicBrainzId = albumInfo.id,
|
||
8 years ago
|
ReleaseId = releaseId,
|
||
9 years ago
|
Overview = albumInfo.disambiguation,
|
||
|
PosterPath = img,
|
||
|
Type = RequestType.Album,
|
||
|
ProviderId = 0,
|
||
|
RequestedUsers = new List<string> { Username },
|
||
|
Status = albumInfo.status,
|
||
|
Issues = IssueState.None,
|
||
|
RequestedDate = DateTime.UtcNow,
|
||
|
ReleaseDate = release,
|
||
|
ArtistName = artist.name,
|
||
|
ArtistId = artist.id
|
||
|
};
|
||
|
|
||
8 years ago
|
try
|
||
9 years ago
|
{
|
||
8 years ago
|
if (ShouldAutoApprove(RequestType.Album))
|
||
9 years ago
|
{
|
||
8 years ago
|
model.Approved = true;
|
||
|
var hpSettings = HeadphonesService.GetSettings();
|
||
|
|
||
|
if (!hpSettings.Enabled)
|
||
|
{
|
||
|
await RequestService.AddRequestAsync(model);
|
||
|
return
|
||
|
Response.AsJson(new JsonResponseModel
|
||
|
{
|
||
|
Result = true,
|
||
|
Message = $"{model.Title} {Resources.UI.Search_SuccessfullyAdded}"
|
||
|
});
|
||
|
}
|
||
|
|
||
|
var sender = new HeadphonesSender(HeadphonesApi, hpSettings, RequestService);
|
||
|
await sender.AddAlbum(model);
|
||
|
return await AddRequest(model, settings, $"{model.Title} {Resources.UI.Search_SuccessfullyAdded}");
|
||
9 years ago
|
}
|
||
|
|
||
9 years ago
|
return await AddRequest(model, settings, $"{model.Title} {Resources.UI.Search_SuccessfullyAdded}");
|
||
9 years ago
|
}
|
||
8 years ago
|
catch (Exception e)
|
||
|
{
|
||
|
Log.Error(e);
|
||
8 years ago
|
await FaultQueue.QueueItemAsync(model, albumInfo.id, RequestType.Album, FaultType.RequestFault, e.Message);
|
||
9 years ago
|
|
||
8 years ago
|
await NotificationService.Publish(new NotificationModel
|
||
|
{
|
||
|
DateTime = DateTime.Now,
|
||
|
User = Username,
|
||
|
RequestType = RequestType.Album,
|
||
|
Title = model.Title,
|
||
|
NotificationType = NotificationType.ItemAddedToFaultQueue
|
||
|
});
|
||
|
throw;
|
||
|
}
|
||
9 years ago
|
}
|
||
|
|
||
|
private string GetMusicBrainzCoverArt(string id)
|
||
|
{
|
||
|
var coverArt = MusicBrainzApi.GetCoverArt(id);
|
||
|
var firstImage = coverArt?.images?.FirstOrDefault();
|
||
|
var img = string.Empty;
|
||
|
|
||
|
if (firstImage != null)
|
||
|
{
|
||
|
img = firstImage.thumbnails?.small ?? firstImage.image;
|
||
|
}
|
||
|
|
||
|
return img;
|
||
|
}
|
||
8 years ago
|
|
||
9 years ago
|
private Response GetSeasons()
|
||
|
{
|
||
|
var seriesId = (int)Request.Query.tvId;
|
||
8 years ago
|
var show = TvApi.ShowLookupByTheTvDbId(seriesId);
|
||
|
var seasons = TvApi.GetSeasons(show.id);
|
||
9 years ago
|
var model = seasons.Select(x => x.number);
|
||
|
return Response.AsJson(model);
|
||
|
}
|
||
9 years ago
|
|
||
8 years ago
|
private async Task<Response> GetEpisodes()
|
||
8 years ago
|
{
|
||
8 years ago
|
var seriesId = (int)Request.Query.tvId;
|
||
8 years ago
|
var model = await GetEpisodes(seriesId);
|
||
|
|
||
|
return Response.AsJson(model);
|
||
|
}
|
||
|
|
||
|
private async Task<List<EpisodeListViewModel>> GetEpisodes(int providerId)
|
||
|
{
|
||
8 years ago
|
var s = await SonarrService.GetSettingsAsync();
|
||
8 years ago
|
var sonarrEnabled = s.Enabled;
|
||
8 years ago
|
var allResults = await RequestService.GetAllAsync();
|
||
8 years ago
|
|
||
8 years ago
|
var seriesTask = Task.Run(
|
||
|
() =>
|
||
|
{
|
||
8 years ago
|
if (sonarrEnabled)
|
||
8 years ago
|
{
|
||
|
var allSeries = SonarrApi.GetSeries(s.ApiKey, s.FullUri);
|
||
8 years ago
|
var selectedSeries = allSeries.FirstOrDefault(x => x.tvdbId == providerId) ?? new Series();
|
||
8 years ago
|
return selectedSeries;
|
||
|
}
|
||
|
return new Series();
|
||
8 years ago
|
});
|
||
|
|
||
8 years ago
|
var model = new List<EpisodeListViewModel>();
|
||
8 years ago
|
|
||
8 years ago
|
var requests = allResults as RequestedModel[] ?? allResults.ToArray();
|
||
8 years ago
|
|
||
8 years ago
|
var existingRequest = requests.FirstOrDefault(x => x.Type == RequestType.TvShow && x.TvDbId == providerId.ToString());
|
||
|
var show = await Task.Run(() => TvApi.ShowLookupByTheTvDbId(providerId));
|
||
8 years ago
|
var tvMazeEpisodesTask = await Task.Run(() => TvApi.EpisodeLookup(show.id));
|
||
|
var tvMazeEpisodes = tvMazeEpisodesTask.ToList();
|
||
8 years ago
|
|
||
8 years ago
|
var sonarrEpisodes = new List<SonarrEpisodes>();
|
||
|
if (sonarrEnabled)
|
||
|
{
|
||
|
var sonarrSeries = await seriesTask;
|
||
|
var sonarrEp = SonarrApi.GetEpisodes(sonarrSeries.id.ToString(), s.ApiKey, s.FullUri);
|
||
|
sonarrEpisodes = sonarrEp?.ToList() ?? new List<SonarrEpisodes>();
|
||
|
}
|
||
8 years ago
|
|
||
8 years ago
|
var plexSettings = await PlexService.GetSettingsAsync();
|
||
|
if (plexSettings.Enable)
|
||
8 years ago
|
{
|
||
8 years ago
|
var plexCacheTask = await PlexChecker.GetEpisodes(providerId);
|
||
|
var plexCache = plexCacheTask.ToList();
|
||
|
foreach (var ep in tvMazeEpisodes)
|
||
|
{
|
||
|
var requested = existingRequest?.Episodes
|
||
|
.Any(episodesModel =>
|
||
|
ep.number == episodesModel.EpisodeNumber &&
|
||
|
ep.season == episodesModel.SeasonNumber) ?? false;
|
||
8 years ago
|
|
||
8 years ago
|
var alreadyInPlex = plexCache.Any(x => x.EpisodeNumber == ep.number && x.SeasonNumber == ep.season);
|
||
|
var inSonarr =
|
||
|
sonarrEpisodes.Any(x => x.seasonNumber == ep.season && x.episodeNumber == ep.number && x.hasFile);
|
||
8 years ago
|
|
||
8 years ago
|
model.Add(new EpisodeListViewModel
|
||
|
{
|
||
|
Id = show.id,
|
||
|
SeasonNumber = ep.season,
|
||
|
EpisodeNumber = ep.number,
|
||
|
Requested = requested || alreadyInPlex || inSonarr,
|
||
|
Name = ep.name,
|
||
|
EpisodeId = ep.id
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
var embySettings = await EmbySettings.GetSettingsAsync();
|
||
|
if (embySettings.Enable)
|
||
|
{
|
||
|
var embyCacheTask = await EmbyChecker.GetEpisodes(providerId);
|
||
|
var cache = embyCacheTask.ToList();
|
||
|
foreach (var ep in tvMazeEpisodes)
|
||
8 years ago
|
{
|
||
8 years ago
|
var requested = existingRequest?.Episodes
|
||
|
.Any(episodesModel =>
|
||
|
ep.number == episodesModel.EpisodeNumber &&
|
||
|
ep.season == episodesModel.SeasonNumber) ?? false;
|
||
|
|
||
|
var alreadyInEmby = cache.Any(x => x.EpisodeNumber == ep.number && x.SeasonNumber == ep.season);
|
||
|
var inSonarr =
|
||
|
sonarrEpisodes.Any(x => x.seasonNumber == ep.season && x.episodeNumber == ep.number && x.hasFile);
|
||
|
|
||
|
model.Add(new EpisodeListViewModel
|
||
|
{
|
||
|
Id = show.id,
|
||
|
SeasonNumber = ep.season,
|
||
|
EpisodeNumber = ep.number,
|
||
|
Requested = requested || alreadyInEmby || inSonarr,
|
||
|
Name = ep.name,
|
||
|
EpisodeId = ep.id
|
||
|
});
|
||
|
}
|
||
8 years ago
|
}
|
||
|
return model;
|
||
8 years ago
|
|
||
8 years ago
|
}
|
||
|
|
||
8 years ago
|
public async Task<bool> CheckRequestLimit(PlexRequestSettings s, RequestType type)
|
||
9 years ago
|
{
|
||
9 years ago
|
if (IsAdmin)
|
||
|
return true;
|
||
|
|
||
8 years ago
|
if (Security.HasPermissions(User, Permissions.BypassRequestLimit))
|
||
9 years ago
|
return true;
|
||
|
|
||
9 years ago
|
var requestLimit = GetRequestLimitForType(type, s);
|
||
|
if (requestLimit == 0)
|
||
|
{
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
var limit = await RequestLimitRepo.GetAllAsync();
|
||
|
var usersLimit = limit.FirstOrDefault(x => x.Username == Username && x.RequestType == type);
|
||
|
if (usersLimit == null)
|
||
|
{
|
||
|
// Have not set a requestLimit yet
|
||
|
return true;
|
||
|
}
|
||
|
|
||
8 years ago
|
return requestLimit > usersLimit.RequestCount;
|
||
9 years ago
|
}
|
||
|
|
||
|
private int GetRequestLimitForType(RequestType type, PlexRequestSettings s)
|
||
|
{
|
||
|
int requestLimit;
|
||
|
switch (type)
|
||
|
{
|
||
|
case RequestType.Movie:
|
||
|
requestLimit = s.MovieWeeklyRequestLimit;
|
||
|
break;
|
||
|
case RequestType.TvShow:
|
||
|
requestLimit = s.TvWeeklyRequestLimit;
|
||
|
break;
|
||
|
case RequestType.Album:
|
||
|
requestLimit = s.AlbumWeeklyRequestLimit;
|
||
|
break;
|
||
|
default:
|
||
|
throw new ArgumentOutOfRangeException(nameof(type), type, null);
|
||
|
}
|
||
|
return requestLimit;
|
||
|
}
|
||
|
|
||
|
private async Task<Response> AddRequest(RequestedModel model, PlexRequestSettings settings, string message)
|
||
|
{
|
||
|
await RequestService.AddRequestAsync(model);
|
||
|
|
||
9 years ago
|
if (ShouldSendNotification(model.Type, settings))
|
||
9 years ago
|
{
|
||
|
var notificationModel = new NotificationModel
|
||
|
{
|
||
|
Title = model.Title,
|
||
|
User = Username,
|
||
|
DateTime = DateTime.Now,
|
||
|
NotificationType = NotificationType.NewRequest,
|
||
8 years ago
|
RequestType = model.Type,
|
||
|
ImgSrc = model.Type == RequestType.Movie ? $"https://image.tmdb.org/t/p/w300/{model.PosterPath}" : model.PosterPath
|
||
9 years ago
|
};
|
||
|
await NotificationService.Publish(notificationModel);
|
||
|
}
|
||
|
|
||
|
var limit = await RequestLimitRepo.GetAllAsync();
|
||
|
var usersLimit = limit.FirstOrDefault(x => x.Username == Username && x.RequestType == model.Type);
|
||
|
if (usersLimit == null)
|
||
|
{
|
||
|
await RequestLimitRepo.InsertAsync(new RequestLimit
|
||
|
{
|
||
|
Username = Username,
|
||
|
RequestType = model.Type,
|
||
|
FirstRequestDate = DateTime.UtcNow,
|
||
|
RequestCount = 1
|
||
|
});
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
usersLimit.RequestCount++;
|
||
|
await RequestLimitRepo.UpdateAsync(usersLimit);
|
||
|
}
|
||
|
|
||
|
return Response.AsJson(new JsonResponseModel { Result = true, Message = message });
|
||
|
}
|
||
8 years ago
|
|
||
8 years ago
|
private async Task<Response> UpdateRequest(RequestedModel model, PlexRequestSettings settings, string message)
|
||
|
{
|
||
|
await RequestService.UpdateRequestAsync(model);
|
||
|
|
||
|
if (ShouldSendNotification(model.Type, settings))
|
||
|
{
|
||
|
var notificationModel = new NotificationModel
|
||
|
{
|
||
|
Title = model.Title,
|
||
|
User = Username,
|
||
|
DateTime = DateTime.Now,
|
||
|
NotificationType = NotificationType.NewRequest,
|
||
8 years ago
|
RequestType = model.Type,
|
||
|
ImgSrc = model.Type == RequestType.Movie ? $"https://image.tmdb.org/t/p/w300/{model.PosterPath}" : model.PosterPath
|
||
8 years ago
|
};
|
||
|
await NotificationService.Publish(notificationModel);
|
||
|
}
|
||
|
|
||
|
var limit = await RequestLimitRepo.GetAllAsync();
|
||
|
var usersLimit = limit.FirstOrDefault(x => x.Username == Username && x.RequestType == model.Type);
|
||
|
if (usersLimit == null)
|
||
|
{
|
||
|
await RequestLimitRepo.InsertAsync(new RequestLimit
|
||
|
{
|
||
|
Username = Username,
|
||
|
RequestType = model.Type,
|
||
|
FirstRequestDate = DateTime.UtcNow,
|
||
|
RequestCount = 1
|
||
|
});
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
usersLimit.RequestCount++;
|
||
|
await RequestLimitRepo.UpdateAsync(usersLimit);
|
||
|
}
|
||
|
|
||
|
return Response.AsJson(new JsonResponseModel { Result = true, Message = message });
|
||
|
}
|
||
|
|
||
8 years ago
|
private IEnumerable<EpisodesModel> GetListDifferences(IEnumerable<EpisodesModel> existing, IEnumerable<Models.EpisodesModel> request)
|
||
8 years ago
|
{
|
||
8 years ago
|
var newRequest = request
|
||
|
.Select(r =>
|
||
8 years ago
|
new EpisodesModel
|
||
8 years ago
|
{
|
||
|
SeasonNumber = r.SeasonNumber,
|
||
|
EpisodeNumber = r.EpisodeNumber
|
||
|
}).ToList();
|
||
8 years ago
|
|
||
8 years ago
|
return newRequest.Except(existing);
|
||
8 years ago
|
}
|
||
8 years ago
|
|
||
|
private async Task<IEnumerable<EpisodesModel>> GetEpisodeRequestDifference(int showId, RequestedModel model)
|
||
|
{
|
||
|
var episodes = await GetEpisodes(showId);
|
||
|
var availableEpisodes = episodes.Where(x => x.Requested).ToList();
|
||
|
var available = availableEpisodes.Select(a => new EpisodesModel { EpisodeNumber = a.EpisodeNumber, SeasonNumber = a.SeasonNumber }).ToList();
|
||
|
|
||
|
var diff = model.Episodes.Except(available);
|
||
|
return diff;
|
||
|
}
|
||
8 years ago
|
|
||
8 years ago
|
public bool ShouldAutoApprove(RequestType requestType)
|
||
8 years ago
|
{
|
||
|
var admin = Security.HasPermissions(Context.CurrentUser, Permissions.Administrator);
|
||
8 years ago
|
// if the user is an admin, they go ahead and allow auto-approval
|
||
|
if (admin) return true;
|
||
8 years ago
|
|
||
|
// check by request type if the category requires approval or not
|
||
|
switch (requestType)
|
||
|
{
|
||
|
case RequestType.Movie:
|
||
8 years ago
|
return Security.HasPermissions(User, Permissions.AutoApproveMovie);
|
||
8 years ago
|
case RequestType.TvShow:
|
||
8 years ago
|
return Security.HasPermissions(User, Permissions.AutoApproveTv);
|
||
8 years ago
|
case RequestType.Album:
|
||
8 years ago
|
return Security.HasPermissions(User, Permissions.AutoApproveAlbum);
|
||
8 years ago
|
default:
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
8 years ago
|
|
||
|
private enum ShowSearchType
|
||
|
{
|
||
|
Popular,
|
||
|
Anticipated,
|
||
|
MostWatched,
|
||
|
Trending
|
||
|
}
|
||
8 years ago
|
|
||
|
private async Task<Response> SendTv(RequestedModel model, Task<SonarrSettings> sonarrSettings, RequestedModel existingRequest, string fullShowName, PlexRequestSettings settings)
|
||
|
{
|
||
|
model.Approved = true;
|
||
|
var s = await sonarrSettings;
|
||
8 years ago
|
var sender = new TvSenderV2(SonarrApi, SickrageApi, Cache);
|
||
|
//var sender = new TvSenderOld(SonarrApi, SickrageApi, Cache);
|
||
8 years ago
|
if (s.Enabled)
|
||
|
{
|
||
|
var result = await sender.SendToSonarr(s, model);
|
||
|
if (!string.IsNullOrEmpty(result?.title))
|
||
|
{
|
||
|
if (existingRequest != null)
|
||
|
{
|
||
|
return await UpdateRequest(model, settings,
|
||
|
$"{fullShowName} {Resources.UI.Search_SuccessfullyAdded}");
|
||
|
}
|
||
|
return
|
||
|
await
|
||
|
AddRequest(model, settings,
|
||
|
$"{fullShowName} {Resources.UI.Search_SuccessfullyAdded}");
|
||
|
}
|
||
|
Log.Debug("Error with sending to sonarr.");
|
||
|
return
|
||
|
Response.AsJson(ValidationHelper.SendSonarrError(result?.ErrorMessages ?? new List<string>()));
|
||
|
}
|
||
|
|
||
|
var srSettings = SickRageService.GetSettings();
|
||
|
if (srSettings.Enabled)
|
||
|
{
|
||
|
var result = sender.SendToSickRage(srSettings, model);
|
||
|
if (result?.result == "success")
|
||
|
{
|
||
|
return await AddRequest(model, settings,
|
||
|
$"{fullShowName} {Resources.UI.Search_SuccessfullyAdded}");
|
||
|
}
|
||
|
return
|
||
|
Response.AsJson(new JsonResponseModel
|
||
|
{
|
||
|
Result = false,
|
||
|
Message = result?.message ?? Resources.UI.Search_SickrageError
|
||
|
});
|
||
|
}
|
||
|
|
||
|
if (!srSettings.Enabled && !s.Enabled)
|
||
|
{
|
||
|
return await AddRequest(model, settings, $"{fullShowName} {Resources.UI.Search_SuccessfullyAdded}");
|
||
|
}
|
||
|
|
||
|
return
|
||
|
Response.AsJson(new JsonResponseModel { Result = false, Message = Resources.UI.Search_TvNotSetUp });
|
||
|
}
|
||
8 years ago
|
|
||
|
private string GetMediaServerName()
|
||
|
{
|
||
|
var e = EmbySettings.GetSettings();
|
||
|
return e.Enable ? "Emby" : "Plex";
|
||
|
}
|
||
9 years ago
|
}
|
||
|
}
|
||
8 years ago
|
|