Removed redundent classes.

This commit is contained in:
Keivan 2010-09-27 22:35:15 -07:00
parent d18029fe5b
commit c7286863b0
8 changed files with 22 additions and 104 deletions

View File

@ -38,12 +38,8 @@ namespace NzbDrone.Core.Test
var target = new SabProvider(config.Object, new Mock<ILog>().Object, http.Object);
ItemInfo nzb = new ItemInfo();
nzb.Link = new Uri("http://www.nzbclub.com/nzb_download.aspx?mid=1950232");
nzb.Title = "This is an Nzb";
//Act
bool result = target.AddByUrl(nzb);
bool result = target.AddByUrl("http://www.nzbclub.com/nzb_download.aspx?mid=1950232", "This is an Nzb");
//Assert
Assert.AreEqual(true, result);
@ -71,12 +67,8 @@ namespace NzbDrone.Core.Test
var target = new SabProvider(config.Object, new Mock<ILog>().Object, http.Object);
ItemInfo nzb = new ItemInfo();
nzb.Link = new Uri("http://www.nzbclub.com/nzb_download.aspx?mid=1950232");
nzb.Title = "This is an Nzb";
//Act
bool result = target.AddByUrl(nzb);
bool result = target.AddByUrl("http://www.nzbclub.com/nzb_download.aspx?mid=1950232", "This is an Nzb");
//Assert
Assert.AreEqual(false, result);
@ -108,12 +100,8 @@ namespace NzbDrone.Core.Test
var target = new SabProvider(config.Object, new Mock<ILog>().Object, http.Object);
Episode episode = new Episode();
episode.FileName = "Ubuntu Test";
//Act
bool result = target.IsInQueue(episode);
bool result = target.IsInQueue("Ubuntu Test");
//Assert
Assert.AreEqual(true, result);
@ -145,10 +133,8 @@ namespace NzbDrone.Core.Test
var target = new SabProvider(config.Object, new Mock<ILog>().Object, http.Object);
Episode episode = new Episode();
//Act
bool result = target.IsInQueue(episode);
bool result = target.IsInQueue(String.Empty);
//Assert
Assert.AreEqual(false, result);
@ -180,10 +166,8 @@ namespace NzbDrone.Core.Test
var target = new SabProvider(config.Object, new Mock<ILog>().Object, http.Object);
Episode episode = new Episode();
//Act
bool result = target.IsInQueue(episode);
bool result = target.IsInQueue(String.Empty);
//Assert
Assert.AreEqual(false, result);

View File

@ -129,6 +129,7 @@
<Reference Include="System.configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.ServiceModel.Web" />
<Reference Include="System.Web" />
<Reference Include="System.XML" />
<Reference Include="System.Xml.Linq" />
@ -145,9 +146,7 @@
<Compile Include="Providers\SabProvider.cs" />
<Compile Include="Repository\Config.cs" />
<Compile Include="Repository\Episode.cs" />
<Compile Include="Repository\ItemInfo.cs" />
<Compile Include="Repository\Quality.cs" />
<Compile Include="Repository\Site.cs" />
<Compile Include="Repository\Series.cs" />
<Compile Include="Main.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />

View File

@ -4,7 +4,7 @@ namespace NzbDrone.Core.Providers
{
public interface IDownloadProvider
{
bool AddByUrl(ItemInfo nzb); //Should accept something other than string (NzbInfo?) returns success or failure
bool IsInQueue(Episode episode);//Should accept something other than string (Episode?) returns bool
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
}
}

View File

@ -22,13 +22,13 @@ namespace NzbDrone.Core.Providers
#region IDownloadProvider Members
public bool AddByUrl(ItemInfo nzb)
public bool AddByUrl(string url, string title)
{
const string mode = "addurl";
const string cat = "tv";
string priority = _config.GetValue("Priority", String.Empty, false);
string name = nzb.Link.ToString().Replace("&", "%26");
string nzbName = HttpUtility.UrlEncode(nzb.Title);
string name = url.Replace("&", "%26");
string nzbName = HttpUtility.UrlEncode(title);
string action = string.Format("mode={0}&name={1}&priority={2}&cat={3}&nzbname={4}", mode, name, priority, cat, nzbName);
string request = GetSabRequest(action);
@ -44,7 +44,7 @@ namespace NzbDrone.Core.Providers
return false;
}
public bool IsInQueue(Episode epsiode)
public bool IsInQueue(string title)
{
string action = "mode=queue&output=xml";
string request = GetSabRequest(action);
@ -60,9 +60,9 @@ namespace NzbDrone.Core.Providers
return false;
//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(epsiode.FileName, 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}'", epsiode.FileName);
_logger.DebugFormat("Episode in queue - '{0}'", title);
return true;
}

View File

@ -5,17 +5,8 @@ namespace NzbDrone.Core.Repository
public class Config
{
[SubSonicPrimaryKey]
public string Key
{
get;
set;
}
public string Value
{
get;
set;
}
public string Key { get; set; }
public string Value { get; set; }
}
}
}

View File

@ -1,13 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.ServiceModel.Syndication;
using SubSonic.SqlGeneration.Schema;
namespace NzbDrone.Core.Repository
{
public class Episode
{
[SubSonicPrimaryKey]
public string EpisodeId { get; set; }
public string SeriesId { get; set; }
public string Title { get; set; }
public string Title2 { get; set; }
@ -19,5 +19,6 @@ namespace NzbDrone.Core.Repository
public int Quality { get; set; }
public bool Proper { get; set; }
public String FileName { get; set; }
public SyndicationItem Feed { get; set; }
}
}

View File

@ -1,21 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NzbDrone.Core.Repository
{
public class ItemInfo
{
public string Id { get; set; }
public string Title { get; set; }
public Site Site { get; set; }
public Uri Link { get; set; }
public string Description { get; set; }
public bool IsPassworded()
{
return Title.EndsWith("(Passworded)", StringComparison.InvariantCultureIgnoreCase);
}
}
}

View File

@ -1,36 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace NzbDrone.Core.Repository
{
public class Site
{
private static readonly IList<Site> Sites = new List<Site>
{
new Site {Name = "nzbmatrix", Url = "nzbmatrix.com", Pattern = @"\d{6,10}"},
new Site {Name = "nzbsDotOrg", Url = "nzbs.org", Pattern = @"\d{5,10}"},
new Site {Name = "nzbsrus", Url = "nzbsrus.com", Pattern = @"\d{6,10}"},
new Site {Name = "lilx", Url = "lilx.net", Pattern = @"\d{6,10}"},
};
public string Name { get; set; }
public string Pattern { get; set; }
public string Url { get; set; }
// TODO: use HttpUtility.ParseQueryString();
// https://nzbmatrix.com/api-nzb-download.php?id=626526
public string ParseId(string url)
{
return Regex.Match(url, Pattern).Value;
}
public static Site Parse(string url)
{
return Sites.Where(site => url.Contains(site.Url)).SingleOrDefault() ??
new Site { Name = "unknown", Pattern = @"\d{6,10}" };
}
}
}