mirror of https://github.com/Sonarr/Sonarr
New: Username and Password for Plex Server (optional)
This commit is contained in:
parent
b65f2e7845
commit
2cc0dc3aab
|
@ -13,6 +13,7 @@ namespace NzbDrone.Common
|
|||
{
|
||||
string DownloadString(string url);
|
||||
string DownloadString(string url, string username, string password);
|
||||
string DownloadString(string url, ICredentials credentials);
|
||||
Dictionary<string, string> GetHeader(string url);
|
||||
|
||||
Stream DownloadStream(string url, NetworkCredential credential = null);
|
||||
|
@ -44,7 +45,7 @@ namespace NzbDrone.Common
|
|||
return DownloadString(url, new NetworkCredential(username, password));
|
||||
}
|
||||
|
||||
private string DownloadString(string url, ICredentials identity)
|
||||
public string DownloadString(string url, ICredentials identity)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
|
@ -30,7 +30,13 @@ namespace NzbDrone.Core.Notifications.Plex
|
|||
[FieldDefinition(1, Label = "Port")]
|
||||
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 bool IsValid
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Xml.Linq;
|
||||
using NLog;
|
||||
using NzbDrone.Common;
|
||||
|
@ -58,7 +59,7 @@ namespace NzbDrone.Core.Notifications.Plex
|
|||
{
|
||||
_logger.Debug("Getting sections from Plex host: {0}", settings.Host);
|
||||
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 mediaContainer = xDoc.Descendants("MediaContainer").FirstOrDefault();
|
||||
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);
|
||||
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)
|
||||
|
@ -85,6 +86,13 @@ namespace NzbDrone.Core.Notifications.Plex
|
|||
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)
|
||||
{
|
||||
_logger.Debug("Sending Test Notifcation to Plex Client: {0}", message.Host);
|
||||
|
|
Loading…
Reference in New Issue