diff --git a/src/NzbDrone.Core/Notifications/Plex/PlexServer.cs b/src/NzbDrone.Core/Notifications/Plex/PlexServer.cs index 7d086e90a..cf52620d7 100644 --- a/src/NzbDrone.Core/Notifications/Plex/PlexServer.cs +++ b/src/NzbDrone.Core/Notifications/Plex/PlexServer.cs @@ -22,23 +22,24 @@ namespace NzbDrone.Core.Notifications.Plex public override void OnDownload(DownloadMessage message) { - UpdateIfEnabled(message.Series); + UpdateIfEnabled(message.Movie); } public override void OnMovieRename(Movie movie) { + UpdateIfEnabled(movie); } public override void OnRename(Series series) { - UpdateIfEnabled(series); + //UpdateIfEnabled(movie); } - private void UpdateIfEnabled(Series series) + private void UpdateIfEnabled(Movie movie) { if (Settings.UpdateLibrary) { - _plexServerService.UpdateLibrary(series, Settings); + _plexServerService.UpdateMovieSections(movie, Settings); } } diff --git a/src/NzbDrone.Core/Notifications/Plex/PlexServerProxy.cs b/src/NzbDrone.Core/Notifications/Plex/PlexServerProxy.cs index 0742ca049..a0c49452f 100644 --- a/src/NzbDrone.Core/Notifications/Plex/PlexServerProxy.cs +++ b/src/NzbDrone.Core/Notifications/Plex/PlexServerProxy.cs @@ -17,6 +17,7 @@ namespace NzbDrone.Core.Notifications.Plex public interface IPlexServerProxy { List GetTvSections(PlexServerSettings settings); + List GetMovieSections(PlexServerSettings settings); void Update(int sectionId, PlexServerSettings settings); void UpdateSeries(int metadataId, PlexServerSettings settings); string Version(PlexServerSettings settings); @@ -66,6 +67,37 @@ namespace NzbDrone.Core.Notifications.Plex .ToList(); } + public List GetMovieSections(PlexServerSettings settings) + { + var request = GetPlexServerRequest("library/sections", Method.GET, settings); + var client = GetPlexServerClient(settings); + var response = client.Execute(request); + + _logger.Trace("Sections response: {0}", response.Content); + CheckForError(response, settings); + + if (response.Content.Contains("_children")) + { + return Json.Deserialize(response.Content) + .Sections + .Where(d => d.Type == "movie") + .Select(s => new PlexSection + { + Id = s.Id, + Language = s.Language, + Locations = s.Locations, + Type = s.Type + }) + .ToList(); + } + + return Json.Deserialize>(response.Content) + .MediaContainer + .Sections + .Where(d => d.Type == "movie") + .ToList(); + } + public void Update(int sectionId, PlexServerSettings settings) { var resource = string.Format("library/sections/{0}/refresh", sectionId); diff --git a/src/NzbDrone.Core/Notifications/Plex/PlexServerService.cs b/src/NzbDrone.Core/Notifications/Plex/PlexServerService.cs index 67b8efe23..cb58e9040 100644 --- a/src/NzbDrone.Core/Notifications/Plex/PlexServerService.cs +++ b/src/NzbDrone.Core/Notifications/Plex/PlexServerService.cs @@ -14,6 +14,7 @@ namespace NzbDrone.Core.Notifications.Plex public interface IPlexServerService { void UpdateLibrary(Series series, PlexServerSettings settings); + void UpdateMovieSections(Movie movie, PlexServerSettings settings); ValidationFailure Test(PlexServerSettings settings); } @@ -62,11 +63,43 @@ namespace NzbDrone.Core.Notifications.Plex } } + public void UpdateMovieSections(Movie movie, PlexServerSettings settings) + { + try + { + _logger.Debug("Sending Update Request to Plex Server"); + + var version = _versionCache.Get(settings.Host, () => GetVersion(settings), TimeSpan.FromHours(2)); + ValidateVersion(version); + + var sections = GetSections(settings); + var partialUpdates = _partialUpdateCache.Get(settings.Host, () => PartialUpdatesAllowed(settings, version), TimeSpan.FromHours(2)); + + // TODO: Investiate partial updates later, for now just update all movie sections... + + //if (partialUpdates) + //{ + // UpdatePartialSection(series, sections, settings); + //} + + //else + //{ + sections.ForEach(s => UpdateSection(s.Id, settings)); + //} + } + + catch (Exception ex) + { + _logger.Warn(ex, "Failed to Update Plex host: " + settings.Host); + throw; + } + } + private List GetSections(PlexServerSettings settings) { _logger.Debug("Getting sections from Plex host: {0}", settings.Host); - return _plexServerProxy.GetTvSections(settings).ToList(); + return _plexServerProxy.GetMovieSections(settings).ToList(); } private bool PartialUpdatesAllowed(PlexServerSettings settings, Version version) diff --git a/src/NzbDrone.Core/Notifications/Slack/Slack.cs b/src/NzbDrone.Core/Notifications/Slack/Slack.cs index d2038aea1..03b74c27f 100644 --- a/src/NzbDrone.Core/Notifications/Slack/Slack.cs +++ b/src/NzbDrone.Core/Notifications/Slack/Slack.cs @@ -37,7 +37,7 @@ namespace NzbDrone.Core.Notifications.Slack new Attachment { Fallback = message.Message, - Title = message.Series.Title, + Title = message.Movie.Title, Text = message.Message, Color = "warning" } @@ -59,7 +59,7 @@ namespace NzbDrone.Core.Notifications.Slack new Attachment { Fallback = message.Message, - Title = message.Series.Title, + Title = message.Movie.Title, Text = message.Message, Color = "good" } @@ -71,8 +71,23 @@ namespace NzbDrone.Core.Notifications.Slack public override void OnMovieRename(Movie movie) { - } - + var payload = new SlackPayload + { + IconEmoji = Settings.Icon, + Username = Settings.Username, + Text = "Renamed", + Attachments = new List + { + new Attachment + { + Title = movie.Title, + } + } + }; + + NotifySlack(payload); + } + public override void OnRename(Series series) { var payload = new SlackPayload