diff --git a/src/Ombi.Api.Plex/IPlexApi.cs b/src/Ombi.Api.Plex/IPlexApi.cs index 746c85b779..6632da875e 100644 --- a/src/Ombi.Api.Plex/IPlexApi.cs +++ b/src/Ombi.Api.Plex/IPlexApi.cs @@ -21,7 +21,7 @@ public interface IPlexApi 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 GetUsers(string authToken); Task GetAccount(string authToken); Task GetRecentlyAdded(string authToken, string uri, string sectionId); Task GetPin(int pinId); diff --git a/src/Ombi.Api.Plex/Models/Friends/PlexFriends.cs b/src/Ombi.Api.Plex/Models/Friends/PlexFriends.cs index e38eca6f6f..f41cbae252 100644 --- a/src/Ombi.Api.Plex/Models/Friends/PlexFriends.cs +++ b/src/Ombi.Api.Plex/Models/Friends/PlexFriends.cs @@ -2,46 +2,26 @@ namespace Ombi.Api.Plex.Models.Friends { - [XmlRoot(ElementName = "Server")] - public class Server - { - [XmlAttribute(AttributeName = "id")] - public string Id { get; set; } - [XmlAttribute(AttributeName = "serverId")] - public string ServerId { get; set; } - [XmlAttribute(AttributeName = "machineIdentifier")] - public string MachineIdentifier { get; set; } - [XmlAttribute(AttributeName = "name")] - public string Name { get; set; } - [XmlAttribute(AttributeName = "lastSeenAt")] - public string LastSeenAt { get; set; } - [XmlAttribute(AttributeName = "numLibraries")] - public string NumLibraries { get; set; } - [XmlAttribute(AttributeName = "owned")] - public string Owned { get; set; } - } - [XmlRoot(ElementName = "User")] public class UserFriends { - [XmlElement(ElementName = "Server")] - public Server Server { get; set; } [XmlAttribute(AttributeName = "id")] public string Id { get; set; } + /// + /// Title is for Home Users only + /// [XmlAttribute(AttributeName = "title")] public string Title { get; set; } [XmlAttribute(AttributeName = "username")] public string Username { get; set; } [XmlAttribute(AttributeName = "email")] public string Email { get; set; } - [XmlAttribute(AttributeName = "recommendationsPlaylistId")] - public string RecommendationsPlaylistId { get; set; } - [XmlAttribute(AttributeName = "thumb")] - public string Thumb { get; set; } + [XmlAttribute(AttributeName = "home")] + public bool HomeUser { get; set; } } [XmlRoot(ElementName = "MediaContainer")] - public class PlexFriends + public class PlexUsers { [XmlElement(ElementName = "User")] public UserFriends[] User { get; set; } diff --git a/src/Ombi.Api.Plex/PlexApi.cs b/src/Ombi.Api.Plex/PlexApi.cs index fae4a78b9b..9c201a1bd5 100644 --- a/src/Ombi.Api.Plex/PlexApi.cs +++ b/src/Ombi.Api.Plex/PlexApi.cs @@ -65,7 +65,7 @@ private string ApplicationName } private const string SignInUri = "https://plex.tv/users/sign_in.json"; - private const string FriendsUri = "https://plex.tv/pms/friends/all"; + private const string FriendsUri = "https://plex.tv/api/users"; private const string GetAccountUri = "https://plex.tv/users/account.json"; private const string ServerUri = "https://plex.tv/pms/servers.xml"; private const string WatchlistUri = "https://metadata.provider.plex.tv/"; @@ -195,12 +195,12 @@ public async Task GetAllEpisodes(string authToken, string host, s /// /// /// - public async Task GetUsers(string authToken) + public async Task GetUsers(string authToken) { var request = new Request(string.Empty, FriendsUri, HttpMethod.Get, ContentType.Xml); await AddHeaders(request, authToken); - return await Api.Request(request); + return await Api.Request(request); } public async Task GetRecentlyAdded(string authToken, string uri, string sectionId) diff --git a/src/Ombi.Schedule.Tests/PlexUserImporterTests.cs b/src/Ombi.Schedule.Tests/PlexUserImporterTests.cs index ff879bf98b..72cacbc505 100644 --- a/src/Ombi.Schedule.Tests/PlexUserImporterTests.cs +++ b/src/Ombi.Schedule.Tests/PlexUserImporterTests.cs @@ -189,7 +189,7 @@ public async Task Import_Doesnt_Import_Banned_Users() { _mocker.Setup, Task>(x => x.GetSettingsAsync()) .ReturnsAsync(new UserManagementSettings { ImportPlexAdmin = false, ImportPlexUsers = true, BannedPlexUserIds = new List { "Banned" } }); - _mocker.Setup>(x => x.GetUsers(It.IsAny())).ReturnsAsync(new PlexFriends + _mocker.Setup>(x => x.GetUsers(It.IsAny())).ReturnsAsync(new PlexUsers { User = new UserFriends[] { @@ -213,7 +213,7 @@ public async Task Import_Doesnt_Import_Managed_User() { _mocker.Setup, Task>(x => x.GetSettingsAsync()) .ReturnsAsync(new UserManagementSettings { ImportPlexAdmin = false, ImportPlexUsers = true }); - _mocker.Setup>(x => x.GetUsers(It.IsAny())).ReturnsAsync(new PlexFriends + _mocker.Setup>(x => x.GetUsers(It.IsAny())).ReturnsAsync(new PlexUsers { User = new UserFriends[] { @@ -222,6 +222,7 @@ public async Task Import_Doesnt_Import_Managed_User() Email = "email", Id = "id", Title = "title", + HomeUser = true } } }); @@ -236,7 +237,7 @@ public async Task Import_Doesnt_Import_DuplicateEmail() { _mocker.Setup, Task>(x => x.GetSettingsAsync()) .ReturnsAsync(new UserManagementSettings { ImportPlexAdmin = false, ImportPlexUsers = true }); - _mocker.Setup>(x => x.GetUsers(It.IsAny())).ReturnsAsync(new PlexFriends + _mocker.Setup>(x => x.GetUsers(It.IsAny())).ReturnsAsync(new PlexUsers { User = new UserFriends[] { @@ -266,7 +267,7 @@ public async Task Import_Created_Plex_User() OmbiRoles.RequestMovie } }); - _mocker.Setup>(x => x.GetUsers(It.IsAny())).ReturnsAsync(new PlexFriends + _mocker.Setup>(x => x.GetUsers(It.IsAny())).ReturnsAsync(new PlexUsers { User = new UserFriends[] { @@ -303,7 +304,7 @@ public async Task Import_Update_Plex_User() OmbiRoles.RequestMovie } }); - _mocker.Setup>(x => x.GetUsers(It.IsAny())).ReturnsAsync(new PlexFriends + _mocker.Setup>(x => x.GetUsers(It.IsAny())).ReturnsAsync(new PlexUsers { User = new UserFriends[] { @@ -342,7 +343,7 @@ public async Task Import_Cleanup_Missing_Plex_Users() }, CleanupPlexUsers = true, }); - _mocker.Setup>(x => x.GetUsers(It.IsAny())).ReturnsAsync(new PlexFriends + _mocker.Setup>(x => x.GetUsers(It.IsAny())).ReturnsAsync(new PlexUsers { User = new UserFriends[] { diff --git a/src/Ombi.Schedule/Jobs/Plex/PlexUserImporter.cs b/src/Ombi.Schedule/Jobs/Plex/PlexUserImporter.cs index 33149489d5..e0ccd88cbe 100644 --- a/src/Ombi.Schedule/Jobs/Plex/PlexUserImporter.cs +++ b/src/Ombi.Schedule/Jobs/Plex/PlexUserImporter.cs @@ -127,15 +127,19 @@ private async Task> ImportPlexUsers(UserManagementSettings userMa continue; } + if (plexUser.HomeUser) + { + _log.LogInformation($"User '{plexUser.Title}' is a Plex Home User. Home Users are not supported"); + continue; + } + // Check if this Plex User already exists - // We are using the Plex USERNAME and Not the TITLE, the Title is for HOME USERS var existingPlexUser = allUsers.FirstOrDefault(x => x.ProviderUserId == plexUser.Id); if (existingPlexUser == null) { - if (!plexUser.Username.HasValue()) { - _log.LogInformation("Could not create Plex user since the have no username, PlexUserId: {0}", plexUser.Id); + _log.LogInformation($"Could not create Plex user since the have no username, PlexUserId: {plexUser.Id}"); continue; } diff --git a/src/Ombi/.vscode/settings.json b/src/Ombi/.vscode/settings.json index 96d5fba50f..f4d17bad14 100644 --- a/src/Ombi/.vscode/settings.json +++ b/src/Ombi/.vscode/settings.json @@ -27,5 +27,6 @@ "plex", "wizard" ], - "rpc.enabled": true + "rpc.enabled": true, + "dotnet.defaultSolution": "Ombi.sln" } diff --git a/src/Ombi/ClientApp/src/app/settings/plex/plex.component.ts b/src/Ombi/ClientApp/src/app/settings/plex/plex.component.ts index 414faf56ff..6873213f90 100644 --- a/src/Ombi/ClientApp/src/app/settings/plex/plex.component.ts +++ b/src/Ombi/ClientApp/src/app/settings/plex/plex.component.ts @@ -137,13 +137,14 @@ export class PlexComponent implements OnInit, OnDestroy { this.removeServer(server); } if (x.server) { - console.log(x.server); var idx = this.settings.servers.findIndex(server => server.id === x.server.id); if (idx >= 0) { this.settings.servers[idx] = x.server; } else { this.settings.servers.push(x.server); } + + this.save(); } }); } @@ -163,6 +164,7 @@ export class PlexComponent implements OnInit, OnDestroy { } if (x.server) { this.settings.servers.push(x.server); + this.save(); } }); } @@ -173,6 +175,7 @@ export class PlexComponent implements OnInit, OnDestroy { this.settings.servers.splice(index, 1); this.selected.setValue(this.settings.servers.length - 1); } + this.save(); } private runCacher(): void {