refactored Episode, Added Quality Enum

pull/2/head
Keivan 14 years ago
parent 01c1943d0e
commit a49850cc89

@ -1,115 +1,120 @@
<?xml version="1.0" encoding="UTF-8" ?>
<queue><active_lang>us-en</active_lang>
<session>5c770e3197e4fe763423ee7c392c25d1</session>
<slots><slot><status>Queued</status>
<index>0</index>
<eta>unknown</eta>
<timeleft>0:00:00</timeleft>
<avg_age>11h</avg_age>
<script>None</script>
<queue>
<active_lang>us-en</active_lang>
<session>5c770e3197e4fe763423ee7c392c25d1</session>
<slots>
<slot>
<status>Queued</status>
<index>0</index>
<eta>unknown</eta>
<timeleft>0:00:00</timeleft>
<avg_age>11h</avg_age>
<script>None</script>
<msgid></msgid>
<verbosity></verbosity>
<mb>770.96</mb>
<sizeleft>770.96 MB</sizeleft>
<filename>Ubuntu Test</filename>
<priority>Normal</priority>
<cat>None</cat>
<mbleft>770.96</mbleft>
<percentage>0</percentage>
<nzo_id>SABnzbd_nzo_xyr5ak</nzo_id>
<msgid></msgid>
<verbosity></verbosity>
<mb>770.96</mb>
<sizeleft>770.96 MB</sizeleft>
<filename>Ubuntu Test</filename>
<priority>Normal</priority>
<cat>None</cat>
<mbleft>770.96</mbleft>
<percentage>0</percentage>
<nzo_id>SABnzbd_nzo_xyr5ak</nzo_id>
<unpackopts>3</unpackopts>
<size>770.96 MB</size>
</slot>
</slots>
<speed>0 </speed>
<size>770.96 MB</size>
<limit>0</limit>
<start>0</start>
<diskspacetotal2>259.45</diskspacetotal2>
<darwin>False</darwin>
<unpackopts>3</unpackopts>
<size>770.96 MB</size>
</slot>
</slots>
<speed>0 </speed>
<size>770.96 MB</size>
<limit>0</limit>
<start>0</start>
<diskspacetotal2>259.45</diskspacetotal2>
<darwin>False</darwin>
<last_warning></last_warning>
<have_warnings>0</have_warnings>
<noofslots>1</noofslots>
<pause_int>0</pause_int>
<categories><category>None</category>
<category>anime</category>
<category>apps</category>
<category>books</category>
<category>consoles</category>
<last_warning></last_warning>
<have_warnings>0</have_warnings>
<noofslots>1</noofslots>
<pause_int>0</pause_int>
<categories>
<category>None</category>
<category>anime</category>
<category>apps</category>
<category>books</category>
<category>consoles</category>
<category>ds-games</category>
<category>emulation</category>
<category>games</category>
<category>misc</category>
<category>movies</category>
<category>music</category>
<category>pda</category>
<category>resources</category>
<category>test</category>
<category>ds-games</category>
<category>emulation</category>
<category>games</category>
<category>misc</category>
<category>movies</category>
<category>music</category>
<category>pda</category>
<category>resources</category>
<category>test</category>
<category>tv</category>
<category>tv-dvd</category>
<category>unknown</category>
<category>wii-games</category>
<category>xbox-dlc</category>
<category>xbox-xbla</category>
</categories>
<diskspacetotal1>259.45</diskspacetotal1>
<mb>770.96</mb>
<category>tv</category>
<category>tv-dvd</category>
<category>unknown</category>
<category>wii-games</category>
<category>xbox-dlc</category>
<category>xbox-xbla</category>
</categories>
<diskspacetotal1>259.45</diskspacetotal1>
<mb>770.96</mb>
<loadavg></loadavg>
<cache_max>157286400</cache_max>
<speedlimit></speedlimit>
<webdir>C:\Program Files\SABnzbd\interfaces\Plush\templates</webdir>
<paused>True</paused>
<isverbose>False</isverbose>
<restart_req>False</restart_req>
<power_options>True</power_options>
<helpuri>http://wiki.sabnzbd.org/</helpuri>
<uptime>4d</uptime>
<loadavg></loadavg>
<cache_max>157286400</cache_max>
<speedlimit></speedlimit>
<webdir>C:\Program Files\SABnzbd\interfaces\Plush\templates</webdir>
<paused>True</paused>
<isverbose>False</isverbose>
<restart_req>False</restart_req>
<power_options>True</power_options>
<helpuri>http://wiki.sabnzbd.org/</helpuri>
<uptime>4d</uptime>
<refresh_rate></refresh_rate>
<version>0.6.x</version>
<color_scheme></color_scheme>
<new_release></new_release>
<nt>True</nt>
<status>Paused</status>
<finish>0</finish>
<cache_art>0</cache_art>
<paused_all>False</paused_all>
<finishaction></finishaction>
<sizeleft>770.96 MB</sizeleft>
<refresh_rate></refresh_rate>
<version>0.6.x</version>
<color_scheme></color_scheme>
<new_release></new_release>
<nt>True</nt>
<status>Paused</status>
<finish>0</finish>
<cache_art>0</cache_art>
<paused_all>False</paused_all>
<finishaction></finishaction>
<sizeleft>770.96 MB</sizeleft>
<cache_size>0B</cache_size>
<mbleft>770.96</mbleft>
<diskspace2>1177.64</diskspace2>
<diskspace1>1177.64</diskspace1>
<scripts><script>None</script>
<script>Alias.config</script>
<script>ConsoleCategories.config</script>
<script>exiso.exe</script>
<script>Movies.exe</script>
<cache_size>0B</cache_size>
<mbleft>770.96</mbleft>
<diskspace2>1177.64</diskspace2>
<diskspace1>1177.64</diskspace1>
<scripts>
<script>None</script>
<script>Alias.config</script>
<script>ConsoleCategories.config</script>
<script>exiso.exe</script>
<script>Movies.exe</script>
<script>Movies.exe.config</script>
<script>Movies.pdb</script>
<script>PreQueue.exe</script>
<script>PreQueue.exe.config</script>
<script>PreQueue.pdb</script>
<script>SABTest.exe</script>
<script>TVMove.exe</script>
<script>TVMove.exe.config</script>
<script>TVMove_0.4.1.exe</script>
<script>Movies.exe.config</script>
<script>Movies.pdb</script>
<script>PreQueue.exe</script>
<script>PreQueue.exe.config</script>
<script>PreQueue.pdb</script>
<script>SABTest.exe</script>
<script>TVMove.exe</script>
<script>TVMove.exe.config</script>
<script>TVMove_0.4.1.exe</script>
<script>XBox360.exe</script>
<script>XBox360.exe.config</script>
</scripts>
<timeleft>0:00:00</timeleft>
<nzb_quota></nzb_quota>
<eta>unknown</eta>
<kbpersec>0.00</kbpersec>
<new_rel_url></new_rel_url>
<queue_details>0</queue_details>
<script>XBox360.exe</script>
<script>XBox360.exe.config</script>
</scripts>
<timeleft>0:00:00</timeleft>
<nzb_quota></nzb_quota>
<eta>unknown</eta>
<kbpersec>0.00</kbpersec>
<new_rel_url></new_rel_url>
<queue_details>0</queue_details>
</queue>

@ -34,7 +34,7 @@ namespace NzbDrone.Core.Test
config.Setup(c => c.GetValue("Priority", String.Empty, false)).Returns(priority);
var http = new Mock<IHttpProvider>();
http.Setup(s => s.GetRequest("http://192.168.5.55:2222/sabnzbd/api?mode=addurl&name=http://www.nzbclub.com/nzb_download.aspx?mid=1950232&priority=0&cat=tv&nzbname=This+is+an+Nzb&apikey=5c770e3197e4fe763423ee7c392c25d1&ma_username=admin&ma_password=pass")).Returns("ok");
http.Setup(s => s.DownloadString("http://192.168.5.55:2222/sabnzbd/api?mode=addurl&name=http://www.nzbclub.com/nzb_download.aspx?mid=1950232&priority=0&cat=tv&nzbname=This+is+an+Nzb&apikey=5c770e3197e4fe763423ee7c392c25d1&ma_username=admin&ma_password=pass")).Returns("ok");
var target = new SabProvider(config.Object, new Mock<ILog>().Object, http.Object);
@ -67,7 +67,7 @@ namespace NzbDrone.Core.Test
config.Setup(c => c.GetValue("Priority", String.Empty, false)).Returns(priority);
var http = new Mock<IHttpProvider>();
http.Setup(s => s.GetRequest("http://192.168.5.55:2222/sabnzbd/api?mode=addurl&name=http://www.nzbclub.com/nzb_download.aspx?mid=1950232&priority=0&cat=tv&nzbname=This+is+an+Nzb&apikey=5c770e3197e4fe763423ee7c392c25d1&ma_username=admin&ma_password=pass")).Returns("error");
http.Setup(s => s.DownloadString("http://192.168.5.55:2222/sabnzbd/api?mode=addurl&name=http://www.nzbclub.com/nzb_download.aspx?mid=1950232&priority=0&cat=tv&nzbname=This+is+an+Nzb&apikey=5c770e3197e4fe763423ee7c392c25d1&ma_username=admin&ma_password=pass")).Returns("error");
var target = new SabProvider(config.Object, new Mock<ILog>().Object, http.Object);
@ -102,16 +102,15 @@ namespace NzbDrone.Core.Test
var http = new Mock<IHttpProvider>();
http.Setup(
s =>
s.GetRequest(
s.DownloadString(
"http://192.168.5.55:2222/sabnzbd/api?mode=queue&output=xml&apikey=5c770e3197e4fe763423ee7c392c25d1&ma_username=admin&ma_password=pass"))
.Returns(new StreamReader(@".\Files\Queue.xml").ReadToEnd());
var target = new SabProvider(config.Object, new Mock<ILog>().Object, http.Object);
Episode episode = new Episode();
FeedItem item = new FeedItem();
item.TitleFix = "Ubuntu Test";
episode.FeedItem = item;
episode.FileName = "Ubuntu Test";
//Act
bool result = target.IsInQueue(episode);
@ -140,16 +139,13 @@ namespace NzbDrone.Core.Test
var http = new Mock<IHttpProvider>();
http.Setup(
s =>
s.GetRequest(
s.DownloadString(
"http://192.168.5.55:2222/sabnzbd/api?mode=queue&output=xml&apikey=5c770e3197e4fe763423ee7c392c25d1&ma_username=admin&ma_password=pass"))
.Returns(new StreamReader(@".\Files\QueueEmpty.xml").ReadToEnd());
var target = new SabProvider(config.Object, new Mock<ILog>().Object, http.Object);
Episode episode = new Episode();
FeedItem item = new FeedItem();
item.TitleFix = "Ubuntu Test";
episode.FeedItem = item;
//Act
bool result = target.IsInQueue(episode);
@ -178,7 +174,7 @@ namespace NzbDrone.Core.Test
var http = new Mock<IHttpProvider>();
http.Setup(
s =>
s.GetRequest(
s.DownloadString(
"http://192.168.5.55:2222/sabnzbd/api?mode=queue&output=xml&apikey=5c770e3197e4fe763423ee7c392c25d1&ma_username=admin&ma_password=pass"))
.Returns(new StreamReader(@".\Files\QueueError.xml").ReadToEnd());
@ -187,7 +183,6 @@ namespace NzbDrone.Core.Test
Episode episode = new Episode();
FeedItem item = new FeedItem();
item.TitleFix = "Ubuntu Test";
episode.FeedItem = item;
//Act
bool result = target.IsInQueue(episode);

@ -1,25 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NzbDrone.Core.Helpers
{
static class Disk
{
/// <summary>
/// Cleans the path. making it a uniform path.
/// this will normalize all different presentations of a single folder.
/// </summary>
/// <param name="path">The path.</param>
/// <returns>Cleaned Path</returns>
public static string CleanPath(string path)
{
if (string.IsNullOrEmpty(path)) throw new ArgumentException("Path can not be null or empty");
return path.ToLower().Trim('/', '\\', ' ');
}
}
}

@ -136,17 +136,18 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Providers\ConfigProvider.cs" />
<Compile Include="Providers\EpisodeProvider.cs" />
<Compile Include="Providers\HttpProvider.cs" />
<Compile Include="Providers\IDownloadProvider.cs" />
<Compile Include="Providers\IHttpProvider.cs" />
<Compile Include="Providers\ISeriesProvider.cs" />
<Compile Include="Providers\ITvDbProvider.cs" />
<Compile Include="Providers\SabProvider.cs" />
<Compile Include="Helpers\Disk.cs" />
<Compile Include="Repository\Config.cs" />
<Compile Include="Repository\Episode.cs" />
<Compile Include="Repository\FeedItem.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" />

@ -23,5 +23,11 @@ namespace NzbDrone.Core.Providers
}
#endregion
public static string CleanPath(string path)
{
if (string.IsNullOrEmpty(path)) throw new ArgumentException("Path can not be null or empty");
return path.ToLower().Trim('/', '\\', ' ');
}
}
}

@ -0,0 +1,68 @@
using System;
using System.Text.RegularExpressions;
using NzbDrone.Core.Repository;
namespace NzbDrone.Core.Providers
{
public class EpisodeProvider
{
private static Regex _parseRegex =
new Regex(
@"(?<showName>.*)
(?:
s(?<seasonNumber>\d+)e(?<episodeNumber>\d+)-?e(?<episodeNumber2>\d+)
| s(?<seasonNumber>\d+)e(?<episodeNumber>\d+)
| (?<seasonNumber>\d+)x(?<episodeNumber>\d+)
| (?<airDate>\d{4}.\d{2}.\d{2})
)
(?:
(?<episodeName>.*?)
(?<release>
(?:hdtv|pdtv|xvid|ws|720p|x264|bdrip|dvdrip|dsr|proper)
.*)
| (?<episodeName>.*)
)", RegexOptions.IgnoreCase | RegexOptions.Compiled | RegexOptions.IgnorePatternWhitespace);
public static Episode Parse(string title)
{
Match match = _parseRegex.Match(title);
if (!match.Success)
return null;
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")
};
}
private static string ReplaceSeparatorChars(string s)
{
if (s == null) return string.Empty;
return s.Replace('.', ' ').Replace('-', ' ').Replace('_', ' ').Trim();
}
private static int ParseInt(string s)
{
int i;
int.TryParse(s, out i);
return i;
}
private static DateTime ParseAirDate(string s)
{
DateTime d;
if (DateTime.TryParse(ReplaceSeparatorChars(s).Replace(' ', '-'), out d))
return d;
return DateTime.MinValue;
}
}
}

@ -5,19 +5,9 @@ namespace NzbDrone.Core.Providers
{
class HttpProvider : IHttpProvider
{
public string GetRequest(string request)
public string DownloadString(string request)
{
//Get the request and return as String Array
try
{
var webClient = new WebClient();
return webClient.DownloadString(request);
}
catch (Exception ex)
{
Console.WriteLine(ex);
return String.Empty;
}
return new WebClient().DownloadString(request);
}
}
}

@ -2,6 +2,6 @@
{
public interface IHttpProvider
{
string GetRequest(string request);
string DownloadString(string request);
}
}

@ -35,7 +35,7 @@ namespace NzbDrone.Core.Providers
_logger.DebugFormat("Adding report [{0}] to the queue.", nzbName);
string response = _http.GetRequest(request).Replace("\n", String.Empty);
string response = _http.DownloadString(request).Replace("\n", String.Empty);
_logger.DebugFormat("Queue Repsonse: [{0}]", response);
if (response == "ok")
@ -48,7 +48,7 @@ namespace NzbDrone.Core.Providers
{
string action = "mode=queue&output=xml";
string request = GetSabRequest(action);
string response = _http.GetRequest(request);
string response = _http.DownloadString(request);
XDocument xDoc = XDocument.Parse(response);
@ -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.FeedItem.TitleFix, StringComparison.InvariantCultureIgnoreCase) select s).Count() != 0)
if ((from s in xDoc.Descendants("slot") where s.Element("filename").Value.Equals(epsiode.FileName, StringComparison.InvariantCultureIgnoreCase) select s).Count() != 0)
{
_logger.DebugFormat("Episode in queue - '{0}'", epsiode.FeedItem.TitleFix);
_logger.DebugFormat("Episode in queue - '{0}'", epsiode.FileName);
return true;
}

@ -1,7 +1,6 @@
using System.IO;
using System.Linq;
using log4net;
using NzbDrone.Core.Helpers;
using NzbDrone.Core.Repository;
using SubSonic.Repository;
using TvdbLib.Data;
@ -44,7 +43,7 @@ namespace NzbDrone.Core.Providers
foreach (string seriesFolder in _diskProvider.GetDirectories(_config.SeriesRoot))
{
var cleanPath = Disk.CleanPath(new DirectoryInfo(seriesFolder).FullName);
var cleanPath = DiskProvider.CleanPath(new DirectoryInfo(seriesFolder).FullName);
if (!_sonioRepo.Exists<Series>(s => s.Path == cleanPath))
{
_logger.InfoFormat("Folder '{0} isn't mapped to a series in the database. Trying to map it.'", cleanPath);

@ -8,120 +8,16 @@ namespace NzbDrone.Core.Repository
{
public class Episode
{
//Information about the current episode being processed
private const string EpisodePattern = @"
(?<showName>.*)
(?:
s(?<seasonNumber>\d+)e(?<episodeNumber>\d+)-?e(?<episodeNumber2>\d+)
| s(?<seasonNumber>\d+)e(?<episodeNumber>\d+)
| (?<seasonNumber>\d+)x(?<episodeNumber>\d+)
| (?<airDate>\d{4}.\d{2}.\d{2})
)
(?:
(?<episodeName>.*?)
(?<release>
(?:hdtv|pdtv|xvid|ws|720p|x264|bdrip|dvdrip|dsr|proper)
.*)
| (?<episodeName>.*)
)
";
public FeedItem FeedItem { get; set; }
public string ShowName { get; set; }
public string EpisodeName { get; set; }
public string EpisodeName2 { get; set; }
public int SeasonNumber { get; set; }
public string SeriesId { get; set; }
public string Title { get; set; }
public string Title2 { get; set; }
public int Season { get; set; }
public int EpisodeNumber { get; set; }
public int EpisodeNumber2 { get; set; }
public DateTime AirDate { get; set; }
public string Release { get; set; }
public int Quality { get; set; }
public bool IsProper
{
get { return FeedItem.Title.Contains("PROPER"); }
}
public bool IsDaily
{
get { return AirDate != DateTime.MinValue; }
}
public bool IsMulti
{
get { return SeasonNumber != 0 && EpisodeNumber != 0 && EpisodeNumber2 != 0; }
}
public string EpisodeTitle
{
get { return IsDaily ? GetDailyEpisode() : IsMulti ? GetMultiEpisode() : GetSeasonEpisode(); }
}
public string Title
{
get { return string.Format("{0} - {1}", ShowName, EpisodeTitle); }
}
public override string ToString()
{
return string.Format("{0} - {1}", ShowName, EpisodeTitle);
}
private string GetDailyEpisode()
{
return AirDate.ToString("yyyy-MM-dd");
}
private string GetMultiEpisode()
{
return string.Format("{0}x{1:D2}-{0}x{2:D2}", SeasonNumber, EpisodeNumber, EpisodeNumber2);
}
private string GetSeasonEpisode()
{
return string.Format("{0}x{1:D2}", SeasonNumber, EpisodeNumber);
}
public static Episode Parse(FeedItem feedItem)
{
Match match = Regex.Match(feedItem.Title, EpisodePattern,
RegexOptions.IgnorePatternWhitespace | RegexOptions.IgnoreCase);
if (!match.Success)
return null;
return new Episode
{
ShowName = ReplaceSeparatorChars(match.Groups["showName"].Value),
SeasonNumber = ParseInt(match.Groups["seasonNumber"].Value),
EpisodeNumber = ParseInt(match.Groups["episodeNumber"].Value),
EpisodeNumber2 = ParseInt(match.Groups["episodeNumber2"].Value),
EpisodeName = ReplaceSeparatorChars(match.Groups["episodeName"].Value),
Release = ReplaceSeparatorChars(match.Groups["release"].Value)
};
}
private static string ReplaceSeparatorChars(string s)
{
if (s == null) return string.Empty;
return s.Replace('.', ' ').Replace('-', ' ').Replace('_', ' ').Trim();
}
private static int ParseInt(string s)
{
int i;
int.TryParse(s, out i);
return i;
}
private static DateTime ParseAirDate(string s)
{
DateTime d;
if (DateTime.TryParse(ReplaceSeparatorChars(s).Replace(' ', '-'), out d))
return d;
return DateTime.MinValue;
}
public bool Proper { get; set; }
public String FileName { get; set; }
}
}

@ -0,0 +1,35 @@
namespace NzbDrone.Core.Repository
{
// ReSharper disable InconsistentNaming
/// <summary>
/// Represents Video Quality
/// </summary>
public enum Quality
{
/// <summary>
/// Quality is unknown
/// </summary>
Unknown = 0,
/// <summary>
/// SD File (Source could be HD)
/// </summary>
SDTV = 1,
/// <summary>
/// SD File (DVD Source)
/// </summary>
DVD = 2,
/// <summary>
/// HD File (HDTV Source)
/// </summary>
HDTV = 3,
/// <summary>
/// HD File (Online Source)
/// </summary>
WEBDL = 4,
/// <summary>
/// HD File (Blu-ray Source)
/// </summary>
Bluray = 5
}
}
Loading…
Cancel
Save