mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-07 21:51:13 -07:00
Some plex work
This commit is contained in:
parent
6054f0d436
commit
10b22cc7ab
8 changed files with 183 additions and 83 deletions
|
@ -1,34 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace RequestPlex.Api.Models
|
|
||||||
{
|
|
||||||
public class MovieResult
|
|
||||||
{
|
|
||||||
public bool adult { get; set; }
|
|
||||||
public string backdrop_path { get; set; }
|
|
||||||
public List<object> genre_ids { get; set; }
|
|
||||||
public int id { get; set; }
|
|
||||||
public string original_language { get; set; }
|
|
||||||
public string original_title { get; set; }
|
|
||||||
public string overview { get; set; }
|
|
||||||
public string release_date { get; set; }
|
|
||||||
public string poster_path { get; set; }
|
|
||||||
public double popularity { get; set; }
|
|
||||||
public string title { get; set; }
|
|
||||||
public bool video { get; set; }
|
|
||||||
public double vote_average { get; set; }
|
|
||||||
public int vote_count { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class MovieSearch
|
|
||||||
{
|
|
||||||
public int page { get; set; }
|
|
||||||
public List<MovieResult> results { get; set; }
|
|
||||||
public int total_pages { get; set; }
|
|
||||||
public int total_results { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
40
RequestPlex.Api/Models/PlexAuthentication.cs
Normal file
40
RequestPlex.Api/Models/PlexAuthentication.cs
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace RequestPlex.Api.Models
|
||||||
|
{
|
||||||
|
public class PlexAuthentication
|
||||||
|
{
|
||||||
|
public User user { get; set; }
|
||||||
|
}
|
||||||
|
public class Subscription
|
||||||
|
{
|
||||||
|
public bool active { get; set; }
|
||||||
|
public string status { get; set; }
|
||||||
|
public object plan { get; set; }
|
||||||
|
public object features { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Roles
|
||||||
|
{
|
||||||
|
public List<object> roles { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class User
|
||||||
|
{
|
||||||
|
public string email { get; set; }
|
||||||
|
public string joined_at { get; set; }
|
||||||
|
public string username { get; set; }
|
||||||
|
public string title { get; set; }
|
||||||
|
public string authentication_token { get; set; }
|
||||||
|
public Subscription subscription { get; set; }
|
||||||
|
public Roles roles { get; set; }
|
||||||
|
public List<string> entitlements { get; set; }
|
||||||
|
public object confirmed_at { get; set; }
|
||||||
|
public int forum_id { get; set; }
|
||||||
|
}
|
||||||
|
}
|
14
RequestPlex.Api/Models/PlexUserRequest.cs
Normal file
14
RequestPlex.Api/Models/PlexUserRequest.cs
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
|
||||||
|
namespace RequestPlex.Api.Models
|
||||||
|
{
|
||||||
|
public class PlexUserRequest
|
||||||
|
{
|
||||||
|
public UserRequest user { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class UserRequest
|
||||||
|
{
|
||||||
|
public string login { get; set; }
|
||||||
|
public string password { get; set; }
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,43 +1,51 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using RequestPlex.Api.Models;
|
||||||
using System.Collections.Specialized;
|
using RestSharp;
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Net;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Nancy.Json;
|
|
||||||
|
|
||||||
namespace RequestPlex.Api
|
namespace RequestPlex.Api
|
||||||
{
|
{
|
||||||
public class PlexApi
|
public class PlexApi
|
||||||
{
|
{
|
||||||
public void GetToken(string username, string password)
|
public PlexAuthentication GetToken(string username, string password)
|
||||||
{
|
{
|
||||||
var plainTextBytes = System.Text.Encoding.UTF8.GetBytes("username:password");
|
var userModel = new PlexUserRequest
|
||||||
string auth = System.Convert.ToBase64String(plainTextBytes);
|
|
||||||
|
|
||||||
using (var client = new WebClient())
|
|
||||||
{
|
{
|
||||||
var values = new NameValueCollection
|
user = new UserRequest
|
||||||
{
|
{
|
||||||
["Authorization"] = "Basic " + auth,
|
password = password,
|
||||||
["X-Plex-Client-Identifier"] = "RequestPlex0001",
|
login = username
|
||||||
["X-Plex-Product"] = "Request Plex",
|
},
|
||||||
["X-Plex-Version"] = "0.1.0"
|
};
|
||||||
};
|
var request = new RestRequest
|
||||||
|
{
|
||||||
|
Method = Method.POST,
|
||||||
|
};
|
||||||
|
|
||||||
client.Headers.Add(values);
|
request.AddHeader("X-Plex-Client-Identifier", "Test213");
|
||||||
|
request.AddHeader("X-Plex-Product", "Request Plex");
|
||||||
|
request.AddHeader("X-Plex-Version", "0.0.1");
|
||||||
|
request.AddHeader("Content-Type", "application/json");
|
||||||
|
|
||||||
var response = client.UploadString("https://plex.tv/users/sign_in.json", "");
|
request.AddJsonBody(userModel);
|
||||||
|
|
||||||
var json = new JavaScriptSerializer();
|
var api = new ApiRequest();
|
||||||
dynamic result = json.DeserializeObject(response);
|
return api.Execute<PlexAuthentication>(request, new Uri("https://plex.tv/users/sign_in.json"));
|
||||||
|
}
|
||||||
|
|
||||||
var token = result["user"]["authentication_token"];
|
public void GetUsers(string authToken)
|
||||||
|
{
|
||||||
|
var request = new RestRequest
|
||||||
|
{
|
||||||
|
Method = Method.POST,
|
||||||
|
};
|
||||||
|
|
||||||
|
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");
|
||||||
|
|
||||||
Debug.WriteLine(token);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -61,7 +61,8 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="ApiRequest.cs" />
|
<Compile Include="ApiRequest.cs" />
|
||||||
<Compile Include="Models\MovieSearch.cs" />
|
<Compile Include="Models\PlexAuthentication.cs" />
|
||||||
|
<Compile Include="Models\PlexUserRequest.cs" />
|
||||||
<Compile Include="PlexApi.cs" />
|
<Compile Include="PlexApi.cs" />
|
||||||
<Compile Include="TheMovieDbApi.cs" />
|
<Compile Include="TheMovieDbApi.cs" />
|
||||||
<Compile Include="MovieBase.cs" />
|
<Compile Include="MovieBase.cs" />
|
||||||
|
|
|
@ -12,7 +12,7 @@ namespace RequestPlex.Core
|
||||||
{
|
{
|
||||||
public class SettingsService
|
public class SettingsService
|
||||||
{
|
{
|
||||||
public void SaveSettings(int port)
|
public void SaveSettings(SettingsModel model)
|
||||||
{
|
{
|
||||||
var db = new DbConfiguration(new SqliteFactory());
|
var db = new DbConfiguration(new SqliteFactory());
|
||||||
var repo = new GenericRepository<SettingsModel>(db);
|
var repo = new GenericRepository<SettingsModel>(db);
|
||||||
|
@ -20,13 +20,12 @@ namespace RequestPlex.Core
|
||||||
var existingSettings = repo.GetAll().FirstOrDefault();
|
var existingSettings = repo.GetAll().FirstOrDefault();
|
||||||
if (existingSettings != null)
|
if (existingSettings != null)
|
||||||
{
|
{
|
||||||
existingSettings.Port = port;
|
existingSettings = model;
|
||||||
repo.Update(existingSettings);
|
repo.Update(existingSettings);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var newSettings = new SettingsModel { Port = port };
|
repo.Insert(model);
|
||||||
repo.Insert(newSettings);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public SettingsModel GetSettings()
|
public SettingsModel GetSettings()
|
||||||
|
|
|
@ -11,6 +11,7 @@ using Nancy.Security;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using RequestPlex.Api;
|
using RequestPlex.Api;
|
||||||
using RequestPlex.Core;
|
using RequestPlex.Core;
|
||||||
|
using RequestPlex.Store;
|
||||||
using RequestPlex.UI.Models;
|
using RequestPlex.UI.Models;
|
||||||
|
|
||||||
namespace RequestPlex.UI.Modules
|
namespace RequestPlex.UI.Modules
|
||||||
|
@ -32,6 +33,7 @@ namespace RequestPlex.UI.Modules
|
||||||
if (settings != null)
|
if (settings != null)
|
||||||
{
|
{
|
||||||
model.Port = settings.Port;
|
model.Port = settings.Port;
|
||||||
|
model.PlexAuthToken = settings.PlexAuthToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
return View["/Admin/Settings", model];
|
return View["/Admin/Settings", model];
|
||||||
|
@ -39,16 +41,10 @@ namespace RequestPlex.UI.Modules
|
||||||
|
|
||||||
Post["admin/"] = _ =>
|
Post["admin/"] = _ =>
|
||||||
{
|
{
|
||||||
var portString = (string)Request.Form.portNumber;
|
var model = this.Bind<SettingsModel>();
|
||||||
int port;
|
|
||||||
|
|
||||||
if (!int.TryParse(portString, out port))
|
|
||||||
{
|
|
||||||
return Context.GetRedirect("~/admin?error=true");
|
|
||||||
}
|
|
||||||
|
|
||||||
var s = new SettingsService();
|
var s = new SettingsService();
|
||||||
s.SaveSettings(port);
|
s.SaveSettings(model);
|
||||||
|
|
||||||
|
|
||||||
return Context.GetRedirect("~/admin");
|
return Context.GetRedirect("~/admin");
|
||||||
|
@ -64,12 +60,36 @@ namespace RequestPlex.UI.Modules
|
||||||
}
|
}
|
||||||
|
|
||||||
var plex = new PlexApi();
|
var plex = new PlexApi();
|
||||||
plex.GetToken(user.username, user.password);
|
var model = plex.GetToken(user.username, user.password);
|
||||||
|
var s = new SettingsService();
|
||||||
|
var oldSettings = s.GetSettings();
|
||||||
|
if (oldSettings != null)
|
||||||
|
{
|
||||||
|
oldSettings.PlexAuthToken = model.user.authentication_token;
|
||||||
|
s.SaveSettings(oldSettings);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var newModel = new SettingsModel
|
||||||
|
{
|
||||||
|
PlexAuthToken = model.user.authentication_token
|
||||||
|
};
|
||||||
|
s.SaveSettings(newModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return Context.GetRedirect("~/admin");
|
return Context.GetRedirect("~/admin");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Get["admin/getusers"] = _ =>
|
||||||
|
{
|
||||||
|
var api = new PlexApi();
|
||||||
|
|
||||||
|
|
||||||
|
return View["/Admin/Settings"];
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
@Html.Partial("/Admin/_Sidebar")
|
@Html.Partial("/Admin/_Sidebar")
|
||||||
@{
|
@{
|
||||||
int port;
|
int port;
|
||||||
|
var authToken = string.Empty;
|
||||||
if (Model.Port == null)
|
if (Model.Port == null)
|
||||||
{
|
{
|
||||||
port = 3579;
|
port = 3579;
|
||||||
|
@ -10,10 +11,14 @@
|
||||||
port = Model.Port;
|
port = Model.Port;
|
||||||
}
|
}
|
||||||
|
|
||||||
//if (string.IsNullOrEmpty(Model.PlexAuthToken))
|
if (Model.PlexAuthToken == null)
|
||||||
//{
|
{
|
||||||
// Model.PlexAuthToken = string.Empty;
|
authToken = string.Empty;
|
||||||
//}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
authToken = Model.PlexAuthToken;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
<div class="col-sm-8">
|
<div class="col-sm-8">
|
||||||
<form class="form-horizontal" method="POST" id="mainForm">
|
<form class="form-horizontal" method="POST" id="mainForm">
|
||||||
|
@ -22,24 +27,24 @@
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="portNumber" class="col-lg-2 control-label">Port</label>
|
<label for="portNumber" class="col-lg-2 control-label">Port</label>
|
||||||
<div class="col-lg-10">
|
<div class="col-lg-10">
|
||||||
<input type="text" class="form-control" id="portNumber" name="portNumber" placeholder="Port Number" value="@port">
|
<input type="text" class="form-control" id="portNumber" name="Port" placeholder="Port Number" value="@port">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="authToken" class="col-lg-2 control-label">Plex Authorization Token</label>
|
<label for="authToken" class="col-lg-2 control-label">Plex Authorization Token</label>
|
||||||
<div class="col-lg-10">
|
<div class="col-lg-10">
|
||||||
<input type="text" class="form-control" id="authToken" name="authToken" placeholder="Plex Auth Token" value="@*@Model.PlexAuthToken*@">
|
<input type="text" class="form-control" id="authToken" name="PlexAuthToken" placeholder="Plex Auth Token" value="@authToken">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="userpass" class="col-lg-2 control-label">Username and Password</label>
|
<label for="userpass" class="col-lg-2 control-label">Username and Password</label>
|
||||||
<div class="col-lg-4">
|
<div class="col-lg-4">
|
||||||
<input type="text" class="form-control" id="username" name="username" placeholder="Username">
|
<input type="text" class="form-control" id="username" name="Username" placeholder="Username">
|
||||||
</div>
|
</div>
|
||||||
<div class="col-lg-4 col-lg-push-1">
|
<div class="col-lg-4 col-lg-push-1">
|
||||||
<input type="text" class="form-control" id="password" name="password" placeholder="Password">
|
<input type="password" class="form-control" id="password" name="Username" placeholder="Password">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
|
@ -48,8 +53,28 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="userAuth" class="col-lg-2 control-label">Enable User Authentication</label>
|
||||||
|
<div class="col-lg-4">
|
||||||
|
<input type="checkbox" class="form-control" id="userAuth" name="UserAuthentication">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<small>Current users that are allowed to authenticate: </small>
|
||||||
|
<select id="users" multiple="" class="form-control">
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<div class="col-lg-10 col-lg-offset-2">
|
||||||
|
<button id="refreshUsers" class="btn btn-primary">Refresh Users</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<br/>
|
||||||
|
<br/>
|
||||||
|
<br/>
|
||||||
|
<br/>
|
||||||
<div>
|
<div>
|
||||||
<small>Please note, you will have to restart after changing these settings.</small>
|
<small class="col-lg-10 col-lg-offset-2">Please note, you will have to restart after changing these settings.</small>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<div class="col-lg-10 col-lg-offset-2">
|
<div class="col-lg-10 col-lg-offset-2">
|
||||||
|
@ -73,6 +98,12 @@
|
||||||
<script>
|
<script>
|
||||||
$(function () {
|
$(function () {
|
||||||
|
|
||||||
|
loadUserList();
|
||||||
|
|
||||||
|
$('#refreshUsers').click(function() {
|
||||||
|
loadUserList();
|
||||||
|
});
|
||||||
|
|
||||||
$('#requestToken').click(function (e) {
|
$('#requestToken').click(function (e) {
|
||||||
var $form = $("#mainForm");
|
var $form = $("#mainForm");
|
||||||
$.ajax({
|
$.ajax({
|
||||||
|
@ -96,5 +127,26 @@
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function loadUserList() {
|
||||||
|
$.ajax({
|
||||||
|
type: "Get",
|
||||||
|
url: "admin/getusers",
|
||||||
|
dataType: "json",
|
||||||
|
success: function (response) {
|
||||||
|
response.each(function (user) {
|
||||||
|
$('#users').append("<option>" + user + "</option>");
|
||||||
|
});
|
||||||
|
},
|
||||||
|
error: function (e) {
|
||||||
|
console.log(e);
|
||||||
|
generateNotify("Something went wrong!", "danger");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
Loading…
Add table
Add a link
Reference in a new issue