mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-14 01:02:57 -07:00
Plex friends api
This commit is contained in:
parent
10b22cc7ab
commit
59d61b3a0f
6 changed files with 160 additions and 66 deletions
|
@ -28,8 +28,6 @@ namespace RequestPlex.Api
|
|||
|
||||
if (response.ErrorException != null)
|
||||
{
|
||||
|
||||
|
||||
var message = "Error retrieving response. Check inner details for more info.";
|
||||
throw new ApplicationException(message, response.ErrorException);
|
||||
}
|
||||
|
|
66
RequestPlex.Api/Models/PlexFriends.cs
Normal file
66
RequestPlex.Api/Models/PlexFriends.cs
Normal file
|
@ -0,0 +1,66 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Serialization;
|
||||
using RestSharp.Deserializers;
|
||||
|
||||
namespace RequestPlex.Api.Models
|
||||
{
|
||||
[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; }
|
||||
[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; }
|
||||
}
|
||||
|
||||
[XmlRoot(ElementName = "MediaContainer")]
|
||||
public class PlexFriends
|
||||
{
|
||||
[XmlElement(ElementName = "User")]
|
||||
public List<UserFriends> User { get; set; }
|
||||
[XmlAttribute(AttributeName = "friendlyName")]
|
||||
public string FriendlyName { get; set; }
|
||||
[XmlAttribute(AttributeName = "identifier")]
|
||||
public string Identifier { get; set; }
|
||||
[XmlAttribute(AttributeName = "machineIdentifier")]
|
||||
public string MachineIdentifier { get; set; }
|
||||
[XmlAttribute(AttributeName = "totalSize")]
|
||||
public string TotalSize { get; set; }
|
||||
[XmlAttribute(AttributeName = "size")]
|
||||
public string Size { get; set; }
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +1,10 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Runtime.Remoting.Messaging;
|
||||
using RequestPlex.Api.Models;
|
||||
using RestSharp;
|
||||
using RestSharp.Deserializers;
|
||||
using RestSharp.Serializers;
|
||||
|
||||
namespace RequestPlex.Api
|
||||
{
|
||||
|
@ -32,19 +36,23 @@ namespace RequestPlex.Api
|
|||
return api.Execute<PlexAuthentication>(request, new Uri("https://plex.tv/users/sign_in.json"));
|
||||
}
|
||||
|
||||
public void GetUsers(string authToken)
|
||||
public PlexFriends GetUsers(string authToken)
|
||||
{
|
||||
var request = new RestRequest
|
||||
{
|
||||
Method = Method.POST,
|
||||
Method = Method.GET,
|
||||
};
|
||||
|
||||
request.AddHeader("X-Plex-Client-Identifier", "Test213");
|
||||
request.AddHeader("X-Plex-Product", "Request Plex");
|
||||
request.AddHeader("X-Plex-Version", "0.0.1");
|
||||
request.AddHeader("X-Plex-Token", authToken);
|
||||
request.AddHeader("Content-Type", "application/json");
|
||||
request.AddHeader("Content-Type", "application/xml");
|
||||
|
||||
var api = new ApiRequest();
|
||||
var users = api.Execute<PlexFriends>(request, new Uri("https://plex.tv/pms/friends/all"));
|
||||
|
||||
return users;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,6 +62,7 @@
|
|||
<ItemGroup>
|
||||
<Compile Include="ApiRequest.cs" />
|
||||
<Compile Include="Models\PlexAuthentication.cs" />
|
||||
<Compile Include="Models\PlexFriends.cs" />
|
||||
<Compile Include="Models\PlexUserRequest.cs" />
|
||||
<Compile Include="PlexApi.cs" />
|
||||
<Compile Include="TheMovieDbApi.cs" />
|
||||
|
|
|
@ -4,6 +4,7 @@ using System.Collections.Generic;
|
|||
using System.ComponentModel;
|
||||
using System.Dynamic;
|
||||
using System.Linq;
|
||||
using System.Web.UI;
|
||||
using Nancy;
|
||||
using Nancy.Extensions;
|
||||
using Nancy.ModelBinding;
|
||||
|
@ -23,7 +24,19 @@ namespace RequestPlex.UI.Modules
|
|||
#if !DEBUG
|
||||
this.RequiresAuthentication();
|
||||
#endif
|
||||
Get["admin/"] = _ =>
|
||||
Get["admin/"] = _ => Admin();
|
||||
|
||||
Post["admin/"] = _ => SaveAdmin();
|
||||
|
||||
Post["admin/requestauth"] = _ => RequestAuthToken();
|
||||
|
||||
Get["admin/getusers"] = _ => GetUsers();
|
||||
|
||||
Get["admin/couchpotato"] = _ => CouchPotato();
|
||||
}
|
||||
|
||||
|
||||
private Response Admin()
|
||||
{
|
||||
dynamic model = new ExpandoObject();
|
||||
model.Errored = Request.Query.error.HasValue;
|
||||
|
@ -37,9 +50,9 @@ namespace RequestPlex.UI.Modules
|
|||
}
|
||||
|
||||
return View["/Admin/Settings", model];
|
||||
};
|
||||
}
|
||||
|
||||
Post["admin/"] = _ =>
|
||||
private Response SaveAdmin()
|
||||
{
|
||||
var model = this.Bind<SettingsModel>();
|
||||
|
||||
|
@ -48,9 +61,9 @@ namespace RequestPlex.UI.Modules
|
|||
|
||||
|
||||
return Context.GetRedirect("~/admin");
|
||||
};
|
||||
}
|
||||
|
||||
Post["admin/requestauth"] = _ =>
|
||||
private Response RequestAuthToken()
|
||||
{
|
||||
var user = this.Bind<PlexAuth>();
|
||||
|
||||
|
@ -77,19 +90,27 @@ namespace RequestPlex.UI.Modules
|
|||
s.SaveSettings(newModel);
|
||||
}
|
||||
|
||||
|
||||
|
||||
return Context.GetRedirect("~/admin");
|
||||
};
|
||||
}
|
||||
|
||||
Get["admin/getusers"] = _ =>
|
||||
|
||||
private Response GetUsers()
|
||||
{
|
||||
var s = new SettingsService();
|
||||
var token = s.GetSettings().PlexAuthToken;
|
||||
var api = new PlexApi();
|
||||
var users = api.GetUsers(token);
|
||||
var usernames = users.User.Select(x => x.Username);
|
||||
return Response.AsJson(usernames); //TODO usernames are not populated.
|
||||
}
|
||||
|
||||
private Response CouchPotato()
|
||||
{
|
||||
dynamic model = new ExpandoObject();
|
||||
|
||||
|
||||
return View["/Admin/Settings"];
|
||||
};
|
||||
|
||||
return View["/Admin/CouchPotato", model];
|
||||
}
|
||||
}
|
||||
}
|
|
@ -60,7 +60,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<small>Current users that are allowed to authenticate: </small>
|
||||
<select id="users" multiple="" class="form-control">
|
||||
<select id="users" multiple="" class="form-control col-lg-10 col-lg-offset-2">
|
||||
</select>
|
||||
|
||||
<div class="form-group">
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue