1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2025-11-06 09:19:38 +02:00

started rss cleanup

This commit is contained in:
kay.one
2011-04-03 20:50:12 -07:00
parent 7a16a907a4
commit 62b2cd510f
43 changed files with 188 additions and 217 deletions

View File

@@ -0,0 +1,249 @@
using System;
using NLog;
using NzbDrone.Core.Repository;
using SubSonic.Repository;
namespace NzbDrone.Core.Providers.Core
{
public class ConfigProvider : IConfigProvider
{
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
private readonly IRepository _sonicRepo;
public ConfigProvider(IRepository dataRepository)
{
_sonicRepo = dataRepository;
}
public String ApiKey
{
get { return GetValue("ApiKey"); }
set { SetValue("ApiKey", value); }
}
public String EpisodeNameFormat
{
get { return GetValue("EpisodeNameFormat"); }
set { SetValue("EpisodeNameFormat", value); }
}
public String SeriesRoot
{
get { return GetValue("SeriesRoots"); }
set { SetValue("SeriesRoots", value); }
}
public String NzbMatrixUsername
{
get { return GetValue("NzbMatrixUsername"); }
set { SetValue("NzbMatrixUsername", value); }
}
public String NzbMatrixApiKey
{
get { return GetValue("NzbMatrixApiKey"); }
set { SetValue("NzbMatrixApiKey", value); }
}
public String NzbsOrgUId
{
get { return GetValue("NzbsOrgUId"); }
set { SetValue("NzbsOrgUId", value); }
}
public String NzbsOrgHash
{
get { return GetValue("NzbsOrgHash"); }
set { SetValue("NzbsOrgHash", value); }
}
public String NzbsrusUId
{
get { return GetValue("NzbsrusUId"); }
set { SetValue("NzbsrusUId", value); }
}
public String NzbsrusHash
{
get { return GetValue("NzbsrusHash"); }
set { SetValue("NzbsrusHash", value); }
}
public String SyncFrequency
{
get { return GetValue("SyncFrequency"); }
set { SetValue("SyncFrequency", value); }
}
public String DownloadPropers
{
get { return GetValue("DownloadPropers"); }
set { SetValue("DownloadPropers", value); }
}
public String Retention
{
get { return GetValue("Retention"); }
set { SetValue("Retention", value); }
}
public String SabHost
{
get { return GetValue("SabHost"); }
set { SetValue("SabHost", value); }
}
public String SabPort
{
get { return GetValue("SabPort"); }
set { SetValue("SabPort", value); }
}
public String SabApiKey
{
get { return GetValue("SabApiKey"); }
set { SetValue("SabApiKey", value); }
}
public String SabUsername
{
get { return GetValue("SabUsername"); }
set { SetValue("SabUsername", value); }
}
public String SabPassword
{
get { return GetValue("SabPassword"); }
set { SetValue("SabPassword", value); }
}
public String SabTvCategory
{
get { return GetValue("SabTvCategory"); }
set { SetValue("SabTvCategory", value); }
}
public String SabTvPriority
{
get { return GetValue("SabTvPriority"); }
set { SetValue("SabTvPriority", value); }
}
public String UseBlackhole
{
get { return GetValue("UseBlackhole"); }
set { SetValue("UseBlackhole", value); }
}
public String BlackholeDirectory
{
get { return GetValue("BlackholeDirectory"); }
set { SetValue("BlackholeDirectory", value); }
}
public bool UseSeasonFolder
{
get { return GetValueBoolean("Sorting_SeasonFolder", true); }
set { SetValue("Sorting_SeasonFolder", value); }
}
public int DefaultQualityProfile
{
get { return GetValueInt("DefaultQualityProfile", 1); }
set { SetValue("DefaultQualityProfile", value); }
}
private string GetValue(string key)
{
return GetValue(key, String.Empty, false);
}
private bool GetValueBoolean(string key, bool defaultValue = false)
{
return Convert.ToBoolean(GetValue(key, defaultValue, false));
}
private int GetValueInt(string key, int defaultValue = 0)
{
return Convert.ToInt16(GetValue(key, defaultValue, false));
}
public string GetValue(string key, object defaultValue, bool makePermanent)
{
string value;
var dbValue = _sonicRepo.Single<Config>(key);
if (dbValue != null && !String.IsNullOrEmpty(dbValue.Value))
return dbValue.Value;
Logger.Debug("Unable to find config key '{0}' defaultValue:'{1}'", key, defaultValue);
if (makePermanent)
SetValue(key, defaultValue.ToString());
value = defaultValue.ToString();
return value;
}
public void SetValue(string key, Boolean value)
{
SetValue(key, value.ToString());
}
public void SetValue(string key, int value)
{
SetValue(key, value.ToString());
}
public void SetValue(string key, string value)
{
if (String.IsNullOrEmpty(key))
throw new ArgumentOutOfRangeException("key");
if (value == null)
throw new ArgumentNullException("key");
Logger.Debug("Writing Setting to file. Key:'{0}' Value:'{1}'", key, value);
var dbValue = _sonicRepo.Single<Config>(key);
if (dbValue == null)
{
_sonicRepo.Add(new Config
{
Key = key,
Value = value
});
}
else
{
dbValue.Value = value;
_sonicRepo.Update(dbValue);
}
}
}
}

View File

@@ -0,0 +1,54 @@
using System;
using System.IO;
namespace NzbDrone.Core.Providers.Core
{
public class DiskProvider : IDiskProvider
{
#region IDiskProvider Members
public bool FolderExists(string path)
{
return Directory.Exists(path);
}
public bool FileExists(string path)
{
return File.Exists(path);
}
public string[] GetDirectories(string path)
{
return Directory.GetDirectories(path);
}
public string[] GetFiles(string path, string pattern, SearchOption searchOption)
{
return Directory.GetFiles(path, pattern, searchOption);
}
public long GetSize(string path)
{
var fi = new FileInfo(path);
return fi.Length;
//return new FileInfo(path).Length;
}
public String CreateDirectory(string path)
{
return Directory.CreateDirectory(path).FullName;
}
public void DeleteFile(string path)
{
File.Delete(path);
}
public void RenameFile(string sourcePath, string destinationPath)
{
File.Move(sourcePath, destinationPath);
}
#endregion
}
}

View File

@@ -0,0 +1,78 @@
using System;
using System.Net;
using NLog;
namespace NzbDrone.Core.Providers.Core
{
internal class HttpProvider : IHttpProvider
{
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
public string DownloadString(string 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;
}
public bool DownloadFile(string request, string filename)
{
try
{
var webClient = new WebClient();
webClient.DownloadFile(request, filename);
return true;
}
catch (Exception ex)
{
Logger.Warn("Failed to get response from: {0}", request);
Logger.TraceException(ex.Message, ex);
}
return false;
}
public bool DownloadFile(string request, string filename, string username, string password)
{
try
{
var webClient = new WebClient();
webClient.Credentials = new NetworkCredential(username, password);
webClient.DownloadFile(request, filename);
return true;
}
catch (Exception ex)
{
Logger.Warn("Failed to get response from: {0}", request);
Logger.TraceException(ex.Message, ex);
}
return false;
}
}
}

View File

@@ -0,0 +1,34 @@
using System;
namespace NzbDrone.Core.Providers.Core
{
public interface IConfigProvider
{
String SeriesRoot { get; set; }
String EpisodeNameFormat { get; set; }
String NzbMatrixUsername { get; set; }
String NzbMatrixApiKey { get; set; }
String NzbsOrgUId { get; set; }
String NzbsOrgHash { get; set; }
String NzbsrusUId { get; set; }
String NzbsrusHash { get; set; }
String DownloadPropers { get; set; }
String Retention { get; set; }
String SabHost { get; set; }
String SabPort { get; set; }
String SabApiKey { get; set; }
String SabUsername { get; set; }
String SabPassword { get; set; }
String SabTvCategory { get; set; }
String UseBlackhole { get; set; }
String BlackholeDirectory { get; set; }
String SyncFrequency { get; set; }
String SabTvPriority { get; set; }
String ApiKey { get; set; }
bool UseSeasonFolder { get; set; }
int DefaultQualityProfile { get; set; }
string GetValue(string key, object defaultValue, bool makePermanent);
void SetValue(string key, string value);
}
}

View File

@@ -0,0 +1,17 @@
using System;
using System.IO;
namespace NzbDrone.Core.Providers.Core
{
public interface IDiskProvider
{
bool FolderExists(string path);
string[] GetDirectories(string path);
String CreateDirectory(string path);
string[] GetFiles(string path, string pattern, SearchOption searchOption);
bool FileExists(string path);
long GetSize(string path);
void DeleteFile(string path);
void RenameFile(string sourcePath, string destinationPath);
}
}

View File

@@ -0,0 +1,10 @@
namespace NzbDrone.Core.Providers.Core
{
public interface IHttpProvider
{
string DownloadString(string request);
string DownloadString(string request, string username, string password);
bool DownloadFile(string request, string filename);
bool DownloadFile(string request, string filename, string username, string password);
}
}

View File

@@ -0,0 +1,11 @@
using System.Collections.Generic;
using NzbDrone.Core.Model;
using Rss;
namespace NzbDrone.Core.Providers.Core
{
public interface IRssProvider
{
IEnumerable<RssItem> GetFeed(FeedInfoModel feedInfo);
}
}

View File

@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using NLog;
using NzbDrone.Core.Model;
using Rss;
namespace NzbDrone.Core.Providers.Core
{
public class RssProvider : IRssProvider
{
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
#region IRssProvider Members
public IEnumerable<RssItem> GetFeed(FeedInfoModel feedInfo)
{
RssFeed feed = null;
try
{
Logger.Info("INFO: Downloading feed {0} from {1}", feedInfo.Name, feedInfo.Url);
feed = RssFeed.Read(feedInfo.Url);
}
catch (Exception e)
{
Logger.ErrorException(String.Format("ERROR: Could not download feed {0} from {1}", feedInfo.Name, feedInfo.Url), e);
}
if (feed == null || feed.Channels == null || feed.Channels.Count == 0)
return Enumerable.Empty<RssItem>();
return feed.Channels[0].Items.Cast<RssItem>();
}
#endregion
}
}