1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-04 10:02:40 +01:00

New: Support for Plex Media Server 1.3.0's new JSON responses

This commit is contained in:
Mark McDowall 2016-11-23 16:38:57 -08:00
parent 7b09b259a8
commit 0a657302f7
6 changed files with 87 additions and 13 deletions

View File

@ -5,7 +5,7 @@ namespace NzbDrone.Core.Notifications.Plex.Models
{
public class PlexPreferences
{
[JsonProperty("_children")]
[JsonProperty("Setting")]
public List<PlexPreference> Preferences { get; set; }
}
@ -15,4 +15,10 @@ public class PlexPreference
public string Type { get; set; }
public string Value { get; set; }
}
public class PlexPreferencesLegacy
{
[JsonProperty("_children")]
public List<PlexPreference> Preferences { get; set; }
}
}

View File

@ -0,0 +1,7 @@
namespace NzbDrone.Core.Notifications.Plex.Models
{
public class PlexResponse<T>
{
public T MediaContainer { get; set; }
}
}

View File

@ -3,11 +3,10 @@
namespace NzbDrone.Core.Notifications.Plex.Models
{
public class PlexSectionDetails
public class PlexSectionLocation
{
public int Id { get; set; }
public string Path { get; set; }
public string Language { get; set; }
}
public class PlexSection
@ -18,13 +17,30 @@ public class PlexSection
public string Type { get; set; }
public string Language { get; set; }
[JsonProperty("_children")]
public List<PlexSectionDetails> Sections { get; set; }
public PlexSectionLocation Location { get; set; }
}
public class PlexMediaContainer
public class PlexSectionsContainer
{
[JsonProperty("Metadata")]
public List<PlexSection> Sections { get; set; }
}
public class PlexSectionLegacy
{
[JsonProperty("key")]
public int Id { get; set; }
public string Type { get; set; }
public string Language { get; set; }
[JsonProperty("_children")]
public List<PlexSectionLocation> Locations { get; set; }
}
public class PlexMediaContainerLegacy
{
[JsonProperty("_children")]
public List<PlexSection> Directories { get; set; }
public List<PlexSectionLegacy> Sections { get; set; }
}
}

View File

@ -12,6 +12,11 @@ public class PlexSectionItem
}
public class PlexSectionResponse
{
public List<PlexSectionItem> Items { get; set; }
}
public class PlexSectionResponseLegacy
{
[JsonProperty("_children")]
public List<PlexSectionItem> Items { get; set; }

View File

@ -44,8 +44,24 @@ public List<PlexSection> GetTvSections(PlexServerSettings settings)
_logger.Trace("Sections response: {0}", response.Content);
CheckForError(response, settings);
return Json.Deserialize<PlexMediaContainer>(response.Content)
.Directories
if (response.Content.Contains("_children"))
{
return Json.Deserialize<PlexMediaContainerLegacy>(response.Content)
.Sections
.Where(d => d.Type == "show")
.Select(s => new PlexSection
{
Id = s.Id,
Language = s.Language,
Location = s.Locations.FirstOrDefault(),
Type = s.Type
})
.ToList();
}
return Json.Deserialize<PlexResponse<PlexSectionsContainer>>(response.Content)
.MediaContainer
.Sections
.Where(d => d.Type == "show")
.ToList();
}
@ -81,6 +97,11 @@ public string Version(PlexServerSettings settings)
_logger.Trace("Version response: {0}", response.Content);
CheckForError(response, settings);
if (response.Content.Contains("MediaContainer"))
{
return Json.Deserialize<PlexResponse<PlexIdentity>>(response.Content).MediaContainer.Version;
}
return Json.Deserialize<PlexIdentity>(response.Content).Version;
}
@ -93,7 +114,12 @@ public List<PlexPreference> Preferences(PlexServerSettings settings)
_logger.Trace("Preferences response: {0}", response.Content);
CheckForError(response, settings);
return Json.Deserialize<PlexPreferences>(response.Content).Preferences;
if (response.Content.Contains("MediaContainer"))
{
return Json.Deserialize<PlexResponse<PlexPreferences>>(response.Content).MediaContainer.Preferences;
}
return Json.Deserialize<PlexPreferencesLegacy>(response.Content).Preferences;
}
public int? GetMetadataId(int sectionId, int tvdbId, string language, PlexServerSettings settings)
@ -107,8 +133,19 @@ public List<PlexPreference> Preferences(PlexServerSettings settings)
_logger.Trace("Sections response: {0}", response.Content);
CheckForError(response, settings);
var items = Json.Deserialize<PlexSectionResponse>(response.Content)
.Items;
List<PlexSectionItem> items;
if (response.Content.Contains("_children"))
{
items = Json.Deserialize<PlexSectionResponseLegacy>(response.Content)
.Items;
}
else
{
items = Json.Deserialize<PlexSectionResponse>(response.Content)
.Items;
}
if (items == null || items.Empty())
{
@ -203,7 +240,9 @@ private void CheckForError(IRestResponse response, PlexServerSettings settings)
throw new PlexAuthenticationException("Unauthorized - Username or password is incorrect");
}
var error = Json.Deserialize<PlexError>(response.Content);
var error = response.Content.Contains("MediaContainer") ?
Json.Deserialize<PlexResponse<PlexError>>(response.Content).MediaContainer :
Json.Deserialize<PlexError>(response.Content);
if (error != null && !error.Error.IsNullOrWhiteSpace())
{

View File

@ -822,6 +822,7 @@
<Compile Include="Notifications\Boxcar\BoxcarSettings.cs" />
<Compile Include="Notifications\GrabMessage.cs" />
<Compile Include="Notifications\Plex\Models\PlexIdentity.cs" />
<Compile Include="Notifications\Plex\Models\PlexResponse.cs" />
<Compile Include="Notifications\Plex\Models\PlexPreferences.cs" />
<Compile Include="Notifications\Plex\Models\PlexSectionItem.cs" />
<Compile Include="Notifications\Plex\Models\PlexSection.cs" />