mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-14 02:26:55 -07:00
fix(plex-api): Switch over to the new API to avoid deprecation & save… (#4986)
* fix(plex-api): Switch over to the new API to avoid deprecation & save the plex settings when modifying the servers * Delete Ombi.sln
This commit is contained in:
parent
aacaa3e140
commit
2f2d35ec86
7 changed files with 30 additions and 41 deletions
|
@ -21,7 +21,7 @@ namespace Ombi.Api.Plex
|
|||
Task<PlexMetadata> GetMetadata(string authToken, string plexFullHost, string itemId);
|
||||
Task<PlexMetadata> GetSeasons(string authToken, string plexFullHost, string ratingKey);
|
||||
Task<PlexContainer> GetAllEpisodes(string authToken, string host, string section, int start, int retCount);
|
||||
Task<PlexFriends> GetUsers(string authToken);
|
||||
Task<PlexUsers> GetUsers(string authToken);
|
||||
Task<PlexAccount> GetAccount(string authToken);
|
||||
Task<PlexMetadata> GetRecentlyAdded(string authToken, string uri, string sectionId);
|
||||
Task<OAuthContainer> GetPin(int pinId);
|
||||
|
|
|
@ -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; }
|
||||
/// <summary>
|
||||
/// Title is for Home Users only
|
||||
/// </summary>
|
||||
[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; }
|
||||
|
|
|
@ -65,7 +65,7 @@ namespace Ombi.Api.Plex
|
|||
}
|
||||
|
||||
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 @@ namespace Ombi.Api.Plex
|
|||
/// </summary>
|
||||
/// <param name="authToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<PlexFriends> GetUsers(string authToken)
|
||||
public async Task<PlexUsers> GetUsers(string authToken)
|
||||
{
|
||||
var request = new Request(string.Empty, FriendsUri, HttpMethod.Get, ContentType.Xml);
|
||||
await AddHeaders(request, authToken);
|
||||
|
||||
return await Api.Request<PlexFriends>(request);
|
||||
return await Api.Request<PlexUsers>(request);
|
||||
}
|
||||
|
||||
public async Task<PlexMetadata> GetRecentlyAdded(string authToken, string uri, string sectionId)
|
||||
|
|
|
@ -189,7 +189,7 @@ namespace Ombi.Schedule.Tests
|
|||
{
|
||||
_mocker.Setup<ISettingsService<UserManagementSettings>, Task<UserManagementSettings>>(x => x.GetSettingsAsync())
|
||||
.ReturnsAsync(new UserManagementSettings { ImportPlexAdmin = false, ImportPlexUsers = true, BannedPlexUserIds = new List<string> { "Banned" } });
|
||||
_mocker.Setup<IPlexApi, Task<PlexFriends>>(x => x.GetUsers(It.IsAny<string>())).ReturnsAsync(new PlexFriends
|
||||
_mocker.Setup<IPlexApi, Task<PlexUsers>>(x => x.GetUsers(It.IsAny<string>())).ReturnsAsync(new PlexUsers
|
||||
{
|
||||
User = new UserFriends[]
|
||||
{
|
||||
|
@ -213,7 +213,7 @@ namespace Ombi.Schedule.Tests
|
|||
{
|
||||
_mocker.Setup<ISettingsService<UserManagementSettings>, Task<UserManagementSettings>>(x => x.GetSettingsAsync())
|
||||
.ReturnsAsync(new UserManagementSettings { ImportPlexAdmin = false, ImportPlexUsers = true });
|
||||
_mocker.Setup<IPlexApi, Task<PlexFriends>>(x => x.GetUsers(It.IsAny<string>())).ReturnsAsync(new PlexFriends
|
||||
_mocker.Setup<IPlexApi, Task<PlexUsers>>(x => x.GetUsers(It.IsAny<string>())).ReturnsAsync(new PlexUsers
|
||||
{
|
||||
User = new UserFriends[]
|
||||
{
|
||||
|
@ -222,6 +222,7 @@ namespace Ombi.Schedule.Tests
|
|||
Email = "email",
|
||||
Id = "id",
|
||||
Title = "title",
|
||||
HomeUser = true
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -236,7 +237,7 @@ namespace Ombi.Schedule.Tests
|
|||
{
|
||||
_mocker.Setup<ISettingsService<UserManagementSettings>, Task<UserManagementSettings>>(x => x.GetSettingsAsync())
|
||||
.ReturnsAsync(new UserManagementSettings { ImportPlexAdmin = false, ImportPlexUsers = true });
|
||||
_mocker.Setup<IPlexApi, Task<PlexFriends>>(x => x.GetUsers(It.IsAny<string>())).ReturnsAsync(new PlexFriends
|
||||
_mocker.Setup<IPlexApi, Task<PlexUsers>>(x => x.GetUsers(It.IsAny<string>())).ReturnsAsync(new PlexUsers
|
||||
{
|
||||
User = new UserFriends[]
|
||||
{
|
||||
|
@ -266,7 +267,7 @@ namespace Ombi.Schedule.Tests
|
|||
OmbiRoles.RequestMovie
|
||||
}
|
||||
});
|
||||
_mocker.Setup<IPlexApi, Task<PlexFriends>>(x => x.GetUsers(It.IsAny<string>())).ReturnsAsync(new PlexFriends
|
||||
_mocker.Setup<IPlexApi, Task<PlexUsers>>(x => x.GetUsers(It.IsAny<string>())).ReturnsAsync(new PlexUsers
|
||||
{
|
||||
User = new UserFriends[]
|
||||
{
|
||||
|
@ -303,7 +304,7 @@ namespace Ombi.Schedule.Tests
|
|||
OmbiRoles.RequestMovie
|
||||
}
|
||||
});
|
||||
_mocker.Setup<IPlexApi, Task<PlexFriends>>(x => x.GetUsers(It.IsAny<string>())).ReturnsAsync(new PlexFriends
|
||||
_mocker.Setup<IPlexApi, Task<PlexUsers>>(x => x.GetUsers(It.IsAny<string>())).ReturnsAsync(new PlexUsers
|
||||
{
|
||||
User = new UserFriends[]
|
||||
{
|
||||
|
@ -342,7 +343,7 @@ namespace Ombi.Schedule.Tests
|
|||
},
|
||||
CleanupPlexUsers = true,
|
||||
});
|
||||
_mocker.Setup<IPlexApi, Task<PlexFriends>>(x => x.GetUsers(It.IsAny<string>())).ReturnsAsync(new PlexFriends
|
||||
_mocker.Setup<IPlexApi, Task<PlexUsers>>(x => x.GetUsers(It.IsAny<string>())).ReturnsAsync(new PlexUsers
|
||||
{
|
||||
User = new UserFriends[]
|
||||
{
|
||||
|
|
|
@ -127,15 +127,19 @@ namespace Ombi.Schedule.Jobs.Plex
|
|||
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;
|
||||
}
|
||||
|
||||
|
|
3
src/Ombi/.vscode/settings.json
vendored
3
src/Ombi/.vscode/settings.json
vendored
|
@ -27,5 +27,6 @@
|
|||
"plex",
|
||||
"wizard"
|
||||
],
|
||||
"rpc.enabled": true
|
||||
"rpc.enabled": true,
|
||||
"dotnet.defaultSolution": "Ombi.sln"
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue