diff --git a/src/NzbDrone.Core/Notifications/Plex/Models/PlexPreferences.cs b/src/NzbDrone.Core/Notifications/Plex/Models/PlexPreferences.cs index 39a7040b7..1cea5ef58 100644 --- a/src/NzbDrone.Core/Notifications/Plex/Models/PlexPreferences.cs +++ b/src/NzbDrone.Core/Notifications/Plex/Models/PlexPreferences.cs @@ -5,7 +5,7 @@ namespace NzbDrone.Core.Notifications.Plex.Models { public class PlexPreferences { - [JsonProperty("_children")] + [JsonProperty("Setting")] public List 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 Preferences { get; set; } + } } diff --git a/src/NzbDrone.Core/Notifications/Plex/Models/PlexResponse.cs b/src/NzbDrone.Core/Notifications/Plex/Models/PlexResponse.cs new file mode 100644 index 000000000..7d2214f54 --- /dev/null +++ b/src/NzbDrone.Core/Notifications/Plex/Models/PlexResponse.cs @@ -0,0 +1,7 @@ +namespace NzbDrone.Core.Notifications.Plex.Models +{ + public class PlexResponse + { + public T MediaContainer { get; set; } + } +} diff --git a/src/NzbDrone.Core/Notifications/Plex/Models/PlexSection.cs b/src/NzbDrone.Core/Notifications/Plex/Models/PlexSection.cs index 11decb6ff..87b5e9faa 100644 --- a/src/NzbDrone.Core/Notifications/Plex/Models/PlexSection.cs +++ b/src/NzbDrone.Core/Notifications/Plex/Models/PlexSection.cs @@ -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 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 Sections { get; set; } + public List Locations { get; set; } } - public class PlexMediaContainer + public class PlexMediaContainerLegacy { [JsonProperty("_children")] - public List Directories { get; set; } + public List Sections { get; set; } } } diff --git a/src/NzbDrone.Core/Notifications/Plex/Models/PlexSectionItem.cs b/src/NzbDrone.Core/Notifications/Plex/Models/PlexSectionItem.cs index 7758c2d0a..009baed7b 100644 --- a/src/NzbDrone.Core/Notifications/Plex/Models/PlexSectionItem.cs +++ b/src/NzbDrone.Core/Notifications/Plex/Models/PlexSectionItem.cs @@ -12,6 +12,11 @@ namespace NzbDrone.Core.Notifications.Plex.Models } public class PlexSectionResponse + { + public List Items { get; set; } + } + + public class PlexSectionResponseLegacy { [JsonProperty("_children")] public List Items { get; set; } diff --git a/src/NzbDrone.Core/Notifications/Plex/PlexServerProxy.cs b/src/NzbDrone.Core/Notifications/Plex/PlexServerProxy.cs index de35ec79d..cc1011b8d 100644 --- a/src/NzbDrone.Core/Notifications/Plex/PlexServerProxy.cs +++ b/src/NzbDrone.Core/Notifications/Plex/PlexServerProxy.cs @@ -44,8 +44,24 @@ namespace NzbDrone.Core.Notifications.Plex _logger.Trace("Sections response: {0}", response.Content); CheckForError(response, settings); - return Json.Deserialize(response.Content) - .Directories + if (response.Content.Contains("_children")) + { + return Json.Deserialize(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>(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>(response.Content).MediaContainer.Version; + } + return Json.Deserialize(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(response.Content).Preferences; + if (response.Content.Contains("MediaContainer")) + { + return Json.Deserialize>(response.Content).MediaContainer.Preferences; + } + + return Json.Deserialize(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(response.Content) - .Items; + List items; + + if (response.Content.Contains("_children")) + { + items = Json.Deserialize(response.Content) + .Items; + } + + else + { + items = Json.Deserialize(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(response.Content); + var error = response.Content.Contains("MediaContainer") ? + Json.Deserialize>(response.Content).MediaContainer : + Json.Deserialize(response.Content); if (error != null && !error.Error.IsNullOrWhiteSpace()) { diff --git a/src/NzbDrone.Core/NzbDrone.Core.csproj b/src/NzbDrone.Core/NzbDrone.Core.csproj index d427f229e..4564e0df8 100644 --- a/src/NzbDrone.Core/NzbDrone.Core.csproj +++ b/src/NzbDrone.Core/NzbDrone.Core.csproj @@ -822,6 +822,7 @@ +