Skip to content

Commit

Permalink
fix(sonarr): 🐛 Correctly monitor episodes
Browse files Browse the repository at this point in the history
  • Loading branch information
tidusjar committed Nov 18, 2023
1 parent 18c3b31 commit 57e7830
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 54 deletions.
2 changes: 1 addition & 1 deletion src/Ombi.Api.Sonarr/SonarrV3Api.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public Task<Tag> GetTag(int tagId, string apiKey, string baseUrl)

public async Task<List<MonitoredEpisodeResult>> MonitorEpisode(int[] episodeIds, bool monitor, string apiKey, string baseUrl)
{
var request = new Request($"{ApiBaseUrl}Episode/monitor", baseUrl, HttpMethod.Put);
var request = new Request($"{ApiBaseUrl}episode/monitor", baseUrl, HttpMethod.Put);
request.AddHeader("X-Api-Key", apiKey);
request.AddJsonBody(new { episodeIds = episodeIds, monitored = monitor });
return await Api.Request<List<MonitoredEpisodeResult>>(request);
Expand Down
66 changes: 13 additions & 53 deletions src/Ombi.Core/Senders/TvSender.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using Microsoft.VisualBasic;
using Ombi.Api.DogNzb;
using Ombi.Api.DogNzb.Models;
using Ombi.Api.SickRage;
using Ombi.Api.SickRage.Models;
using Ombi.Api.Sonarr;
Expand All @@ -23,15 +19,13 @@ namespace Ombi.Core.Senders
{
public class TvSender : ITvSender
{
public TvSender(ISonarrApi sonarrApi, ISonarrV3Api sonarrV3Api, ILogger<TvSender> log, ISettingsService<SonarrSettings> sonarrSettings,
ISettingsService<DogNzbSettings> dog, IDogNzbApi dogApi, ISettingsService<SickRageSettings> srSettings,
public TvSender(ISonarrV3Api sonarrV3Api, ILogger<TvSender> log, ISettingsService<SonarrSettings> sonarrSettings,
ISettingsService<SickRageSettings> srSettings,
ISickRageApi srApi, IRepository<UserQualityProfiles> userProfiles, IRepository<RequestQueue> requestQueue, INotificationHelper notify)
{
SonarrApi = sonarrV3Api;
Logger = log;
SonarrSettings = sonarrSettings;
DogNzbSettings = dog;
DogNzbApi = dogApi;
SickRageSettings = srSettings;
SickRageApi = srApi;
UserQualityProfiles = userProfiles;
Expand All @@ -40,11 +34,9 @@ public TvSender(ISonarrApi sonarrApi, ISonarrV3Api sonarrV3Api, ILogger<TvSender
}

private ISonarrV3Api SonarrApi { get; }
private IDogNzbApi DogNzbApi { get; }
private ISickRageApi SickRageApi { get; }
private ILogger<TvSender> Logger { get; }
private ISettingsService<SonarrSettings> SonarrSettings { get; }
private ISettingsService<DogNzbSettings> DogNzbSettings { get; }
private ISettingsService<SickRageSettings> SickRageSettings { get; }
private IRepository<UserQualityProfiles> UserQualityProfiles { get; }
private readonly IRepository<RequestQueue> _requestQueueRepository;
Expand All @@ -67,23 +59,7 @@ public async Task<SenderResult> Send(ChildRequests model)
};
}
}
var dog = await DogNzbSettings.GetSettingsAsync();
if (dog.Enabled)
{
var result = await SendToDogNzb(model, dog);
if (!result.Failure)
{
return new SenderResult
{
Sent = true,
Success = true
};
}
return new SenderResult
{
Message = result.ErrorMessage
};
}

var sr = await SickRageSettings.GetSettingsAsync();
if (sr.Enabled)
{
Expand Down Expand Up @@ -137,12 +113,6 @@ await _requestQueueRepository.Add(new RequestQueue
};
}

private async Task<DogNzbAddResult> SendToDogNzb(ChildRequests model, DogNzbSettings settings)
{
var id = model.ParentRequest.ExternalProviderId;
return await DogNzbApi.AddTvShow(settings.ApiKey, id.ToString());
}

/// <summary>
/// Send the request to Sonarr to process
/// </summary>
Expand Down Expand Up @@ -216,30 +186,19 @@ public async Task<NewSeries> SendToSonarr(ChildRequests model, SonarrSettings s)
}

// Overrides on the request take priority
if (model.ParentRequest.QualityOverride.HasValue)
if (model.ParentRequest.QualityOverride.HasValue && model.ParentRequest.QualityOverride.Value > 0)
{
var qualityOverride = model.ParentRequest.QualityOverride.Value;
if (qualityOverride > 0)
{
qualityToUse = qualityOverride;
}
qualityToUse = model.ParentRequest.QualityOverride.Value;
}
if (model.ParentRequest.RootFolder.HasValue)

if (model.ParentRequest.RootFolder.HasValue && model.ParentRequest.RootFolder.Value > 0)
{
var rootfolderOverride = model.ParentRequest.RootFolder.Value;
if (rootfolderOverride > 0)
{
rootFolderPath = await GetSonarrRootPath(rootfolderOverride, s);
}
rootFolderPath = await GetSonarrRootPath(model.ParentRequest.RootFolder.Value, s);
}

if (model.ParentRequest.LanguageProfile.HasValue)
if (model.ParentRequest.LanguageProfile.HasValue && model.ParentRequest.LanguageProfile.Value > 0)
{
var languageProfile = model.ParentRequest.LanguageProfile.Value;
if (languageProfile > 0)
{
languageProfileId = languageProfile;
}
languageProfileId = model.ParentRequest.LanguageProfile.Value;
}

try
Expand Down Expand Up @@ -424,10 +383,11 @@ private async Task SendToSonarr(ChildRequests model, SonarrSeries result, Sonarr

await SonarrApi.MonitorEpisode(epToUnmonitored.Select(x => x.id).ToArray(), false, s.ApiKey, s.FullUri);
}
// Now update the episodes that need updating
await SonarrApi.MonitorEpisode(episodesToUpdate.Where(x => x.seasonNumber == season.SeasonNumber).Select(x => x.id).ToArray(), true, s.ApiKey, s.FullUri);
}

// Now update the episodes that need updating
await SonarrApi.MonitorEpisode(episodesToUpdate.Select(x => x.id).ToArray(), true, s.ApiKey, s.FullUri);

if (!s.AddOnly)
{
await SearchForRequest(model, sonarrEpList, result, s, episodesToUpdate);
Expand Down

0 comments on commit 57e7830

Please sign in to comment.