From 7c5646d416372983ac8996b1a6539e671db18c86 Mon Sep 17 00:00:00 2001 From: tidusjar Date: Thu, 16 Sep 2021 14:59:35 +0100 Subject: [PATCH] feat(plex): :zap: Use the new Plex Pass includeGuids feature for syncing plex movies --- src/Ombi.Api.Plex/Models/Metadata.cs | 4 ++- src/Ombi.Api.Plex/PlexApi.cs | 1 + .../Jobs/Plex/PlexContentSync.cs | 27 ++++++++++++------- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/Ombi.Api.Plex/Models/Metadata.cs b/src/Ombi.Api.Plex/Models/Metadata.cs index 92e66b35c..d0bb227ad 100644 --- a/src/Ombi.Api.Plex/Models/Metadata.cs +++ b/src/Ombi.Api.Plex/Models/Metadata.cs @@ -1,3 +1,5 @@ +using System.Collections.Generic; + namespace Ombi.Api.Plex.Models { public class Metadata @@ -44,7 +46,7 @@ namespace Ombi.Api.Plex.Models public string grandparentTheme { get; set; } public string chapterSource { get; set; } public Medium[] Media { get; set; } - public PlexGuids[] Guid { get; set; } + public List Guid { get; set; } = new List(); // public Director[] Director { get; set; } // public Writer[] Writer { get; set; } } diff --git a/src/Ombi.Api.Plex/PlexApi.cs b/src/Ombi.Api.Plex/PlexApi.cs index b80534bb9..77c129cd7 100644 --- a/src/Ombi.Api.Plex/PlexApi.cs +++ b/src/Ombi.Api.Plex/PlexApi.cs @@ -123,6 +123,7 @@ namespace Ombi.Api.Plex public async Task GetLibrary(string authToken, string plexFullHost, string libraryId) { var request = new Request($"library/sections/{libraryId}/all", plexFullHost, HttpMethod.Get); + request.AddQueryString("includeGuids","1"); await AddHeaders(request, authToken); return await Api.Request(request); } diff --git a/src/Ombi.Schedule/Jobs/Plex/PlexContentSync.cs b/src/Ombi.Schedule/Jobs/Plex/PlexContentSync.cs index dbad7ac84..0c210668c 100644 --- a/src/Ombi.Schedule/Jobs/Plex/PlexContentSync.cs +++ b/src/Ombi.Schedule/Jobs/Plex/PlexContentSync.cs @@ -287,17 +287,26 @@ namespace Ombi.Schedule.Jobs.Plex } Logger.LogDebug("Adding movie {0}", movie.title); - var metaData = await PlexApi.GetMetadata(servers.PlexAuthToken, servers.FullUri, - movie.ratingKey); - - var meta = metaData.MediaContainer.Metadata.FirstOrDefault(); - var guids = new List + var guids = new List(); + if (!movie.Guid.Any()) { - meta.guid - }; - if (meta.Guid != null) + var metaData = await PlexApi.GetMetadata(servers.PlexAuthToken, servers.FullUri, + movie.ratingKey); + + var meta = metaData.MediaContainer.Metadata.FirstOrDefault(); + guids.Add(meta.guid); + if (meta.Guid != null) + { + foreach (var g in meta.Guid) + { + guids.Add(g.Id); + } + } + } + else { - foreach (var g in meta.Guid) + // Currently a Plex Pass feature only + foreach (var g in movie.Guid) { guids.Add(g.Id); }