mirror of
https://github.com/Sonarr/Sonarr
synced 2025-01-03 05:35:29 +00:00
Resharper code cleanup
This commit is contained in:
parent
c7286863b0
commit
d00744aafa
11 changed files with 46 additions and 130 deletions
|
@ -11,7 +11,6 @@ namespace NzbDrone.Core
|
||||||
{
|
{
|
||||||
public static class Main
|
public static class Main
|
||||||
{
|
{
|
||||||
|
|
||||||
public static void BindKernel(IKernel kernel)
|
public static void BindKernel(IKernel kernel)
|
||||||
{
|
{
|
||||||
string connectionString = String.Format("Data Source={0};Version=3;", Path.Combine(AppPath, "nzbdrone.db"));
|
string connectionString = String.Format("Data Source={0};Version=3;", Path.Combine(AppPath, "nzbdrone.db"));
|
||||||
|
@ -30,4 +29,4 @@ namespace NzbDrone.Core
|
||||||
get { return new DirectoryInfo(HttpContext.Current.Server.MapPath("\\")).Parent.FullName; }
|
get { return new DirectoryInfo(HttpContext.Current.Server.MapPath("\\")).Parent.FullName; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -11,7 +11,6 @@ namespace NzbDrone.Core.Providers
|
||||||
private readonly ILog _logger;
|
private readonly ILog _logger;
|
||||||
private readonly IRepository _sonicRepo;
|
private readonly IRepository _sonicRepo;
|
||||||
|
|
||||||
|
|
||||||
public ConfigProvider(ILog logger, IRepository dataRepository)
|
public ConfigProvider(ILog logger, IRepository dataRepository)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
@ -19,7 +18,6 @@ namespace NzbDrone.Core.Providers
|
||||||
_sonicRepo = dataRepository;
|
_sonicRepo = dataRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private string GetValue(string key)
|
private string GetValue(string key)
|
||||||
{
|
{
|
||||||
return GetValue(key, String.Empty, false);
|
return GetValue(key, String.Empty, false);
|
||||||
|
@ -27,39 +25,23 @@ namespace NzbDrone.Core.Providers
|
||||||
|
|
||||||
public String SeriesRoot
|
public String SeriesRoot
|
||||||
{
|
{
|
||||||
get
|
get { return GetValue(SERIES_ROOTS); }
|
||||||
{
|
|
||||||
return GetValue(SERIES_ROOTS);
|
|
||||||
}
|
|
||||||
|
|
||||||
set
|
|
||||||
{
|
|
||||||
SetValue(SERIES_ROOTS, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
set { SetValue(SERIES_ROOTS, value); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public string GetValue(string key, object defaultValue, bool makePermanent)
|
public string GetValue(string key, object defaultValue, bool makePermanent)
|
||||||
{
|
{
|
||||||
string value;
|
string value;
|
||||||
|
|
||||||
var dbValue = _sonicRepo.Single<Config>(key);
|
var dbValue = _sonicRepo.Single<Config>(key);
|
||||||
|
|
||||||
if (dbValue != null && !String.IsNullOrEmpty(dbValue.Value))
|
if (dbValue != null && !String.IsNullOrEmpty(dbValue.Value)) return dbValue.Value;
|
||||||
{
|
|
||||||
return dbValue.Value;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
_logger.WarnFormat("Unable to find config key '{0}' defaultValue:'{1}'", key, defaultValue);
|
_logger.WarnFormat("Unable to find config key '{0}' defaultValue:'{1}'", key, defaultValue);
|
||||||
if (makePermanent)
|
if (makePermanent) SetValue(key, defaultValue.ToString());
|
||||||
{
|
|
||||||
SetValue(key, defaultValue.ToString());
|
|
||||||
}
|
|
||||||
value = defaultValue.ToString();
|
value = defaultValue.ToString();
|
||||||
|
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,10 +54,7 @@ namespace NzbDrone.Core.Providers
|
||||||
|
|
||||||
var dbValue = _sonicRepo.Single<Config>(key);
|
var dbValue = _sonicRepo.Single<Config>(key);
|
||||||
|
|
||||||
if (dbValue == null)
|
if (dbValue == null) _sonicRepo.Add(new Config {Key = key, Value = value});
|
||||||
{
|
|
||||||
_sonicRepo.Add(new Config { Key = key, Value = value });
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
dbValue.Value = value;
|
dbValue.Value = value;
|
||||||
|
|
|
@ -6,9 +6,7 @@ namespace NzbDrone.Core.Providers
|
||||||
{
|
{
|
||||||
public class EpisodeProvider
|
public class EpisodeProvider
|
||||||
{
|
{
|
||||||
private static Regex _parseRegex =
|
private static readonly Regex _parseRegex = new Regex(@"(?<showName>.*)
|
||||||
new Regex(
|
|
||||||
@"(?<showName>.*)
|
|
||||||
(?:
|
(?:
|
||||||
s(?<seasonNumber>\d+)e(?<episodeNumber>\d+)-?e(?<episodeNumber2>\d+)
|
s(?<seasonNumber>\d+)e(?<episodeNumber>\d+)-?e(?<episodeNumber2>\d+)
|
||||||
| s(?<seasonNumber>\d+)e(?<episodeNumber>\d+)
|
| s(?<seasonNumber>\d+)e(?<episodeNumber>\d+)
|
||||||
|
@ -23,24 +21,13 @@ namespace NzbDrone.Core.Providers
|
||||||
| (?<episodeName>.*)
|
| (?<episodeName>.*)
|
||||||
)", RegexOptions.IgnoreCase | RegexOptions.Compiled | RegexOptions.IgnorePatternWhitespace);
|
)", RegexOptions.IgnoreCase | RegexOptions.Compiled | RegexOptions.IgnorePatternWhitespace);
|
||||||
|
|
||||||
|
|
||||||
public static Episode Parse(string title)
|
public static Episode Parse(string title)
|
||||||
{
|
{
|
||||||
Match match = _parseRegex.Match(title);
|
Match match = _parseRegex.Match(title);
|
||||||
|
|
||||||
if (!match.Success)
|
if (!match.Success) return null;
|
||||||
return null;
|
|
||||||
|
|
||||||
return new Episode
|
return new Episode {Season = ParseInt(match.Groups["seasonNumber"].Value), EpisodeNumber = ParseInt(match.Groups["episodeNumber"].Value), EpisodeNumber2 = ParseInt(match.Groups["episodeNumber2"].Value), Title = ReplaceSeparatorChars(match.Groups["episodeName"].Value), Release = ReplaceSeparatorChars(match.Groups["release"].Value), Proper = title.Contains("PROPER")};
|
||||||
{
|
|
||||||
|
|
||||||
Season = ParseInt(match.Groups["seasonNumber"].Value),
|
|
||||||
EpisodeNumber = ParseInt(match.Groups["episodeNumber"].Value),
|
|
||||||
EpisodeNumber2 = ParseInt(match.Groups["episodeNumber2"].Value),
|
|
||||||
Title = ReplaceSeparatorChars(match.Groups["episodeName"].Value),
|
|
||||||
Release = ReplaceSeparatorChars(match.Groups["release"].Value),
|
|
||||||
Proper = title.Contains("PROPER")
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string ReplaceSeparatorChars(string s)
|
private static string ReplaceSeparatorChars(string s)
|
||||||
|
@ -59,10 +46,8 @@ namespace NzbDrone.Core.Providers
|
||||||
private static DateTime ParseAirDate(string s)
|
private static DateTime ParseAirDate(string s)
|
||||||
{
|
{
|
||||||
DateTime d;
|
DateTime d;
|
||||||
if (DateTime.TryParse(ReplaceSeparatorChars(s).Replace(' ', '-'), out d))
|
if (DateTime.TryParse(ReplaceSeparatorChars(s).Replace(' ', '-'), out d)) return d;
|
||||||
return d;
|
|
||||||
return DateTime.MinValue;
|
return DateTime.MinValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,13 +1,12 @@
|
||||||
using System;
|
using System.Net;
|
||||||
using System.Net;
|
|
||||||
|
|
||||||
namespace NzbDrone.Core.Providers
|
namespace NzbDrone.Core.Providers
|
||||||
{
|
{
|
||||||
class HttpProvider : IHttpProvider
|
internal class HttpProvider : IHttpProvider
|
||||||
{
|
{
|
||||||
public string DownloadString(string request)
|
public string DownloadString(string request)
|
||||||
{
|
{
|
||||||
return new WebClient().DownloadString(request);
|
return new WebClient().DownloadString(request);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,10 +1,8 @@
|
||||||
using NzbDrone.Core.Repository;
|
namespace NzbDrone.Core.Providers
|
||||||
|
|
||||||
namespace NzbDrone.Core.Providers
|
|
||||||
{
|
{
|
||||||
public interface IDownloadProvider
|
public interface IDownloadProvider
|
||||||
{
|
{
|
||||||
bool AddByUrl(string url, string title); //Should accept something other than string (NzbInfo?) returns success or failure
|
bool AddByUrl(string url, string title); //Should accept something other than string (NzbInfo?) returns success or failure
|
||||||
bool IsInQueue(string title);//Should accept something other than string (Episode?) returns bool
|
bool IsInQueue(string title); //Should accept something other than string (Episode?) returns bool
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -4,4 +4,4 @@
|
||||||
{
|
{
|
||||||
string DownloadString(string request);
|
string DownloadString(string request);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,9 +1,8 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Web;
|
using System.Web;
|
||||||
using log4net;
|
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
using NzbDrone.Core.Repository;
|
using log4net;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Providers
|
namespace NzbDrone.Core.Providers
|
||||||
{
|
{
|
||||||
|
@ -38,8 +37,7 @@ namespace NzbDrone.Core.Providers
|
||||||
string response = _http.DownloadString(request).Replace("\n", String.Empty);
|
string response = _http.DownloadString(request).Replace("\n", String.Empty);
|
||||||
_logger.DebugFormat("Queue Repsonse: [{0}]", response);
|
_logger.DebugFormat("Queue Repsonse: [{0}]", response);
|
||||||
|
|
||||||
if (response == "ok")
|
if (response == "ok") return true;
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -53,14 +51,14 @@ namespace NzbDrone.Core.Providers
|
||||||
XDocument xDoc = XDocument.Parse(response);
|
XDocument xDoc = XDocument.Parse(response);
|
||||||
|
|
||||||
//If an Error Occurred, retuyrn)
|
//If an Error Occurred, retuyrn)
|
||||||
if (xDoc.Descendants("error").Count() != 0)
|
if (xDoc.Descendants("error").Count() != 0) return false;
|
||||||
return false;
|
|
||||||
|
|
||||||
if (xDoc.Descendants("queue").Count() == 0)
|
if (xDoc.Descendants("queue").Count() == 0) return false;
|
||||||
return false;
|
|
||||||
|
|
||||||
//Get the Count of Items in Queue where 'filename' is Equal to goodName, if not zero, return true (isInQueue)))
|
//Get the Count of Items in Queue where 'filename' is Equal to goodName, if not zero, return true (isInQueue)))
|
||||||
if ((from s in xDoc.Descendants("slot") where s.Element("filename").Value.Equals(title, StringComparison.InvariantCultureIgnoreCase) select s).Count() != 0)
|
if ((from s in xDoc.Descendants("slot")
|
||||||
|
where s.Element("filename").Value.Equals(title, StringComparison.InvariantCultureIgnoreCase)
|
||||||
|
select s).Count() != 0)
|
||||||
{
|
{
|
||||||
_logger.DebugFormat("Episode in queue - '{0}'", title);
|
_logger.DebugFormat("Episode in queue - '{0}'", title);
|
||||||
|
|
||||||
|
@ -79,9 +77,7 @@ namespace NzbDrone.Core.Providers
|
||||||
string password = _config.GetValue("Password", String.Empty, false);
|
string password = _config.GetValue("Password", String.Empty, false);
|
||||||
string apiKey = _config.GetValue("ApiKey", String.Empty, false);
|
string apiKey = _config.GetValue("ApiKey", String.Empty, false);
|
||||||
|
|
||||||
return string.Format(
|
return string.Format(@"http://{0}/sabnzbd/api?$Action&apikey={1}&ma_username={2}&ma_password={3}", sabnzbdInfo, apiKey, username, password).Replace("$Action", action);
|
||||||
@"http://{0}/sabnzbd/api?$Action&apikey={1}&ma_username={2}&ma_password={3}",
|
|
||||||
sabnzbdInfo, apiKey, username, password).Replace("$Action", action);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -36,11 +36,8 @@ namespace NzbDrone.Core.Providers
|
||||||
return _sonioRepo.Single<Series>(s => s.TvdbId == tvdbId.ToString());
|
return _sonioRepo.Single<Series>(s => s.TvdbId == tvdbId.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void SyncSeriesWithDisk()
|
public void SyncSeriesWithDisk()
|
||||||
{
|
{
|
||||||
|
|
||||||
foreach (string seriesFolder in _diskProvider.GetDirectories(_config.SeriesRoot))
|
foreach (string seriesFolder in _diskProvider.GetDirectories(_config.SeriesRoot))
|
||||||
{
|
{
|
||||||
var cleanPath = DiskProvider.CleanPath(new DirectoryInfo(seriesFolder).FullName);
|
var cleanPath = DiskProvider.CleanPath(new DirectoryInfo(seriesFolder).FullName);
|
||||||
|
@ -50,7 +47,6 @@ namespace NzbDrone.Core.Providers
|
||||||
AddShow(cleanPath);
|
AddShow(cleanPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -58,10 +54,7 @@ namespace NzbDrone.Core.Providers
|
||||||
private void AddShow(string path)
|
private void AddShow(string path)
|
||||||
{
|
{
|
||||||
var searchResults = _tvDb.SearchSeries(new DirectoryInfo(path).Name);
|
var searchResults = _tvDb.SearchSeries(new DirectoryInfo(path).Name);
|
||||||
if (searchResults.Count != 0 && !_sonioRepo.Exists<Series>(s => s.TvdbId == searchResults[0].Id.ToString()))
|
if (searchResults.Count != 0 && !_sonioRepo.Exists<Series>(s => s.TvdbId == searchResults[0].Id.ToString())) AddShow(path, _tvDb.GetSeries(searchResults[0].Id, searchResults[0].Language));
|
||||||
{
|
|
||||||
AddShow(path, _tvDb.GetSeries(searchResults[0].Id, searchResults[0].Language));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AddShow(string path, TvdbSeries series)
|
private void AddShow(string path, TvdbSeries series)
|
||||||
|
|
|
@ -8,6 +8,7 @@ namespace NzbDrone.Core.Repository
|
||||||
{
|
{
|
||||||
[SubSonicPrimaryKey]
|
[SubSonicPrimaryKey]
|
||||||
public string EpisodeId { get; set; }
|
public string EpisodeId { get; set; }
|
||||||
|
|
||||||
public string SeriesId { get; set; }
|
public string SeriesId { get; set; }
|
||||||
public string Title { get; set; }
|
public string Title { get; set; }
|
||||||
public string Title2 { get; set; }
|
public string Title2 { get; set; }
|
||||||
|
@ -19,6 +20,6 @@ namespace NzbDrone.Core.Repository
|
||||||
public int Quality { get; set; }
|
public int Quality { get; set; }
|
||||||
public bool Proper { get; set; }
|
public bool Proper { get; set; }
|
||||||
public String FileName { get; set; }
|
public String FileName { get; set; }
|
||||||
public SyndicationItem Feed { get; set; }
|
public SyndicationItem Feed { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -2,34 +2,33 @@ namespace NzbDrone.Core.Repository
|
||||||
{
|
{
|
||||||
// ReSharper disable InconsistentNaming
|
// ReSharper disable InconsistentNaming
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents Video Quality
|
/// Represents Video Quality
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public enum Quality
|
public enum Quality
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Quality is unknown
|
/// Quality is unknown
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Unknown = 0,
|
Unknown = 0,
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// SD File (Source could be HD)
|
/// SD File (Source could be HD)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
SDTV = 1,
|
SDTV = 1,
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// SD File (DVD Source)
|
/// SD File (DVD Source)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
DVD = 2,
|
DVD = 2,
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// HD File (HDTV Source)
|
/// HD File (HDTV Source)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
HDTV = 3,
|
HDTV = 3,
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// HD File (Online Source)
|
/// HD File (Online Source)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
WEBDL = 4,
|
WEBDL = 4,
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// HD File (Blu-ray Source)
|
/// HD File (Blu-ray Source)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Bluray = 5
|
Bluray = 5
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -6,54 +6,21 @@ namespace NzbDrone.Core.Repository
|
||||||
public class Series
|
public class Series
|
||||||
{
|
{
|
||||||
[SubSonicPrimaryKey]
|
[SubSonicPrimaryKey]
|
||||||
public string TvdbId
|
public string TvdbId { get; set; }
|
||||||
{
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
}
|
|
||||||
|
|
||||||
public string SeriesName
|
public string SeriesName { get; set; }
|
||||||
{
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Status
|
public string Status { get; set; }
|
||||||
{
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
}
|
|
||||||
|
|
||||||
[SubSonicLongString]
|
[SubSonicLongString]
|
||||||
public string Overview
|
public string Overview { get; set; }
|
||||||
{
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DayOfWeek? AirsDayOfWeek
|
public DayOfWeek? AirsDayOfWeek { get; set; }
|
||||||
{
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String AirTimes
|
public String AirTimes { get; set; }
|
||||||
{
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Language
|
public string Language { get; set; }
|
||||||
{
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Path
|
|
||||||
{
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
public string Path { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue