mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-11 15:56:05 -07:00
Got mostly everything working for #254 Ready for testing
This commit is contained in:
parent
131a99b1bb
commit
0699d777d6
7 changed files with 84 additions and 40 deletions
|
@ -36,7 +36,8 @@ namespace PlexRequests.Api.Interfaces
|
||||||
List<SonarrProfile> GetProfiles(string apiKey, Uri baseUrl);
|
List<SonarrProfile> GetProfiles(string apiKey, Uri baseUrl);
|
||||||
|
|
||||||
SonarrAddSeries AddSeries(int tvdbId, string title, int qualityId, bool seasonFolders, string rootPath,
|
SonarrAddSeries AddSeries(int tvdbId, string title, int qualityId, bool seasonFolders, string rootPath,
|
||||||
int seasonCount, int[] seasons, string apiKey, Uri baseUrl, bool monitored = true);
|
int seasonCount, int[] seasons, string apiKey, Uri baseUrl, bool monitor = true,
|
||||||
|
bool searchForMissingEpisodes = false);
|
||||||
|
|
||||||
SystemStatus SystemStatus(string apiKey, Uri baseUrl);
|
SystemStatus SystemStatus(string apiKey, Uri baseUrl);
|
||||||
|
|
||||||
|
|
|
@ -64,7 +64,7 @@ namespace PlexRequests.Api
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SonarrAddSeries AddSeries(int tvdbId, string title, int qualityId, bool seasonFolders, string rootPath, int seasonCount, int[] seasons, string apiKey, Uri baseUrl, bool monitor = true)
|
public SonarrAddSeries AddSeries(int tvdbId, string title, int qualityId, bool seasonFolders, string rootPath, int seasonCount, int[] seasons, string apiKey, Uri baseUrl, bool monitor = true, bool searchForMissingEpisodes = false)
|
||||||
{
|
{
|
||||||
Log.Debug("Adding series {0}", title);
|
Log.Debug("Adding series {0}", title);
|
||||||
Log.Debug("Seasons = {0}, out of {1} seasons", seasons.DumpJson(), seasonCount);
|
Log.Debug("Seasons = {0}, out of {1} seasons", seasons.DumpJson(), seasonCount);
|
||||||
|
@ -86,6 +86,16 @@ namespace PlexRequests.Api
|
||||||
monitored = monitor
|
monitored = monitor
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (!searchForMissingEpisodes)
|
||||||
|
{
|
||||||
|
options.addOptions = new AddOptions
|
||||||
|
{
|
||||||
|
searchForMissingEpisodes = false,
|
||||||
|
ignoreEpisodesWithFiles = true,
|
||||||
|
ignoreEpisodesWithoutFiles = true
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
for (var i = 1; i <= seasonCount; i++)
|
for (var i = 1; i <= seasonCount; i++)
|
||||||
{
|
{
|
||||||
var season = new Season
|
var season = new Season
|
||||||
|
@ -107,9 +117,8 @@ namespace PlexRequests.Api
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var policy = RetryHandler.RetryAndWaitPolicy((exception, timespan) => Log.Error(exception, "Exception when calling AddSeries for Sonarr, Retrying {0}", timespan), new TimeSpan[] {
|
var policy = RetryHandler.RetryAndWaitPolicy((exception, timespan) => Log.Error(exception, "Exception when calling AddSeries for Sonarr, Retrying {0}", timespan), new TimeSpan[] {
|
||||||
TimeSpan.FromSeconds (2),
|
TimeSpan.FromSeconds (1),
|
||||||
TimeSpan.FromSeconds(5),
|
TimeSpan.FromSeconds(2),
|
||||||
TimeSpan.FromSeconds(10)
|
|
||||||
});
|
});
|
||||||
|
|
||||||
result = policy.Execute(() => Api.ExecuteJson<SonarrAddSeries>(request, baseUrl));
|
result = policy.Execute(() => Api.ExecuteJson<SonarrAddSeries>(request, baseUrl));
|
||||||
|
|
|
@ -26,17 +26,20 @@
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using NLog;
|
||||||
|
|
||||||
namespace PlexRequests.Helpers
|
namespace PlexRequests.Helpers
|
||||||
{
|
{
|
||||||
public class PlexHelper
|
public class PlexHelper
|
||||||
{
|
{
|
||||||
|
|
||||||
|
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||||
public static string GetProviderIdFromPlexGuid(string guid)
|
public static string GetProviderIdFromPlexGuid(string guid)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(guid))
|
if (string.IsNullOrEmpty(guid))
|
||||||
return guid;
|
return guid;
|
||||||
|
|
||||||
var guidSplit = guid.Split(new[] {'/', '?'}, StringSplitOptions.RemoveEmptyEntries);
|
var guidSplit = guid.Split(new[] { '/', '?' }, StringSplitOptions.RemoveEmptyEntries);
|
||||||
if (guidSplit.Length > 1)
|
if (guidSplit.Length > 1)
|
||||||
{
|
{
|
||||||
return guidSplit[1];
|
return guidSplit[1];
|
||||||
|
@ -50,7 +53,8 @@ namespace PlexRequests.Helpers
|
||||||
//guid="com.plexapp.agents.thetvdb://269586/2/8?lang=en"
|
//guid="com.plexapp.agents.thetvdb://269586/2/8?lang=en"
|
||||||
if (string.IsNullOrEmpty(guid))
|
if (string.IsNullOrEmpty(guid))
|
||||||
return null;
|
return null;
|
||||||
|
try
|
||||||
|
{
|
||||||
var guidSplit = guid.Split(new[] { '/', '?' }, StringSplitOptions.RemoveEmptyEntries);
|
var guidSplit = guid.Split(new[] { '/', '?' }, StringSplitOptions.RemoveEmptyEntries);
|
||||||
if (guidSplit.Length > 2)
|
if (guidSplit.Length > 2)
|
||||||
{
|
{
|
||||||
|
@ -59,6 +63,13 @@ namespace PlexRequests.Helpers
|
||||||
ep.EpisodeNumber = int.Parse(guidSplit[3]);
|
ep.EpisodeNumber = int.Parse(guidSplit[3]);
|
||||||
}
|
}
|
||||||
return ep;
|
return ep;
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Log.Error(e);
|
||||||
|
return ep;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -108,9 +108,29 @@ namespace PlexRequests.Store
|
||||||
Other = 4, // Provide a message
|
Other = 4, // Provide a message
|
||||||
}
|
}
|
||||||
|
|
||||||
public class EpisodesModel
|
public class EpisodesModel : IEquatable<EpisodesModel>
|
||||||
{
|
{
|
||||||
public int SeasonNumber { get; set; }
|
public int SeasonNumber { get; set; }
|
||||||
public int EpisodeNumber { get; set; }
|
public int EpisodeNumber { get; set; }
|
||||||
|
public bool Equals(EpisodesModel other)
|
||||||
|
{
|
||||||
|
// Check whether the compared object is null.
|
||||||
|
if (ReferenceEquals(other, null)) return false;
|
||||||
|
|
||||||
|
//Check whether the compared object references the same data.
|
||||||
|
if (ReferenceEquals(this, other)) return true;
|
||||||
|
|
||||||
|
//Check whether the properties are equal.
|
||||||
|
return SeasonNumber.Equals(other.SeasonNumber) && EpisodeNumber.Equals(other.EpisodeNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int GetHashCode()
|
||||||
|
{
|
||||||
|
var hashSeason = SeasonNumber.GetHashCode();
|
||||||
|
var hashEp = EpisodeNumber.GetHashCode();
|
||||||
|
|
||||||
|
//Calculate the hash code.
|
||||||
|
return hashSeason + hashEp;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
1
PlexRequests.UI/Content/requests.js
vendored
1
PlexRequests.UI/Content/requests.js
vendored
|
@ -592,6 +592,7 @@ function tvLoad() {
|
||||||
context.episodes = tvObject;
|
context.episodes = tvObject;
|
||||||
var html = searchTemplate(context);
|
var html = searchTemplate(context);
|
||||||
$tvl.append(html);
|
$tvl.append(html);
|
||||||
|
tvObject = new Array();
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -83,6 +83,7 @@ namespace PlexRequests.UI.Helpers
|
||||||
// Series Exists
|
// Series Exists
|
||||||
// Request the episodes in the existing series
|
// Request the episodes in the existing series
|
||||||
await RequestEpisodesWithExistingSeries(model, series, sonarrSettings);
|
await RequestEpisodesWithExistingSeries(model, series, sonarrSettings);
|
||||||
|
return new SonarrAddSeries {title = series.title};
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -91,29 +92,22 @@ namespace PlexRequests.UI.Helpers
|
||||||
sonarrSettings.SeasonFolders, sonarrSettings.RootPath, 0, new int[0], sonarrSettings.ApiKey,
|
sonarrSettings.SeasonFolders, sonarrSettings.RootPath, 0, new int[0], sonarrSettings.ApiKey,
|
||||||
sonarrSettings.FullUri, false));
|
sonarrSettings.FullUri, false));
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(addResult?.title))
|
|
||||||
{
|
// Get the series that was just added
|
||||||
var sw = new Stopwatch();
|
|
||||||
sw.Start();
|
|
||||||
while (series == null)
|
|
||||||
{
|
|
||||||
await Task.Delay(TimeSpan.FromSeconds(5));
|
|
||||||
series = await GetSonarrSeries(sonarrSettings, model.ProviderId);
|
series = await GetSonarrSeries(sonarrSettings, model.ProviderId);
|
||||||
|
series.monitored = false; // Un-monitor the series
|
||||||
|
|
||||||
// Check how long we have been doing this for
|
// Un-monitor all seasons
|
||||||
if (sw.Elapsed > TimeSpan.FromSeconds(30))
|
foreach (var season in series.seasons)
|
||||||
{
|
{
|
||||||
// 30 seconds is a long time, it's not going to work.
|
season.monitored = false;
|
||||||
throw new ApiRequestException("Sonarr still didn't have the series added after 30 seconds.");
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
sw.Stop();
|
|
||||||
|
|
||||||
// Update the series, Since we cannot add as unmonitoed due to the following bug: https://github.com/Sonarr/Sonarr/issues/1404
|
// 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);
|
SonarrApi.UpdateSeries(series, sonarrSettings.ApiKey, sonarrSettings.FullUri);
|
||||||
}
|
|
||||||
|
|
||||||
// We now have the series in Sonarr
|
|
||||||
|
// We now have the series in Sonarr, update it to request the episodes.
|
||||||
await RequestEpisodesWithExistingSeries(model, series, sonarrSettings);
|
await RequestEpisodesWithExistingSeries(model, series, sonarrSettings);
|
||||||
|
|
||||||
return addResult;
|
return addResult;
|
||||||
|
|
|
@ -585,8 +585,16 @@ namespace PlexRequests.UI.Modules
|
||||||
if (episodeRequest)
|
if (episodeRequest)
|
||||||
{
|
{
|
||||||
difference = GetListDifferences(existingRequest.Episodes, episodeModel.Episodes).ToList();
|
difference = GetListDifferences(existingRequest.Episodes, episodeModel.Episodes).ToList();
|
||||||
if (!difference.Any())
|
if (difference.Any())
|
||||||
{
|
{
|
||||||
|
existingRequest.Episodes = episodeModel.Episodes
|
||||||
|
.Select(r =>
|
||||||
|
new EpisodesModel
|
||||||
|
{
|
||||||
|
SeasonNumber = r.SeasonNumber,
|
||||||
|
EpisodeNumber = r.EpisodeNumber
|
||||||
|
}).ToList();
|
||||||
|
|
||||||
return await AddUserToRequest(existingRequest, settings, fullShowName);
|
return await AddUserToRequest(existingRequest, settings, fullShowName);
|
||||||
}
|
}
|
||||||
// We have an episode that has not yet been requested, let's continue
|
// We have an episode that has not yet been requested, let's continue
|
||||||
|
@ -730,7 +738,7 @@ namespace PlexRequests.UI.Modules
|
||||||
private async Task<Response> AddUserToRequest(RequestedModel existingRequest, PlexRequestSettings settings, string fullShowName)
|
private async Task<Response> AddUserToRequest(RequestedModel existingRequest, PlexRequestSettings settings, string fullShowName)
|
||||||
{
|
{
|
||||||
// check if the current user is already marked as a requester for this show, if not, add them
|
// check if the current user is already marked as a requester for this show, if not, add them
|
||||||
if (!existingRequest.UserHasRequested(Username))
|
if (!existingRequest.UserHasRequested(Username) || existingRequest.Episodes.Any())
|
||||||
{
|
{
|
||||||
existingRequest.RequestedUsers.Add(Username);
|
existingRequest.RequestedUsers.Add(Username);
|
||||||
await RequestService.UpdateRequestAsync(existingRequest);
|
await RequestService.UpdateRequestAsync(existingRequest);
|
||||||
|
@ -1092,17 +1100,17 @@ namespace PlexRequests.UI.Modules
|
||||||
return Response.AsJson(new JsonResponseModel { Result = true, Message = message });
|
return Response.AsJson(new JsonResponseModel { Result = true, Message = message });
|
||||||
}
|
}
|
||||||
|
|
||||||
private IEnumerable<Store.EpisodesModel> GetListDifferences(IEnumerable<Store.EpisodesModel> model, IEnumerable<Models.EpisodesModel> request)
|
private IEnumerable<Store.EpisodesModel> GetListDifferences(IEnumerable<EpisodesModel> existing, IEnumerable<Models.EpisodesModel> request)
|
||||||
{
|
{
|
||||||
var newRequest = request
|
var newRequest = request
|
||||||
.Select(r =>
|
.Select(r =>
|
||||||
new Store.EpisodesModel
|
new EpisodesModel
|
||||||
{
|
{
|
||||||
SeasonNumber = r.SeasonNumber,
|
SeasonNumber = r.SeasonNumber,
|
||||||
EpisodeNumber = r.EpisodeNumber
|
EpisodeNumber = r.EpisodeNumber
|
||||||
}).ToList();
|
}).ToList();
|
||||||
|
|
||||||
return newRequest.Except(model);
|
return newRequest.Except(existing);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue