public async Task <NewSeries> AddSeries(NewSeries seriesToAdd, string apiKey, string baseUrl) { if (!string.IsNullOrEmpty(seriesToAdd.Validate())) { return(new NewSeries { ErrorMessages = new List <string> { seriesToAdd.Validate() } }); } var request = new Request($"{ApiBaseUrl}series/", baseUrl, HttpMethod.Post); request.AddHeader("X-Api-Key", apiKey); request.AddJsonBody(seriesToAdd); try { return(await Api.Request <NewSeries>(request)); } catch (JsonSerializationException) { var error = await Api.Request <List <SonarrError> >(request); var messages = error?.Select(x => x.errorMessage).ToList(); return(new NewSeries { ErrorMessages = messages }); } }
public async Task <ActionResult <Result> > Create([Bind("Name", "Season")] NewSeries series) { _context.Series.Add(new Series { Name = series.Name, Seasons = series.Seasons }); await _context.SaveChangesAsync(); Result res = new Result { Text = "Done" }; return(res); }
void btnAddSeries_Click(object sender, RoutedEventArgs e) { try { NewSeries frm = new NewSeries(); frm.Owner = GetTopParent(); frm.Init(0, string.Empty); bool?result = frm.ShowDialog(); if (result.HasValue && result.Value) { //ok, now its safe to use textbox, search wont mess with it RefreshSeries(); VM_AnimeSeries_User ser = frm.AnimeSeries; txtSeriesSearch.Text = ser?.AniDBAnime?.AniDBAnime?.FormattedTitle ?? ser?.SeriesName ?? string.Empty; } } catch (Exception ex) { Utils.ShowErrorMessage(ex); } }
void btnAddSeries_Click(object sender, RoutedEventArgs e) { try { NewSeries frm = new NewSeries(); frm.Owner = GetTopParent(); frm.Init(0, ""); bool?result = frm.ShowDialog(); if (result.HasValue && result.Value == true) { RefreshSeries(); AnimeSeriesVM ser = frm.AnimeSeries; txtSeriesSearch.Text = ser.AniDB_Anime.FormattedTitle; } } catch (Exception ex) { Utils.ShowErrorMessage(ex); } }
/// <summary> /// Send the request to Sonarr to process /// </summary> /// <param name="s"></param> /// <param name="model"></param> /// <returns></returns> public async Task <NewSeries> SendToSonarr(ChildRequests model, SonarrSettings s) { if (string.IsNullOrEmpty(s.ApiKey)) { return(null); } int qualityToUse; string rootFolderPath; string seriesType; var profiles = await UserQualityProfiles.GetAll().FirstOrDefaultAsync(x => x.UserId == model.RequestedUserId); if (model.SeriesType == SeriesType.Anime) { // Get the root path from the rootfolder selected. // For some reason, if we haven't got one use the first root folder in Sonarr rootFolderPath = await GetSonarrRootPath(model.ParentRequest.RootFolder ?? int.Parse(s.RootPathAnime), s); int.TryParse(s.QualityProfileAnime, out qualityToUse); if (profiles != null) { if (profiles.SonarrRootPathAnime > 0) { rootFolderPath = await GetSonarrRootPath(profiles.SonarrRootPathAnime, s); } if (profiles.SonarrQualityProfileAnime > 0) { qualityToUse = profiles.SonarrQualityProfileAnime; } } seriesType = "anime"; } else { int.TryParse(s.QualityProfile, out qualityToUse); // Get the root path from the rootfolder selected. // For some reason, if we haven't got one use the first root folder in Sonarr rootFolderPath = await GetSonarrRootPath(model.ParentRequest.RootFolder ?? int.Parse(s.RootPath), s); if (profiles != null) { if (profiles.SonarrRootPath > 0) { rootFolderPath = await GetSonarrRootPath(profiles.SonarrRootPath, s); } if (profiles.SonarrQualityProfile > 0) { qualityToUse = profiles.SonarrQualityProfile; } } seriesType = "standard"; } // Overrides on the request take priority if (model.ParentRequest.QualityOverride.HasValue) { qualityToUse = model.ParentRequest.QualityOverride.Value; } // Are we using v3 sonarr? var sonarrV3 = s.V3; var languageProfileId = s.LanguageProfile; try { // Does the series actually exist? var allSeries = await SonarrApi.GetSeries(s.ApiKey, s.FullUri); var existingSeries = allSeries.FirstOrDefault(x => x.tvdbId == model.ParentRequest.TvDbId); if (existingSeries == null) { // Time to add a new one var newSeries = new NewSeries { title = model.ParentRequest.Title, imdbId = model.ParentRequest.ImdbId, tvdbId = model.ParentRequest.TvDbId, cleanTitle = model.ParentRequest.Title, monitored = true, seasonFolder = s.SeasonFolders, rootFolderPath = rootFolderPath, qualityProfileId = qualityToUse, titleSlug = model.ParentRequest.Title, seriesType = seriesType, addOptions = new AddOptions { ignoreEpisodesWithFiles = false, // There shouldn't be any episodes with files, this is a new season ignoreEpisodesWithoutFiles = false, // We want all missing searchForMissingEpisodes = false // we want dont want to search yet. We want to make sure everything is unmonitored/monitored correctly. } }; if (sonarrV3) { newSeries.languageProfileId = languageProfileId; } // Montitor the correct seasons, // If we have that season in the model then it's monitored! var seasonsToAdd = GetSeasonsToCreate(model); newSeries.seasons = seasonsToAdd; var result = await SonarrApi.AddSeries(newSeries, s.ApiKey, s.FullUri); existingSeries = await SonarrApi.GetSeriesById(result.id, s.ApiKey, s.FullUri); await SendToSonarr(model, existingSeries, s); } else { await SendToSonarr(model, existingSeries, s); } return(new NewSeries { id = existingSeries.id, seasons = existingSeries.seasons.ToList(), cleanTitle = existingSeries.cleanTitle, title = existingSeries.title, tvdbId = existingSeries.tvdbId }); } catch (Exception e) { Logger.LogError(LoggingEvents.SonarrSender, e, "Exception thrown when attempting to send series over to Sonarr"); throw; } }
/// <summary> /// Send the request to Sonarr to process /// </summary> /// <param name="s"></param> /// <param name="model"></param> /// <param name="qualityId">This is for any qualities overriden from the UI</param> /// <returns></returns> public async Task <NewSeries> SendToSonarr(ChildRequests model, string qualityId = null) { var s = await SonarrSettings.GetSettingsAsync(); if (!s.Enabled) { return(null); } if (string.IsNullOrEmpty(s.ApiKey)) { return(null); } var qualityProfile = 0; 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(s.QualityProfile, out qualityProfile); } // Get the root path from the rootfolder selected. // For some reason, if we haven't got one use the first root folder in Sonarr // TODO make this overrideable via the UI var rootFolderPath = await GetSonarrRootPath(model.ParentRequest.RootFolder ?? int.Parse(s.RootPath), s); try { // Does the series actually exist? var allSeries = await SonarrApi.GetSeries(s.ApiKey, s.FullUri); var existingSeries = allSeries.FirstOrDefault(x => x.tvdbId == model.ParentRequest.TvDbId); if (existingSeries == null) { // Time to add a new one var newSeries = new NewSeries { title = model.ParentRequest.Title, imdbId = model.ParentRequest.ImdbId, tvdbId = model.ParentRequest.TvDbId, cleanTitle = model.ParentRequest.Title, monitored = true, seasonFolder = s.SeasonFolders, rootFolderPath = rootFolderPath, qualityProfileId = qualityProfile, titleSlug = model.ParentRequest.Title, addOptions = new AddOptions { ignoreEpisodesWithFiles = true, // There shouldn't be any episodes with files, this is a new season ignoreEpisodesWithoutFiles = true, // We want all missing searchForMissingEpisodes = false // we want dont want to search yet. We want to make sure everything is unmonitored/monitored correctly. } }; // Montitor the correct seasons, // If we have that season in the model then it's monitored! var seasonsToAdd = new List <Season>(); for (var i = 1; i < model.ParentRequest.TotalSeasons + 1; i++) { var index = i; var season = new Season { seasonNumber = i, monitored = model.SeasonRequests.Any(x => x.SeasonNumber == index) }; seasonsToAdd.Add(season); } newSeries.seasons = seasonsToAdd; var result = await SonarrApi.AddSeries(newSeries, s.ApiKey, s.FullUri); existingSeries = await SonarrApi.GetSeriesById(result.id, s.ApiKey, s.FullUri); await SendToSonarr(model, existingSeries, s); } else { await SendToSonarr(model, existingSeries, s); } return(new NewSeries { id = existingSeries.id, seasons = existingSeries.seasons.ToList(), cleanTitle = existingSeries.cleanTitle, title = existingSeries.title, tvdbId = existingSeries.tvdbId }); } catch (Exception e) { Logger.LogError(LoggingEvents.SonarrSender, e, "Exception thrown when attempting to send series over to Sonarr"); throw; } }