From b5a268510d1a66a770c265239f57e5263a3bd5de Mon Sep 17 00:00:00 2001 From: tidusjar Date: Wed, 6 Apr 2022 21:42:24 +0100 Subject: [PATCH] Updated projects, updated entities to use a string as the primary keys. migrations need doing --- .../Ombi.Api.CouchPotato.csproj | 2 +- src/Ombi.Api.Discord/Ombi.Api.Discord.csproj | 2 +- src/Ombi.Api.DogNzb/Ombi.Api.DogNzb.csproj | 2 +- src/Ombi.Api.Emby/Ombi.Api.Emby.csproj | 2 +- .../Ombi.Api.FanartTv.csproj | 2 +- src/Ombi.Api.Github/Ombi.Api.Github.csproj | 2 +- src/Ombi.Api.Gotify/Ombi.Api.Gotify.csproj | 2 +- src/Ombi.Api.GroupMe/Ombi.Api.GroupMe.csproj | 2 +- .../Ombi.Api.Jellyfin.csproj | 2 +- src/Ombi.Api.Lidarr/Ombi.Api.Lidarr.csproj | 2 +- .../Ombi.Api.Mattermost.csproj | 2 +- .../Ombi.Api.MediaServer.csproj | 2 +- .../Ombi.Api.MusicBrainz.csproj | 2 +- .../Ombi.Api.Notifications.csproj | 2 +- src/Ombi.Api.Plex/IPlexApi.cs | 8 +- src/Ombi.Api.Plex/Models/Metadata.cs | 6 +- src/Ombi.Api.Plex/Ombi.Api.Plex.csproj | 2 +- src/Ombi.Api.Plex/PlexApi.cs | 10 +- .../Ombi.Api.Pushbullet.csproj | 2 +- .../Ombi.Api.Pushover.csproj | 2 +- src/Ombi.Api.Radarr/Ombi.Api.Radarr.csproj | 2 +- .../Ombi.Api.RottenTomatoes.csproj | 2 +- src/Ombi.Api.Service/Ombi.Api.Service.csproj | 2 +- .../Ombi.Api.SickRage.csproj | 2 +- src/Ombi.Api.Slack/Ombi.Api.Slack.csproj | 2 +- src/Ombi.Api.Sonarr/Ombi.Api.Sonarr.csproj | 2 +- .../Ombi.Api.Telegram.csproj | 2 +- src/Ombi.Api.Trakt/Ombi.Api.Trakt.csproj | 2 +- src/Ombi.Api.TvMaze/Ombi.Api.TvMaze.csproj | 2 +- src/Ombi.Api/Ombi.Api.csproj | 2 +- src/Ombi.Core/Ombi.Core.csproj | 2 +- .../Ombi.DependencyInjection.csproj | 2 +- src/Ombi.Helpers/Ombi.Helpers.csproj | 2 +- src/Ombi.Helpers/PlexHelper.cs | 2 +- src/Ombi.Hubs/Ombi.Hubs.csproj | 2 +- src/Ombi.I18n/Ombi.I18n.csproj | 4 +- src/Ombi.Mapping/Ombi.Mapping.csproj | 2 +- .../Ombi.Notifications.Templates.csproj | 2 +- .../Ombi.Notifications.csproj | 2 +- .../Ombi.Schedule.Tests.csproj | 1 + .../PlexContentSyncTests.cs | 26 ++-- .../PlexWatchlistImportTests.cs | 57 +++++++++ .../Jobs/Plex/Models/ProcessedContent.cs | 2 +- .../Jobs/Plex/PlexContentSync.cs | 6 +- .../Jobs/Plex/PlexWatchlistImport.cs | 112 +++++++++++++++++- src/Ombi.Schedule/Ombi.Schedule.csproj | 2 +- src/Ombi.Settings/Ombi.Settings.csproj | 2 +- src/Ombi.Store/Entities/OmbiUser.cs | 1 + src/Ombi.Store/Entities/PlexEpisode.cs | 6 +- src/Ombi.Store/Entities/PlexServerContent.cs | 8 +- src/Ombi.Store/Ombi.Store.csproj | 2 +- .../Repository/IPlexContentRepository.cs | 4 +- .../Repository/PlexContentRepository.cs | 4 +- src/Ombi.Test.Common/Ombi.Test.Common.csproj | 2 +- .../Ombi.Api.TheMovieDb.csproj | 2 +- 55 files changed, 248 insertions(+), 87 deletions(-) create mode 100644 src/Ombi.Schedule.Tests/PlexWatchlistImportTests.cs diff --git a/src/Ombi.Api.CouchPotato/Ombi.Api.CouchPotato.csproj b/src/Ombi.Api.CouchPotato/Ombi.Api.CouchPotato.csproj index 6353f4bf9..89c47d251 100644 --- a/src/Ombi.Api.CouchPotato/Ombi.Api.CouchPotato.csproj +++ b/src/Ombi.Api.CouchPotato/Ombi.Api.CouchPotato.csproj @@ -2,7 +2,7 @@ net6.0 - 8.0 + latest Debug;Release;NonUiBuild diff --git a/src/Ombi.Api.Discord/Ombi.Api.Discord.csproj b/src/Ombi.Api.Discord/Ombi.Api.Discord.csproj index 4945a2fb2..70032d638 100644 --- a/src/Ombi.Api.Discord/Ombi.Api.Discord.csproj +++ b/src/Ombi.Api.Discord/Ombi.Api.Discord.csproj @@ -6,7 +6,7 @@ 3.0.0.0 - 8.0 + latest Debug;Release;NonUiBuild diff --git a/src/Ombi.Api.DogNzb/Ombi.Api.DogNzb.csproj b/src/Ombi.Api.DogNzb/Ombi.Api.DogNzb.csproj index 6353f4bf9..89c47d251 100644 --- a/src/Ombi.Api.DogNzb/Ombi.Api.DogNzb.csproj +++ b/src/Ombi.Api.DogNzb/Ombi.Api.DogNzb.csproj @@ -2,7 +2,7 @@ net6.0 - 8.0 + latest Debug;Release;NonUiBuild diff --git a/src/Ombi.Api.Emby/Ombi.Api.Emby.csproj b/src/Ombi.Api.Emby/Ombi.Api.Emby.csproj index b524c9ce4..f60971192 100644 --- a/src/Ombi.Api.Emby/Ombi.Api.Emby.csproj +++ b/src/Ombi.Api.Emby/Ombi.Api.Emby.csproj @@ -6,7 +6,7 @@ 3.0.0.0 - 8.0 + latest Debug;Release;NonUiBuild diff --git a/src/Ombi.Api.FanartTv/Ombi.Api.FanartTv.csproj b/src/Ombi.Api.FanartTv/Ombi.Api.FanartTv.csproj index 4945a2fb2..70032d638 100644 --- a/src/Ombi.Api.FanartTv/Ombi.Api.FanartTv.csproj +++ b/src/Ombi.Api.FanartTv/Ombi.Api.FanartTv.csproj @@ -6,7 +6,7 @@ 3.0.0.0 - 8.0 + latest Debug;Release;NonUiBuild diff --git a/src/Ombi.Api.Github/Ombi.Api.Github.csproj b/src/Ombi.Api.Github/Ombi.Api.Github.csproj index 6353f4bf9..89c47d251 100644 --- a/src/Ombi.Api.Github/Ombi.Api.Github.csproj +++ b/src/Ombi.Api.Github/Ombi.Api.Github.csproj @@ -2,7 +2,7 @@ net6.0 - 8.0 + latest Debug;Release;NonUiBuild diff --git a/src/Ombi.Api.Gotify/Ombi.Api.Gotify.csproj b/src/Ombi.Api.Gotify/Ombi.Api.Gotify.csproj index 1285c073c..be32916f8 100644 --- a/src/Ombi.Api.Gotify/Ombi.Api.Gotify.csproj +++ b/src/Ombi.Api.Gotify/Ombi.Api.Gotify.csproj @@ -6,7 +6,7 @@ 3.0.0.0 - 8.0 + latest Debug;Release;NonUiBuild diff --git a/src/Ombi.Api.GroupMe/Ombi.Api.GroupMe.csproj b/src/Ombi.Api.GroupMe/Ombi.Api.GroupMe.csproj index 6353f4bf9..89c47d251 100644 --- a/src/Ombi.Api.GroupMe/Ombi.Api.GroupMe.csproj +++ b/src/Ombi.Api.GroupMe/Ombi.Api.GroupMe.csproj @@ -2,7 +2,7 @@ net6.0 - 8.0 + latest Debug;Release;NonUiBuild diff --git a/src/Ombi.Api.Jellyfin/Ombi.Api.Jellyfin.csproj b/src/Ombi.Api.Jellyfin/Ombi.Api.Jellyfin.csproj index dfdb5a93f..0c745556e 100644 --- a/src/Ombi.Api.Jellyfin/Ombi.Api.Jellyfin.csproj +++ b/src/Ombi.Api.Jellyfin/Ombi.Api.Jellyfin.csproj @@ -6,7 +6,7 @@ 3.0.0.0 - 8.0 + latest Debug;Release;NonUiBuild diff --git a/src/Ombi.Api.Lidarr/Ombi.Api.Lidarr.csproj b/src/Ombi.Api.Lidarr/Ombi.Api.Lidarr.csproj index 6353f4bf9..89c47d251 100644 --- a/src/Ombi.Api.Lidarr/Ombi.Api.Lidarr.csproj +++ b/src/Ombi.Api.Lidarr/Ombi.Api.Lidarr.csproj @@ -2,7 +2,7 @@ net6.0 - 8.0 + latest Debug;Release;NonUiBuild diff --git a/src/Ombi.Api.Mattermost/Ombi.Api.Mattermost.csproj b/src/Ombi.Api.Mattermost/Ombi.Api.Mattermost.csproj index a25024b6c..16c3a8558 100644 --- a/src/Ombi.Api.Mattermost/Ombi.Api.Mattermost.csproj +++ b/src/Ombi.Api.Mattermost/Ombi.Api.Mattermost.csproj @@ -6,7 +6,7 @@ 3.0.0.0 - 8.0 + latest Debug;Release;NonUiBuild diff --git a/src/Ombi.Api.MediaServer/Ombi.Api.MediaServer.csproj b/src/Ombi.Api.MediaServer/Ombi.Api.MediaServer.csproj index f167146af..a1b98b765 100644 --- a/src/Ombi.Api.MediaServer/Ombi.Api.MediaServer.csproj +++ b/src/Ombi.Api.MediaServer/Ombi.Api.MediaServer.csproj @@ -6,7 +6,7 @@ 3.0.0.0 - 8.0 + latest Debug;Release;NonUiBuild diff --git a/src/Ombi.Api.MusicBrainz/Ombi.Api.MusicBrainz.csproj b/src/Ombi.Api.MusicBrainz/Ombi.Api.MusicBrainz.csproj index 584b980ce..c8a78e491 100644 --- a/src/Ombi.Api.MusicBrainz/Ombi.Api.MusicBrainz.csproj +++ b/src/Ombi.Api.MusicBrainz/Ombi.Api.MusicBrainz.csproj @@ -2,7 +2,7 @@ net6.0 - 8.0 + latest Debug;Release;NonUiBuild diff --git a/src/Ombi.Api.Notifications/Ombi.Api.Notifications.csproj b/src/Ombi.Api.Notifications/Ombi.Api.Notifications.csproj index f84a8add6..6406ef9de 100644 --- a/src/Ombi.Api.Notifications/Ombi.Api.Notifications.csproj +++ b/src/Ombi.Api.Notifications/Ombi.Api.Notifications.csproj @@ -2,7 +2,7 @@ net6.0 - 8.0 + latest Debug;Release;NonUiBuild diff --git a/src/Ombi.Api.Plex/IPlexApi.cs b/src/Ombi.Api.Plex/IPlexApi.cs index 445a7e6ce..b80ef1827 100644 --- a/src/Ombi.Api.Plex/IPlexApi.cs +++ b/src/Ombi.Api.Plex/IPlexApi.cs @@ -17,9 +17,9 @@ namespace Ombi.Api.Plex Task GetServer(string authToken); Task GetLibrarySections(string authToken, string plexFullHost); Task GetLibrary(string authToken, string plexFullHost, string libraryId); - Task GetEpisodeMetaData(string authToken, string host, int ratingKey); - Task GetMetadata(string authToken, string plexFullHost, int itemId); - Task GetSeasons(string authToken, string plexFullHost, int ratingKey); + Task GetEpisodeMetaData(string authToken, string host, string ratingKey); + Task GetMetadata(string authToken, string plexFullHost, string itemId); + Task GetSeasons(string authToken, string plexFullHost, string ratingKey); Task GetAllEpisodes(string authToken, string host, string section, int start, int retCount); Task GetUsers(string authToken); Task GetAccount(string authToken); @@ -27,6 +27,6 @@ namespace Ombi.Api.Plex Task GetPin(int pinId); Task GetOAuthUrl(string code, string applicationUrl); Task AddUser(string emailAddress, string serverId, string authToken, int[] libs); - Task GetWatchlist(string plexToken, CancellationToken cancellationToken); + Task GetWatchlist(string plexToken, CancellationToken cancellationToken); } } \ No newline at end of file diff --git a/src/Ombi.Api.Plex/Models/Metadata.cs b/src/Ombi.Api.Plex/Models/Metadata.cs index 65cb21e95..3481e9b57 100644 --- a/src/Ombi.Api.Plex/Models/Metadata.cs +++ b/src/Ombi.Api.Plex/Models/Metadata.cs @@ -4,7 +4,7 @@ namespace Ombi.Api.Plex.Models { public class Metadata { - public int ratingKey { get; set; } + public string ratingKey { get; set; } public string key { get; set; } public string studio { get; set; } public string type { get; set; } @@ -22,8 +22,8 @@ namespace Ombi.Api.Plex.Models public int childCount { get; set; } public Genre[] Genre { get; set; } public string primaryExtraKey { get; set; } - public int parentRatingKey { get; set; } - public int grandparentRatingKey { get; set; } + public string parentRatingKey { get; set; } + public string grandparentRatingKey { get; set; } public string guid { get; set; } public int librarySectionID { get; set; } public string librarySectionKey { get; set; } diff --git a/src/Ombi.Api.Plex/Ombi.Api.Plex.csproj b/src/Ombi.Api.Plex/Ombi.Api.Plex.csproj index 4945a2fb2..70032d638 100644 --- a/src/Ombi.Api.Plex/Ombi.Api.Plex.csproj +++ b/src/Ombi.Api.Plex/Ombi.Api.Plex.csproj @@ -6,7 +6,7 @@ 3.0.0.0 - 8.0 + latest Debug;Release;NonUiBuild diff --git a/src/Ombi.Api.Plex/PlexApi.cs b/src/Ombi.Api.Plex/PlexApi.cs index cee668236..ea7140366 100644 --- a/src/Ombi.Api.Plex/PlexApi.cs +++ b/src/Ombi.Api.Plex/PlexApi.cs @@ -147,21 +147,21 @@ namespace Ombi.Api.Plex /// /// /// - public async Task GetEpisodeMetaData(string authToken, string plexFullHost, int ratingKey) + public async Task GetEpisodeMetaData(string authToken, string plexFullHost, string ratingKey) { var request = new Request($"/library/metadata/{ratingKey}", plexFullHost, HttpMethod.Get); await AddHeaders(request, authToken); return await Api.Request(request); } - public async Task GetMetadata(string authToken, string plexFullHost, int itemId) + public async Task GetMetadata(string authToken, string plexFullHost, string itemId) { var request = new Request($"library/metadata/{itemId}", plexFullHost, HttpMethod.Get); await AddHeaders(request, authToken); return await Api.Request(request); } - public async Task GetSeasons(string authToken, string plexFullHost, int ratingKey) + public async Task GetSeasons(string authToken, string plexFullHost, string ratingKey) { var request = new Request($"library/metadata/{ratingKey}/children", plexFullHost, HttpMethod.Get); await AddHeaders(request, authToken); @@ -290,12 +290,12 @@ namespace Ombi.Api.Plex } } - public async Task GetWatchlist(string plexToken, CancellationToken cancellationToken) + public async Task GetWatchlist(string plexToken, CancellationToken cancellationToken) { var request = new Request(string.Empty, WatchlistUri, HttpMethod.Get); await AddHeaders(request, plexToken); - var result = await Api.Request(request, cancellationToken); + var result = await Api.Request(request, cancellationToken); return result; } diff --git a/src/Ombi.Api.Pushbullet/Ombi.Api.Pushbullet.csproj b/src/Ombi.Api.Pushbullet/Ombi.Api.Pushbullet.csproj index 4945a2fb2..70032d638 100644 --- a/src/Ombi.Api.Pushbullet/Ombi.Api.Pushbullet.csproj +++ b/src/Ombi.Api.Pushbullet/Ombi.Api.Pushbullet.csproj @@ -6,7 +6,7 @@ 3.0.0.0 - 8.0 + latest Debug;Release;NonUiBuild diff --git a/src/Ombi.Api.Pushover/Ombi.Api.Pushover.csproj b/src/Ombi.Api.Pushover/Ombi.Api.Pushover.csproj index 1285c073c..be32916f8 100644 --- a/src/Ombi.Api.Pushover/Ombi.Api.Pushover.csproj +++ b/src/Ombi.Api.Pushover/Ombi.Api.Pushover.csproj @@ -6,7 +6,7 @@ 3.0.0.0 - 8.0 + latest Debug;Release;NonUiBuild diff --git a/src/Ombi.Api.Radarr/Ombi.Api.Radarr.csproj b/src/Ombi.Api.Radarr/Ombi.Api.Radarr.csproj index f14df4f5f..889aa0ea6 100644 --- a/src/Ombi.Api.Radarr/Ombi.Api.Radarr.csproj +++ b/src/Ombi.Api.Radarr/Ombi.Api.Radarr.csproj @@ -6,7 +6,7 @@ 3.0.0.0 - 8.0 + latest Debug;Release;NonUiBuild diff --git a/src/Ombi.Api.RottenTomatoes/Ombi.Api.RottenTomatoes.csproj b/src/Ombi.Api.RottenTomatoes/Ombi.Api.RottenTomatoes.csproj index 6353f4bf9..89c47d251 100644 --- a/src/Ombi.Api.RottenTomatoes/Ombi.Api.RottenTomatoes.csproj +++ b/src/Ombi.Api.RottenTomatoes/Ombi.Api.RottenTomatoes.csproj @@ -2,7 +2,7 @@ net6.0 - 8.0 + latest Debug;Release;NonUiBuild diff --git a/src/Ombi.Api.Service/Ombi.Api.Service.csproj b/src/Ombi.Api.Service/Ombi.Api.Service.csproj index a344de142..38bcd678a 100644 --- a/src/Ombi.Api.Service/Ombi.Api.Service.csproj +++ b/src/Ombi.Api.Service/Ombi.Api.Service.csproj @@ -8,7 +8,7 @@ Ombi.Api.Service Ombi.Api.Service - 8.0 + latest Debug;Release;NonUiBuild diff --git a/src/Ombi.Api.SickRage/Ombi.Api.SickRage.csproj b/src/Ombi.Api.SickRage/Ombi.Api.SickRage.csproj index 6353f4bf9..89c47d251 100644 --- a/src/Ombi.Api.SickRage/Ombi.Api.SickRage.csproj +++ b/src/Ombi.Api.SickRage/Ombi.Api.SickRage.csproj @@ -2,7 +2,7 @@ net6.0 - 8.0 + latest Debug;Release;NonUiBuild diff --git a/src/Ombi.Api.Slack/Ombi.Api.Slack.csproj b/src/Ombi.Api.Slack/Ombi.Api.Slack.csproj index 4945a2fb2..70032d638 100644 --- a/src/Ombi.Api.Slack/Ombi.Api.Slack.csproj +++ b/src/Ombi.Api.Slack/Ombi.Api.Slack.csproj @@ -6,7 +6,7 @@ 3.0.0.0 - 8.0 + latest Debug;Release;NonUiBuild diff --git a/src/Ombi.Api.Sonarr/Ombi.Api.Sonarr.csproj b/src/Ombi.Api.Sonarr/Ombi.Api.Sonarr.csproj index 4945a2fb2..70032d638 100644 --- a/src/Ombi.Api.Sonarr/Ombi.Api.Sonarr.csproj +++ b/src/Ombi.Api.Sonarr/Ombi.Api.Sonarr.csproj @@ -6,7 +6,7 @@ 3.0.0.0 - 8.0 + latest Debug;Release;NonUiBuild diff --git a/src/Ombi.Api.Telegram/Ombi.Api.Telegram.csproj b/src/Ombi.Api.Telegram/Ombi.Api.Telegram.csproj index 6353f4bf9..89c47d251 100644 --- a/src/Ombi.Api.Telegram/Ombi.Api.Telegram.csproj +++ b/src/Ombi.Api.Telegram/Ombi.Api.Telegram.csproj @@ -2,7 +2,7 @@ net6.0 - 8.0 + latest Debug;Release;NonUiBuild diff --git a/src/Ombi.Api.Trakt/Ombi.Api.Trakt.csproj b/src/Ombi.Api.Trakt/Ombi.Api.Trakt.csproj index e07f40c60..fd9632e56 100644 --- a/src/Ombi.Api.Trakt/Ombi.Api.Trakt.csproj +++ b/src/Ombi.Api.Trakt/Ombi.Api.Trakt.csproj @@ -6,7 +6,7 @@ 3.0.0.0 - 8.0 + latest Debug;Release;NonUiBuild diff --git a/src/Ombi.Api.TvMaze/Ombi.Api.TvMaze.csproj b/src/Ombi.Api.TvMaze/Ombi.Api.TvMaze.csproj index f167146af..a1b98b765 100644 --- a/src/Ombi.Api.TvMaze/Ombi.Api.TvMaze.csproj +++ b/src/Ombi.Api.TvMaze/Ombi.Api.TvMaze.csproj @@ -6,7 +6,7 @@ 3.0.0.0 - 8.0 + latest Debug;Release;NonUiBuild diff --git a/src/Ombi.Api/Ombi.Api.csproj b/src/Ombi.Api/Ombi.Api.csproj index 83c3ee62e..7670d4d14 100644 --- a/src/Ombi.Api/Ombi.Api.csproj +++ b/src/Ombi.Api/Ombi.Api.csproj @@ -6,7 +6,7 @@ 3.0.0.0 - 8.0 + latest Debug;Release;NonUiBuild diff --git a/src/Ombi.Core/Ombi.Core.csproj b/src/Ombi.Core/Ombi.Core.csproj index 0f7ca6845..67ecdbe13 100644 --- a/src/Ombi.Core/Ombi.Core.csproj +++ b/src/Ombi.Core/Ombi.Core.csproj @@ -6,7 +6,7 @@ 3.0.0.0 - 8.0 + latest Debug;Release;NonUiBuild diff --git a/src/Ombi.DependencyInjection/Ombi.DependencyInjection.csproj b/src/Ombi.DependencyInjection/Ombi.DependencyInjection.csproj index e65f2d5a2..93b839c07 100644 --- a/src/Ombi.DependencyInjection/Ombi.DependencyInjection.csproj +++ b/src/Ombi.DependencyInjection/Ombi.DependencyInjection.csproj @@ -6,7 +6,7 @@ 3.0.0.0 - 8.0 + latest Debug;Release;NonUiBuild diff --git a/src/Ombi.Helpers/Ombi.Helpers.csproj b/src/Ombi.Helpers/Ombi.Helpers.csproj index afc881d94..2098fa51f 100644 --- a/src/Ombi.Helpers/Ombi.Helpers.csproj +++ b/src/Ombi.Helpers/Ombi.Helpers.csproj @@ -6,7 +6,7 @@ 3.0.0.0 - 8.0 + latest Debug;Release;NonUiBuild diff --git a/src/Ombi.Helpers/PlexHelper.cs b/src/Ombi.Helpers/PlexHelper.cs index 7951a7edf..4ae39f6ce 100644 --- a/src/Ombi.Helpers/PlexHelper.cs +++ b/src/Ombi.Helpers/PlexHelper.cs @@ -104,7 +104,7 @@ namespace Ombi.Helpers return new ProviderId(); } - public static string GetPlexMediaUrl(string machineId, int mediaId, string plexHost) + public static string GetPlexMediaUrl(string machineId, string mediaId, string plexHost) { var url = $"web/#!/server/{machineId}/details?key=%2flibrary%2Fmetadata%2F{mediaId}"; diff --git a/src/Ombi.Hubs/Ombi.Hubs.csproj b/src/Ombi.Hubs/Ombi.Hubs.csproj index fc65e2dc2..f6bee2eb1 100644 --- a/src/Ombi.Hubs/Ombi.Hubs.csproj +++ b/src/Ombi.Hubs/Ombi.Hubs.csproj @@ -2,7 +2,7 @@ net6.0 - 8.0 + latest Debug;Release;NonUiBuild diff --git a/src/Ombi.I18n/Ombi.I18n.csproj b/src/Ombi.I18n/Ombi.I18n.csproj index f44037974..a3387cdea 100644 --- a/src/Ombi.I18n/Ombi.I18n.csproj +++ b/src/Ombi.I18n/Ombi.I18n.csproj @@ -1,4 +1,4 @@ - + net6.0 @@ -6,7 +6,7 @@ 3.0.0.0 - 8.0 + latest Debug;Release;NonUiBuild diff --git a/src/Ombi.Mapping/Ombi.Mapping.csproj b/src/Ombi.Mapping/Ombi.Mapping.csproj index 9ad1f1135..322942cf2 100644 --- a/src/Ombi.Mapping/Ombi.Mapping.csproj +++ b/src/Ombi.Mapping/Ombi.Mapping.csproj @@ -6,7 +6,7 @@ 3.0.0.0 - 8.0 + latest Debug;Release;NonUiBuild diff --git a/src/Ombi.Notifications.Templates/Ombi.Notifications.Templates.csproj b/src/Ombi.Notifications.Templates/Ombi.Notifications.Templates.csproj index 87a876caa..99e7509b4 100644 --- a/src/Ombi.Notifications.Templates/Ombi.Notifications.Templates.csproj +++ b/src/Ombi.Notifications.Templates/Ombi.Notifications.Templates.csproj @@ -6,7 +6,7 @@ 3.0.0.0 - 8.0 + latest Debug;Release;NonUiBuild diff --git a/src/Ombi.Notifications/Ombi.Notifications.csproj b/src/Ombi.Notifications/Ombi.Notifications.csproj index 6b497c23e..41fd3ae17 100644 --- a/src/Ombi.Notifications/Ombi.Notifications.csproj +++ b/src/Ombi.Notifications/Ombi.Notifications.csproj @@ -6,7 +6,7 @@ 3.0.0.0 - 8.0 + latest Debug;Release;NonUiBuild diff --git a/src/Ombi.Schedule.Tests/Ombi.Schedule.Tests.csproj b/src/Ombi.Schedule.Tests/Ombi.Schedule.Tests.csproj index fd23ee60b..d8e698d0e 100644 --- a/src/Ombi.Schedule.Tests/Ombi.Schedule.Tests.csproj +++ b/src/Ombi.Schedule.Tests/Ombi.Schedule.Tests.csproj @@ -19,6 +19,7 @@ + diff --git a/src/Ombi.Schedule.Tests/PlexContentSyncTests.cs b/src/Ombi.Schedule.Tests/PlexContentSyncTests.cs index da128794c..8540f0037 100644 --- a/src/Ombi.Schedule.Tests/PlexContentSyncTests.cs +++ b/src/Ombi.Schedule.Tests/PlexContentSyncTests.cs @@ -47,7 +47,7 @@ namespace Ombi.Schedule.Tests } }; var contentToAdd = new HashSet(); - var contentProcessed = new Dictionary(); + var contentProcessed = new Dictionary(); _mocker.Setup(x => x.GetFirstContentByCustom(It.IsAny>>())) .Returns(Task.FromResult(new PlexServerContent())); @@ -76,18 +76,18 @@ namespace Ombi.Schedule.Tests Id = "imdb://tt0322259" } }, - ratingKey = 1 + ratingKey = "1" }, } }; var contentToAdd = new HashSet(); - var contentProcessed = new Dictionary(); + var contentProcessed = new Dictionary(); await _subject.MovieLoop(new PlexServers(), content, contentToAdd, contentProcessed); var first = contentToAdd.First(); Assert.That(first.ImdbId, Is.EqualTo("tt0322259")); - _mocker.Verify(x => x.GetMetadata(It.IsAny(), It.IsAny(),It.IsAny()), Times.Never); + _mocker.Verify(x => x.GetMetadata(It.IsAny(), It.IsAny(),It.IsAny()), Times.Never); } [Test] @@ -99,7 +99,7 @@ namespace Ombi.Schedule.Tests { new Metadata { - ratingKey = 11, + ratingKey = "11", title = "test1", year = 2021, type = "movie", @@ -107,8 +107,8 @@ namespace Ombi.Schedule.Tests } }; var contentToAdd = new HashSet(); - var contentProcessed = new Dictionary(); - _mocker.Setup(x => x.GetMetadata(It.IsAny(), It.IsAny(), It.IsAny())) + var contentProcessed = new Dictionary(); + _mocker.Setup(x => x.GetMetadata(It.IsAny(), It.IsAny(), It.IsAny())) .Returns(Task.FromResult(new PlexMetadata { MediaContainer = new Mediacontainer @@ -117,7 +117,7 @@ namespace Ombi.Schedule.Tests { new Metadata { - ratingKey = 11, + ratingKey = "11", title = "test1", year = 2021, type = "movie", @@ -138,7 +138,7 @@ namespace Ombi.Schedule.Tests var first = contentToAdd.First(); Assert.That(first.ImdbId, Is.EqualTo("tt0322259")); - _mocker.Verify(x => x.GetMetadata(It.IsAny(), It.IsAny(), It.IsAny()), Times.Once); + _mocker.Verify(x => x.GetMetadata(It.IsAny(), It.IsAny(), It.IsAny()), Times.Once); } [Test] @@ -150,7 +150,7 @@ namespace Ombi.Schedule.Tests { new Metadata { - ratingKey = 11, + ratingKey = "11", title = "test1", year = 2021, type = "movie", @@ -165,7 +165,7 @@ namespace Ombi.Schedule.Tests } }; var contentToAdd = new HashSet(); - var contentProcessed = new Dictionary(); + var contentProcessed = new Dictionary(); _mocker.Setup(x => x.GetFirstContentByCustom(It.IsAny>>())) .Returns(Task.FromResult(new PlexServerContent @@ -188,7 +188,7 @@ namespace Ombi.Schedule.Tests { new Metadata { - ratingKey = 11, + ratingKey = "11", title = "test1", year = 2021, type = "movie", @@ -203,7 +203,7 @@ namespace Ombi.Schedule.Tests } }; var contentToAdd = new HashSet(); - var contentProcessed = new Dictionary(); + var contentProcessed = new Dictionary(); _mocker.Setup(x => x.GetFirstContentByCustom(It.IsAny>>())) .Returns(Task.FromResult(new PlexServerContent diff --git a/src/Ombi.Schedule.Tests/PlexWatchlistImportTests.cs b/src/Ombi.Schedule.Tests/PlexWatchlistImportTests.cs new file mode 100644 index 000000000..e0c6ef589 --- /dev/null +++ b/src/Ombi.Schedule.Tests/PlexWatchlistImportTests.cs @@ -0,0 +1,57 @@ +using Moq; +using Moq.AutoMock; +using NUnit.Framework; +using Ombi.Api.Plex; +using Ombi.Api.Plex.Models; +using Ombi.Core.Authentication; +using Ombi.Core.Settings; +using Ombi.Core.Settings.Models.External; +using Ombi.Schedule.Jobs.Plex; +using Ombi.Store.Entities; +using Ombi.Test.Common; +using Quartz; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Security.Principal; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace Ombi.Schedule.Tests +{ + [TestFixture] + public class PlexWatchlistImportTests + { + + private PlexWatchlistImport _subject; + private AutoMocker _mocker; + private Mock _context; + + [SetUp] + public void Setup() + { + _mocker = new AutoMocker(); + var um = MockHelper.MockUserManager(new List { new OmbiUser { Id = "abc", UserType = UserType.PlexUser, MediaServerToken = "abc", UserName = "abc", NormalizedUserName = "ABC" } }); + _mocker.Use(um); + _context = _mocker.GetMock(); + _context.Setup(x => x.CancellationToken).Returns(CancellationToken.None); + _subject = _mocker.CreateInstance(); + } + + [Test] + public async Task TerminatesWhenPlexIsNotEnabled() + { + _mocker.Setup, Task>(x => x.GetSettingsAsync()).ReturnsAsync(new PlexSettings { Enable = false }); + await _subject.Execute(null); + } + + [Test] + public async Task EmptyWatchList() + { + _mocker.Setup, Task>(x => x.GetSettingsAsync()).ReturnsAsync(new PlexSettings { Enable = true }); + _mocker.Setup>(x => x.GetWatchlist(It.IsAny(), It.IsAny())).ReturnsAsync(new PlexWatchlist()); + await _subject.Execute(_context.Object); + } + } +} diff --git a/src/Ombi.Schedule/Jobs/Plex/Models/ProcessedContent.cs b/src/Ombi.Schedule/Jobs/Plex/Models/ProcessedContent.cs index fc46e88b7..84748c1f7 100644 --- a/src/Ombi.Schedule/Jobs/Plex/Models/ProcessedContent.cs +++ b/src/Ombi.Schedule/Jobs/Plex/Models/ProcessedContent.cs @@ -5,7 +5,7 @@ namespace Ombi.Schedule.Jobs.Plex.Models { public class ProcessedContent { - public IEnumerable Content { get; set; } + public IEnumerable Content { get; set; } public IEnumerable Episodes { get; set; } public bool HasProcessedContent => Content?.Any() ?? false; diff --git a/src/Ombi.Schedule/Jobs/Plex/PlexContentSync.cs b/src/Ombi.Schedule/Jobs/Plex/PlexContentSync.cs index 62d0fb1b9..170f6b943 100644 --- a/src/Ombi.Schedule/Jobs/Plex/PlexContentSync.cs +++ b/src/Ombi.Schedule/Jobs/Plex/PlexContentSync.cs @@ -167,7 +167,7 @@ namespace Ombi.Schedule.Jobs.Plex private async Task ProcessServer(PlexServers servers, bool recentlyAddedSearch) { var retVal = new ProcessedContent(); - var contentProcessed = new Dictionary(); + var contentProcessed = new Dictionary(); var episodesProcessed = new List(); Logger.LogDebug("Getting all content from server {0}", servers.Name); var allContent = await GetAllContent(servers, recentlyAddedSearch); @@ -290,7 +290,7 @@ namespace Ombi.Schedule.Jobs.Plex } public async Task MovieLoop(PlexServers servers, Mediacontainer content, HashSet contentToAdd, - Dictionary contentProcessed) + Dictionary contentProcessed) { Logger.LogDebug("Processing Movies"); foreach (var movie in content?.Metadata ?? Array.Empty()) @@ -437,7 +437,7 @@ namespace Ombi.Schedule.Jobs.Plex } } - private async Task ProcessTvShow(PlexServers servers, Metadata show, HashSet contentToAdd, Dictionary contentProcessed) + private async Task ProcessTvShow(PlexServers servers, Metadata show, HashSet contentToAdd, Dictionary contentProcessed) { var seasonList = await PlexApi.GetSeasons(servers.PlexAuthToken, servers.FullUri, show.ratingKey); diff --git a/src/Ombi.Schedule/Jobs/Plex/PlexWatchlistImport.cs b/src/Ombi.Schedule/Jobs/Plex/PlexWatchlistImport.cs index d3626fc8d..7c808ccf2 100644 --- a/src/Ombi.Schedule/Jobs/Plex/PlexWatchlistImport.cs +++ b/src/Ombi.Schedule/Jobs/Plex/PlexWatchlistImport.cs @@ -1,4 +1,13 @@ -using Quartz; +using Ombi.Api.Plex; +using Ombi.Api.Plex.Models; +using Ombi.Core.Authentication; +using Ombi.Core.Engine.Interfaces; +using Ombi.Core.Settings; +using Ombi.Core.Settings.Models.External; +using Ombi.Helpers; +using Ombi.Store.Entities; +using Ombi.Store.Repository.Requests; +using Quartz; using System; using System.Collections.Generic; using System.Linq; @@ -9,14 +18,107 @@ namespace Ombi.Schedule.Jobs.Plex { public class PlexWatchlistImport : IPlexWatchlistImport { - public void Dispose() + private readonly IPlexApi _plexApi; + private readonly ISettingsService _settings; + private readonly OmbiUserManager _ombiUserManager; + private readonly IMovieRequestRepository _movieRequestRepository; + private readonly ITvRequestRepository _tvRequestRepository; + private readonly IMovieRequestEngine _movieRequestEngine; + + public PlexWatchlistImport(IPlexApi plexApi, ISettingsService settings, OmbiUserManager ombiUserManager, + IMovieRequestRepository movieRequestRepository, ITvRequestRepository tvRequestRepository, IMovieRequestEngine movieRequestEngine) + { + _plexApi = plexApi; + _settings = settings; + _ombiUserManager = ombiUserManager; + _movieRequestRepository = movieRequestRepository; + _tvRequestRepository = tvRequestRepository; + _movieRequestEngine = movieRequestEngine; + } + + public async Task Execute(IJobExecutionContext context) + { + var token = "-DpQi6mzq2QMakYgFr2g"; // !!!!!!!!!!!!!!!!!!!! TODO REMOVE !!!!!!!!!!!!!!!!!!!!!!! + + var settings = await _settings.GetSettingsAsync(); + if (!settings.Enable) + { + return; + } + + var plexUsersWithTokens = _ombiUserManager.Users.Where(x => x.UserType == UserType.PlexUser && x.MediaServerToken != null).ToList(); + foreach (var user in plexUsersWithTokens) + { + var watchlist = await _plexApi.GetWatchlist(user.MediaServerToken, context.CancellationToken); + if (watchlist == null || !watchlist.Metadata.Any()) + { + continue; + } + + var items = watchlist.Metadata; + foreach (var item in items) + { + switch (item.type) + { + case "show": + await ProcessShow(item); + break; + case "movie": + await ProcessMovie(item, null); + break; + } + } + + + } + } + + private async Task ProcessMovie(Metadata movie, PlexServers servers) { - throw new NotImplementedException(); + var providerIds = await GetProviderIds(movie, servers); + if (!providerIds.TheMovieDb.HasValue()) + { + // We need a MovieDbId to support this; + return; + } + //_movieRequestEngine.RequestMovie(new() { TheMovieDbId = }); } - public Task Execute(IJobExecutionContext context) + private async Task GetProviderIds(Metadata movie, PlexServers servers) { - throw new NotImplementedException(); + var guids = new List(); + if (!movie.Guid.Any()) + { + 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 + { + // Currently a Plex Pass feature only + foreach (var g in movie.Guid) + { + guids.Add(g.Id); + } + } + var providerIds = PlexHelper.GetProviderIdsFromMetadata(guids.ToArray()); + return providerIds; } + + private async Task ProcessShow(Metadata metadata) + { + + } + + public void Dispose() { } } } diff --git a/src/Ombi.Schedule/Ombi.Schedule.csproj b/src/Ombi.Schedule/Ombi.Schedule.csproj index ed1a7d9a1..a972aa6bb 100644 --- a/src/Ombi.Schedule/Ombi.Schedule.csproj +++ b/src/Ombi.Schedule/Ombi.Schedule.csproj @@ -6,7 +6,7 @@ 3.0.0.0 - 8.0 + latest Debug;Release;NonUiBuild diff --git a/src/Ombi.Settings/Ombi.Settings.csproj b/src/Ombi.Settings/Ombi.Settings.csproj index 4b3aa4c60..3821892f0 100644 --- a/src/Ombi.Settings/Ombi.Settings.csproj +++ b/src/Ombi.Settings/Ombi.Settings.csproj @@ -6,7 +6,7 @@ 3.0.0.0 - 8.0 + latest Debug;Release;NonUiBuild diff --git a/src/Ombi.Store/Entities/OmbiUser.cs b/src/Ombi.Store/Entities/OmbiUser.cs index 1b7ea6f7c..376db28f7 100644 --- a/src/Ombi.Store/Entities/OmbiUser.cs +++ b/src/Ombi.Store/Entities/OmbiUser.cs @@ -36,6 +36,7 @@ namespace Ombi.Store.Entities public RequestLimitType? MusicRequestLimitType { get; set; } public string UserAccessToken { get; set; } + public string MediaServerToken { get; set; } public List NotificationUserIds { get; set; } public List UserNotificationPreferences { get; set; } diff --git a/src/Ombi.Store/Entities/PlexEpisode.cs b/src/Ombi.Store/Entities/PlexEpisode.cs index 02cfc8a07..a9628a13d 100644 --- a/src/Ombi.Store/Entities/PlexEpisode.cs +++ b/src/Ombi.Store/Entities/PlexEpisode.cs @@ -7,15 +7,15 @@ namespace Ombi.Store.Entities [Table("PlexEpisode")] public class PlexEpisode : MediaServerEpisode { - public int Key { get; set; } // RatingKey + public string Key { get; set; } // RatingKey /// /// The parent key. /// - public int ParentKey { get; set; } + public string ParentKey { get; set; } /// /// The grandparent key. /// - public int GrandparentKey { get; set; } + public string GrandparentKey { get; set; } [NotMapped] public PlexServerContent PlexSeries { diff --git a/src/Ombi.Store/Entities/PlexServerContent.cs b/src/Ombi.Store/Entities/PlexServerContent.cs index f33ddb2f1..8af5e250e 100644 --- a/src/Ombi.Store/Entities/PlexServerContent.cs +++ b/src/Ombi.Store/Entities/PlexServerContent.cs @@ -40,7 +40,7 @@ namespace Ombi.Store.Entities /// /// Plex's internal ID for this item /// - public int Key { get; set; } + public string Key { get; set; } public int? RequestId { get; set; } @@ -50,9 +50,9 @@ namespace Ombi.Store.Entities [Table("PlexSeasonsContent")] public class PlexSeasonsContent : Entity { - public int PlexContentId { get; set; } + public string PlexContentId { get; set; } public int SeasonNumber { get; set; } - public int SeasonKey { get; set; } - public int ParentKey { get; set; } + public string SeasonKey { get; set; } + public string ParentKey { get; set; } } } \ No newline at end of file diff --git a/src/Ombi.Store/Ombi.Store.csproj b/src/Ombi.Store/Ombi.Store.csproj index f35da548f..1c145f55a 100644 --- a/src/Ombi.Store/Ombi.Store.csproj +++ b/src/Ombi.Store/Ombi.Store.csproj @@ -7,7 +7,7 @@ true - 8.0 + latest Debug;Release;NonUiBuild diff --git a/src/Ombi.Store/Repository/IPlexContentRepository.cs b/src/Ombi.Store/Repository/IPlexContentRepository.cs index f3c6d0ae2..aeb4aae0a 100644 --- a/src/Ombi.Store/Repository/IPlexContentRepository.cs +++ b/src/Ombi.Store/Repository/IPlexContentRepository.cs @@ -13,8 +13,8 @@ namespace Ombi.Store.Repository Task ContentExists(string providerId); Task Get(string providerId, ProviderType type); Task GetByType(string providerId, ProviderType type, MediaType mediaType); - Task GetByKey(int key); - Task GetEpisodeByKey(int key); + Task GetByKey(string key); + Task GetEpisodeByKey(string key); IEnumerable GetWhereContentByCustom(Expression> predicate); Task GetFirstContentByCustom(Expression> predicate); Task DeleteEpisode(PlexEpisode content); diff --git a/src/Ombi.Store/Repository/PlexContentRepository.cs b/src/Ombi.Store/Repository/PlexContentRepository.cs index 9ae5adce8..96dfbe8e1 100644 --- a/src/Ombi.Store/Repository/PlexContentRepository.cs +++ b/src/Ombi.Store/Repository/PlexContentRepository.cs @@ -92,7 +92,7 @@ namespace Ombi.Store.Repository return null; } - public async Task GetByKey(int key) + public async Task GetByKey(string key) { return await Db.PlexServerContent.Include(x => x.Seasons).FirstOrDefaultAsync(x => x.Key == key); } @@ -154,7 +154,7 @@ namespace Ombi.Store.Repository await InternalSaveChanges(); } - public async Task GetEpisodeByKey(int key) + public async Task GetEpisodeByKey(string key) { return await Db.PlexEpisode.FirstOrDefaultAsync(x => x.Key == key); } diff --git a/src/Ombi.Test.Common/Ombi.Test.Common.csproj b/src/Ombi.Test.Common/Ombi.Test.Common.csproj index 71b05f59c..512055143 100644 --- a/src/Ombi.Test.Common/Ombi.Test.Common.csproj +++ b/src/Ombi.Test.Common/Ombi.Test.Common.csproj @@ -2,7 +2,7 @@ net6.0 - 8.0 + latest Debug;Release;NonUiBuild diff --git a/src/Ombi.TheMovieDbApi/Ombi.Api.TheMovieDb.csproj b/src/Ombi.TheMovieDbApi/Ombi.Api.TheMovieDb.csproj index 41ac19686..ddab7e3f8 100644 --- a/src/Ombi.TheMovieDbApi/Ombi.Api.TheMovieDb.csproj +++ b/src/Ombi.TheMovieDbApi/Ombi.Api.TheMovieDb.csproj @@ -7,7 +7,7 @@ 3.0.0.0 - 8.0 + latest Debug;Release;NonUiBuild