private MovieSenderResult SendToCp(RequestedModel model, CouchPotatoSettings settings, string qualityId) { var result = CpApi.AddMovie(model.ImdbId, settings.ApiKey, model.Title, settings.FullUri, qualityId); return(new MovieSenderResult { Result = result, MovieSendingEnabled = true }); }
public bool UpdateRequest(RequestedModel model) { var entity = new RequestBlobs { Type = model.Type, Content = ByteConverterHelper.ReturnBytes(model), ProviderId = model.ProviderId, Id = model.Id }; return(Repo.Update(entity)); }
private bool SendMovie(CouchPotatoSettings settings, RequestedModel r, ICouchPotatoApi cp) { Log.Info("Adding movie to CP : {0}", r.Title); var result = cp.AddMovie(r.ImdbId, settings.ApiKey, r.Title, settings.FullUri, settings.ProfileId); Log.Trace("Adding movie to CP result {0}", result); return(result); }
public async Task <bool> UpdateRequestAsync(RequestedModel model) { var entity = new RequestBlobs { Type = model.Type, Content = ByteConverterHelper.ReturnBytes(model), ProviderId = model.ProviderId, Id = model.Id }; return(await Repo.UpdateAsync(entity).ConfigureAwait(false)); }
private async Task <Response> RequestMovieAndUpdateStatus(RequestedModel request, string qualityId) { var cpSettings = await CpService.GetSettingsAsync(); Log.Info("Adding movie to CouchPotato : {0}", request.Title); if (!cpSettings.Enabled) { // Approve it request.Approved = true; Log.Warn("We approved movie: {0} but could not add it to CouchPotato because it has not been setup", request.Title); // Update the record var inserted = await Service.UpdateRequestAsync(request); return(Response.AsJson(inserted ? new JsonResponseModel { Result = true, Message = "This has been approved, but It has not been sent to CouchPotato because it has not been configured." } : new JsonResponseModel { Result = false, Message = "We could not approve this request. Please try again or check the logs." })); } var result = CpApi.AddMovie(request.ImdbId, cpSettings.ApiKey, request.Title, cpSettings.FullUri, string.IsNullOrEmpty(qualityId) ? cpSettings.ProfileId : qualityId); Log.Trace("Adding movie to CP result {0}", result); if (result) { // Approve it request.Approved = true; // Update the record var inserted = await Service.UpdateRequestAsync(request); return(Response.AsJson(inserted ? new JsonResponseModel { Result = true } : new JsonResponseModel { Result = false, Message = "We could not approve this request. Please try again or check the logs." })); } return (Response.AsJson( new { Result = false, Message = "Something went wrong adding the movie to CouchPotato! Please check your settings." })); }
private async Task <Response> RequestMovieAndUpdateStatus(RequestedModel request, string qualityId) { var result = await MovieSender.Send(request, qualityId); if (!result.MovieSendingEnabled) { // Approve it request.Approved = true; Log.Warn("We approved movie: {0} but could not add it to CouchPotato/Watcher because it has not been setup", request.Title); // Update the record var inserted = await Service.UpdateRequestAsync(request); return(Response.AsJson(inserted ? new JsonResponseModel { Result = true, Message = "This has been approved, but It has not been sent to CouchPotato/Watcher because it has not been configured." } : new JsonResponseModel { Result = false, Message = "We could not approve this request. Please try again or check the logs." })); } if (result.Result) { // Approve it request.Approved = true; // Update the record var inserted = await Service.UpdateRequestAsync(request); return(Response.AsJson(inserted ? new JsonResponseModel { Result = true } : new JsonResponseModel { Result = false, Message = "We could not approve this request. Please try again or check the logs." })); } return (Response.AsJson( new { Result = false, Message = "Something went wrong adding the movie! Please check your settings." })); }
public async Task <int> AddRequestAsync(RequestedModel model) { var entity = new RequestBlobs { Type = model.Type, Content = ByteConverterHelper.ReturnBytes(model), ProviderId = model.ProviderId }; var id = await Repo.InsertAsync(entity).ConfigureAwait(false); model.Id = id; entity = new RequestBlobs { Type = model.Type, Content = ByteConverterHelper.ReturnBytes(model), ProviderId = model.ProviderId, Id = id, MusicId = model.MusicBrainzId }; var result = await Repo.UpdateAsync(entity).ConfigureAwait(false); return(result ? id : -1); }
public long AddRequest(RequestedModel model) { var entity = new RequestBlobs { Type = model.Type, Content = ByteConverterHelper.ReturnBytes(model), ProviderId = model.ProviderId }; var id = Repo.Insert(entity); model.Id = (int)id; entity = new RequestBlobs { Type = model.Type, Content = ByteConverterHelper.ReturnBytes(model), ProviderId = model.ProviderId, Id = (int)id, MusicId = model.MusicBrainzId }; var result = Repo.Update(entity); return(result ? id : -1); }
private async Task <bool> AddArtist(RequestedModel request) { var index = await Api.GetIndex(Settings.ApiKey, Settings.FullUri); var artistExists = index.Any(x => x.ArtistID == request.ArtistId); bool artistAdd = false; if (!artistExists) { artistAdd = await Api.AddArtist(Settings.ApiKey, Settings.FullUri, request.ArtistId); Log.Info("Artist add result for {1}: {0}", artistAdd, request.ArtistName); } return(artistExists || artistAdd); }
public SickRageTvAdd SendToSickRage(SickRageSettings sickRageSettings, RequestedModel model, string qualityId) { Log.Info("Sending to SickRage {0}", model.Title); if (sickRageSettings.Qualities.All(x => x.Key != qualityId)) { qualityId = sickRageSettings.QualityProfile; } var apiResult = SickrageApi.AddSeries(model.ProviderId, model.SeasonCount, model.SeasonList, qualityId, sickRageSettings.ApiKey, sickRageSettings.FullUri); var result = apiResult.Result; return(result); }
public long AddRequest(RequestedModel model) { var entity = new RequestBlobs { Type = model.Type, Content = ByteConverterHelper.ReturnBytes(model), ProviderId = model.ProviderId }; var id = Repo.Insert(entity); // TODO Keep an eye on this, since we are now doing 2 DB update for 1 single request, inserting and then updating model.Id = (int)id; entity = new RequestBlobs { Type = model.Type, Content = ByteConverterHelper.ReturnBytes(model), ProviderId = model.ProviderId, Id = (int)id, MusicId = model.MusicBrainzId }; var result = Repo.Update(entity); return(result ? id : -1); }
public SonarrAddSeries SendToSonarr(SonarrSettings sonarrSettings, RequestedModel model, string qualityId) { int qualityProfile; if (!string.IsNullOrEmpty(qualityId) || !int.TryParse(qualityId, out qualityProfile)) // try to parse the passed in quality, otherwise use the settings default quality { int.TryParse(sonarrSettings.QualityProfile, out qualityProfile); } var result = SonarrApi.AddSeries(model.ProviderId, model.Title, qualityProfile, sonarrSettings.SeasonFolders, sonarrSettings.RootPath, model.SeasonCount, model.SeasonList, sonarrSettings.ApiKey, sonarrSettings.FullUri); Log.Trace("Sonarr Add Result: "); Log.Trace(result.DumpJson()); return(result); }
internal async Task RequestAllEpisodesInASeasonWithExistingSeries(RequestedModel model, Series selectedSeries, SonarrSettings sonarrSettings) { // Show Exists // Look up all episodes var ep = SonarrApi.GetEpisodes(selectedSeries.id.ToString(), sonarrSettings.ApiKey, sonarrSettings.FullUri); var episodes = ep?.ToList() ?? new List <SonarrEpisodes>(); var internalEpisodeIds = new List <int>(); var tasks = new List <Task>(); var requestedEpisodes = model.Episodes; foreach (var r in episodes) { if (r.hasFile) // If it already has the file, there is no point in updating it { continue; } var epComparison = new EpisodesModel { EpisodeNumber = r.episodeNumber, SeasonNumber = r.seasonNumber }; // Make sure we are looking for the right episode and season if (!requestedEpisodes.Contains(epComparison)) { continue; } // Lookup the individual episode details var episodeInfo = SonarrApi.GetEpisode(r.id.ToString(), sonarrSettings.ApiKey, sonarrSettings.FullUri); // If the season is not in thr episodeInfo.monitored = true; // Set the episode to monitored tasks.Add(Task.Run(() => SonarrApi.UpdateEpisode(episodeInfo, sonarrSettings.ApiKey, sonarrSettings.FullUri))); internalEpisodeIds.Add(r.id); } await Task.WhenAll(tasks.ToArray()); SonarrApi.SearchForEpisodes(internalEpisodeIds.ToArray(), sonarrSettings.ApiKey, sonarrSettings.FullUri); }
public async Task <MovieSenderResult> Send(RequestedModel model, string qualityId = "") { var cpSettings = await CouchPotatoSettings.GetSettingsAsync(); var watcherSettings = await WatcherSettings.GetSettingsAsync(); if (cpSettings.Enabled) { return(SendToCp(model, cpSettings, string.IsNullOrEmpty(qualityId) ? cpSettings.ProfileId : qualityId)); } if (watcherSettings.Enabled) { return(SendToWatcher(model, watcherSettings)); } return(new MovieSenderResult { Result = false, MovieSendingEnabled = false }); }
public async Task NotifyUsers(RequestedModel model, string apiKey, NotificationType type) { try { var plexUser = PlexApi.GetUsers(apiKey); var userAccount = PlexApi.GetAccount(apiKey); var adminUsername = userAccount.Username ?? string.Empty; var users = UserHelper.GetUsersWithFeature(Features.RequestAddedNotification).ToList(); Log.Debug("Notifying Users Count {0}", users.Count); var selectedUsers = users.Select(x => x.Username).Intersect(model.RequestedUsers, StringComparer.CurrentCultureIgnoreCase); foreach (var user in selectedUsers) { Log.Info("Notifying user {0}", user); if (user.Equals(adminUsername, StringComparison.CurrentCultureIgnoreCase)) { Log.Info("This user is the Plex server owner"); await PublishUserNotification(userAccount.Username, userAccount.Email, model.Title, model.PosterPath, type); return; } var email = plexUser.User.FirstOrDefault(x => x.Username.Equals(user, StringComparison.CurrentCultureIgnoreCase)); if (email == null) { Log.Info("There is no email address for this Plex user, cannot send notification"); // We do not have a plex user that requested this! continue; } Log.Info("Sending notification to: {0} at: {1}, for title: {2}", email.Username, email.Email, model.Title); await PublishUserNotification(email.Username, email.Email, model.Title, model.PosterPath, type); } } catch (Exception e) { Log.Error(e); } }
private async Task <bool> SetAlbumStatus(RequestedModel request) { var counter = 0; var setStatus = await Api.QueueAlbum(Settings.ApiKey, Settings.FullUri, request.MusicBrainzId); while (!setStatus) { Thread.Sleep(WaitTime); counter++; Log.Trace("Setting Album status. Counter = {0}", counter); setStatus = await Api.QueueAlbum(Settings.ApiKey, Settings.FullUri, request.MusicBrainzId); if (counter > CounterMax) { Log.Trace("Album status is still not active. Counter = {0}. Returning false", counter); Log.Warn("We tried to se the status for the album but headphones didn't want to snatch it."); return(false); } } return(true); }
public SickRageTvAdd SendToSickRage(SickRageSettings sickRageSettings, RequestedModel model, string qualityId) { Log.Info("Sending to SickRage {0}", model.Title); if (!sickRageSettings.Qualities.Any(x => x.Key == qualityId)) { qualityId = sickRageSettings.QualityProfile; } Log.Trace("Calling `AddSeries` with the following settings:"); Log.Trace(sickRageSettings.DumpJson()); Log.Trace("And the following `model`:"); Log.Trace(model.DumpJson()); var apiResult = SickrageApi.AddSeries(model.ProviderId, model.SeasonCount, model.SeasonList, qualityId, sickRageSettings.ApiKey, sickRageSettings.FullUri); var result = apiResult.Result; Log.Trace("SickRage Add Result: "); Log.Trace(result.DumpJson()); return(result); }
public async Task HappyPathSendSeriesToSonarr() { var seriesResult = new SonarrAddSeries() { monitored = true }; SonarrMock.Setup(x => x.GetSeries(It.IsAny <string>(), It.IsAny <Uri>())).Returns(new List <Series>()); SonarrMock.Setup( x => x.AddSeries( It.IsAny <int>(), It.IsAny <string>(), It.IsAny <int>(), It.IsAny <bool>(), It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int[]>(), It.IsAny <string>(), It.IsAny <Uri>(), It.IsAny <bool>(), It.IsAny <bool>())).Returns(seriesResult); Sender = new TvSender(SonarrMock.Object, SickrageMock.Object); var request = new RequestedModel(); var result = await Sender.SendToSonarr(GetSonarrSettings(), request); Assert.That(result, Is.EqualTo(seriesResult)); SonarrMock.Verify(x => x.AddSeries(It.IsAny <int>(), It.IsAny <string>(), It.IsAny <int>(), It.IsAny <bool>(), It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int[]>(), It.IsAny <string>(), It.IsAny <Uri>(), true, It.IsAny <bool>()), Times.Once); }
private MovieSenderResult SendToWatcher(RequestedModel model, WatcherSettings settings) { var result = WatcherApi.AddMovie(model.ImdbId, settings.ApiKey, settings.FullUri); if (result.Error) { Log.Error(result.ErrorMessage); return(new MovieSenderResult { Result = false }); } if (result.response) { return(new MovieSenderResult { Result = true, MovieSendingEnabled = true }); } Log.Error(result.message); return(new MovieSenderResult { Result = false, MovieSendingEnabled = true }); }
private bool ProcessTvShow(RequestedModel tvModel, SonarrSettings sonarr, SickRageSettings sickrage) { try { var sender = new TvSenderOld(SonarrApi, SrApi); if (sonarr.Enabled) { var task = sender.SendToSonarr(sonarr, tvModel, sonarr.QualityProfile); var a = task.Result; if (string.IsNullOrEmpty(a?.title)) { // Couldn't send it return(false); } return(true); } if (sickrage.Enabled) { var result = sender.SendToSickRage(sickrage, tvModel); if (result?.result != "success") { // Couldn't send it return(false); } // Approve it tvModel.Approved = true; RequestService.UpdateRequest(tvModel); return(true); } return(false); } catch (Exception e) { Log.Error(e); return(false); // It fails so it will get added back into the queue } }
private bool ProcessMovies(RequestedModel model) { try { var result = MovieSender.Send(model).Result; if (result.Result) { // Approve it now model.Approved = true; RequestService.UpdateRequest(model); return(true); } ; return(false); } catch (Exception e) { Log.Error(e); return(false); // It fails so it will get added back into the queue } }
private MovieSenderResult SendToRadarr(RequestedModel model, RadarrSettings settings) { var qualityProfile = 0; int.TryParse(settings.QualityProfile, out qualityProfile); var result = RadarrApi.AddMovie(model.ProviderId, model.Title, model.ReleaseDate.Year, qualityProfile, settings.RootPath, settings.ApiKey, settings.FullUri, true); if (!string.IsNullOrEmpty(result.Error?.message)) { Log.Error(result.Error.message); return(new MovieSenderResult { Result = false, Error = true }); } if (!string.IsNullOrEmpty(result.title)) { return(new MovieSenderResult { Result = true, MovieSendingEnabled = true }); } return(new MovieSenderResult { Result = false, MovieSendingEnabled = true }); }
public SonarrAddSeries AddSeries(SonarrSettings sonarrSettings, RequestedModel model, string rootFolderPath, int qualityId) { //WORKS // Add the series var seriesToAdd = new SonarrAddSeries { seasonFolder = sonarrSettings.SeasonFolders, title = model.Title, qualityProfileId = qualityId, tvdbId = model.ProviderId, titleSlug = model.Title, seasons = new List <Season>(), rootFolderPath = rootFolderPath, monitored = true, // Montior the series images = new List <SonarrImage>(), addOptions = new AddOptions { ignoreEpisodesWithFiles = true, // We don't really care about these ignoreEpisodesWithoutFiles = false, // We want to get the whole season searchForMissingEpisodes = true // we want to search for missing } }; for (var i = 1; i <= model.SeasonCount; i++) { var season = new Season { seasonNumber = i, // The model.SeasonList.Lenth is 0 when this is a "request all" monitored = model.SeasonList.Length == 0 || model.SeasonList.Any(x => x == i) }; seriesToAdd.seasons.Add(season); } return(SonarrApi.AddSeries(seriesToAdd, sonarrSettings.ApiKey, sonarrSettings.FullUri)); }
public async Task <SonarrAddSeries> SendToSonarr(SonarrSettings sonarrSettings, RequestedModel model, string qualityId) { var qualityProfile = 0; var episodeRequest = model.Episodes.Any(); if (!string.IsNullOrEmpty(qualityId)) // try to parse the passed in quality, otherwise use the settings default quality { int.TryParse(qualityId, out qualityProfile); } if (qualityProfile <= 0) { int.TryParse(sonarrSettings.QualityProfile, out qualityProfile); } var series = await GetSonarrSeries(sonarrSettings, model.ProviderId); if (episodeRequest) { // Does series exist? if (series != null) { // Series Exists // Request the episodes in the existing series await RequestEpisodesWithExistingSeries(model, series, sonarrSettings); return(new SonarrAddSeries { title = series.title }); } // Series doesn't exist, need to add it as unmonitored. var addResult = await Task.Run(() => SonarrApi.AddSeries(model.ProviderId, model.Title, qualityProfile, sonarrSettings.SeasonFolders, sonarrSettings.RootPath, 0, new int[0], sonarrSettings.ApiKey, sonarrSettings.FullUri, false)); // Get the series that was just added series = await GetSonarrSeries(sonarrSettings, model.ProviderId); series.monitored = true; // We want to make sure we are monitoring the series // Un-monitor all seasons foreach (var season in series.seasons) { season.monitored = false; } // Update the series, Since we cannot add as un-monitored due to the following bug: https://github.com/Sonarr/Sonarr/issues/1404 SonarrApi.UpdateSeries(series, sonarrSettings.ApiKey, sonarrSettings.FullUri); // We now have the series in Sonarr, update it to request the episodes. await RequestAllEpisodesInASeasonWithExistingSeries(model, series, sonarrSettings); return(addResult); } if (series != null) { var requestAll = model.SeasonsRequested.Equals("All", StringComparison.CurrentCultureIgnoreCase); var first = model.SeasonsRequested.Equals("First", StringComparison.CurrentCultureIgnoreCase); var latest = model.SeasonsRequested.Equals("Latest", StringComparison.CurrentCultureIgnoreCase); if (model.SeasonList.Any()) { // Monitor the seasons that we have chosen foreach (var season in series.seasons) { if (model.SeasonList.Contains(season.seasonNumber)) { season.monitored = true; } } } if (requestAll) { // Monitor all seasons foreach (var season in series.seasons) { season.monitored = true; } } if (first) { var firstSeries = series?.seasons?.OrderBy(x => x.seasonNumber)?.FirstOrDefault() ?? new Season(); firstSeries.monitored = true; } if (latest) { var lastSeries = series?.seasons?.OrderByDescending(x => x.seasonNumber)?.FirstOrDefault() ?? new Season(); lastSeries.monitored = true; } // Update the series in sonarr with the new monitored status SonarrApi.UpdateSeries(series, sonarrSettings.ApiKey, sonarrSettings.FullUri); await RequestAllEpisodesInASeasonWithExistingSeries(model, series, sonarrSettings); return(new SonarrAddSeries { title = series.title }); // We have updated it } var result = SonarrApi.AddSeries(model.ProviderId, model.Title, qualityProfile, sonarrSettings.SeasonFolders, sonarrSettings.RootPath, model.SeasonCount, model.SeasonList, sonarrSettings.ApiKey, sonarrSettings.FullUri, true, true); return(result); }
public async Task NotifyUsers(RequestedModel model, NotificationType type) { try { var settings = await PlexSettings.GetSettingsAsync(); var plexUser = PlexApi.GetUsers(settings.PlexAuthToken); // TODO emby var userAccount = PlexApi.GetAccount(settings.PlexAuthToken); var localUsers = UserHelper.GetUsers().ToList(); var adminUsername = userAccount.Username ?? string.Empty; var users = UserHelper.GetUsersWithFeature(Features.RequestAddedNotification).ToList(); Log.Debug("Notifying Users Count {0}", users.Count); // Get the usernames or alias depending if they have an alias var userNamesWithFeature = users.Select(x => x.UsernameOrAlias).ToList(); Log.Debug("Users with the feature count {0}", userNamesWithFeature.Count); Log.Debug("Usernames: "); foreach (var u in userNamesWithFeature) { Log.Debug(u); } Log.Debug("Users in the requested model count: {0}", model.AllUsers.Count); Log.Debug("usernames from model: "); foreach (var modelAllUser in model.AllUsers) { Log.Debug(modelAllUser); } if (model.AllUsers == null || !model.AllUsers.Any()) { Log.Debug("There are no users in the model.AllUsers, no users to notify"); return; } var usersToNotify = userNamesWithFeature.Intersect(model.AllUsers, StringComparer.CurrentCultureIgnoreCase).ToList(); if (!usersToNotify.Any()) { Log.Debug("Could not find any users after the .Intersect()"); } Log.Debug("Users being notified for this request count {0}", users.Count); foreach (var user in usersToNotify) { Log.Info("Notifying user {0}", user); if (user.Equals(adminUsername, StringComparison.CurrentCultureIgnoreCase)) { Log.Info("This user is the Plex server owner"); await PublishUserNotification(userAccount.Username, userAccount.Email, model.Title, model.PosterPath, type, model.Type); return; } var email = plexUser.User.FirstOrDefault(x => x.Username.Equals(user, StringComparison.CurrentCultureIgnoreCase)); if (email == null) // This is not a Plex User { // Local User? var local = localUsers.FirstOrDefault(x => x.UsernameOrAlias.Equals(user)); if (local != null) { Log.Info("Sending notification to: {0} at: {1}, for title: {2}", local.UsernameOrAlias, local.EmailAddress, model.Title); await PublishUserNotification(local.UsernameOrAlias, local.EmailAddress, model.Title, model.PosterPath, type, model.Type); continue; } } Log.Info("Sending notification to: {0} at: {1}, for title: {2}", email.Username, email.Email, model.Title); await PublishUserNotification(email.Username, email.Email, model.Title, model.PosterPath, type, model.Type); } } catch (Exception e) { Log.Error(e); } }
public async Task <SonarrAddSeries> SendToSonarr(SonarrSettings sonarrSettings, RequestedModel model) { return(await SendToSonarr(sonarrSettings, model, string.Empty)); }
private Response RequestAlbum(string releaseId) { var settings = PrService.GetSettings(); var existingRequest = RequestService.CheckRequest(releaseId); Log.Debug("Checking for an existing request"); if (existingRequest != null) { Log.Debug("We do have an existing album request"); if (!existingRequest.UserHasRequested(Username)) { Log.Debug("Not in the requested list so adding them and updating the request. User: {0}", Username); existingRequest.RequestedUsers.Add(Username); RequestService.UpdateRequest(existingRequest); } return(Response.AsJson(new JsonResponseModel { Result = true, Message = settings.UsersCanViewOnlyOwnRequests ? $"{existingRequest.Title} was successfully added!" : $"{existingRequest.Title} has already been requested!" })); } Log.Debug("This is a new request"); var albumInfo = MusicBrainzApi.GetAlbum(releaseId); DateTime release; DateTimeHelper.CustomParse(albumInfo.ReleaseEvents?.FirstOrDefault()?.date, out release); var artist = albumInfo.ArtistCredits?.FirstOrDefault()?.artist; if (artist == null) { return(Response.AsJson(new JsonResponseModel { Result = false, Message = "We could not find the artist on MusicBrainz. Please try again later or contact your admin" })); } var albums = Checker.GetPlexAlbums(); var alreadyInPlex = Checker.IsAlbumAvailable(albums.ToArray(), albumInfo.title, release.ToString("yyyy"), artist.name); if (alreadyInPlex) { return(Response.AsJson(new JsonResponseModel { Result = false, Message = $"{albumInfo.title} is already in Plex!" })); } var img = GetMusicBrainzCoverArt(albumInfo.id); Log.Trace("Album Details:"); Log.Trace(albumInfo.DumpJson()); Log.Trace("CoverArt Details:"); Log.Trace(img.DumpJson()); var model = new RequestedModel { Title = albumInfo.title, MusicBrainzId = albumInfo.id, 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 }; if (ShouldAutoApprove(RequestType.Album, settings)) { Log.Debug("We don't require approval OR the user is in the whitelist"); var hpSettings = HeadphonesService.GetSettings(); Log.Trace("Headphone Settings:"); Log.Trace(hpSettings.DumpJson()); if (!hpSettings.Enabled) { RequestService.AddRequest(model); return (Response.AsJson(new JsonResponseModel { Result = true, Message = $"{model.Title} was successfully added!" })); } var sender = new HeadphonesSender(HeadphonesApi, hpSettings, RequestService); sender.AddAlbum(model).Wait(); model.Approved = true; RequestService.AddRequest(model); if (ShouldSendNotification()) { var notify2 = new NotificationModel { Title = model.Title, User = Username, DateTime = DateTime.Now, NotificationType = NotificationType.NewRequest }; NotificationService.Publish(notify2); } return (Response.AsJson(new JsonResponseModel { Result = true, Message = $"{model.Title} was successfully added!" })); } if (ShouldSendNotification()) { var notify2 = new NotificationModel { Title = model.Title, User = Username, DateTime = DateTime.Now, NotificationType = NotificationType.NewRequest }; NotificationService.Publish(notify2); } var result = RequestService.AddRequest(model); return(Response.AsJson(new JsonResponseModel { Result = true, Message = $"{model.Title} was successfully added!" })); }
public void DeleteRequest(RequestedModel request) { var blob = Repo.Get(request.Id); Repo.Delete(blob); }
public SickRageTvAdd SendToSickRage(SickRageSettings sickRageSettings, RequestedModel model) { return(SendToSickRage(sickRageSettings, model, sickRageSettings.QualityProfile)); }
/// <summary> /// Broken Way /// </summary> /// <param name="sonarrSettings"></param> /// <param name="model"></param> /// <param name="qualityId"></param> /// <returns></returns> public async Task <SonarrAddSeries> SendToSonarr(SonarrSettings sonarrSettings, RequestedModel model, string qualityId) { var qualityProfile = 0; var episodeRequest = model.Episodes.Any(); if (!string.IsNullOrEmpty(qualityId)) // try to parse the passed in quality, otherwise use the settings default quality { int.TryParse(qualityId, out qualityProfile); } if (qualityProfile <= 0) { int.TryParse(sonarrSettings.QualityProfile, out qualityProfile); } var series = await GetSonarrSeries(sonarrSettings, model.ProviderId); var requestAll = model.SeasonsRequested?.Equals("All", StringComparison.CurrentCultureIgnoreCase); var first = model.SeasonsRequested?.Equals("First", StringComparison.CurrentCultureIgnoreCase); var latest = model.SeasonsRequested?.Equals("Latest", StringComparison.CurrentCultureIgnoreCase); var specificSeasonRequest = model.SeasonList?.Any(); var rootFolderPath = model.RootFolderSelected <= 0 ? sonarrSettings.FullRootPath : await GetRootPath(model.RootFolderSelected, sonarrSettings); if (episodeRequest) { // Does series exist? if (series != null) { // Series Exists // Request the episodes in the existing series await RequestEpisodesWithExistingSeries(model, series, sonarrSettings); return(new SonarrAddSeries { title = series.title }); } // Series doesn't exist, need to add it as unmonitored. var addResult = await Task.Run(() => SonarrApi.AddSeries(model.ProviderId, model.Title, qualityProfile, sonarrSettings.SeasonFolders, rootFolderPath, 0, new int[0], sonarrSettings.ApiKey, sonarrSettings.FullUri, false)); // Get the series that was just added series = await GetSonarrSeries(sonarrSettings, model.ProviderId); series.monitored = true; // We want to make sure we are monitoring the series // Un-monitor all seasons foreach (var season in series.seasons) { season.monitored = false; } // Update the series, Since we cannot add as un-monitored due to the following bug: https://github.com/Sonarr/Sonarr/issues/1404 SonarrApi.UpdateSeries(series, sonarrSettings.ApiKey, sonarrSettings.FullUri); // We now have the series in Sonarr, update it to request the episodes. await RequestAllEpisodesInASeasonWithExistingSeries(model, series, sonarrSettings); return(addResult); } // Series exists, don't need to add it if (series == null) { // Set the series as monitored with a season count as 0 so it doesn't search for anything SonarrApi.AddSeriesNew(model.ProviderId, model.Title, qualityProfile, sonarrSettings.SeasonFolders, rootFolderPath, new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 }, sonarrSettings.ApiKey, sonarrSettings.FullUri); await Task.Delay(TimeSpan.FromSeconds(1)); series = await GetSonarrSeries(sonarrSettings, model.ProviderId); foreach (var s in series.seasons) { s.monitored = false; } SonarrApi.UpdateSeries(series, sonarrSettings.ApiKey, sonarrSettings.FullUri); } if (requestAll ?? false) { // Monitor all seasons foreach (var season in series.seasons) { season.monitored = true; } SonarrApi.UpdateSeries(series, sonarrSettings.ApiKey, sonarrSettings.FullUri); SonarrApi.SearchForSeries(series.id, sonarrSettings.ApiKey, sonarrSettings.FullUri); // Search For all episodes!" //// This is a work around for this issue: https://github.com/Sonarr/Sonarr/issues/1507 //// The above is the previous code. //SonarrApi.AddSeries(model.ProviderId, model.Title, qualityProfile, // sonarrSettings.SeasonFolders, sonarrSettings.RootPath, 0, model.SeasonList, sonarrSettings.ApiKey, // sonarrSettings.FullUri, true, true); return(new SonarrAddSeries { title = series.title }); // We have updated it } if (first ?? false) { var firstSeries = (series?.seasons?.OrderBy(x => x.seasonNumber)).FirstOrDefault(x => x.seasonNumber > 0) ?? new Season(); firstSeries.monitored = true; var episodes = SonarrApi.GetEpisodes(series.id.ToString(), sonarrSettings.ApiKey, sonarrSettings.FullUri); // Need to get the episodes so we mark them as monitored var episodesToUpdate = new List <SonarrEpisodes>(); foreach (var e in episodes) { if (e.hasFile || e.seasonNumber != firstSeries.seasonNumber) { continue; } e.monitored = true; // Mark only the episodes we want as monitored episodesToUpdate.Add(e); } foreach (var sonarrEpisode in episodesToUpdate) { SonarrApi.UpdateEpisode(sonarrEpisode, sonarrSettings.ApiKey, sonarrSettings.FullUri); } SonarrApi.UpdateSeries(series, sonarrSettings.ApiKey, sonarrSettings.FullUri); SonarrApi.SearchForSeason(series.id, firstSeries.seasonNumber, sonarrSettings.ApiKey, sonarrSettings.FullUri); return(new SonarrAddSeries { title = series.title }); // We have updated it } if (latest ?? false) { var lastSeries = series?.seasons?.OrderByDescending(x => x.seasonNumber)?.FirstOrDefault() ?? new Season(); lastSeries.monitored = true; var episodes = SonarrApi.GetEpisodes(series.id.ToString(), sonarrSettings.ApiKey, sonarrSettings.FullUri); // Need to get the episodes so we mark them as monitored var episodesToUpdate = new List <SonarrEpisodes>(); foreach (var e in episodes) { if (e.hasFile || e.seasonNumber != lastSeries.seasonNumber) { continue; } e.monitored = true; // Mark only the episodes we want as monitored episodesToUpdate.Add(e); } foreach (var sonarrEpisode in episodesToUpdate) { SonarrApi.UpdateEpisode(sonarrEpisode, sonarrSettings.ApiKey, sonarrSettings.FullUri); } SonarrApi.UpdateSeries(series, sonarrSettings.ApiKey, sonarrSettings.FullUri); SonarrApi.SearchForSeason(series.id, lastSeries.seasonNumber, sonarrSettings.ApiKey, sonarrSettings.FullUri); return(new SonarrAddSeries { title = series.title }); // We have updated it } if (specificSeasonRequest ?? false) { // Monitor the seasons that we have chosen foreach (var season in series.seasons) { if (model.SeasonList.Contains(season.seasonNumber)) { season.monitored = true; SonarrApi.UpdateSeries(series, sonarrSettings.ApiKey, sonarrSettings.FullUri); SonarrApi.SearchForSeason(series.id, season.seasonNumber, sonarrSettings.ApiKey, sonarrSettings.FullUri); } } return(new SonarrAddSeries { title = series.title }); // We have updated it } return(null); }