mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-11 15:56:05 -07:00
#254 MOSTLY DONE! At last, this took a while.
So currently if a series exists then we will correctly monitor the episodes selected. TODO: When the series doesn't exist in sonarr we need to add the series and then wait for the episode metadata to be populated. Also need to add in all of the regular checks and notification e.g. whitelist etc.
This commit is contained in:
parent
8b46925f08
commit
b14fd36ecd
21 changed files with 1380 additions and 861 deletions
|
@ -1,45 +1,51 @@
|
||||||
#region Copyright
|
#region Copyright
|
||||||
// /************************************************************************
|
// /************************************************************************
|
||||||
// Copyright (c) 2016 Jamie Rees
|
// Copyright (c) 2016 Jamie Rees
|
||||||
// File: ISonarrApi.cs
|
// File: ISonarrApi.cs
|
||||||
// Created By: Jamie Rees
|
// Created By: Jamie Rees
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining
|
// Permission is hereby granted, free of charge, to any person obtaining
|
||||||
// a copy of this software and associated documentation files (the
|
// a copy of this software and associated documentation files (the
|
||||||
// "Software"), to deal in the Software without restriction, including
|
// "Software"), to deal in the Software without restriction, including
|
||||||
// without limitation the rights to use, copy, modify, merge, publish,
|
// without limitation the rights to use, copy, modify, merge, publish,
|
||||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
// permit persons to whom the Software is furnished to do so, subject to
|
// permit persons to whom the Software is furnished to do so, subject to
|
||||||
// the following conditions:
|
// the following conditions:
|
||||||
//
|
//
|
||||||
// The above copyright notice and this permission notice shall be
|
// The above copyright notice and this permission notice shall be
|
||||||
// included in all copies or substantial portions of the Software.
|
// included in all copies or substantial portions of the Software.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
// ************************************************************************/
|
// ************************************************************************/
|
||||||
#endregion
|
#endregion
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
using PlexRequests.Api.Models.Sonarr;
|
using PlexRequests.Api.Models.Sonarr;
|
||||||
|
|
||||||
namespace PlexRequests.Api.Interfaces
|
namespace PlexRequests.Api.Interfaces
|
||||||
{
|
{
|
||||||
public interface ISonarrApi
|
public interface ISonarrApi
|
||||||
{
|
{
|
||||||
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);
|
int seasonCount, int[] seasons, string apiKey, Uri baseUrl);
|
||||||
|
|
||||||
SystemStatus SystemStatus(string apiKey, Uri baseUrl);
|
SystemStatus SystemStatus(string apiKey, Uri baseUrl);
|
||||||
|
|
||||||
List<Series> GetSeries(string apiKey, Uri baseUrl);
|
List<Series> GetSeries(string apiKey, Uri baseUrl);
|
||||||
}
|
Series GetSeries(string seriesId, string apiKey, Uri baseUrl);
|
||||||
|
IEnumerable<SonarrEpisodes> GetEpisodes(string seriesId, string apiKey, Uri baseUrl);
|
||||||
|
SonarrEpisode GetEpisode(string episodeId, string apiKey, Uri baseUrl);
|
||||||
|
SonarrEpisode UpdateEpisode(SonarrEpisode episodeInfo, string apiKey, Uri baseUrl);
|
||||||
|
SonarrAddEpisodeResult SearchForEpisodes(int[] episodeIds, string apiKey, Uri baseUrl);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -78,8 +78,12 @@
|
||||||
<Compile Include="SickRage\SickRageShowInformation.cs" />
|
<Compile Include="SickRage\SickRageShowInformation.cs" />
|
||||||
<Compile Include="SickRage\SickRageStatus.cs" />
|
<Compile Include="SickRage\SickRageStatus.cs" />
|
||||||
<Compile Include="SickRage\SickRageTvAdd.cs" />
|
<Compile Include="SickRage\SickRageTvAdd.cs" />
|
||||||
|
<Compile Include="Sonarr\SonarrAddEpisodeBody.cs" />
|
||||||
|
<Compile Include="Sonarr\SonarrAddEpisodeResult.cs" />
|
||||||
<Compile Include="Sonarr\SonarrAddSeries.cs" />
|
<Compile Include="Sonarr\SonarrAddSeries.cs" />
|
||||||
<Compile Include="Sonarr\SonarrAllSeries.cs" />
|
<Compile Include="Sonarr\SonarrAllSeries.cs" />
|
||||||
|
<Compile Include="Sonarr\SonarrEpisode.cs" />
|
||||||
|
<Compile Include="Sonarr\SonarrEpisodes.cs" />
|
||||||
<Compile Include="Sonarr\SonarrError.cs" />
|
<Compile Include="Sonarr\SonarrError.cs" />
|
||||||
<Compile Include="Sonarr\SonarrProfile.cs" />
|
<Compile Include="Sonarr\SonarrProfile.cs" />
|
||||||
<Compile Include="Sonarr\SystemStatus.cs" />
|
<Compile Include="Sonarr\SystemStatus.cs" />
|
||||||
|
|
34
PlexRequests.Api.Models/Sonarr/SonarrAddEpisodeBody.cs
Normal file
34
PlexRequests.Api.Models/Sonarr/SonarrAddEpisodeBody.cs
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
#region Copyright
|
||||||
|
// /************************************************************************
|
||||||
|
// Copyright (c) 2016 Jamie Rees
|
||||||
|
// File: SonarrAddEpisodeBody.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.
|
||||||
|
// ************************************************************************/
|
||||||
|
#endregion
|
||||||
|
namespace PlexRequests.Api.Models.Sonarr
|
||||||
|
{
|
||||||
|
public class SonarrAddEpisodeBody
|
||||||
|
{
|
||||||
|
public string name { get; set; }
|
||||||
|
public int[] episodeIds { get; set; }
|
||||||
|
}
|
||||||
|
}
|
58
PlexRequests.Api.Models/Sonarr/SonarrAddEpisodeResult.cs
Normal file
58
PlexRequests.Api.Models/Sonarr/SonarrAddEpisodeResult.cs
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
#region Copyright
|
||||||
|
// /************************************************************************
|
||||||
|
// Copyright (c) 2016 Jamie Rees
|
||||||
|
// File: SonarrAddEpisodeResult.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.
|
||||||
|
// ************************************************************************/
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace PlexRequests.Api.Models.Sonarr
|
||||||
|
{
|
||||||
|
public class Body
|
||||||
|
{
|
||||||
|
public List<int> episodeIds { get; set; }
|
||||||
|
public bool sendUpdatesToClient { get; set; }
|
||||||
|
public bool updateScheduledTask { get; set; }
|
||||||
|
public string completionMessage { get; set; }
|
||||||
|
public string name { get; set; }
|
||||||
|
public string trigger { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class SonarrAddEpisodeResult
|
||||||
|
{
|
||||||
|
public string name { get; set; }
|
||||||
|
public Body body { get; set; }
|
||||||
|
public string priority { get; set; }
|
||||||
|
public string status { get; set; }
|
||||||
|
public string queued { get; set; }
|
||||||
|
public string trigger { get; set; }
|
||||||
|
public string state { get; set; }
|
||||||
|
public bool manual { get; set; }
|
||||||
|
public string startedOn { get; set; }
|
||||||
|
public bool sendUpdatesToClient { get; set; }
|
||||||
|
public bool updateScheduledTask { get; set; }
|
||||||
|
public int id { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
73
PlexRequests.Api.Models/Sonarr/SonarrEpisode.cs
Normal file
73
PlexRequests.Api.Models/Sonarr/SonarrEpisode.cs
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
#region Copyright
|
||||||
|
// /************************************************************************
|
||||||
|
// Copyright (c) 2016 Jamie Rees
|
||||||
|
// File: SonarrEpisode.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.
|
||||||
|
// ************************************************************************/
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
namespace PlexRequests.Api.Models.Sonarr
|
||||||
|
{
|
||||||
|
|
||||||
|
public class Revision
|
||||||
|
{
|
||||||
|
public int version { get; set; }
|
||||||
|
public int real { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class EpisodeFile
|
||||||
|
{
|
||||||
|
public int seriesId { get; set; }
|
||||||
|
public int seasonNumber { get; set; }
|
||||||
|
public string relativePath { get; set; }
|
||||||
|
public string path { get; set; }
|
||||||
|
public long size { get; set; }
|
||||||
|
public string dateAdded { get; set; }
|
||||||
|
public Quality quality { get; set; }
|
||||||
|
public bool qualityCutoffNotMet { get; set; }
|
||||||
|
public int id { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public class SonarrEpisode
|
||||||
|
{
|
||||||
|
public int seriesId { get; set; }
|
||||||
|
public int episodeFileId { get; set; }
|
||||||
|
public int seasonNumber { get; set; }
|
||||||
|
public int episodeNumber { get; set; }
|
||||||
|
public string title { get; set; }
|
||||||
|
public string airDate { get; set; }
|
||||||
|
public string airDateUtc { get; set; }
|
||||||
|
public string overview { get; set; }
|
||||||
|
public EpisodeFile episodeFile { get; set; }
|
||||||
|
public bool hasFile { get; set; }
|
||||||
|
public bool monitored { get; set; }
|
||||||
|
public int absoluteEpisodeNumber { get; set; }
|
||||||
|
public bool unverifiedSceneNumbering { get; set; }
|
||||||
|
public Series series { get; set; }
|
||||||
|
public int id { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
47
PlexRequests.Api.Models/Sonarr/SonarrEpisodes.cs
Normal file
47
PlexRequests.Api.Models/Sonarr/SonarrEpisodes.cs
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
#region Copyright
|
||||||
|
// /************************************************************************
|
||||||
|
// Copyright (c) 2016 Jamie Rees
|
||||||
|
// File: SonarrEpisodes.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.
|
||||||
|
// ************************************************************************/
|
||||||
|
#endregion
|
||||||
|
namespace PlexRequests.Api.Models.Sonarr
|
||||||
|
{
|
||||||
|
public class SonarrEpisodes
|
||||||
|
{
|
||||||
|
|
||||||
|
public int seriesId { get; set; }
|
||||||
|
public int episodeFileId { get; set; }
|
||||||
|
public int seasonNumber { get; set; }
|
||||||
|
public int episodeNumber { get; set; }
|
||||||
|
public string title { get; set; }
|
||||||
|
public string overview { get; set; }
|
||||||
|
public bool hasFile { get; set; }
|
||||||
|
public bool monitored { get; set; }
|
||||||
|
public bool unverifiedSceneNumbering { get; set; }
|
||||||
|
public int id { get; set; }
|
||||||
|
public string airDate { get; set; }
|
||||||
|
public string airDateUtc { get; set; }
|
||||||
|
public int? absoluteEpisodeNumber { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -63,11 +63,11 @@ namespace PlexRequests.Api
|
||||||
request.AddUrlSegment("imdbid", imdbid);
|
request.AddUrlSegment("imdbid", imdbid);
|
||||||
request.AddUrlSegment("title", title);
|
request.AddUrlSegment("title", title);
|
||||||
|
|
||||||
var obj = RetryHandler.Execute(() => Api.ExecuteJson<JObject>(request, baseUrl), new[] {
|
var obj = RetryHandler.Execute(() => Api.ExecuteJson<JObject>(request, baseUrl),
|
||||||
TimeSpan.FromSeconds (2),
|
(exception, timespan) => Log.Error(exception, "Exception when calling AddMovie for CP, Retrying {0}", timespan), new[] {
|
||||||
TimeSpan.FromSeconds(5),
|
TimeSpan.FromSeconds (2),
|
||||||
TimeSpan.FromSeconds(10)},
|
TimeSpan.FromSeconds(5),
|
||||||
(exception, timespan) => Log.Error(exception, "Exception when calling AddMovie for CP, Retrying {0}", timespan));
|
TimeSpan.FromSeconds(10)});
|
||||||
|
|
||||||
|
|
||||||
if (obj.Count > 0)
|
if (obj.Count > 0)
|
||||||
|
@ -103,11 +103,11 @@ namespace PlexRequests.Api
|
||||||
request.AddUrlSegment("apikey", apiKey);
|
request.AddUrlSegment("apikey", apiKey);
|
||||||
|
|
||||||
|
|
||||||
var obj = RetryHandler.Execute<CouchPotatoStatus>(() => Api.Execute<CouchPotatoStatus>(request, url), new TimeSpan[] {
|
var obj = RetryHandler.Execute<CouchPotatoStatus>(() => Api.Execute<CouchPotatoStatus>(request, url),
|
||||||
TimeSpan.FromSeconds (2),
|
(exception, timespan) => Log.Error(exception, "Exception when calling GetStatus for CP, Retrying {0}", timespan), new TimeSpan[] {
|
||||||
TimeSpan.FromSeconds(5),
|
TimeSpan.FromSeconds (2),
|
||||||
TimeSpan.FromSeconds(10)},
|
TimeSpan.FromSeconds(5),
|
||||||
(exception, timespan) => Log.Error(exception, "Exception when calling GetStatus for CP, Retrying {0}", timespan));
|
TimeSpan.FromSeconds(10)});
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
@ -122,8 +122,8 @@ namespace PlexRequests.Api
|
||||||
|
|
||||||
request.AddUrlSegment("apikey", apiKey);
|
request.AddUrlSegment("apikey", apiKey);
|
||||||
|
|
||||||
var obj = RetryHandler.Execute(() => Api.Execute<CouchPotatoProfiles>(request, url), null,
|
var obj = RetryHandler.Execute(() => Api.Execute<CouchPotatoProfiles>(request, url),
|
||||||
(exception, timespan) => Log.Error(exception, "Exception when calling GetProfiles for CP, Retrying {0}", timespan));
|
(exception, timespan) => Log.Error(exception, "Exception when calling GetProfiles for CP, Retrying {0}", timespan), null);
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
@ -144,12 +144,11 @@ namespace PlexRequests.Api
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var obj = RetryHandler.Execute(() => Api.Execute<CouchPotatoMovies>(request, baseUrl),
|
var obj = RetryHandler.Execute(() => Api.Execute<CouchPotatoMovies>(request, baseUrl),
|
||||||
new[] {
|
(exception, timespan) => Log.Error(exception, "Exception when calling GetMovies for CP, Retrying {0}", timespan), new[] {
|
||||||
TimeSpan.FromSeconds (5),
|
TimeSpan.FromSeconds (5),
|
||||||
TimeSpan.FromSeconds(10),
|
TimeSpan.FromSeconds(10),
|
||||||
TimeSpan.FromSeconds(30)
|
TimeSpan.FromSeconds(30)
|
||||||
},
|
});
|
||||||
(exception, timespan) => Log.Error(exception, "Exception when calling GetMovies for CP, Retrying {0}", timespan));
|
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
@ -172,8 +171,8 @@ namespace PlexRequests.Api
|
||||||
request.AddUrlSegment("username", StringHasher.CalcuateMd5Hash(username));
|
request.AddUrlSegment("username", StringHasher.CalcuateMd5Hash(username));
|
||||||
request.AddUrlSegment("password", StringHasher.CalcuateMd5Hash(password));
|
request.AddUrlSegment("password", StringHasher.CalcuateMd5Hash(password));
|
||||||
|
|
||||||
var obj = RetryHandler.Execute(() => Api.Execute<CoucPotatoApiKey>(request, baseUrl), null,
|
var obj = RetryHandler.Execute(() => Api.Execute<CoucPotatoApiKey>(request, baseUrl),
|
||||||
(exception, timespan) => Log.Error(exception, "Exception when calling GetApiKey for CP, Retrying {0}", timespan));
|
(exception, timespan) => Log.Error(exception, "Exception when calling GetApiKey for CP, Retrying {0}", timespan), null);
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,64 +1,89 @@
|
||||||
#region Copyright
|
#region Copyright
|
||||||
// /************************************************************************
|
// /************************************************************************
|
||||||
// Copyright (c) 2016 Jamie Rees
|
// Copyright (c) 2016 Jamie Rees
|
||||||
// File: MockSonarrApi.cs
|
// File: MockSonarrApi.cs
|
||||||
// Created By: Jamie Rees
|
// Created By: Jamie Rees
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining
|
// Permission is hereby granted, free of charge, to any person obtaining
|
||||||
// a copy of this software and associated documentation files (the
|
// a copy of this software and associated documentation files (the
|
||||||
// "Software"), to deal in the Software without restriction, including
|
// "Software"), to deal in the Software without restriction, including
|
||||||
// without limitation the rights to use, copy, modify, merge, publish,
|
// without limitation the rights to use, copy, modify, merge, publish,
|
||||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
// permit persons to whom the Software is furnished to do so, subject to
|
// permit persons to whom the Software is furnished to do so, subject to
|
||||||
// the following conditions:
|
// the following conditions:
|
||||||
//
|
//
|
||||||
// The above copyright notice and this permission notice shall be
|
// The above copyright notice and this permission notice shall be
|
||||||
// included in all copies or substantial portions of the Software.
|
// included in all copies or substantial portions of the Software.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
// ************************************************************************/
|
// ************************************************************************/
|
||||||
#endregion
|
#endregion
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
using PlexRequests.Api.Interfaces;
|
using PlexRequests.Api.Interfaces;
|
||||||
using PlexRequests.Api.Models.Sonarr;
|
using PlexRequests.Api.Models.Sonarr;
|
||||||
|
|
||||||
namespace PlexRequests.Api.Mocks
|
namespace PlexRequests.Api.Mocks
|
||||||
{
|
{
|
||||||
public class MockSonarrApi : ISonarrApi
|
public class MockSonarrApi : ISonarrApi
|
||||||
{
|
{
|
||||||
public List<SonarrProfile> GetProfiles(string apiKey, Uri baseUrl)
|
public List<SonarrProfile> GetProfiles(string apiKey, Uri baseUrl)
|
||||||
{
|
{
|
||||||
var json = MockApiData.Sonarr_Profiles;
|
var json = MockApiData.Sonarr_Profiles;
|
||||||
var obj = JsonConvert.DeserializeObject<List<SonarrProfile>>(json);
|
var obj = JsonConvert.DeserializeObject<List<SonarrProfile>>(json);
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SonarrAddSeries AddSeries(int tvdbId, string title, int qualityId, bool seasonFolders, string rootPath, int seasonCount, int[] seasons,
|
public SonarrAddSeries AddSeries(int tvdbId, string title, int qualityId, bool seasonFolders, string rootPath, int seasonCount, int[] seasons,
|
||||||
string apiKey, Uri baseUrl)
|
string apiKey, Uri baseUrl)
|
||||||
{
|
{
|
||||||
var json = MockApiData.Sonarr_AddSeriesResult;
|
var json = MockApiData.Sonarr_AddSeriesResult;
|
||||||
var obj = JsonConvert.DeserializeObject<SonarrAddSeries>(json);
|
var obj = JsonConvert.DeserializeObject<SonarrAddSeries>(json);
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SystemStatus SystemStatus(string apiKey, Uri baseUrl)
|
public SystemStatus SystemStatus(string apiKey, Uri baseUrl)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Series> GetSeries(string apiKey, Uri baseUrl)
|
public List<Series> GetSeries(string apiKey, Uri baseUrl)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public Series GetSeries(string seriesId, string apiKey, Uri baseUrl)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<SonarrEpisodes> GetEpisodes(string seriesId, string apiKey, Uri baseUrl)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public SonarrEpisode GetEpisode(string episodeId, string apiKey, Uri baseUrl)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public SonarrEpisode UpdateEpisode(SonarrEpisode episodeInfo, string apiKey, Uri baseUrl)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public SonarrAddEpisodeResult SearchForEpisodes(int[] episodeIds, string apiKey, Uri baseUrl)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -1,268 +1,260 @@
|
||||||
#region Copyright
|
#region Copyright
|
||||||
// /************************************************************************
|
// /************************************************************************
|
||||||
// Copyright (c) 2016 Jamie Rees
|
// Copyright (c) 2016 Jamie Rees
|
||||||
// File: PlexApi.cs
|
// File: PlexApi.cs
|
||||||
// Created By: Jamie Rees
|
// Created By: Jamie Rees
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining
|
// Permission is hereby granted, free of charge, to any person obtaining
|
||||||
// a copy of this software and associated documentation files (the
|
// a copy of this software and associated documentation files (the
|
||||||
// "Software"), to deal in the Software without restriction, including
|
// "Software"), to deal in the Software without restriction, including
|
||||||
// without limitation the rights to use, copy, modify, merge, publish,
|
// without limitation the rights to use, copy, modify, merge, publish,
|
||||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
// permit persons to whom the Software is furnished to do so, subject to
|
// permit persons to whom the Software is furnished to do so, subject to
|
||||||
// the following conditions:
|
// the following conditions:
|
||||||
//
|
//
|
||||||
// The above copyright notice and this permission notice shall be
|
// The above copyright notice and this permission notice shall be
|
||||||
// included in all copies or substantial portions of the Software.
|
// included in all copies or substantial portions of the Software.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
// ************************************************************************/
|
// ************************************************************************/
|
||||||
using Polly;
|
using Polly;
|
||||||
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
using NLog;
|
using NLog;
|
||||||
|
|
||||||
using PlexRequests.Api.Interfaces;
|
using PlexRequests.Api.Interfaces;
|
||||||
using PlexRequests.Api.Models.Plex;
|
using PlexRequests.Api.Models.Plex;
|
||||||
using PlexRequests.Helpers;
|
using PlexRequests.Helpers;
|
||||||
using PlexRequests.Helpers.Exceptions;
|
using PlexRequests.Helpers.Exceptions;
|
||||||
|
|
||||||
using RestSharp;
|
using RestSharp;
|
||||||
|
|
||||||
namespace PlexRequests.Api
|
namespace PlexRequests.Api
|
||||||
{
|
{
|
||||||
public class PlexApi : IPlexApi
|
public class PlexApi : IPlexApi
|
||||||
{
|
{
|
||||||
static PlexApi()
|
static PlexApi()
|
||||||
{
|
{
|
||||||
Version = AssemblyHelper.GetAssemblyVersion();
|
Version = AssemblyHelper.GetAssemblyVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlexApi (IApiRequest api)
|
public PlexApi (IApiRequest api)
|
||||||
{
|
{
|
||||||
Api = api;
|
Api = api;
|
||||||
}
|
}
|
||||||
|
|
||||||
private IApiRequest Api { get; }
|
private IApiRequest Api { get; }
|
||||||
|
|
||||||
private const string SignInUri = "https://plex.tv/users/sign_in.json";
|
private const string SignInUri = "https://plex.tv/users/sign_in.json";
|
||||||
private const string FriendsUri = "https://plex.tv/pms/friends/all";
|
private const string FriendsUri = "https://plex.tv/pms/friends/all";
|
||||||
private const string GetAccountUri = "https://plex.tv/users/account";
|
private const string GetAccountUri = "https://plex.tv/users/account";
|
||||||
|
|
||||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||||
private static string Version { get; }
|
private static string Version { get; }
|
||||||
|
|
||||||
public PlexAuthentication SignIn(string username, string password)
|
public PlexAuthentication SignIn(string username, string password)
|
||||||
{
|
{
|
||||||
var userModel = new PlexUserRequest
|
var userModel = new PlexUserRequest
|
||||||
{
|
{
|
||||||
user = new UserRequest
|
user = new UserRequest
|
||||||
{
|
{
|
||||||
password = password,
|
password = password,
|
||||||
login = username
|
login = username
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
var request = new RestRequest
|
var request = new RestRequest
|
||||||
{
|
{
|
||||||
Method = Method.POST
|
Method = Method.POST
|
||||||
};
|
};
|
||||||
|
|
||||||
AddHeaders(ref request);
|
AddHeaders(ref request);
|
||||||
|
|
||||||
request.AddJsonBody(userModel);
|
request.AddJsonBody(userModel);
|
||||||
|
|
||||||
var obj = RetryHandler.Execute<PlexAuthentication>(() => Api.Execute<PlexAuthentication> (request, new Uri(SignInUri)),
|
var obj = RetryHandler.Execute<PlexAuthentication>(() => Api.Execute<PlexAuthentication> (request, new Uri(SignInUri)),
|
||||||
null,
|
(exception, timespan) => Log.Error (exception, "Exception when calling SignIn for Plex, Retrying {0}", timespan), null);
|
||||||
(exception, timespan) => Log.Error (exception, "Exception when calling SignIn for Plex, Retrying {0}", timespan));
|
|
||||||
|
return obj;
|
||||||
return obj;
|
}
|
||||||
}
|
|
||||||
|
public PlexFriends GetUsers(string authToken)
|
||||||
public PlexFriends GetUsers(string authToken)
|
{
|
||||||
{
|
var request = new RestRequest
|
||||||
var request = new RestRequest
|
{
|
||||||
{
|
Method = Method.GET,
|
||||||
Method = Method.GET,
|
};
|
||||||
};
|
|
||||||
|
AddHeaders(ref request, authToken);
|
||||||
AddHeaders(ref request, authToken);
|
|
||||||
|
var users = RetryHandler.Execute(() => Api.ExecuteXml<PlexFriends> (request, new Uri(FriendsUri)),
|
||||||
var users = RetryHandler.Execute(() => Api.ExecuteXml<PlexFriends> (request, new Uri(FriendsUri)),
|
(exception, timespan) => Log.Error (exception, "Exception when calling GetUsers for Plex, Retrying {0}", timespan), null);
|
||||||
null,
|
|
||||||
(exception, timespan) => Log.Error (exception, "Exception when calling GetUsers for Plex, Retrying {0}", timespan));
|
|
||||||
|
return users;
|
||||||
|
}
|
||||||
return users;
|
|
||||||
}
|
/// <summary>
|
||||||
|
/// Gets the users.
|
||||||
/// <summary>
|
/// </summary>
|
||||||
/// Gets the users.
|
/// <param name="authToken">The authentication token.</param>
|
||||||
/// </summary>
|
/// <param name="searchTerm">The search term.</param>
|
||||||
/// <param name="authToken">The authentication token.</param>
|
/// <param name="plexFullHost">The full plex host.</param>
|
||||||
/// <param name="searchTerm">The search term.</param>
|
/// <returns></returns>
|
||||||
/// <param name="plexFullHost">The full plex host.</param>
|
public PlexSearch SearchContent(string authToken, string searchTerm, Uri plexFullHost)
|
||||||
/// <returns></returns>
|
{
|
||||||
public PlexSearch SearchContent(string authToken, string searchTerm, Uri plexFullHost)
|
var request = new RestRequest
|
||||||
{
|
{
|
||||||
var request = new RestRequest
|
Method = Method.GET,
|
||||||
{
|
Resource = "search?query={searchTerm}"
|
||||||
Method = Method.GET,
|
};
|
||||||
Resource = "search?query={searchTerm}"
|
|
||||||
};
|
request.AddUrlSegment("searchTerm", searchTerm);
|
||||||
|
AddHeaders(ref request, authToken);
|
||||||
request.AddUrlSegment("searchTerm", searchTerm);
|
|
||||||
AddHeaders(ref request, authToken);
|
var search = RetryHandler.Execute<PlexSearch>(() => Api.ExecuteXml<PlexSearch> (request, plexFullHost),
|
||||||
|
(exception, timespan) => Log.Error (exception, "Exception when calling SearchContent for Plex, Retrying {0}", timespan), null);
|
||||||
var search = RetryHandler.Execute<PlexSearch>(() => Api.ExecuteXml<PlexSearch> (request, plexFullHost),
|
|
||||||
null,
|
return search;
|
||||||
(exception, timespan) => Log.Error (exception, "Exception when calling SearchContent for Plex, Retrying {0}", timespan));
|
}
|
||||||
|
|
||||||
return search;
|
public PlexStatus GetStatus(string authToken, Uri uri)
|
||||||
}
|
{
|
||||||
|
var request = new RestRequest
|
||||||
public PlexStatus GetStatus(string authToken, Uri uri)
|
{
|
||||||
{
|
Method = Method.GET,
|
||||||
var request = new RestRequest
|
};
|
||||||
{
|
|
||||||
Method = Method.GET,
|
AddHeaders(ref request, authToken);
|
||||||
};
|
|
||||||
|
var users = RetryHandler.Execute<PlexStatus>(() => Api.ExecuteXml<PlexStatus> (request, uri),
|
||||||
AddHeaders(ref request, authToken);
|
(exception, timespan) => Log.Error (exception, "Exception when calling GetStatus for Plex, Retrying {0}", timespan), null);
|
||||||
|
|
||||||
var users = RetryHandler.Execute<PlexStatus>(() => Api.ExecuteXml<PlexStatus> (request, uri),
|
return users;
|
||||||
null,
|
}
|
||||||
(exception, timespan) => Log.Error (exception, "Exception when calling GetStatus for Plex, Retrying {0}", timespan));
|
|
||||||
|
public PlexAccount GetAccount(string authToken)
|
||||||
return users;
|
{
|
||||||
}
|
var request = new RestRequest
|
||||||
|
{
|
||||||
public PlexAccount GetAccount(string authToken)
|
Method = Method.GET,
|
||||||
{
|
};
|
||||||
var request = new RestRequest
|
|
||||||
{
|
AddHeaders(ref request, authToken);
|
||||||
Method = Method.GET,
|
|
||||||
};
|
var account = RetryHandler.Execute<PlexAccount>(() => Api.ExecuteXml<PlexAccount> (request, new Uri(GetAccountUri)),
|
||||||
|
(exception, timespan) => Log.Error (exception, "Exception when calling GetAccount for Plex, Retrying {0}", timespan), null);
|
||||||
AddHeaders(ref request, authToken);
|
|
||||||
|
return account;
|
||||||
var account = RetryHandler.Execute<PlexAccount>(() => Api.ExecuteXml<PlexAccount> (request, new Uri(GetAccountUri)),
|
}
|
||||||
null,
|
|
||||||
(exception, timespan) => Log.Error (exception, "Exception when calling GetAccount for Plex, Retrying {0}", timespan));
|
public PlexLibraries GetLibrarySections(string authToken, Uri plexFullHost)
|
||||||
|
{
|
||||||
return account;
|
var request = new RestRequest
|
||||||
}
|
{
|
||||||
|
Method = Method.GET,
|
||||||
public PlexLibraries GetLibrarySections(string authToken, Uri plexFullHost)
|
Resource = "library/sections"
|
||||||
{
|
};
|
||||||
var request = new RestRequest
|
|
||||||
{
|
AddHeaders(ref request, authToken);
|
||||||
Method = Method.GET,
|
|
||||||
Resource = "library/sections"
|
try
|
||||||
};
|
{
|
||||||
|
var lib = RetryHandler.Execute<PlexLibraries>(() => Api.ExecuteXml<PlexLibraries> (request, plexFullHost),
|
||||||
AddHeaders(ref request, authToken);
|
(exception, timespan) => Log.Error (exception, "Exception when calling GetLibrarySections for Plex, Retrying {0}", timespan), new TimeSpan[] {
|
||||||
|
TimeSpan.FromSeconds (5),
|
||||||
try
|
TimeSpan.FromSeconds(10),
|
||||||
{
|
TimeSpan.FromSeconds(30)
|
||||||
var lib = RetryHandler.Execute<PlexLibraries>(() => Api.ExecuteXml<PlexLibraries> (request, plexFullHost),
|
});
|
||||||
new TimeSpan[] {
|
|
||||||
TimeSpan.FromSeconds (5),
|
return lib;
|
||||||
TimeSpan.FromSeconds(10),
|
}
|
||||||
TimeSpan.FromSeconds(30)
|
catch (Exception e)
|
||||||
},
|
{
|
||||||
(exception, timespan) => Log.Error (exception, "Exception when calling GetLibrarySections for Plex, Retrying {0}", timespan));
|
Log.Error(e,"There has been a API Exception when attempting to get the Plex Libraries");
|
||||||
|
return new PlexLibraries();
|
||||||
return lib;
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
|
||||||
{
|
public PlexSearch GetLibrary(string authToken, Uri plexFullHost, string libraryId)
|
||||||
Log.Error(e,"There has been a API Exception when attempting to get the Plex Libraries");
|
{
|
||||||
return new PlexLibraries();
|
var request = new RestRequest
|
||||||
}
|
{
|
||||||
}
|
Method = Method.GET,
|
||||||
|
Resource = "library/sections/{libraryId}/all"
|
||||||
public PlexSearch GetLibrary(string authToken, Uri plexFullHost, string libraryId)
|
};
|
||||||
{
|
|
||||||
var request = new RestRequest
|
request.AddUrlSegment("libraryId", libraryId);
|
||||||
{
|
AddHeaders(ref request, authToken);
|
||||||
Method = Method.GET,
|
|
||||||
Resource = "library/sections/{libraryId}/all"
|
try
|
||||||
};
|
{
|
||||||
|
var lib = RetryHandler.Execute<PlexSearch>(() => Api.ExecuteXml<PlexSearch> (request, plexFullHost),
|
||||||
request.AddUrlSegment("libraryId", libraryId);
|
(exception, timespan) => Log.Error (exception, "Exception when calling GetLibrary for Plex, Retrying {0}", timespan), new TimeSpan[] {
|
||||||
AddHeaders(ref request, authToken);
|
TimeSpan.FromSeconds (5),
|
||||||
|
TimeSpan.FromSeconds(10),
|
||||||
try
|
TimeSpan.FromSeconds(30)
|
||||||
{
|
});
|
||||||
var lib = RetryHandler.Execute<PlexSearch>(() => Api.ExecuteXml<PlexSearch> (request, plexFullHost),
|
|
||||||
new TimeSpan[] {
|
return lib;
|
||||||
TimeSpan.FromSeconds (5),
|
}
|
||||||
TimeSpan.FromSeconds(10),
|
catch (Exception e)
|
||||||
TimeSpan.FromSeconds(30)
|
{
|
||||||
},
|
Log.Error(e,"There has been a API Exception when attempting to get the Plex Library");
|
||||||
(exception, timespan) => Log.Error (exception, "Exception when calling GetLibrary for Plex, Retrying {0}", timespan));
|
return new PlexSearch();
|
||||||
|
}
|
||||||
return lib;
|
}
|
||||||
}
|
|
||||||
catch (Exception e)
|
public PlexMetadata GetMetadata(string authToken, Uri plexFullHost, string itemId)
|
||||||
{
|
{
|
||||||
Log.Error(e,"There has been a API Exception when attempting to get the Plex Library");
|
var request = new RestRequest
|
||||||
return new PlexSearch();
|
{
|
||||||
}
|
Method = Method.GET,
|
||||||
}
|
Resource = "library/metadata/{itemId}"
|
||||||
|
};
|
||||||
public PlexMetadata GetMetadata(string authToken, Uri plexFullHost, string itemId)
|
|
||||||
{
|
request.AddUrlSegment("itemId", itemId);
|
||||||
var request = new RestRequest
|
AddHeaders(ref request, authToken);
|
||||||
{
|
|
||||||
Method = Method.GET,
|
try
|
||||||
Resource = "library/metadata/{itemId}"
|
{
|
||||||
};
|
var lib = RetryHandler.Execute(() => Api.ExecuteXml<PlexMetadata>(request, plexFullHost),
|
||||||
|
(exception, timespan) => Log.Error(exception, "Exception when calling GetMetadata for Plex, Retrying {0}", timespan), new[] {
|
||||||
request.AddUrlSegment("itemId", itemId);
|
TimeSpan.FromSeconds (5),
|
||||||
AddHeaders(ref request, authToken);
|
TimeSpan.FromSeconds(10),
|
||||||
|
TimeSpan.FromSeconds(30)
|
||||||
try
|
});
|
||||||
{
|
|
||||||
var lib = RetryHandler.Execute(() => Api.ExecuteXml<PlexMetadata>(request, plexFullHost),
|
return lib;
|
||||||
new[] {
|
}
|
||||||
TimeSpan.FromSeconds (5),
|
catch (Exception e)
|
||||||
TimeSpan.FromSeconds(10),
|
{
|
||||||
TimeSpan.FromSeconds(30)
|
Log.Error(e, "There has been a API Exception when attempting to get the Plex GetMetadata");
|
||||||
},
|
return new PlexMetadata();
|
||||||
(exception, timespan) => Log.Error(exception, "Exception when calling GetMetadata for Plex, Retrying {0}", timespan));
|
}
|
||||||
|
}
|
||||||
return lib;
|
|
||||||
}
|
private void AddHeaders(ref RestRequest request, string authToken)
|
||||||
catch (Exception e)
|
{
|
||||||
{
|
request.AddHeader("X-Plex-Token", authToken);
|
||||||
Log.Error(e, "There has been a API Exception when attempting to get the Plex GetMetadata");
|
AddHeaders(ref request);
|
||||||
return new PlexMetadata();
|
}
|
||||||
}
|
|
||||||
}
|
private void AddHeaders(ref RestRequest request)
|
||||||
|
{
|
||||||
private void AddHeaders(ref RestRequest request, string authToken)
|
request.AddHeader("X-Plex-Client-Identifier", "Test213");
|
||||||
{
|
request.AddHeader("X-Plex-Product", "Request Plex");
|
||||||
request.AddHeader("X-Plex-Token", authToken);
|
request.AddHeader("X-Plex-Version", Version);
|
||||||
AddHeaders(ref request);
|
request.AddHeader("Content-Type", "application/xml");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
private void AddHeaders(ref RestRequest request)
|
}
|
||||||
{
|
|
||||||
request.AddHeader("X-Plex-Client-Identifier", "Test213");
|
|
||||||
request.AddHeader("X-Plex-Product", "Request Plex");
|
|
||||||
request.AddHeader("X-Plex-Version", Version);
|
|
||||||
request.AddHeader("Content-Type", "application/xml");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -35,25 +35,29 @@ namespace PlexRequests.Api
|
||||||
{
|
{
|
||||||
private static readonly TimeSpan[] DefaultTime = { TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(10) };
|
private static readonly TimeSpan[] DefaultTime = { TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(10) };
|
||||||
|
|
||||||
public static T Execute<T>(Func<T> action, TimeSpan[] timeSpan)
|
public static T Execute<T>(Func<T> action, TimeSpan[] timeSpan = null)
|
||||||
{
|
|
||||||
var policy = RetryAndWaitPolicy(timeSpan);
|
|
||||||
|
|
||||||
return policy.Execute(action);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static T Execute<T>(Func<T> func, TimeSpan[] timeSpan, Action<Exception, TimeSpan> action)
|
|
||||||
{
|
{
|
||||||
if (timeSpan == null)
|
if (timeSpan == null)
|
||||||
{
|
{
|
||||||
timeSpan = DefaultTime;
|
timeSpan = DefaultTime;
|
||||||
}
|
}
|
||||||
var policy = RetryAndWaitPolicy(timeSpan, action);
|
var policy = RetryAndWaitPolicy(timeSpan);
|
||||||
|
|
||||||
|
return policy.Execute(action);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static T Execute<T>(Func<T> func, Action<Exception, TimeSpan> action, TimeSpan[] timeSpan = null)
|
||||||
|
{
|
||||||
|
if (timeSpan == null)
|
||||||
|
{
|
||||||
|
timeSpan = DefaultTime;
|
||||||
|
}
|
||||||
|
var policy = RetryAndWaitPolicy(action, timeSpan);
|
||||||
|
|
||||||
return policy.Execute(func);
|
return policy.Execute(func);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static RetryPolicy RetryAndWaitPolicy(TimeSpan[] timeSpan, Action action)
|
public static RetryPolicy RetryAndWaitPolicy(Action action, TimeSpan[] timeSpan = null)
|
||||||
{
|
{
|
||||||
if (timeSpan == null)
|
if (timeSpan == null)
|
||||||
{
|
{
|
||||||
|
@ -75,7 +79,7 @@ namespace PlexRequests.Api
|
||||||
return policy;
|
return policy;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static RetryPolicy RetryAndWaitPolicy(TimeSpan[] timeSpan, Action<Exception, TimeSpan> action)
|
public static RetryPolicy RetryAndWaitPolicy(Action<Exception, TimeSpan> action, TimeSpan[] timeSpan = null)
|
||||||
{
|
{
|
||||||
if (timeSpan == null)
|
if (timeSpan == null)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,227 +1,217 @@
|
||||||
#region Copyright
|
#region Copyright
|
||||||
// /************************************************************************
|
// /************************************************************************
|
||||||
// Copyright (c) 2016 Jamie Rees
|
// Copyright (c) 2016 Jamie Rees
|
||||||
// File: SickrageApi.cs
|
// File: SickrageApi.cs
|
||||||
// Created By: Jamie Rees
|
// Created By: Jamie Rees
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining
|
// Permission is hereby granted, free of charge, to any person obtaining
|
||||||
// a copy of this software and associated documentation files (the
|
// a copy of this software and associated documentation files (the
|
||||||
// "Software"), to deal in the Software without restriction, including
|
// "Software"), to deal in the Software without restriction, including
|
||||||
// without limitation the rights to use, copy, modify, merge, publish,
|
// without limitation the rights to use, copy, modify, merge, publish,
|
||||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
// permit persons to whom the Software is furnished to do so, subject to
|
// permit persons to whom the Software is furnished to do so, subject to
|
||||||
// the following conditions:
|
// the following conditions:
|
||||||
//
|
//
|
||||||
// The above copyright notice and this permission notice shall be
|
// The above copyright notice and this permission notice shall be
|
||||||
// included in all copies or substantial portions of the Software.
|
// included in all copies or substantial portions of the Software.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
// ************************************************************************/
|
// ************************************************************************/
|
||||||
#endregion
|
#endregion
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
using NLog;
|
using NLog;
|
||||||
|
|
||||||
using PlexRequests.Api.Interfaces;
|
using PlexRequests.Api.Interfaces;
|
||||||
using PlexRequests.Api.Models.SickRage;
|
using PlexRequests.Api.Models.SickRage;
|
||||||
using PlexRequests.Helpers;
|
using PlexRequests.Helpers;
|
||||||
using PlexRequests.Helpers.Exceptions;
|
using PlexRequests.Helpers.Exceptions;
|
||||||
|
|
||||||
using RestSharp;
|
using RestSharp;
|
||||||
|
|
||||||
namespace PlexRequests.Api
|
namespace PlexRequests.Api
|
||||||
{
|
{
|
||||||
public class SickrageApi : ISickRageApi
|
public class SickrageApi : ISickRageApi
|
||||||
{
|
{
|
||||||
private static readonly Logger Log = LogManager.GetCurrentClassLogger();
|
private static readonly Logger Log = LogManager.GetCurrentClassLogger();
|
||||||
|
|
||||||
public SickrageApi()
|
public SickrageApi()
|
||||||
{
|
{
|
||||||
Api = new ApiRequest();
|
Api = new ApiRequest();
|
||||||
}
|
}
|
||||||
|
|
||||||
private ApiRequest Api { get; }
|
private ApiRequest Api { get; }
|
||||||
|
|
||||||
public SickRageSeasonList VerifyShowHasLoaded(int tvdbId, string apiKey, Uri baseUrl)
|
public SickRageSeasonList VerifyShowHasLoaded(int tvdbId, string apiKey, Uri baseUrl)
|
||||||
{
|
{
|
||||||
Log.Trace("Entered `VerifyShowHasLoaded({0} <- id)`", tvdbId);
|
Log.Trace("Entered `VerifyShowHasLoaded({0} <- id)`", tvdbId);
|
||||||
var request = new RestRequest { Resource = "/api/{apiKey}/?cmd=show.seasonlist", Method = Method.GET };
|
var request = new RestRequest { Resource = "/api/{apiKey}/?cmd=show.seasonlist", Method = Method.GET };
|
||||||
request.AddUrlSegment("apiKey", apiKey);
|
request.AddUrlSegment("apiKey", apiKey);
|
||||||
request.AddQueryParameter("tvdbid", tvdbId.ToString());
|
request.AddQueryParameter("tvdbid", tvdbId.ToString());
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var policy = RetryHandler.RetryAndWaitPolicy(
|
var policy = RetryHandler.RetryAndWaitPolicy((exception, timespan) => Log.Error(exception, "Exception when calling VerifyShowHasLoaded for SR, Retrying {0}", timespan), null);
|
||||||
null,
|
|
||||||
(exception, timespan) => Log.Error(exception, "Exception when calling VerifyShowHasLoaded for SR, Retrying {0}", timespan));
|
var obj = policy.Execute(() => Api.ExecuteJson<SickRageSeasonList>(request, baseUrl));
|
||||||
|
return obj;
|
||||||
var obj = policy.Execute(() => Api.ExecuteJson<SickRageSeasonList>(request, baseUrl));
|
}
|
||||||
return obj;
|
catch (Exception e)
|
||||||
}
|
{
|
||||||
catch (Exception e)
|
Log.Error(e);
|
||||||
{
|
return new SickRageSeasonList();
|
||||||
Log.Error(e);
|
}
|
||||||
return new SickRageSeasonList();
|
}
|
||||||
}
|
|
||||||
}
|
public async Task<SickRageTvAdd> AddSeries(int tvdbId, int seasonCount, int[] seasons, string quality, string apiKey, Uri baseUrl)
|
||||||
|
{
|
||||||
public async Task<SickRageTvAdd> AddSeries(int tvdbId, int seasonCount, int[] seasons, string quality, string apiKey, Uri baseUrl)
|
var futureStatus = seasons.Length > 0 && !seasons.Any(x => x == seasonCount) ? SickRageStatus.Skipped : SickRageStatus.Wanted;
|
||||||
{
|
var status = seasons.Length > 0 ? SickRageStatus.Skipped : SickRageStatus.Wanted;
|
||||||
var futureStatus = seasons.Length > 0 && !seasons.Any(x => x == seasonCount) ? SickRageStatus.Skipped : SickRageStatus.Wanted;
|
|
||||||
var status = seasons.Length > 0 ? SickRageStatus.Skipped : SickRageStatus.Wanted;
|
Log.Trace("Future Status: {0}", futureStatus);
|
||||||
|
Log.Trace("Current Status: {0}", status);
|
||||||
Log.Trace("Future Status: {0}", futureStatus);
|
|
||||||
Log.Trace("Current Status: {0}", status);
|
var request = new RestRequest { Resource = "/api/{apiKey}/?cmd=show.addnew", Method = Method.GET };
|
||||||
|
request.AddUrlSegment("apiKey", apiKey);
|
||||||
var request = new RestRequest { Resource = "/api/{apiKey}/?cmd=show.addnew", Method = Method.GET };
|
request.AddQueryParameter("tvdbid", tvdbId.ToString());
|
||||||
request.AddUrlSegment("apiKey", apiKey);
|
request.AddQueryParameter("status", status);
|
||||||
request.AddQueryParameter("tvdbid", tvdbId.ToString());
|
request.AddQueryParameter("future_status", futureStatus);
|
||||||
request.AddQueryParameter("status", status);
|
if (!quality.Equals("default", StringComparison.CurrentCultureIgnoreCase))
|
||||||
request.AddQueryParameter("future_status", futureStatus);
|
{
|
||||||
if (!quality.Equals("default", StringComparison.CurrentCultureIgnoreCase))
|
Log.Trace("Settings quality to {0}", quality);
|
||||||
{
|
request.AddQueryParameter("initial", quality);
|
||||||
Log.Trace("Settings quality to {0}", quality);
|
}
|
||||||
request.AddQueryParameter("initial", quality);
|
|
||||||
}
|
var policy = RetryHandler.RetryAndWaitPolicy((exception, timespan) => Log.Error(exception, "Exception when calling AddSeries for SR, Retrying {0}", timespan), null);
|
||||||
|
|
||||||
var policy = RetryHandler.RetryAndWaitPolicy(
|
var obj = policy.Execute(() => Api.Execute<SickRageTvAdd>(request, baseUrl));
|
||||||
null,
|
Log.Trace("obj Result:");
|
||||||
(exception, timespan) => Log.Error(exception, "Exception when calling AddSeries for SR, Retrying {0}", timespan));
|
Log.Trace(obj.DumpJson());
|
||||||
|
|
||||||
var obj = policy.Execute(() => Api.Execute<SickRageTvAdd>(request, baseUrl));
|
if (obj.result != "failure")
|
||||||
Log.Trace("obj Result:");
|
{
|
||||||
Log.Trace(obj.DumpJson());
|
var sw = new Stopwatch();
|
||||||
|
sw.Start();
|
||||||
if (obj.result != "failure")
|
|
||||||
{
|
var seasonIncrement = 0;
|
||||||
var sw = new Stopwatch();
|
var seasonList = new SickRageSeasonList();
|
||||||
sw.Start();
|
try
|
||||||
|
{
|
||||||
var seasonIncrement = 0;
|
while (seasonIncrement < seasonCount)
|
||||||
var seasonList = new SickRageSeasonList();
|
{
|
||||||
try
|
seasonList = VerifyShowHasLoaded(tvdbId, apiKey, baseUrl);
|
||||||
{
|
if (seasonList.result.Equals("failure"))
|
||||||
while (seasonIncrement < seasonCount)
|
{
|
||||||
{
|
Thread.Sleep(3000);
|
||||||
seasonList = VerifyShowHasLoaded(tvdbId, apiKey, baseUrl);
|
continue;
|
||||||
if (seasonList.result.Equals("failure"))
|
}
|
||||||
{
|
seasonIncrement = seasonList.Data?.Length ?? 0;
|
||||||
Thread.Sleep(3000);
|
Log.Trace("New seasonIncrement -> {0}", seasonIncrement);
|
||||||
continue;
|
|
||||||
}
|
if (sw.ElapsedMilliseconds > 30000) // Break out after 30 seconds, it's not going to get added
|
||||||
seasonIncrement = seasonList.Data?.Length ?? 0;
|
{
|
||||||
Log.Trace("New seasonIncrement -> {0}", seasonIncrement);
|
Log.Warn("Couldn't find out if the show had been added after 10 seconds. I doubt we can change the status to wanted.");
|
||||||
|
break;
|
||||||
if (sw.ElapsedMilliseconds > 30000) // Break out after 30 seconds, it's not going to get added
|
}
|
||||||
{
|
}
|
||||||
Log.Warn("Couldn't find out if the show had been added after 10 seconds. I doubt we can change the status to wanted.");
|
sw.Stop();
|
||||||
break;
|
}
|
||||||
}
|
catch (Exception e)
|
||||||
}
|
{
|
||||||
sw.Stop();
|
Log.Error("Exception thrown when getting the seasonList");
|
||||||
}
|
Log.Error(e);
|
||||||
catch (Exception e)
|
}
|
||||||
{
|
}
|
||||||
Log.Error("Exception thrown when getting the seasonList");
|
Log.Trace("seasons.Length > 0 where seasons.Len -> {0}", seasons.Length);
|
||||||
Log.Error(e);
|
try
|
||||||
}
|
{
|
||||||
}
|
if (seasons.Length > 0)
|
||||||
Log.Trace("seasons.Length > 0 where seasons.Len -> {0}", seasons.Length);
|
{
|
||||||
try
|
//handle the seasons requested
|
||||||
{
|
foreach (var s in seasons)
|
||||||
if (seasons.Length > 0)
|
{
|
||||||
{
|
Log.Trace("Adding season {0}", s);
|
||||||
//handle the seasons requested
|
|
||||||
foreach (var s in seasons)
|
var result = await AddSeason(tvdbId, s, apiKey, baseUrl);
|
||||||
{
|
Log.Trace("SickRage adding season results: ");
|
||||||
Log.Trace("Adding season {0}", s);
|
Log.Trace(result.DumpJson());
|
||||||
|
}
|
||||||
var result = await AddSeason(tvdbId, s, apiKey, baseUrl);
|
}
|
||||||
Log.Trace("SickRage adding season results: ");
|
}
|
||||||
Log.Trace(result.DumpJson());
|
catch (Exception e)
|
||||||
}
|
{
|
||||||
}
|
Log.Trace("Exception when adding seasons:");
|
||||||
}
|
Log.Error(e);
|
||||||
catch (Exception e)
|
throw;
|
||||||
{
|
}
|
||||||
Log.Trace("Exception when adding seasons:");
|
|
||||||
Log.Error(e);
|
Log.Trace("Finished with the API, returning the obj");
|
||||||
throw;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.Trace("Finished with the API, returning the obj");
|
public SickRagePing Ping(string apiKey, Uri baseUrl)
|
||||||
return obj;
|
{
|
||||||
}
|
var request = new RestRequest { Resource = "/api/{apiKey}/?cmd=sb.ping", Method = Method.GET };
|
||||||
|
|
||||||
public SickRagePing Ping(string apiKey, Uri baseUrl)
|
var policy = RetryHandler.RetryAndWaitPolicy((exception, timespan) => Log.Error(exception, "Exception when calling Ping for SR, Retrying {0}", timespan), null);
|
||||||
{
|
|
||||||
var request = new RestRequest { Resource = "/api/{apiKey}/?cmd=sb.ping", Method = Method.GET };
|
request.AddUrlSegment("apiKey", apiKey);
|
||||||
|
var obj = policy.Execute(() => Api.ExecuteJson<SickRagePing>(request, baseUrl));
|
||||||
var policy = RetryHandler.RetryAndWaitPolicy(
|
|
||||||
null,
|
return obj;
|
||||||
(exception, timespan) => Log.Error(exception, "Exception when calling Ping for SR, Retrying {0}", timespan));
|
}
|
||||||
|
|
||||||
request.AddUrlSegment("apiKey", apiKey);
|
public async Task<SickRageTvAdd> AddSeason(int tvdbId, int season, string apiKey, Uri baseUrl)
|
||||||
var obj = policy.Execute(() => Api.ExecuteJson<SickRagePing>(request, baseUrl));
|
{
|
||||||
|
var request = new RestRequest { Resource = "/api/{apiKey}/?cmd=episode.setstatus", Method = Method.GET };
|
||||||
return obj;
|
request.AddUrlSegment("apiKey", apiKey);
|
||||||
}
|
request.AddQueryParameter("tvdbid", tvdbId.ToString());
|
||||||
|
request.AddQueryParameter("season", season.ToString());
|
||||||
public async Task<SickRageTvAdd> AddSeason(int tvdbId, int season, string apiKey, Uri baseUrl)
|
request.AddQueryParameter("status", SickRageStatus.Wanted);
|
||||||
{
|
|
||||||
var request = new RestRequest { Resource = "/api/{apiKey}/?cmd=episode.setstatus", Method = Method.GET };
|
await Task.Run(() => Thread.Sleep(2000));
|
||||||
request.AddUrlSegment("apiKey", apiKey);
|
return await Task.Run(
|
||||||
request.AddQueryParameter("tvdbid", tvdbId.ToString());
|
() =>
|
||||||
request.AddQueryParameter("season", season.ToString());
|
{
|
||||||
request.AddQueryParameter("status", SickRageStatus.Wanted);
|
var policy = RetryHandler.RetryAndWaitPolicy((exception, timespan) => Log.Error(exception, "Exception when calling AddSeason for SR, Retrying {0}", timespan), null);
|
||||||
|
|
||||||
await Task.Run(() => Thread.Sleep(2000));
|
var result = policy.Execute(() => Api.Execute<SickRageTvAdd>(request, baseUrl));
|
||||||
return await Task.Run(
|
|
||||||
() =>
|
return result;
|
||||||
{
|
}).ConfigureAwait(false);
|
||||||
var policy = RetryHandler.RetryAndWaitPolicy(
|
}
|
||||||
null,
|
|
||||||
(exception, timespan) => Log.Error(exception, "Exception when calling AddSeason for SR, Retrying {0}", timespan));
|
public async Task<SickrageShows> GetShows(string apiKey, Uri baseUrl)
|
||||||
|
{
|
||||||
var result = policy.Execute(() => Api.Execute<SickRageTvAdd>(request, baseUrl));
|
var request = new RestRequest { Resource = "/api/{apiKey}/?cmd=shows", Method = Method.GET };
|
||||||
|
request.AddUrlSegment("apiKey", apiKey);
|
||||||
return result;
|
|
||||||
}).ConfigureAwait(false);
|
return await Task.Run(
|
||||||
}
|
() =>
|
||||||
|
{
|
||||||
public async Task<SickrageShows> GetShows(string apiKey, Uri baseUrl)
|
try
|
||||||
{
|
{
|
||||||
var request = new RestRequest { Resource = "/api/{apiKey}/?cmd=shows", Method = Method.GET };
|
var policy = RetryHandler.RetryAndWaitPolicy((exception, timespan) => Log.Error(exception, "Exception when calling GetShows for SR, Retrying {0}", timespan), new[] { TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(30) });
|
||||||
request.AddUrlSegment("apiKey", apiKey);
|
|
||||||
|
return policy.Execute(() => Api.Execute<SickrageShows>(request, baseUrl));
|
||||||
return await Task.Run(
|
}
|
||||||
() =>
|
catch (ApiRequestException)
|
||||||
{
|
{
|
||||||
try
|
Log.Error("There has been a API exception when Getting the Sickrage shows");
|
||||||
{
|
return null;
|
||||||
var policy = RetryHandler.RetryAndWaitPolicy(
|
}
|
||||||
new[] { TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(30) },
|
}).ConfigureAwait(false);
|
||||||
(exception, timespan) => Log.Error(exception, "Exception when calling GetShows for SR, Retrying {0}", timespan));
|
}
|
||||||
|
}
|
||||||
return policy.Execute(() => Api.Execute<SickrageShows>(request, baseUrl));
|
|
||||||
}
|
|
||||||
catch (ApiRequestException)
|
|
||||||
{
|
|
||||||
Log.Error("There has been a API exception when Getting the Sickrage shows");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}).ConfigureAwait(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -1,167 +1,299 @@
|
||||||
#region Copyright
|
#region Copyright
|
||||||
// /************************************************************************
|
// /************************************************************************
|
||||||
// Copyright (c) 2016 Jamie Rees
|
// Copyright (c) 2016 Jamie Rees
|
||||||
// File: CouchPotatoApi.cs
|
// File: CouchPotatoApi.cs
|
||||||
// Created By: Jamie Rees
|
// Created By: Jamie Rees
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining
|
// Permission is hereby granted, free of charge, to any person obtaining
|
||||||
// a copy of this software and associated documentation files (the
|
// a copy of this software and associated documentation files (the
|
||||||
// "Software"), to deal in the Software without restriction, including
|
// "Software"), to deal in the Software without restriction, including
|
||||||
// without limitation the rights to use, copy, modify, merge, publish,
|
// without limitation the rights to use, copy, modify, merge, publish,
|
||||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
// permit persons to whom the Software is furnished to do so, subject to
|
// permit persons to whom the Software is furnished to do so, subject to
|
||||||
// the following conditions:
|
// the following conditions:
|
||||||
//
|
//
|
||||||
// The above copyright notice and this permission notice shall be
|
// The above copyright notice and this permission notice shall be
|
||||||
// included in all copies or substantial portions of the Software.
|
// included in all copies or substantial portions of the Software.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
// ************************************************************************/
|
// ************************************************************************/
|
||||||
#endregion
|
#endregion
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
using NLog;
|
using NLog;
|
||||||
using PlexRequests.Api.Interfaces;
|
using PlexRequests.Api.Interfaces;
|
||||||
using PlexRequests.Api.Models.Sonarr;
|
using PlexRequests.Api.Models.Sonarr;
|
||||||
using PlexRequests.Helpers;
|
using PlexRequests.Helpers;
|
||||||
|
|
||||||
using RestSharp;
|
using RestSharp;
|
||||||
using Newtonsoft.Json.Linq;
|
|
||||||
|
namespace PlexRequests.Api
|
||||||
using PlexRequests.Helpers.Exceptions;
|
{
|
||||||
|
public class SonarrApi : ISonarrApi
|
||||||
namespace PlexRequests.Api
|
{
|
||||||
{
|
public SonarrApi()
|
||||||
public class SonarrApi : ISonarrApi
|
{
|
||||||
{
|
Api = new ApiRequest();
|
||||||
public SonarrApi()
|
}
|
||||||
{
|
private ApiRequest Api { get; set; }
|
||||||
Api = new ApiRequest();
|
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||||
}
|
|
||||||
private ApiRequest Api { get; set; }
|
public List<SonarrProfile> GetProfiles(string apiKey, Uri baseUrl)
|
||||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
{
|
||||||
|
var request = new RestRequest { Resource = "/api/profile", Method = Method.GET };
|
||||||
public List<SonarrProfile> GetProfiles(string apiKey, Uri baseUrl)
|
|
||||||
{
|
request.AddHeader("X-Api-Key", apiKey);
|
||||||
var request = new RestRequest { Resource = "/api/profile", Method = Method.GET };
|
var policy = RetryHandler.RetryAndWaitPolicy((exception, timespan) => Log.Error(exception, "Exception when calling GetProfiles for Sonarr, Retrying {0}", timespan), new TimeSpan[] {
|
||||||
|
TimeSpan.FromSeconds (2),
|
||||||
request.AddHeader("X-Api-Key", apiKey);
|
TimeSpan.FromSeconds(5),
|
||||||
var policy = RetryHandler.RetryAndWaitPolicy (new TimeSpan[] {
|
TimeSpan.FromSeconds(10)
|
||||||
TimeSpan.FromSeconds (2),
|
});
|
||||||
TimeSpan.FromSeconds(5),
|
|
||||||
TimeSpan.FromSeconds(10)
|
var obj = policy.Execute(() => Api.ExecuteJson<List<SonarrProfile>>(request, baseUrl));
|
||||||
}, (exception, timespan) => Log.Error (exception, "Exception when calling GetProfiles for Sonarr, Retrying {0}", timespan));
|
|
||||||
|
return obj;
|
||||||
var obj = policy.Execute(() => Api.ExecuteJson<List<SonarrProfile>>(request, baseUrl));
|
}
|
||||||
|
|
||||||
return obj;
|
public SonarrAddSeries AddSeries(int tvdbId, string title, int qualityId, bool seasonFolders, string rootPath, int seasonCount, int[] seasons, string apiKey, Uri baseUrl)
|
||||||
}
|
{
|
||||||
|
Log.Debug("Adding series {0}", title);
|
||||||
public SonarrAddSeries AddSeries(int tvdbId, string title, int qualityId, bool seasonFolders, string rootPath, int seasonCount, int[] seasons, string apiKey, Uri baseUrl)
|
Log.Debug("Seasons = {0}, out of {1} seasons", seasons.DumpJson(), seasonCount);
|
||||||
{
|
var request = new RestRequest
|
||||||
Log.Debug("Adding series {0}", title);
|
{
|
||||||
Log.Debug("Seasons = {0}, out of {1} seasons", seasons.DumpJson(), seasonCount);
|
Resource = "/api/Series?",
|
||||||
var request = new RestRequest
|
Method = Method.POST
|
||||||
{
|
};
|
||||||
Resource = "/api/Series?",
|
|
||||||
Method = Method.POST
|
var options = new SonarrAddSeries
|
||||||
};
|
{
|
||||||
|
seasonFolder = seasonFolders,
|
||||||
var options = new SonarrAddSeries
|
title = title,
|
||||||
{
|
qualityProfileId = qualityId,
|
||||||
seasonFolder = seasonFolders,
|
tvdbId = tvdbId,
|
||||||
title = title,
|
titleSlug = title,
|
||||||
qualityProfileId = qualityId,
|
seasons = new List<Season>(),
|
||||||
tvdbId = tvdbId,
|
rootFolderPath = rootPath
|
||||||
titleSlug = title,
|
};
|
||||||
seasons = new List<Season>(),
|
|
||||||
rootFolderPath = rootPath
|
for (var i = 1; i <= seasonCount; i++)
|
||||||
};
|
{
|
||||||
|
var season = new Season
|
||||||
for (var i = 1; i <= seasonCount; i++)
|
{
|
||||||
{
|
seasonNumber = i,
|
||||||
var season = new Season
|
monitored = seasons.Length == 0 || seasons.Any(x => x == i)
|
||||||
{
|
};
|
||||||
seasonNumber = i,
|
options.seasons.Add(season);
|
||||||
monitored = seasons.Length == 0 || seasons.Any(x => x == i)
|
}
|
||||||
};
|
|
||||||
options.seasons.Add(season);
|
Log.Debug("Sonarr API Options:");
|
||||||
}
|
Log.Debug(options.DumpJson());
|
||||||
|
|
||||||
Log.Debug("Sonarr API Options:");
|
request.AddHeader("X-Api-Key", apiKey);
|
||||||
Log.Debug(options.DumpJson());
|
request.AddJsonBody(options);
|
||||||
|
|
||||||
request.AddHeader("X-Api-Key", apiKey);
|
SonarrAddSeries result;
|
||||||
request.AddJsonBody(options);
|
try
|
||||||
|
{
|
||||||
SonarrAddSeries result;
|
var policy = RetryHandler.RetryAndWaitPolicy((exception, timespan) => Log.Error(exception, "Exception when calling AddSeries for Sonarr, Retrying {0}", timespan), new TimeSpan[] {
|
||||||
try
|
TimeSpan.FromSeconds (2),
|
||||||
{
|
TimeSpan.FromSeconds(5),
|
||||||
var policy = RetryHandler.RetryAndWaitPolicy (new TimeSpan[] {
|
TimeSpan.FromSeconds(10)
|
||||||
TimeSpan.FromSeconds (2),
|
});
|
||||||
TimeSpan.FromSeconds(5),
|
|
||||||
TimeSpan.FromSeconds(10)
|
result = policy.Execute(() => Api.ExecuteJson<SonarrAddSeries>(request, baseUrl));
|
||||||
}, (exception, timespan) => Log.Error (exception, "Exception when calling AddSeries for Sonarr, Retrying {0}", timespan));
|
}
|
||||||
|
catch (JsonSerializationException jse)
|
||||||
result = policy.Execute(() => Api.ExecuteJson<SonarrAddSeries>(request, baseUrl));
|
{
|
||||||
}
|
Log.Error(jse);
|
||||||
catch (JsonSerializationException jse)
|
var error = Api.ExecuteJson<List<SonarrError>>(request, baseUrl);
|
||||||
{
|
var messages = error?.Select(x => x.errorMessage).ToList();
|
||||||
Log.Error(jse);
|
messages?.ForEach(x => Log.Error(x));
|
||||||
var error = Api.ExecuteJson<List<SonarrError>>(request, baseUrl);
|
result = new SonarrAddSeries { ErrorMessages = messages };
|
||||||
var messages = error?.Select(x => x.errorMessage).ToList();
|
}
|
||||||
messages?.ForEach(x => Log.Error(x));
|
|
||||||
result = new SonarrAddSeries { ErrorMessages = messages };
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
public SystemStatus SystemStatus(string apiKey, Uri baseUrl)
|
||||||
}
|
{
|
||||||
|
var request = new RestRequest { Resource = "/api/system/status", Method = Method.GET };
|
||||||
public SystemStatus SystemStatus(string apiKey, Uri baseUrl)
|
request.AddHeader("X-Api-Key", apiKey);
|
||||||
{
|
|
||||||
var request = new RestRequest { Resource = "/api/system/status", Method = Method.GET };
|
var policy = RetryHandler.RetryAndWaitPolicy((exception, timespan) => Log.Error(exception, "Exception when calling SystemStatus for Sonarr, Retrying {0}", timespan), new TimeSpan[] {
|
||||||
request.AddHeader("X-Api-Key", apiKey);
|
TimeSpan.FromSeconds (2),
|
||||||
|
TimeSpan.FromSeconds(5),
|
||||||
var policy = RetryHandler.RetryAndWaitPolicy (new TimeSpan[] {
|
TimeSpan.FromSeconds(10)
|
||||||
TimeSpan.FromSeconds (2),
|
});
|
||||||
TimeSpan.FromSeconds(5),
|
|
||||||
TimeSpan.FromSeconds(10)
|
var obj = policy.Execute(() => Api.ExecuteJson<SystemStatus>(request, baseUrl));
|
||||||
}, (exception, timespan) => Log.Error (exception, "Exception when calling SystemStatus for Sonarr, Retrying {0}", timespan));
|
|
||||||
|
return obj;
|
||||||
var obj = policy.Execute(() => Api.ExecuteJson<SystemStatus>(request, baseUrl));
|
}
|
||||||
|
|
||||||
return obj;
|
public List<Series> GetSeries(string apiKey, Uri baseUrl)
|
||||||
}
|
{
|
||||||
|
var request = new RestRequest { Resource = "/api/series", Method = Method.GET };
|
||||||
public List<Series> GetSeries(string apiKey, Uri baseUrl)
|
request.AddHeader("X-Api-Key", apiKey);
|
||||||
{
|
try
|
||||||
var request = new RestRequest { Resource = "/api/series", Method = Method.GET };
|
{
|
||||||
request.AddHeader("X-Api-Key", apiKey);
|
var policy = RetryHandler.RetryAndWaitPolicy((exception, timespan) => Log.Error(exception, "Exception when calling GetSeries for Sonarr, Retrying {0}", timespan), new TimeSpan[] {
|
||||||
try
|
TimeSpan.FromSeconds (5),
|
||||||
{
|
TimeSpan.FromSeconds(10),
|
||||||
var policy = RetryHandler.RetryAndWaitPolicy (new TimeSpan[] {
|
TimeSpan.FromSeconds(30)
|
||||||
TimeSpan.FromSeconds (5),
|
});
|
||||||
TimeSpan.FromSeconds(10),
|
|
||||||
TimeSpan.FromSeconds(30)
|
return policy.Execute(() => Api.ExecuteJson<List<Series>>(request, baseUrl));
|
||||||
}, (exception, timespan) => Log.Error (exception, "Exception when calling GetSeries for Sonarr, Retrying {0}", timespan));
|
}
|
||||||
|
catch (Exception e)
|
||||||
return policy.Execute(() => Api.ExecuteJson<List<Series>>(request, baseUrl));
|
{
|
||||||
}
|
Log.Error(e, "There has been an API exception when getting the Sonarr Series");
|
||||||
catch (Exception e)
|
return null;
|
||||||
{
|
}
|
||||||
Log.Error(e, "There has been an API exception when getting the Sonarr Series");
|
}
|
||||||
return null;
|
|
||||||
}
|
public Series GetSeries(string seriesId, string apiKey, Uri baseUrl)
|
||||||
}
|
{
|
||||||
}
|
var request = new RestRequest { Resource = "/api/series/{seriesId}", Method = Method.GET };
|
||||||
|
request.AddHeader("X-Api-Key", apiKey);
|
||||||
|
request.AddUrlSegment("seriesId", seriesId);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var policy =
|
||||||
|
RetryHandler.RetryAndWaitPolicy(
|
||||||
|
(exception, timespan) =>
|
||||||
|
Log.Error(exception, "Exception when calling GetSeries by ID for Sonarr, Retrying {0}",
|
||||||
|
timespan));
|
||||||
|
|
||||||
|
return policy.Execute(() => Api.ExecuteJson<Series>(request, baseUrl));
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Log.Error(e, "There has been an API exception when getting the Sonarr Series by ID");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns all episodes for the given series.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="seriesId">The series identifier.</param>
|
||||||
|
/// <param name="apiKey">The API key.</param>
|
||||||
|
/// <param name="baseUrl">The base URL.</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public IEnumerable<SonarrEpisodes> GetEpisodes(string seriesId, string apiKey, Uri baseUrl)
|
||||||
|
{
|
||||||
|
var request = new RestRequest { Resource = "/api/Episode", Method = Method.GET };
|
||||||
|
request.AddHeader("X-Api-Key", apiKey);
|
||||||
|
request.AddQueryParameter("seriesId", seriesId);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var policy = RetryHandler.RetryAndWaitPolicy((exception, timespan) =>
|
||||||
|
Log.Error(exception, "Exception when calling GetEpisodes for Sonarr, Retrying {0}", timespan));
|
||||||
|
|
||||||
|
return policy.Execute(() => Api.ExecuteJson<List<SonarrEpisodes>>(request, baseUrl));
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Log.Error(e, "There has been an API exception when getting the Sonarr GetEpisodes");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the episode with the matching id.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="episodeId">The episode identifier.</param>
|
||||||
|
/// <param name="apiKey">The API key.</param>
|
||||||
|
/// <param name="baseUrl">The base URL.</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public SonarrEpisode GetEpisode(string episodeId, string apiKey, Uri baseUrl)
|
||||||
|
{
|
||||||
|
var request = new RestRequest { Resource = "/api/Episode/{episodeId}", Method = Method.GET };
|
||||||
|
request.AddHeader("X-Api-Key", apiKey);
|
||||||
|
request.AddUrlSegment("episodeId", episodeId);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var policy = RetryHandler.RetryAndWaitPolicy((exception, timespan) =>
|
||||||
|
Log.Error(exception, "Exception when calling GetEpisode by ID for Sonarr, Retrying {0}", timespan));
|
||||||
|
|
||||||
|
return policy.Execute(() => Api.ExecuteJson<SonarrEpisode>(request, baseUrl));
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Log.Error(e, "There has been an API exception when getting the Sonarr GetEpisode by ID");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Update the given episodes, currently only monitored is changed, all other modifications are ignored.
|
||||||
|
/// Required: All parameters (you should perform a GET/{id} and submit the full body with the changes, as other values may be editable in the future.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="episodeInfo">The episode information.</param>
|
||||||
|
/// <param name="apiKey">The API key.</param>
|
||||||
|
/// <param name="baseUrl">The base URL.</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public SonarrEpisode UpdateEpisode(SonarrEpisode episodeInfo, string apiKey, Uri baseUrl)
|
||||||
|
{
|
||||||
|
var request = new RestRequest { Resource = "/api/Episode", Method = Method.PUT };
|
||||||
|
request.AddHeader("X-Api-Key", apiKey);
|
||||||
|
request.AddJsonBody(episodeInfo);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var policy = RetryHandler.RetryAndWaitPolicy((exception, timespan) =>
|
||||||
|
Log.Error(exception, "Exception when calling UpdateEpisode for Sonarr, Retrying {0}", timespan));
|
||||||
|
|
||||||
|
return policy.Execute(() => Api.ExecuteJson<SonarrEpisode>(request, baseUrl));
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Log.Error(e, "There has been an API exception when put the Sonarr UpdateEpisode");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Search for one or more episodes
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="episodeIds">The episode ids.</param>
|
||||||
|
/// <param name="apiKey">The API key.</param>
|
||||||
|
/// <param name="baseUrl">The base URL.</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public SonarrAddEpisodeResult SearchForEpisodes(int[] episodeIds, string apiKey, Uri baseUrl)
|
||||||
|
{
|
||||||
|
var request = new RestRequest { Resource = "/api/Command", Method = Method.POST };
|
||||||
|
request.AddHeader("X-Api-Key", apiKey);
|
||||||
|
|
||||||
|
var body = new SonarrAddEpisodeBody
|
||||||
|
{
|
||||||
|
name = "EpisodeSearch",
|
||||||
|
episodeIds = episodeIds
|
||||||
|
};
|
||||||
|
|
||||||
|
request.AddJsonBody(body);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var policy = RetryHandler.RetryAndWaitPolicy((exception, timespan) =>
|
||||||
|
Log.Error(exception, "Exception when calling SearchForEpisodes for Sonarr, Retrying {0}", timespan));
|
||||||
|
|
||||||
|
return policy.Execute(() => Api.ExecuteJson<SonarrAddEpisodeResult>(request, baseUrl));
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Log.Error(e, "There has been an API exception when put the Sonarr SearchForEpisodes");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -69,14 +69,14 @@ namespace PlexRequests.UI
|
||||||
private IKernel _kernel;
|
private IKernel _kernel;
|
||||||
protected override IKernel GetApplicationContainer()
|
protected override IKernel GetApplicationContainer()
|
||||||
{
|
{
|
||||||
Debug.WriteLine("GetAppContainer");
|
Debug.WriteLine("GetAppContainer");
|
||||||
_kernel.Load<FactoryModule>();
|
_kernel.Load<FactoryModule>();
|
||||||
return _kernel;
|
return _kernel;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void ApplicationStartup(IKernel container, IPipelines pipelines)
|
protected override void ApplicationStartup(IKernel container, IPipelines pipelines)
|
||||||
{
|
{
|
||||||
Debug.WriteLine("Bootstrapper.ApplicationStartup");
|
Debug.WriteLine("Bootstrapper.ApplicationStartup");
|
||||||
ConfigureContainer(container);
|
ConfigureContainer(container);
|
||||||
|
|
||||||
JsonSettings.MaxJsonLength = int.MaxValue;
|
JsonSettings.MaxJsonLength = int.MaxValue;
|
||||||
|
@ -119,21 +119,22 @@ namespace PlexRequests.UI
|
||||||
#endif
|
#endif
|
||||||
protected override void ConfigureConventions(NancyConventions nancyConventions)
|
protected override void ConfigureConventions(NancyConventions nancyConventions)
|
||||||
{
|
{
|
||||||
Debug.WriteLine("Configuring the conventions");
|
Debug.WriteLine("Configuring the conventions");
|
||||||
base.ConfigureConventions(nancyConventions);
|
base.ConfigureConventions(nancyConventions);
|
||||||
Debug.WriteLine("Finished BASE");
|
|
||||||
var settingsService = new SettingsServiceV2<PlexRequestSettings>(new SettingsJsonRepository(new DbConfiguration(new SqliteFactory()), new MemoryCacheProvider()));
|
var settingsService = new SettingsServiceV2<PlexRequestSettings>(new SettingsJsonRepository(new DbConfiguration(new SqliteFactory()), new MemoryCacheProvider()));
|
||||||
var settings = settingsService.GetSettings();
|
var settings = settingsService.GetSettings();
|
||||||
var assetLocation = settings.BaseUrl ?? string.Empty;
|
var assetLocation = string.Empty;
|
||||||
|
if (!string.IsNullOrEmpty(settings.BaseUrl))
|
||||||
|
{
|
||||||
|
assetLocation = $"{settings.BaseUrl}/";
|
||||||
|
}
|
||||||
|
|
||||||
Debug.WriteLine($"AssetLocation {assetLocation}");
|
Debug.WriteLine($"AssetLocation {assetLocation}");
|
||||||
nancyConventions.StaticContentsConventions.Add(
|
|
||||||
StaticContentConventionBuilder.AddDirectory($"{assetLocation}/Content_{AssemblyHelper.GetProductVersion()}", "Content")
|
|
||||||
);
|
|
||||||
Debug.WriteLine("Added Content");
|
|
||||||
nancyConventions.StaticContentsConventions.AddDirectory($"{assetLocation}/docs", "swagger-ui");
|
|
||||||
|
|
||||||
nancyConventions.StaticContentsConventions.AddDirectory($"{assetLocation}/fonts", "Content/fonts");
|
nancyConventions.StaticContentsConventions.AddDirectory($"{assetLocation}Content", "Content");
|
||||||
|
nancyConventions.StaticContentsConventions.AddDirectory($"{assetLocation}docs", "swagger-ui");
|
||||||
|
nancyConventions.StaticContentsConventions.AddDirectory($"{assetLocation}fonts", "Content/fonts");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override DiagnosticsConfiguration DiagnosticsConfiguration => new DiagnosticsConfiguration { Password = @"password" };
|
protected override DiagnosticsConfiguration DiagnosticsConfiguration => new DiagnosticsConfiguration { Password = @"password" };
|
||||||
|
@ -170,10 +171,9 @@ Debug.WriteLine("Added Content");
|
||||||
notificationService.Subscribe(new SlackNotification(container.Get<ISlackApi>(), slackService));
|
notificationService.Subscribe(new SlackNotification(container.Get<ISlackApi>(), slackService));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void RequestStartup(IKernel container, IPipelines pipelines, NancyContext context)
|
protected override void RequestStartup(IKernel container, IPipelines pipelines, NancyContext context)
|
||||||
{
|
{
|
||||||
Debug.WriteLine("RequestStartup");
|
|
||||||
//CORS Enable
|
//CORS Enable
|
||||||
pipelines.AfterRequest.AddItemToEndOfPipeline((ctx) =>
|
pipelines.AfterRequest.AddItemToEndOfPipeline((ctx) =>
|
||||||
{
|
{
|
||||||
|
@ -187,7 +187,7 @@ Debug.WriteLine("Added Content");
|
||||||
|
|
||||||
private void ConfigureContainer(IKernel container)
|
private void ConfigureContainer(IKernel container)
|
||||||
{
|
{
|
||||||
Debug.WriteLine("Configuring ServiceLoc/Container");
|
Debug.WriteLine("Configuring ServiceLoc/Container");
|
||||||
var loc = ServiceLocator.Instance;
|
var loc = ServiceLocator.Instance;
|
||||||
loc.SetContainer(container);
|
loc.SetContainer(container);
|
||||||
}
|
}
|
||||||
|
|
39
PlexRequests.UI/Content/search.js
vendored
39
PlexRequests.UI/Content/search.js
vendored
|
@ -538,6 +538,7 @@ $(function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#episodesModal').on('show.bs.modal', function (event) {
|
$('#episodesModal').on('show.bs.modal', function (event) {
|
||||||
|
finishLoading("episodesRequest", "primary");
|
||||||
var button = $(event.relatedTarget); // Button that triggered the modal
|
var button = $(event.relatedTarget); // Button that triggered the modal
|
||||||
var id = button.data('identifier'); // Extract info from data-* attributes
|
var id = button.data('identifier'); // Extract info from data-* attributes
|
||||||
var url = createBaseUrl(base, '/search/episodes/');
|
var url = createBaseUrl(base, '/search/episodes/');
|
||||||
|
@ -552,8 +553,6 @@ $(function () {
|
||||||
$content.html("");
|
$content.html("");
|
||||||
$('#selectedEpisodeId').val(id);
|
$('#selectedEpisodeId').val(id);
|
||||||
results.forEach(function (result) {
|
results.forEach(function (result) {
|
||||||
|
|
||||||
|
|
||||||
var episodes = buildEpisodesView(result);
|
var episodes = buildEpisodesView(result);
|
||||||
|
|
||||||
if (!seenSeasons.find(x => x === episodes.season)) {
|
if (!seenSeasons.find(x => x === episodes.season)) {
|
||||||
|
@ -572,6 +571,42 @@ $(function () {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Save Modal click
|
||||||
|
$("#episodesRequest").click(function (e) {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
var tvId = $('#selectedEpisodeId').val();
|
||||||
|
|
||||||
|
$("#episodesRequest").prop("disabled", true);
|
||||||
|
loadingButton("episodesRequest", "primary");
|
||||||
|
|
||||||
|
|
||||||
|
var $form = $('#form' + tvId);
|
||||||
|
|
||||||
|
var model = [];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var $checkedEpisodes = $('.selectedEpisodes:checkbox:checked');
|
||||||
|
$checkedEpisodes.each(function (index, element) {
|
||||||
|
var $element = $('#' + element.id);
|
||||||
|
var tempObj = {};
|
||||||
|
tempObj.episodeNumber = $element.attr("epNumber");
|
||||||
|
tempObj.seasonNumber = $element.attr("epSeason");
|
||||||
|
model.push(tempObj);
|
||||||
|
});
|
||||||
|
|
||||||
|
var finalObj = {
|
||||||
|
ShowId: tvId,
|
||||||
|
Episodes: model
|
||||||
|
}
|
||||||
|
|
||||||
|
var url = createBaseUrl(mainBaseUrl, "search/request/tvEpisodes");
|
||||||
|
var type = $form.prop('method');
|
||||||
|
|
||||||
|
sendRequestAjax(JSON.stringify(finalObj), type, url, tvId);
|
||||||
|
});
|
||||||
|
|
||||||
function buildSeasonsContext(result) {
|
function buildSeasonsContext(result) {
|
||||||
var context = {
|
var context = {
|
||||||
id: result
|
id: result
|
||||||
|
|
2
PlexRequests.UI/Content/site.js
vendored
2
PlexRequests.UI/Content/site.js
vendored
|
@ -8,6 +8,8 @@
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var mainBaseUrl = $('#baseUrl').text();
|
||||||
|
|
||||||
function Humanize(date) {
|
function Humanize(date) {
|
||||||
var mNow = moment();
|
var mNow = moment();
|
||||||
var mDate = moment(date).local();
|
var mDate = moment(date).local();
|
||||||
|
|
|
@ -73,7 +73,7 @@ namespace PlexRequests.UI.Helpers
|
||||||
if (settings.ThemeName == "PlexBootstrap.css") settings.ThemeName = Themes.PlexTheme;
|
if (settings.ThemeName == "PlexBootstrap.css") settings.ThemeName = Themes.PlexTheme;
|
||||||
if (settings.ThemeName == "OriginalBootstrap.css") settings.ThemeName = Themes.OriginalTheme;
|
if (settings.ThemeName == "OriginalBootstrap.css") settings.ThemeName = Themes.OriginalTheme;
|
||||||
|
|
||||||
var startUrl = $"{content}/Content_{Assembly}";
|
var startUrl = $"{content}/Content";
|
||||||
|
|
||||||
var styleAssets = new List<string>
|
var styleAssets = new List<string>
|
||||||
{
|
{
|
||||||
|
@ -123,7 +123,7 @@ namespace PlexRequests.UI.Helpers
|
||||||
|
|
||||||
var content = GetContentUrl(assetLocation);
|
var content = GetContentUrl(assetLocation);
|
||||||
|
|
||||||
sb.AppendLine($"<script src=\"{content}/Content_{Assembly}/search.js\" type=\"text/javascript\"></script>");
|
sb.AppendLine($"<script src=\"{content}/Content/search.js\" type=\"text/javascript\"></script>");
|
||||||
|
|
||||||
return helper.Raw(sb.ToString());
|
return helper.Raw(sb.ToString());
|
||||||
}
|
}
|
||||||
|
@ -135,7 +135,7 @@ namespace PlexRequests.UI.Helpers
|
||||||
|
|
||||||
var content = GetContentUrl(assetLocation);
|
var content = GetContentUrl(assetLocation);
|
||||||
|
|
||||||
sb.AppendLine($"<script src=\"{content}/Content_{Assembly}/requests.js\" type=\"text/javascript\"></script>");
|
sb.AppendLine($"<script src=\"{content}/Content/requests.js\" type=\"text/javascript\"></script>");
|
||||||
|
|
||||||
return helper.Raw(sb.ToString());
|
return helper.Raw(sb.ToString());
|
||||||
}
|
}
|
||||||
|
@ -147,7 +147,7 @@ namespace PlexRequests.UI.Helpers
|
||||||
|
|
||||||
var content = GetContentUrl(assetLocation);
|
var content = GetContentUrl(assetLocation);
|
||||||
|
|
||||||
sb.AppendLine($"<script src=\"{content}/Content_{Assembly}/issues.js\" type=\"text/javascript\"></script>");
|
sb.AppendLine($"<script src=\"{content}/Content/issues.js\" type=\"text/javascript\"></script>");
|
||||||
|
|
||||||
return helper.Raw(sb.ToString());
|
return helper.Raw(sb.ToString());
|
||||||
}
|
}
|
||||||
|
@ -157,7 +157,7 @@ namespace PlexRequests.UI.Helpers
|
||||||
var assetLocation = GetBaseUrl();
|
var assetLocation = GetBaseUrl();
|
||||||
var content = GetContentUrl(assetLocation);
|
var content = GetContentUrl(assetLocation);
|
||||||
|
|
||||||
var asset = $"<script src=\"{content}/Content_{Assembly}/issue-details.js\" type=\"text/javascript\"></script>";
|
var asset = $"<script src=\"{content}/Content/issue-details.js\" type=\"text/javascript\"></script>";
|
||||||
|
|
||||||
return helper.Raw(asset);
|
return helper.Raw(asset);
|
||||||
}
|
}
|
||||||
|
@ -169,8 +169,8 @@ namespace PlexRequests.UI.Helpers
|
||||||
|
|
||||||
var content = GetContentUrl(assetLocation);
|
var content = GetContentUrl(assetLocation);
|
||||||
|
|
||||||
sb.AppendLine($"<script src=\"{content}/Content_{Assembly}/datatables.min.js\" type=\"text/javascript\"></script>");
|
sb.AppendLine($"<script src=\"{content}/Content/datatables.min.js\" type=\"text/javascript\"></script>");
|
||||||
sb.AppendLine($"<link rel=\"stylesheet\" type=\"text/css\" href=\"{content}/Content_{Assembly}/dataTables.bootstrap.css\" />");
|
sb.AppendLine($"<link rel=\"stylesheet\" type=\"text/css\" href=\"{content}/Content/dataTables.bootstrap.css\" />");
|
||||||
|
|
||||||
return helper.Raw(sb.ToString());
|
return helper.Raw(sb.ToString());
|
||||||
}
|
}
|
||||||
|
@ -186,7 +186,7 @@ namespace PlexRequests.UI.Helpers
|
||||||
var assetLocation = GetBaseUrl();
|
var assetLocation = GetBaseUrl();
|
||||||
var content = GetContentUrl(assetLocation);
|
var content = GetContentUrl(assetLocation);
|
||||||
|
|
||||||
var asset = $"<script src=\"{content}/Content_{Assembly}/analytics.js\" type=\"text/javascript\"></script>";
|
var asset = $"<script src=\"{content}/Content/analytics.js\" type=\"text/javascript\"></script>";
|
||||||
|
|
||||||
return helper.Raw(asset);
|
return helper.Raw(asset);
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,24 +44,34 @@ namespace PlexRequests.UI.Helpers
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IEnumerable<IBinding> Resolve(Multimap<Type, IBinding> bindings, Type service)
|
public IEnumerable<IBinding> Resolve(Multimap<Type, IBinding> bindings, Type service)
|
||||||
{
|
{
|
||||||
Debug.WriteLine("Contrar thing");
|
|
||||||
|
|
||||||
if (service.IsGenericType)
|
if (service.IsGenericType)
|
||||||
{
|
{
|
||||||
var genericType = service.GetGenericTypeDefinition();
|
var genericType = service.GetGenericTypeDefinition();
|
||||||
var genericArguments = genericType.GetGenericArguments();
|
var genericArguments = genericType.GetGenericArguments();
|
||||||
if (!genericArguments.Any())
|
if (!genericArguments.Any())
|
||||||
{
|
{
|
||||||
return Enumerable.Empty<IBinding>();
|
return Enumerable.Empty<IBinding>();
|
||||||
}
|
}
|
||||||
if (genericArguments.Length == 1 && genericArguments.Single().GenericParameterAttributes.HasFlag(GenericParameterAttributes.Contravariant))
|
if (genericArguments.Length == 1 && genericArguments.Single().GenericParameterAttributes.HasFlag(GenericParameterAttributes.Contravariant))
|
||||||
{
|
{
|
||||||
var argument = service.GetGenericArguments().Single();
|
var argument = service.GetGenericArguments().FirstOrDefault();
|
||||||
|
if (argument == null)
|
||||||
|
{
|
||||||
|
return Enumerable.Empty<IBinding>();
|
||||||
|
}
|
||||||
|
|
||||||
var matches =
|
var matches =
|
||||||
bindings.Where(
|
bindings.Where(
|
||||||
kvp =>
|
kvp =>
|
||||||
kvp.Key.IsGenericType && kvp.Key.GetGenericTypeDefinition() == genericType && kvp.Key.GetGenericArguments().Single() != argument
|
{
|
||||||
&& kvp.Key.GetGenericArguments().Single().IsAssignableFrom(argument)).SelectMany(kvp => kvp.Value);
|
var assignableFrom = kvp.Key.GetGenericArguments().FirstOrDefault();
|
||||||
|
|
||||||
|
return kvp.Key.IsGenericType && kvp.Key.GetGenericTypeDefinition() == genericType &&
|
||||||
|
kvp.Key.GetGenericArguments().FirstOrDefault() != argument
|
||||||
|
&& assignableFrom.IsAssignableFrom(argument);
|
||||||
|
|
||||||
|
|
||||||
|
}).SelectMany(kvp => kvp.Value);
|
||||||
return matches;
|
return matches;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
41
PlexRequests.UI/Models/EpisodeRequestModel.cs
Normal file
41
PlexRequests.UI/Models/EpisodeRequestModel.cs
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
#region Copyright
|
||||||
|
// /************************************************************************
|
||||||
|
// Copyright (c) 2016 Jamie Rees
|
||||||
|
// File: EpisodeRequestModel.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.
|
||||||
|
// ************************************************************************/
|
||||||
|
#endregion
|
||||||
|
namespace PlexRequests.UI.Models
|
||||||
|
{
|
||||||
|
public class EpisodeRequestModel
|
||||||
|
{
|
||||||
|
public int ShowId { get; set; }
|
||||||
|
public EpisodesModel[] Episodes { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public class EpisodesModel
|
||||||
|
{
|
||||||
|
public int SeasonNumber { get; set; }
|
||||||
|
public int EpisodeNumber { get; set; }
|
||||||
|
}
|
||||||
|
}
|
|
@ -49,8 +49,10 @@ using PlexRequests.UI.Models;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
using Nancy.Extensions;
|
using Nancy.Extensions;
|
||||||
|
using Nancy.ModelBinding;
|
||||||
using Nancy.Responses;
|
using Nancy.Responses;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using PlexRequests.Api.Models.Sonarr;
|
||||||
using PlexRequests.Api.Models.Tv;
|
using PlexRequests.Api.Models.Tv;
|
||||||
using PlexRequests.Core.Models;
|
using PlexRequests.Core.Models;
|
||||||
using PlexRequests.Helpers.Analytics;
|
using PlexRequests.Helpers.Analytics;
|
||||||
|
@ -103,7 +105,7 @@ namespace PlexRequests.UI.Modules
|
||||||
TvApi = new TvMazeApi();
|
TvApi = new TvMazeApi();
|
||||||
|
|
||||||
|
|
||||||
Get["SearchIndex","/", true] = async (x, ct) => await RequestLoad();
|
Get["SearchIndex", "/", true] = async (x, ct) => await RequestLoad();
|
||||||
|
|
||||||
Get["movie/{searchTerm}", true] = async (x, ct) => await SearchMovie((string)x.searchTerm);
|
Get["movie/{searchTerm}", true] = async (x, ct) => await SearchMovie((string)x.searchTerm);
|
||||||
Get["tv/{searchTerm}", true] = async (x, ct) => await SearchTvShow((string)x.searchTerm);
|
Get["tv/{searchTerm}", true] = async (x, ct) => await SearchTvShow((string)x.searchTerm);
|
||||||
|
@ -115,6 +117,7 @@ namespace PlexRequests.UI.Modules
|
||||||
|
|
||||||
Post["request/movie", true] = async (x, ct) => await RequestMovie((int)Request.Form.movieId);
|
Post["request/movie", true] = async (x, ct) => await RequestMovie((int)Request.Form.movieId);
|
||||||
Post["request/tv", true] = async (x, ct) => await RequestTvShow((int)Request.Form.tvId, (string)Request.Form.seasons);
|
Post["request/tv", true] = async (x, ct) => await RequestTvShow((int)Request.Form.tvId, (string)Request.Form.seasons);
|
||||||
|
Post["request/tvEpisodes", true] = async (x, ct) => await RequestEpisodes();
|
||||||
Post["request/album", true] = async (x, ct) => await RequestAlbum((string)Request.Form.albumId);
|
Post["request/album", true] = async (x, ct) => await RequestAlbum((string)Request.Form.albumId);
|
||||||
|
|
||||||
Post["/notifyuser", true] = async (x, ct) => await NotifyUser((bool)Request.Form.notify);
|
Post["/notifyuser", true] = async (x, ct) => await NotifyUser((bool)Request.Form.notify);
|
||||||
|
@ -436,7 +439,7 @@ namespace PlexRequests.UI.Modules
|
||||||
Analytics.TrackEventAsync(Category.Search, Action.Request, "Movie", Username, CookieHelper.GetAnalyticClientId(Cookies));
|
Analytics.TrackEventAsync(Category.Search, Action.Request, "Movie", Username, CookieHelper.GetAnalyticClientId(Cookies));
|
||||||
var movieInfo = MovieApi.GetMovieInformation(movieId).Result;
|
var movieInfo = MovieApi.GetMovieInformation(movieId).Result;
|
||||||
var fullMovieName = $"{movieInfo.Title}{(movieInfo.ReleaseDate.HasValue ? $" ({movieInfo.ReleaseDate.Value.Year})" : string.Empty)}";
|
var fullMovieName = $"{movieInfo.Title}{(movieInfo.ReleaseDate.HasValue ? $" ({movieInfo.ReleaseDate.Value.Year})" : string.Empty)}";
|
||||||
|
|
||||||
var existingRequest = await RequestService.CheckRequestAsync(movieId);
|
var existingRequest = await RequestService.CheckRequestAsync(movieId);
|
||||||
if (existingRequest != null)
|
if (existingRequest != null)
|
||||||
{
|
{
|
||||||
|
@ -449,7 +452,7 @@ namespace PlexRequests.UI.Modules
|
||||||
|
|
||||||
return Response.AsJson(new JsonResponseModel { Result = true, Message = settings.UsersCanViewOnlyOwnRequests ? $"{fullMovieName} {Resources.UI.Search_SuccessfullyAdded}" : $"{fullMovieName} {Resources.UI.Search_AlreadyRequested}" });
|
return Response.AsJson(new JsonResponseModel { Result = true, Message = settings.UsersCanViewOnlyOwnRequests ? $"{fullMovieName} {Resources.UI.Search_SuccessfullyAdded}" : $"{fullMovieName} {Resources.UI.Search_AlreadyRequested}" });
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var movies = Checker.GetPlexMovies();
|
var movies = Checker.GetPlexMovies();
|
||||||
|
@ -533,9 +536,8 @@ namespace PlexRequests.UI.Modules
|
||||||
return Response.AsJson(new JsonResponseModel { Result = false, Message = Resources.UI.Search_WeeklyRequestLimitTVShow });
|
return Response.AsJson(new JsonResponseModel { Result = false, Message = Resources.UI.Search_WeeklyRequestLimitTVShow });
|
||||||
}
|
}
|
||||||
Analytics.TrackEventAsync(Category.Search, Action.Request, "TvShow", Username, CookieHelper.GetAnalyticClientId(Cookies));
|
Analytics.TrackEventAsync(Category.Search, Action.Request, "TvShow", Username, CookieHelper.GetAnalyticClientId(Cookies));
|
||||||
var tvApi = new TvMazeApi();
|
|
||||||
|
|
||||||
var showInfo = tvApi.ShowLookupByTheTvDbId(showId);
|
var showInfo = TvApi.ShowLookupByTheTvDbId(showId);
|
||||||
DateTime firstAir;
|
DateTime firstAir;
|
||||||
DateTime.TryParse(showInfo.premiered, out firstAir);
|
DateTime.TryParse(showInfo.premiered, out firstAir);
|
||||||
string fullShowName = $"{showInfo.name} ({firstAir.Year})";
|
string fullShowName = $"{showInfo.name} ({firstAir.Year})";
|
||||||
|
@ -687,7 +689,7 @@ namespace PlexRequests.UI.Modules
|
||||||
}
|
}
|
||||||
Analytics.TrackEventAsync(Category.Search, Action.Request, "Album", Username, CookieHelper.GetAnalyticClientId(Cookies));
|
Analytics.TrackEventAsync(Category.Search, Action.Request, "Album", Username, CookieHelper.GetAnalyticClientId(Cookies));
|
||||||
var existingRequest = await RequestService.CheckRequestAsync(releaseId);
|
var existingRequest = await RequestService.CheckRequestAsync(releaseId);
|
||||||
|
|
||||||
if (existingRequest != null)
|
if (existingRequest != null)
|
||||||
{
|
{
|
||||||
if (!existingRequest.UserHasRequested(Username))
|
if (!existingRequest.UserHasRequested(Username))
|
||||||
|
@ -697,7 +699,7 @@ namespace PlexRequests.UI.Modules
|
||||||
}
|
}
|
||||||
return Response.AsJson(new JsonResponseModel { Result = true, Message = settings.UsersCanViewOnlyOwnRequests ? $"{existingRequest.Title} {Resources.UI.Search_SuccessfullyAdded}" : $"{existingRequest.Title} {Resources.UI.Search_AlreadyRequested}" });
|
return Response.AsJson(new JsonResponseModel { Result = true, Message = settings.UsersCanViewOnlyOwnRequests ? $"{existingRequest.Title} {Resources.UI.Search_SuccessfullyAdded}" : $"{existingRequest.Title} {Resources.UI.Search_AlreadyRequested}" });
|
||||||
}
|
}
|
||||||
|
|
||||||
var albumInfo = MusicBrainzApi.GetAlbum(releaseId);
|
var albumInfo = MusicBrainzApi.GetAlbum(releaseId);
|
||||||
DateTime release;
|
DateTime release;
|
||||||
DateTimeHelper.CustomParse(albumInfo.ReleaseEvents?.FirstOrDefault()?.date, out release);
|
DateTimeHelper.CustomParse(albumInfo.ReleaseEvents?.FirstOrDefault()?.date, out release);
|
||||||
|
@ -954,5 +956,65 @@ namespace PlexRequests.UI.Modules
|
||||||
|
|
||||||
return Response.AsJson(new JsonResponseModel { Result = true, Message = message });
|
return Response.AsJson(new JsonResponseModel { Result = true, Message = message });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task<Response> RequestEpisodes()
|
||||||
|
{
|
||||||
|
var req = (Dictionary<string, object>.ValueCollection)this.Request.Form.Values;
|
||||||
|
var json = req.FirstOrDefault().ToString();
|
||||||
|
var model = JsonConvert.DeserializeObject<EpisodeRequestModel>(json);
|
||||||
|
//var model = this.Bind<EpisodeRequestModel>();
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return Nancy.Response.NoBody;
|
||||||
|
}
|
||||||
|
var sonarrSettings = await SonarrService.GetSettingsAsync();
|
||||||
|
if (!sonarrSettings.Enabled)
|
||||||
|
{
|
||||||
|
return Response.AsJson("Need sonarr");
|
||||||
|
}
|
||||||
|
|
||||||
|
var existingRequest = await RequestService.CheckRequestAsync(model.ShowId);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Find the correct series
|
||||||
|
var task = await Task.Run(() => SonarrApi.GetSeries(sonarrSettings.ApiKey, sonarrSettings.FullUri)).ConfigureAwait(false);
|
||||||
|
var selectedSeries = task.FirstOrDefault(series => series.tvdbId == model.ShowId);
|
||||||
|
if (selectedSeries == null)
|
||||||
|
{
|
||||||
|
|
||||||
|
// Need to add the series as unmonitored.
|
||||||
|
return Response.AsJson("");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Show Exists
|
||||||
|
// Look up all episodes
|
||||||
|
var episodes = SonarrApi.GetEpisodes(selectedSeries.id.ToString(), sonarrSettings.ApiKey, sonarrSettings.FullUri).ToList();
|
||||||
|
var internalEpisodeIds = new List<int>();
|
||||||
|
var tasks = new List<Task>();
|
||||||
|
foreach (var r in model.Episodes)
|
||||||
|
{
|
||||||
|
var episode =
|
||||||
|
episodes.FirstOrDefault(
|
||||||
|
x => x.episodeNumber == r.EpisodeNumber && x.seasonNumber == r.SeasonNumber);
|
||||||
|
if (episode == null)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
var episodeInfo = SonarrApi.GetEpisode(episode.id.ToString(), sonarrSettings.ApiKey, sonarrSettings.FullUri);
|
||||||
|
episodeInfo.monitored = true; // Set the episode to monitored
|
||||||
|
tasks.Add(Task.Run(() => SonarrApi.UpdateEpisode(episodeInfo, sonarrSettings.ApiKey,
|
||||||
|
sonarrSettings.FullUri)));
|
||||||
|
internalEpisodeIds.Add(episode.id);
|
||||||
|
}
|
||||||
|
Task.WaitAll(tasks.ToArray());
|
||||||
|
|
||||||
|
SonarrApi.SearchForEpisodes(internalEpisodeIds.ToArray(), sonarrSettings.ApiKey, sonarrSettings.FullUri);
|
||||||
|
|
||||||
|
|
||||||
|
return Response.AsJson(new JsonResponseModel() { Result = true });
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -200,6 +200,7 @@
|
||||||
<Compile Include="ModelDataProviders\UserUpdateViewModelDataProvider.cs" />
|
<Compile Include="ModelDataProviders\UserUpdateViewModelDataProvider.cs" />
|
||||||
<Compile Include="ModelDataProviders\RequestedModelDataProvider.cs" />
|
<Compile Include="ModelDataProviders\RequestedModelDataProvider.cs" />
|
||||||
<Compile Include="Models\DatatablesModel.cs" />
|
<Compile Include="Models\DatatablesModel.cs" />
|
||||||
|
<Compile Include="Models\EpisodeRequestModel.cs" />
|
||||||
<Compile Include="Models\IssuesDetailsViewModel.cs" />
|
<Compile Include="Models\IssuesDetailsViewModel.cs" />
|
||||||
<Compile Include="Models\IssuesViewMOdel.cs" />
|
<Compile Include="Models\IssuesViewMOdel.cs" />
|
||||||
<Compile Include="Models\JsonUpdateAvailableModel.cs" />
|
<Compile Include="Models\JsonUpdateAvailableModel.cs" />
|
||||||
|
|
|
@ -172,33 +172,34 @@
|
||||||
<div class="col-sm-2 col-sm-push-3">
|
<div class="col-sm-2 col-sm-push-3">
|
||||||
<form method="POST" action="@url/search/request/{{type}}" id="form{{id}}">
|
<form method="POST" action="@url/search/request/{{type}}" id="form{{id}}">
|
||||||
<input name="{{type}}Id" type="text" value="{{id}}" hidden="hidden" />
|
<input name="{{type}}Id" type="text" value="{{id}}" hidden="hidden" />
|
||||||
{{#if_eq available true}}
|
|
||||||
<button style="text-align: right" class="btn btn-success-outline disabled" disabled><i class="fa fa-check"></i> @UI.Search_Available</button>
|
|
||||||
{{else}}
|
|
||||||
{{#if_eq requested true}}
|
|
||||||
<button style="text-align: right" class="btn btn-primary-outline disabled" disabled><i class="fa fa-check"></i> @UI.Search_Requested</button>
|
|
||||||
{{else}}
|
|
||||||
{{#if_eq type "movie"}}
|
{{#if_eq type "movie"}}
|
||||||
<button id="{{id}}" style="text-align: right" class="btn btn-primary-outline requestMovie" type="submit"><i class="fa fa-plus"></i> @UI.Search_Request</button>
|
{{#if_eq available true}}
|
||||||
|
<button style="text-align: right" class="btn btn-success-outline disabled" disabled><i class="fa fa-check"></i> @UI.Search_Available</button>
|
||||||
|
{{else}}
|
||||||
|
{{#if_eq requested true}}
|
||||||
|
<button style="text-align: right" class="btn btn-primary-outline disabled" disabled><i class="fa fa-check"></i> @UI.Search_Requested</button>
|
||||||
|
{{else}}
|
||||||
|
<button id="{{id}}" style="text-align: right" class="btn btn-primary-outline requestMovie" type="submit"><i class="fa fa-plus"></i> @UI.Search_Request</button>
|
||||||
|
{{/if_eq}}
|
||||||
|
{{/if_eq}}
|
||||||
{{/if_eq}}
|
{{/if_eq}}
|
||||||
{{#if_eq type "tv"}}
|
{{#if_eq type "tv"}}
|
||||||
<div class="dropdown">
|
<div class="dropdown">
|
||||||
<button id="{{id}}" class="btn btn-primary-outline dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
|
<button id="{{id}}" class="btn btn-primary-outline dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
|
||||||
<i class="fa fa-plus"></i> @UI.Search_Request
|
<i class="fa fa-plus"></i> @UI.Search_Request
|
||||||
<span class="caret"></span>
|
<span class="caret"></span>
|
||||||
</button>
|
</button>
|
||||||
<ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
|
<ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
|
||||||
<li><a id="{{id}}" season-select="0" class="dropdownTv " href="#">@UI.Search_AllSeasons</a></li>
|
<li><a id="{{id}}" season-select="0" class="dropdownTv " href="#">@UI.Search_AllSeasons</a></li>
|
||||||
<li><a id="{{id}}" season-select="1" class="dropdownTv" href="#">@UI.Search_FirstSeason</a></li>
|
<li><a id="{{id}}" season-select="1" class="dropdownTv" href="#">@UI.Search_FirstSeason</a></li>
|
||||||
<li><a id="{{id}}" season-select="2" class="dropdownTv" href="#">@UI.Search_LatestSeason</a></li>
|
<li><a id="{{id}}" season-select="2" class="dropdownTv" href="#">@UI.Search_LatestSeason</a></li>
|
||||||
<li><a id="SeasonSelect" data-identifier="{{id}}" data-toggle="modal" data-target="#seasonsModal" href="#">@UI.Search_SelectSeason...</a></li>
|
<li><a id="SeasonSelect" data-identifier="{{id}}" data-toggle="modal" data-target="#seasonsModal" href="#">@UI.Search_SelectSeason...</a></li>
|
||||||
<li><a id="EpisodeSelect" data-identifier="{{id}}" data-toggle="modal" data-target="#episodesModal" href="#">@UI.Search_SelectEpisode...</a></li>
|
<li><a id="EpisodeSelect" data-identifier="{{id}}" data-toggle="modal" data-target="#episodesModal" href="#">@UI.Search_SelectEpisode...</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
{{/if_eq}}
|
|
||||||
{{/if_eq}}
|
|
||||||
{{/if_eq}}
|
{{/if_eq}}
|
||||||
|
|
||||||
|
|
||||||
<br />
|
<br />
|
||||||
</form>
|
</form>
|
||||||
{{#if_eq available true}}
|
{{#if_eq available true}}
|
||||||
|
@ -304,6 +305,7 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div hidden="hidden" id="selectedEpisodeId"></div>
|
<div hidden="hidden" id="selectedEpisodeId"></div>
|
||||||
|
<div hidden="hidden" id="episodeTvID"></div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<button type="button" class="btn btn-default" data-dismiss="modal">@UI.Common_Close</button>
|
<button type="button" class="btn btn-default" data-dismiss="modal">@UI.Common_Close</button>
|
||||||
<button type="button" id="episodesRequest" class="btn btn-primary">@UI.Search_Request</button>
|
<button type="button" id="episodesRequest" class="btn btn-primary">@UI.Search_Request</button>
|
||||||
|
@ -345,7 +347,9 @@
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script id="seasonNumber-template" type="text/x-handlebars-template">
|
<script id="seasonNumber-template" type="text/x-handlebars-template">
|
||||||
<div class="row"></div>
|
<br />
|
||||||
|
<br />
|
||||||
|
<br />
|
||||||
<div id="seasonNumber{{seasonNumber}}">
|
<div id="seasonNumber{{seasonNumber}}">
|
||||||
<strong>@UI.Search_Season {{seasonNumber}}</strong>
|
<strong>@UI.Search_Season {{seasonNumber}}</strong>
|
||||||
</div>
|
</div>
|
||||||
|
@ -357,7 +361,7 @@
|
||||||
<script id="episode-template" type="text/x-handlebars-template">
|
<script id="episode-template" type="text/x-handlebars-template">
|
||||||
<div class="form-group col-md-6">
|
<div class="form-group col-md-6">
|
||||||
<div class="checkbox" style="margin-bottom:0px; margin-top:0px;">
|
<div class="checkbox" style="margin-bottom:0px; margin-top:0px;">
|
||||||
<input type="checkbox" class="selectedEpisodes" id="{{id}}" name="{{id}}"><label for="{{id}}">{{number}}. {{name}}</label>
|
<input type="checkbox" class="selectedEpisodes" id="{{id}}" epNumber="{{number}}" epSeason="{{season}}" name="{{id}}"><label for="{{id}}">{{number}}. {{name}}</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue