Skip to content

Commit

Permalink
Merge pull request #570 from tidusjar/dev
Browse files Browse the repository at this point in the history
Dev to master
  • Loading branch information
tidusjar authored Oct 9, 2016
2 parents 962e663 + 24b1d82 commit ce956aa
Show file tree
Hide file tree
Showing 55 changed files with 1,991 additions and 316 deletions.
2 changes: 1 addition & 1 deletion PlexRequests.Api.Interfaces/ICouchPotatoApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ public interface ICouchPotatoApi
CouchPotatoProfiles GetProfiles(Uri url, string apiKey);
CouchPotatoMovies GetMovies(Uri baseUrl, string apiKey, string[] status);

CoucPotatoApiKey GetApiKey(Uri baseUrl, string username, string password);
CouchPotatoApiKey GetApiKey(Uri baseUrl, string username, string password);
}
}
1 change: 1 addition & 0 deletions PlexRequests.Api.Interfaces/IPlexApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,6 @@ public interface IPlexApi
PlexSearch GetAllEpisodes(string authToken, Uri host, string section, int startPage, int returnCount);
PlexServer GetServer(string authToken);
PlexSeasonMetadata GetSeasons(string authToken, Uri plexFullHost, string ratingKey);
RecentlyAdded RecentlyAdded(string authToken, Uri plexFullHost);
}
}
3 changes: 3 additions & 0 deletions PlexRequests.Api.Interfaces/ISonarrApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ SonarrAddSeries AddSeries(int tvdbId, string title, int qualityId, bool seasonFo
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);
SonarrEpisodes UpdateEpisode(SonarrEpisodes episodeInfo, string apiKey, Uri baseUrl);
SonarrAddEpisodeResult SearchForEpisodes(int[] episodeIds, string apiKey, Uri baseUrl);
Series UpdateSeries(Series series, string apiKey, Uri baseUrl);
SonarrSeasonSearchResult SearchForSeason(int seriesId, int seasonNumber, string apiKey, Uri baseUrl);
SonarrSeriesSearchResult SearchForSeries(int seriesId, string apiKey, Uri baseUrl);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: CoucPotatoApiKey.cs
// File: CouchPotatoApiKey.cs
// Created By: Jamie Rees
//
// Permission is hereby granted, free of charge, to any person obtaining
Expand All @@ -28,10 +28,10 @@

namespace PlexRequests.Api.Models.Movie
{
public class CoucPotatoApiKey
public class CouchPotatoApiKey
{
[JsonProperty("success")]
public bool Result { get; set; }
public bool success { get; set; }
[JsonProperty("api_key")]
public string ApiKey { get; set; }
}
Expand Down
84 changes: 84 additions & 0 deletions PlexRequests.Api.Models/Plex/RecentlyAdded.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: RecentlyAdded.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.Plex
{
public class RecentlyAddedChild
{
public string _elementType { get; set; }
public string allowSync { get; set; }
public string librarySectionID { get; set; }
public string librarySectionTitle { get; set; }
public string librarySectionUUID { get; set; }
public int ratingKey { get; set; }
public string key { get; set; }
public int parentRatingKey { get; set; }
public string type { get; set; }
public string title { get; set; }
public string parentKey { get; set; }
public string parentTitle { get; set; }
public string parentSummary { get; set; }
public string summary { get; set; }
public int index { get; set; }
public int parentIndex { get; set; }
public string thumb { get; set; }
public string art { get; set; }
public string parentThumb { get; set; }
public int leafCount { get; set; }
public int viewedLeafCount { get; set; }
public int addedAt { get; set; }
public int updatedAt { get; set; }
public List<object> _children { get; set; }
public string studio { get; set; }
public string contentRating { get; set; }
public string rating { get; set; }
public int? viewCount { get; set; }
public int? lastViewedAt { get; set; }
public int? year { get; set; }
public int? duration { get; set; }
public string originallyAvailableAt { get; set; }
public string chapterSource { get; set; }
public string parentTheme { get; set; }
public string titleSort { get; set; }
public string tagline { get; set; }
public int? viewOffset { get; set; }
public string originalTitle { get; set; }
}

public class RecentlyAdded
{
public string _elementType { get; set; }
public string allowSync { get; set; }
public string identifier { get; set; }
public string mediaTagPrefix { get; set; }
public string mediaTagVersion { get; set; }
public string mixedParents { get; set; }
public List<RecentlyAddedChild> _children { get; set; }
}
}
6 changes: 5 additions & 1 deletion PlexRequests.Api.Models/PlexRequests.Api.Models.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<Compile Include="Movie\CouchPotatoMovies.cs" />
<Compile Include="Movie\CouchPotatoProfiles.cs" />
<Compile Include="Movie\CouchPotatoStatus.cs" />
<Compile Include="Movie\CoucPotatoApiKey.cs" />
<Compile Include="Movie\CouchPotatoApiKey.cs" />
<Compile Include="Music\HeadphonesAlbumSearchResult.cs" />
<Compile Include="Music\HeadphonesArtistSearchResult.cs" />
<Compile Include="Music\HeadphonesGetIndex.cs" />
Expand All @@ -73,6 +73,7 @@
<Compile Include="Plex\PlexStatus.cs" />
<Compile Include="Plex\PlexMediaType.cs" />
<Compile Include="Plex\PlexUserRequest.cs" />
<Compile Include="Plex\RecentlyAdded.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SickRage\SickRageBase.cs" />
<Compile Include="SickRage\SickrageShows.cs" />
Expand All @@ -89,6 +90,9 @@
<Compile Include="Sonarr\SonarrEpisodes.cs" />
<Compile Include="Sonarr\SonarrError.cs" />
<Compile Include="Sonarr\SonarrProfile.cs" />
<Compile Include="Sonarr\SonarrSearchCommand.cs" />
<Compile Include="Sonarr\SonarrSeasonSearchResult.cs" />
<Compile Include="Sonarr\SonarrSeriesSearchResult.cs" />
<Compile Include="Sonarr\SystemStatus.cs" />
<Compile Include="Tv\Authentication.cs" />
<Compile Include="Tv\TvMazeEpisodes.cs" />
Expand Down
2 changes: 1 addition & 1 deletion PlexRequests.Api.Models/Sonarr/SonarrAddEpisodeBody.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ namespace PlexRequests.Api.Models.Sonarr
public class SonarrAddEpisodeBody
{
public string name { get; set; }
public int[] episodeIds { get; set; }
public int[] episodeIds { get; set; }
}
}
38 changes: 38 additions & 0 deletions PlexRequests.Api.Models/Sonarr/SonarrSearchCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: SonarrSearchCommand.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.Xml.Linq;

namespace PlexRequests.Api.Models.Sonarr
{
public class SonarrSearchCommand
{
public int seriesId { get; set; }
public int seasonNumber { get; set; }
public string name { get; set; }
}
}
55 changes: 55 additions & 0 deletions PlexRequests.Api.Models/Sonarr/SonarrSeasonSearchResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: SonarrSeasonSearchResult.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 SeasonBody
{
public int seriesId { get; set; }
public int seasonNumber { 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 SonarrSeasonSearchResult
{
public string name { get; set; }
public SeasonBody 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; }
}
}
56 changes: 56 additions & 0 deletions PlexRequests.Api.Models/Sonarr/SonarrSeriesSearchResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: SonarrSeriesSearchResult.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 SeriesBody
{
public int seriesId { 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 SonarrSeriesSearchResult
{
public string name { get; set; }
public SeriesBody body { get; set; }
public string priority { get; set; }
public string status { get; set; }
public string queued { get; set; }
public string started { get; set; }
public string trigger { get; set; }
public string state { get; set; }
public bool manual { get; set; }
public string startedOn { get; set; }
public string stateChangeTime { get; set; }
public bool sendUpdatesToClient { get; set; }
public bool updateScheduledTask { get; set; }
public int id { get; set; }
}
}
6 changes: 3 additions & 3 deletions PlexRequests.Api/CouchPotatoApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,18 +160,18 @@ public CouchPotatoMovies GetMovies(Uri baseUrl, string apiKey, string[] status)
}
}

public CoucPotatoApiKey GetApiKey(Uri baseUrl, string username, string password)
public CouchPotatoApiKey GetApiKey(Uri baseUrl, string username, string password)
{
var request = new RestRequest
{
Resource = "getkey/?p={username}&u={password}",
Resource = "getkey/?u={username}&p={password}",
Method = Method.GET
};

request.AddUrlSegment("username", StringHasher.CalcuateMd5Hash(username));
request.AddUrlSegment("password", StringHasher.CalcuateMd5Hash(password));

var obj = RetryHandler.Execute(() => Api.Execute<CoucPotatoApiKey>(request, baseUrl),
var obj = RetryHandler.Execute(() => Api.Execute<CouchPotatoApiKey>(request, baseUrl),
(exception, timespan) => Log.Error(exception, "Exception when calling GetApiKey for CP, Retrying {0}", timespan), null);

return obj;
Expand Down
33 changes: 33 additions & 0 deletions PlexRequests.Api/PlexApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,39 @@ public PlexServer GetServer(string authToken)
return servers;
}

public RecentlyAdded RecentlyAdded(string authToken, Uri plexFullHost)
{
var request = new RestRequest
{
Method = Method.GET,
Resource = "library/recentlyAdded"
};

request.AddHeader("X-Plex-Token", authToken);
request.AddHeader("X-Plex-Client-Identifier", $"PlexRequests.Net{Version}");
request.AddHeader("X-Plex-Product", "Plex Requests .Net");
request.AddHeader("X-Plex-Version", Version);
request.AddHeader("Content-Type", "application/json");
request.AddHeader("Accept", "application/json");

try
{
var lib = RetryHandler.Execute(() => Api.ExecuteJson<RecentlyAdded>(request, plexFullHost),
(exception, timespan) => Log.Error(exception, "Exception when calling RecentlyAdded for Plex, Retrying {0}", timespan), new[] {
TimeSpan.FromSeconds (5),
TimeSpan.FromSeconds(10),
TimeSpan.FromSeconds(30)
});

return lib;
}
catch (Exception e)
{
Log.Error(e, "There has been a API Exception when attempting to get the Plex RecentlyAdded");
return new RecentlyAdded();
}
}

private void AddHeaders(ref RestRequest request, string authToken)
{
request.AddHeader("X-Plex-Token", authToken);
Expand Down
Loading

0 comments on commit ce956aa

Please sign in to comment.