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

pull/6/head
Mark McDowall 8 years ago
parent 7b09b259a8
commit 0a657302f7

@ -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 @@ namespace NzbDrone.Core.Notifications.Plex.Models
public string Type { get; set; }
public string Value { get; set; }
}
public class PlexPreferencesLegacy
{
[JsonProperty("_children")]
public List<PlexPreference> Preferences { get; set; }
}
}

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

@ -3,11 +3,10 @@ using Newtonsoft.Json;
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 @@ namespace NzbDrone.Core.Notifications.Plex.Models
public string Type { get; set; }
public string Language { get; set; }
public PlexSectionLocation Location { get; set; }
}
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<PlexSectionDetails> Sections { get; set; }
public List<PlexSectionLocation> Locations { get; set; }
}
public class PlexMediaContainer
public class PlexMediaContainerLegacy
{
[JsonProperty("_children")]
public List<PlexSection> Directories { get; set; }
public List<PlexSectionLegacy> Sections { get; set; }
}
}

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

@ -44,8 +44,24 @@ namespace NzbDrone.Core.Notifications.Plex
_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 @@ namespace NzbDrone.Core.Notifications.Plex
_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 @@ namespace NzbDrone.Core.Notifications.Plex
_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 @@ namespace NzbDrone.Core.Notifications.Plex
_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 @@ namespace NzbDrone.Core.Notifications.Plex
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())
{

@ -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" />

Loading…
Cancel
Save