Update Plex Movie Sections

pull/2/head
vertigo235 8 years ago
parent 290c4e1f2e
commit 6bbd64e59a

@ -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);
}
}

@ -17,6 +17,7 @@ namespace NzbDrone.Core.Notifications.Plex
public interface IPlexServerProxy
{
List<PlexSection> GetTvSections(PlexServerSettings settings);
List<PlexSection> 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<PlexSection> 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<PlexMediaContainerLegacy>(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<PlexResponse<PlexSectionsContainer>>(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);

@ -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<PlexSection> 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)

Loading…
Cancel
Save