diff --git a/src/NzbDrone.Common/HttpProvider.cs b/src/NzbDrone.Common/HttpProvider.cs index c64b081c6..283e8946b 100644 --- a/src/NzbDrone.Common/HttpProvider.cs +++ b/src/NzbDrone.Common/HttpProvider.cs @@ -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 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 { diff --git a/src/NzbDrone.Core/Notifications/Plex/PlexServerSettings.cs b/src/NzbDrone.Core/Notifications/Plex/PlexServerSettings.cs index 020f7f65f..272d0efcc 100644 --- a/src/NzbDrone.Core/Notifications/Plex/PlexServerSettings.cs +++ b/src/NzbDrone.Core/Notifications/Plex/PlexServerSettings.cs @@ -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 diff --git a/src/NzbDrone.Core/Notifications/Plex/PlexService.cs b/src/NzbDrone.Core/Notifications/Plex/PlexService.cs index fc02d0cc7..7fddd2a64 100644 --- a/src/NzbDrone.Core/Notifications/Plex/PlexService.cs +++ b/src/NzbDrone.Core/Notifications/Plex/PlexService.cs @@ -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);