New: Username and Password for Plex Server (optional)

pull/4/head
Mark McDowall 11 years ago
parent b65f2e7845
commit 2cc0dc3aab

@ -13,6 +13,7 @@ namespace NzbDrone.Common
{ {
string DownloadString(string url); string DownloadString(string url);
string DownloadString(string url, string username, string password); string DownloadString(string url, string username, string password);
string DownloadString(string url, ICredentials credentials);
Dictionary<string, string> GetHeader(string url); Dictionary<string, string> GetHeader(string url);
Stream DownloadStream(string url, NetworkCredential credential = null); Stream DownloadStream(string url, NetworkCredential credential = null);
@ -44,7 +45,7 @@ namespace NzbDrone.Common
return DownloadString(url, new NetworkCredential(username, password)); return DownloadString(url, new NetworkCredential(username, password));
} }
private string DownloadString(string url, ICredentials identity) public string DownloadString(string url, ICredentials identity)
{ {
try try
{ {

@ -30,7 +30,13 @@ namespace NzbDrone.Core.Notifications.Plex
[FieldDefinition(1, Label = "Port")] [FieldDefinition(1, Label = "Port")]
public Int32 Port { get; set; } public Int32 Port { get; set; }
[FieldDefinition(2, Label = "Update Library", Type = FieldType.Checkbox)] [FieldDefinition(2, Label = "Username")]
public String Username { get; set; }
[FieldDefinition(3, Label = "Password")]
public String Password { get; set; }
[FieldDefinition(4, Label = "Update Library", Type = FieldType.Checkbox)]
public Boolean UpdateLibrary { get; set; } public Boolean UpdateLibrary { get; set; }
public bool IsValid public bool IsValid

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Net;
using System.Xml.Linq; using System.Xml.Linq;
using NLog; using NLog;
using NzbDrone.Common; using NzbDrone.Common;
@ -58,7 +59,7 @@ namespace NzbDrone.Core.Notifications.Plex
{ {
_logger.Debug("Getting sections from Plex host: {0}", settings.Host); _logger.Debug("Getting sections from Plex host: {0}", settings.Host);
var url = String.Format("http://{0}:{1}/library/sections", settings.Host, settings.Port); var url = String.Format("http://{0}:{1}/library/sections", settings.Host, settings.Port);
var xmlStream = _httpProvider.DownloadStream(url, null); var xmlStream = _httpProvider.DownloadStream(url, GetCredentials(settings));
var xDoc = XDocument.Load(xmlStream); var xDoc = XDocument.Load(xmlStream);
var mediaContainer = xDoc.Descendants("MediaContainer").FirstOrDefault(); var mediaContainer = xDoc.Descendants("MediaContainer").FirstOrDefault();
var directories = mediaContainer.Descendants("Directory").Where(x => x.Attribute("type").Value == "show"); var directories = mediaContainer.Descendants("Directory").Where(x => x.Attribute("type").Value == "show");
@ -70,7 +71,7 @@ namespace NzbDrone.Core.Notifications.Plex
{ {
_logger.Debug("Updating Plex host: {0}, Section: {1}", settings.Host, key); _logger.Debug("Updating Plex host: {0}, Section: {1}", settings.Host, key);
var url = String.Format("http://{0}:{1}/library/sections/{2}/refresh", settings.Host, settings.Port, key); var url = String.Format("http://{0}:{1}/library/sections/{2}/refresh", settings.Host, settings.Port, key);
_httpProvider.DownloadString(url); _httpProvider.DownloadString(url, GetCredentials(settings));
} }
public string SendCommand(string host, int port, string command, string username, string password) public string SendCommand(string host, int port, string command, string username, string password)
@ -85,6 +86,13 @@ namespace NzbDrone.Core.Notifications.Plex
return _httpProvider.DownloadString(url); return _httpProvider.DownloadString(url);
} }
private NetworkCredential GetCredentials(PlexServerSettings settings)
{
if (settings.Username.IsNullOrWhiteSpace()) return null;
return new NetworkCredential(settings.Username, settings.Password);
}
public void Execute(TestPlexClientCommand message) public void Execute(TestPlexClientCommand message)
{ {
_logger.Debug("Sending Test Notifcation to Plex Client: {0}", message.Host); _logger.Debug("Sending Test Notifcation to Plex Client: {0}", message.Host);

Loading…
Cancel
Save