XbmcProvider will use HttpProvider.

Added DownloadString for HttpProvider that allows for authenticaion (required for XBMC with username/password).
This commit is contained in:
markus101 2011-03-06 22:33:59 -08:00
parent 2f8ad5db45
commit 9e15b27e3a
4 changed files with 42 additions and 19 deletions

View File

@ -1,12 +1,43 @@
using System.Net;
using System;
using System.Net;
using NLog;
namespace NzbDrone.Core.Providers
{
internal class HttpProvider : IHttpProvider
{
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
public string DownloadString(string request)
{
return new WebClient().DownloadString(request);
try
{
return new WebClient().DownloadString(request);
}
catch (Exception ex)
{
Logger.Warn("Failed to get response from: {0}", request);
Logger.TraceException(ex.Message, ex);
}
return String.Empty;
}
public string DownloadString(string request, string username, string password)
{
try
{
var webClient = new WebClient();
webClient.Credentials = new NetworkCredential(username, password);
return webClient.DownloadString(request);
}
catch (Exception ex)
{
Logger.Warn("Failed to get response from: {0}", request);
Logger.TraceException(ex.Message, ex);
}
return String.Empty;
}
}
}

View File

@ -3,5 +3,6 @@
public interface IHttpProvider
{
string DownloadString(string request);
string DownloadString(string request, string username, string password);
}
}

View File

@ -39,7 +39,7 @@ namespace NzbDrone.Core.Providers
foreach (var file in fileList)
{
//Todo: Where should we handle XBMC notifying/library updating etc? RenameProvider seems like a likely place, since we want to update XBMC after renaming (might as well)
//Notifications will be sent from the Renamer, depending on the bool NewDownload (which will be set to true from here), a normal rename will be treated as such.
_renameProvider.RenameEpisodeFile(file.EpisodeFileId, true);
}
}

View File

@ -13,14 +13,16 @@ namespace NzbDrone.Core.Providers
public class XbmcProvider : IXbmcProvider
{
private readonly IConfigProvider _configProvider;
private readonly IHttpProvider _httpProvider;
private WebClient _webClient;
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
public XbmcProvider(IConfigProvider configProvider)
public XbmcProvider(IConfigProvider configProvider, IHttpProvider httpProvider)
{
_webClient = new WebClient();
_configProvider = configProvider;
_httpProvider = httpProvider;
}
#region IXbmcProvider Members
@ -84,25 +86,14 @@ namespace NzbDrone.Core.Providers
{
var username = _configProvider.GetValue("XbmcUsername", String.Empty, true);
var password = _configProvider.GetValue("XbmcPassword", String.Empty, true);
var url = String.Format("http://{0}/xbmcCmds/xbmcHttp?command={1}", host, command);
if (!String.IsNullOrEmpty(username))
{
_webClient.Credentials = new NetworkCredential(username, password);
return _httpProvider.DownloadString(url, username, password);
}
var url = String.Format("http://{0}/xbmcCmds/xbmcHttp?command={1}", host, command);
try
{
return _webClient.DownloadString(url);
}
catch (Exception ex)
{
Logger.Warn("Unable to Connect to XBMC Host: {0}", host);
Logger.DebugException(ex.Message, ex);
}
return string.Empty;
return _httpProvider.DownloadString(url);
}
private string GetXbmcSeriesPath(string host, int seriesId)