Merge remote-tracking branch 'origin/tvrage'

This commit is contained in:
Mark McDowall 2012-12-19 22:55:27 -08:00
commit b577d78494
22 changed files with 1317 additions and 11 deletions

View File

@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Results>0</Results>

View File

@ -0,0 +1,420 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Results>
<show>
<showid>6753</showid>
<name>Top Gear</name>
<link>http://www.tvrage.com/Top_Gear</link>
<country>UK</country>
<started>Oct/20/2002</started>
<ended></ended>
<seasons>18</seasons>
<status>Returning Series</status>
<runtime>60</runtime>
<classification>Reality</classification>
<genres>
<genre></genre>
<genre>Automobiles</genre>
<genre>Comedy</genre>
</genres>
<network country="UK">BBC TWO</network>
<airtime>20:00</airtime>
<airday>Sunday</airday>
</show>
<show>
<showid>19321</showid>
<name>Top Gear (1978)</name>
<link>http://www.tvrage.com/shows/id-19321</link>
<country>UK</country>
<started>Jul/13/1978</started>
<ended>Dec/17/2001</ended>
<seasons>24</seasons>
<status>Canceled/Ended</status>
<runtime>30</runtime>
<classification>Reality</classification>
<genres>
<genre>Automobiles</genre>
</genres>
<network country="UK">BBC TWO</network>
<airtime>12:00</airtime>
<airday>Sunday</airday>
<akas>
<aka country="UK">Top Gear Xtra</aka>
</akas>
</show>
<show>
<showid>20568</showid>
<name>Top Gear (US)</name>
<link>http://www.tvrage.com/Top_Gear_US</link>
<country>US</country>
<started>Nov/21/2010</started>
<ended></ended>
<seasons>3</seasons>
<status>Returning Series</status>
<runtime>60</runtime>
<classification>Documentary</classification>
<genres>
<genre>Automobiles</genre>
<genre>Comedy</genre>
</genres>
<network country="US">History Channel</network>
<airtime>21:00</airtime>
<airday>Tuesday</airday>
<akas>
<aka attr="Unofficial Working Title">Top Gear USA</aka>
</akas>
</show>
<show>
<showid>20324</showid>
<name>Top Gear Australia</name>
<link>http://www.tvrage.com/shows/id-20324</link>
<country>AU</country>
<started>Sep/29/2008</started>
<ended></ended>
<seasons>4</seasons>
<status>Returning Series</status>
<runtime>60</runtime>
<classification>Documentary</classification>
<genres>
<genre>Automobiles</genre>
<genre>Comedy</genre>
</genres>
<network country="AU">GEM</network>
<airtime>18:30</airtime>
<airday>Saturday</airday>
</show>
<show>
<showid>20569</showid>
<name>Top Gear Motorsport</name>
<link>http://www.tvrage.com/shows/id-20569</link>
<country>UK</country>
<started>Mar/24/1995</started>
<ended>1998</ended>
<seasons>3</seasons>
<status>Canceled/Ended</status>
<runtime>30</runtime>
<classification>Sports</classification>
<genres>
<genre>Educational</genre>
<genre>Family</genre>
<genre>How To/Do It Yourself</genre>
</genres>
<network country="UK">BBC TWO</network>
<airtime>12:00</airtime>
<airday>Wednesday</airday>
</show>
<show>
<showid>6249</showid>
<name>Top Secret Life of Edgar Briggs</name>
<link>http://www.tvrage.com/shows/id-6249</link>
<country>UK</country>
<started>Sep/15/1974</started>
<ended>Dec/20/1974</ended>
<seasons>1</seasons>
<status>Canceled/Ended</status>
<runtime>30</runtime>
<classification>Scripted</classification>
<genres>
<genre>Comedy</genre>
</genres>
<network country="UK">ITV</network>
<airtime>19:00</airtime>
<airday>Friday</airday>
</show>
<show>
<showid>25253</showid>
<name>Popstar Wesley: Op weg naar de Top</name>
<link>http://www.tvrage.com/shows/id-25253</link>
<country>NL</country>
<started>Feb/06/2010</started>
<ended>Feb/27/2010</ended>
<seasons>1</seasons>
<status>Canceled/Ended</status>
<runtime>15</runtime>
<classification>Reality</classification>
<genres>
<genre>How To/Do It Yourself</genre>
<genre>Music</genre>
<genre>Talent</genre>
</genres>
<network country="NL">SBS 6</network>
<airtime>23:15</airtime>
<airday>Saturday</airday>
</show>
<show>
<showid>19649</showid>
<name>Top Chef: Masters</name>
<link>http://www.tvrage.com/Top_Chef-Masters</link>
<country>US</country>
<started>Jun/10/2009</started>
<ended></ended>
<seasons>4</seasons>
<status>Returning Series</status>
<runtime>60</runtime>
<classification>Reality</classification>
<genres>
<genre>Cooking/Food</genre>
<genre>Family</genre>
<genre>Talent</genre>
</genres>
<network country="US">Bravo</network>
<airtime>22:00</airtime>
<airday>Wednesday</airday>
</show>
<show>
<showid>26212</showid>
<name>Top Chef: Just Desserts</name>
<link>http://www.tvrage.com/Top_Chef-Just_Desserts</link>
<country>US</country>
<started>Sep/15/2010</started>
<ended></ended>
<seasons>2</seasons>
<status>New Series</status>
<runtime>60</runtime>
<classification>Reality</classification>
<genres>
<genre>Celebrities</genre>
<genre>Cooking/Food</genre>
<genre>Educational</genre>
<genre>Family</genre>
<genre>How To/Do It Yourself</genre>
<genre>Talent</genre>
</genres>
<network country="US">Bravo</network>
<airtime>22:00</airtime>
<airday>Wednesday</airday>
</show>
<show>
<showid>11210</showid>
<name>Top Design</name>
<link>http://www.tvrage.com/shows/id-11210</link>
<country>US</country>
<started>Jan/31/2007</started>
<ended>Nov/05/2008</ended>
<seasons>2</seasons>
<status>Canceled/Ended</status>
<runtime>60</runtime>
<classification>Reality</classification>
<genres>
<genre>Celebrities</genre>
<genre>Educational</genre>
<genre>Family</genre>
<genre>Housing/Building</genre>
<genre>How To/Do It Yourself</genre>
</genres>
<network country="US">Bravo</network>
<airtime>22:00</airtime>
<airday>Wednesday</airday>
<akas>
<aka attr="Working Title">Top Decorator</aka>
<aka attr="Working Title">Top Designer</aka>
</akas>
</show>
<show>
<showid>15390</showid>
<name>Air Gear</name>
<link>http://www.tvrage.com/shows/id-15390</link>
<country>AJ</country>
<started>Apr/04/2006</started>
<ended>Sep/26/2006</ended>
<seasons>1</seasons>
<status>Canceled/Ended</status>
<runtime>30</runtime>
<classification>Animation</classification>
<genres>
<genre>Anime</genre>
<genre>Adventure</genre>
<genre>Sci-Fi</genre>
<genre>Tech/Gaming</genre>
</genres>
<network country="JP">TV Tokyo</network>
<airtime>12:00</airtime>
<airday>Wednesday</airday>
</show>
<show>
<showid>30933</showid>
<name>Top Guns</name>
<link>http://www.tvrage.com/shows/id-30933</link>
<country>US</country>
<started>Feb/15/2012</started>
<ended></ended>
<seasons>1</seasons>
<status>New Series</status>
<runtime>60</runtime>
<classification>Reality</classification>
<genres>
<genre>Action</genre>
<genre>Family</genre>
<genre>How To/Do It Yourself</genre>
<genre>Talent</genre>
</genres>
<network country="US">H2 TV</network>
<airtime>22:00</airtime>
<airday>Wednesday</airday>
</show>
<show>
<showid>28150</showid>
<name>Top Chef Canada</name>
<link>http://www.tvrage.com/shows/id-28150</link>
<country>CA</country>
<started>Apr/11/2011</started>
<ended></ended>
<seasons>2</seasons>
<status>New Series</status>
<runtime>60</runtime>
<classification>Reality</classification>
<genres>
<genre>Cooking/Food</genre>
<genre>Family</genre>
<genre>Talent</genre>
</genres>
<network country="CA">Food Network Canada</network>
<airtime>21:00</airtime>
<airday>Monday</airday>
</show>
<show>
<showid>6386</showid>
<name>Top of the Pops Saturday</name>
<link>http://www.tvrage.com/shows/id-6386</link>
<country>UK</country>
<started>Sep/20/2003</started>
<ended>Mar/26/2005</ended>
<seasons>2</seasons>
<status>Canceled/Ended</status>
<runtime>60</runtime>
<classification>Variety</classification>
<genres>
<genre>Children</genre>
</genres>
<network country="UK">BBC One</network>
<airtime>23:00</airtime>
<airday>Saturday</airday>
</show>
<show>
<showid>29633</showid>
<name>Top Secret Recipe</name>
<link>http://www.tvrage.com/shows/id-29633</link>
<country>US</country>
<started>Oct/07/2011</started>
<ended></ended>
<seasons>1</seasons>
<status>New Series</status>
<runtime>60</runtime>
<classification>Reality</classification>
<genres>
<genre>Cooking/Food</genre>
<genre>How To/Do It Yourself</genre>
</genres>
<network country="US">CMT</network>
<airtime>21:00</airtime>
<airday>Thursday</airday>
</show>
<show>
<showid>26650</showid>
<name>The Top 100: NFL's Greatest Players</name>
<link>http://www.tvrage.com/shows/id-26650</link>
<country>US</country>
<started>Sep/03/2010</started>
<ended>Nov/04/2010</ended>
<seasons>1</seasons>
<status>New Series</status>
<runtime>60</runtime>
<classification>Sports</classification>
<genres>
<genre>Sports</genre>
</genres>
<network country="US">NFL Network</network>
<airtime>21:00</airtime>
<airday>Thursday</airday>
</show>
<show>
<showid>7047</showid>
<name>Top of the Pops Reloaded</name>
<link>http://www.tvrage.com/shows/id-7047</link>
<country>UK</country>
<started>Sep/2005</started>
<ended>Mar/2006</ended>
<seasons>2</seasons>
<status>Canceled/Ended</status>
<runtime>45</runtime>
<classification>Variety</classification>
<genres>
<genre>Children</genre>
<genre>Music</genre>
<genre>Sketch/Improv</genre>
</genres>
<network country="UK">CBBC</network>
<airtime>11:00</airtime>
<airday>Saturday</airday>
</show>
<show>
<showid>19475</showid>
<name>Top Model Ghana</name>
<link>http://www.tvrage.com/shows/id-19475</link>
<country>GH</country>
<started>Aug/26/2006</started>
<ended>Oct/16/2006</ended>
<seasons>1</seasons>
<status>Canceled/Ended</status>
<runtime>60</runtime>
<classification>Reality</classification>
<genres>
<genre>Celebrities</genre>
<genre>Family</genre>
<genre>Fashion/Make-up</genre>
<genre>Talent</genre>
<genre>Travel</genre>
</genres>
<network country="GH">GTV</network>
<airtime>21:00</airtime>
<airday>Monday</airday>
<akas>
<aka attr="Alternate title" country="US">Ghana's Next Top Model</aka>
<aka attr="Abbreviated title" country="GH">TMG</aka>
<aka attr="1st Season title" country="GH">Top Model Ghana, Cycle</aka>
</akas>
</show>
<show>
<showid>31823</showid>
<name>Top 100 Video Games of All Time</name>
<link>http://www.tvrage.com/shows/id-31823</link>
<country>US</country>
<started>Jun/11/2012</started>
<ended></ended>
<seasons>1</seasons>
<status>New Series</status>
<runtime>60</runtime>
<classification>Mini-Series</classification>
<genres>
<genre>Family</genre>
<genre>Teens</genre>
</genres>
<network country="US">G4</network>
<airtime>20:00</airtime>
<airday>Weekdays</airday>
</show>
<show>
<showid>25003</showid>
<name>Cantore Stories: On Top of the World</name>
<link>http://www.tvrage.com/Cantore_Stories-On_Top_of_the_World</link>
<country>US</country>
<started>Jan/24/2010</started>
<ended></ended>
<seasons>1</seasons>
<status>New Series</status>
<runtime>60</runtime>
<classification>Reality</classification>
<genres>
<genre>Adventure</genre>
<genre>Educational</genre>
<genre>Family</genre>
<genre>Travel</genre>
</genres>
<network country="US">The Weather Channel</network>
<airtime>22:00</airtime>
<airday>Sunday</airday>
<akas>
<aka attr="Short title" country="US">Cantore Stories</aka>
</akas>
</show>
</Results>

View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Results>
<show>
<showid>27518</showid>
<name>Suits</name>
<link>http://www.tvrage.com/Suits</link>
<country>US</country>
<started>Jun/23/2011</started>
<ended></ended>
<seasons>2</seasons>
<status>Returning Series</status>
<runtime>60</runtime>
<classification>Scripted</classification>
<genres>
<genre>Drama</genre>
<genre>Financial/Business</genre>
</genres>
<network country="US">USA</network>
<airtime>22:00</airtime>
<airday>Thursday</airday>
<akas>
<aka attr="Working title" country="US">A Legal Mind</aka>
</akas>
</show>
</Results>

View File

@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Showinfo></Showinfo>

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Showinfo>
<showid>29999</showid>
<showname>Anger Management</showname>
<showlink>http://tvrage.com/shows/id-29999</showlink>
<seasons>2</seasons>
<started>2012</started>
<startdate>Jun/28/2012</startdate>
<ended></ended>
<origin_country>US</origin_country>
<status>Returning Series</status>
<classification>Scripted</classification>
<genres>
<genre>Comedy</genre>
</genres>
<runtime>30</runtime>
<network country="US">FX</network>
<airtime>21:30</airtime>
<airday>Thursday</airday>
<timezone>GMT-5 -DST</timezone>
</Showinfo>

View File

@ -139,6 +139,12 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="ProviderTests\TvRageMappingProviderTests\FindMatchingTvRageSeriesFixture.cs" />
<Compile Include="ProviderTests\TvRageMappingProviderTests\ProcessResultsFixture.cs" />
<Compile Include="ProviderTests\TvRageProviderTests\GetSeriesFixture.cs" />
<Compile Include="ProviderTests\TvRageProviderTests\ParseDayOfWeekFixture.cs" />
<Compile Include="ProviderTests\TvRageProviderTests\GetUtcOffsetFixture.cs" />
<Compile Include="ProviderTests\TvRageProviderTests\SearchSeriesFixture.cs" />
<Compile Include="QualityTypesTest.cs" />
<Compile Include="EpisodeParseResultTest.cs" />
<Compile Include="Integeration\ServiceIntegerationFixture.cs" />
@ -328,6 +334,21 @@
<SubType>Designer</SubType>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<Content Include="Files\TvRage\SeriesInfo_empty.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Files\TvRage\SeriesInfo_one.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Files\TvRage\SearchResults_one.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Files\TvRage\SearchResults_many.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Files\TvRage\SearchResults_empty.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Files\Xem\Ids.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>

View File

@ -0,0 +1,92 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FizzWare.NBuilder;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.Model.TvRage;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Repository;
using NzbDrone.Test.Common;
namespace NzbDrone.Core.Test.ProviderTests.TvRageMappingProviderTests
{
public class FindMatchingTvRageSeriesFixture : TestBase
{
private IList<TvRageSearchResult> _searchResults;
private Series _series;
private Episode _episode;
private TvRageSeries _tvRageSeries;
[SetUp]
public void Setup()
{
_searchResults = Builder<TvRageSearchResult>
.CreateListOfSize(5)
.Build();
_series = Builder<Series>
.CreateNew()
.With(s => s.TvRageId = 0)
.With(s => s.TvRageTitle = null)
.With(s => s.UtcOffset = 0)
.Build();
_episode = Builder<Episode>
.CreateNew()
.With(e => e.AirDate = DateTime.Today.AddDays(-365))
.Build();
_tvRageSeries = Builder<TvRageSeries>
.CreateNew()
.With(s => s.UtcOffset = -8)
.Build();
Mocker.GetMock<EpisodeProvider>()
.Setup(s => s.GetEpisode(_series.SeriesId, 1, 1))
.Returns(_episode);
Mocker.GetMock<SceneMappingProvider>()
.Setup(s => s.GetCleanName(_series.SeriesId))
.Returns("");
Mocker.GetMock<TvRageProvider>()
.Setup(s => s.SearchSeries(_series.Title))
.Returns(_searchResults);
Mocker.GetMock<TvRageProvider>()
.Setup(s => s.GetSeries(_searchResults.First().ShowId))
.Returns(_tvRageSeries);
}
private void WithMatchingResult()
{
_series.CleanTitle = Parser.NormalizeTitle(_searchResults.First().Name);
}
[Test]
public void should_not_set_tvRage_info_when_result_is_null()
{
var result = Mocker.Resolve<TvRageMappingProvider>()
.FindMatchingTvRageSeries(_series);
result.TvRageId.Should().Be(0);
result.TvRageTitle.Should().Be(null);
result.UtcOffset.Should().Be(0);
}
[Test]
public void should_set_tvRage_info_when_result_is_returned()
{
WithMatchingResult();
var result = Mocker.Resolve<TvRageMappingProvider>()
.FindMatchingTvRageSeries(_series);
result.TvRageId.Should().Be(_searchResults.First().ShowId);
result.TvRageTitle.Should().Be(_searchResults.First().Name);
result.UtcOffset.Should().Be(_tvRageSeries.UtcOffset);
}
}
}

View File

@ -0,0 +1,76 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FizzWare.NBuilder;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.Model.TvRage;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Repository;
using NzbDrone.Test.Common;
namespace NzbDrone.Core.Test.ProviderTests.TvRageMappingProviderTests
{
public class ProcessResultsFixture : TestBase
{
private IList<TvRageSearchResult> _searchResults;
private Series _series;
private Episode _episode;
[SetUp]
public void Setup()
{
_searchResults = Builder<TvRageSearchResult>
.CreateListOfSize(5)
.Build();
_series = Builder<Series>.CreateNew().Build();
_episode = Builder<Episode>
.CreateNew()
.With(e => e.AirDate = DateTime.Today.AddDays(-365))
.Build();
}
[Test]
public void should_return_null_if_no_match_is_found()
{
Mocker.Resolve<TvRageMappingProvider>()
.ProcessResults(_searchResults, _series, "nomatchhere", _episode)
.Should()
.BeNull();
}
[Test]
public void should_return_result_if_series_clean_name_matches()
{
_series.CleanTitle = Parser.NormalizeTitle(_searchResults.First().Name);
Mocker.Resolve<TvRageMappingProvider>()
.ProcessResults(_searchResults, _series, "nomatchhere", _episode)
.Should()
.Be(_searchResults.First());
}
[Test]
public void should_return_result_if_scene_clean_name_matches()
{
Mocker.Resolve<TvRageMappingProvider>()
.ProcessResults(_searchResults, _series, Parser.NormalizeTitle(_searchResults.First().Name), _episode)
.Should()
.Be(_searchResults.First());
}
[Test]
public void should_return_result_if_firstAired_matches()
{
_episode.AirDate = _searchResults.Last().Started;
Mocker.Resolve<TvRageMappingProvider>()
.ProcessResults(_searchResults, _series, "nomatchhere", _episode)
.Should()
.Be(_searchResults.Last());
}
}
}

View File

@ -0,0 +1,59 @@
// ReSharper disable RedundantUsingDirective
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using Ninject;
using NzbDrone.Common;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common;
using TvdbLib.Data;
using TvdbLib.Exceptions;
namespace NzbDrone.Core.Test.ProviderTests.TvRageProviderTests
{
[TestFixture]
// ReSharper disable InconsistentNaming
public class GetSeriesFixture : CoreTest
{
private const string showinfo = "http://services.tvrage.com/feeds/showinfo.php?key=NW4v0PSmQIoVmpbASLdD&sid=";
private void WithEmptyResults()
{
Mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadStream(It.Is<String>(u => u.StartsWith(showinfo)), null))
.Returns(new FileStream(@".\Files\TVRage\SeriesInfo_empty.xml", FileMode.Open, FileAccess.Read, FileShare.Read));
}
private void WithOneResult()
{
Mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadStream(It.Is<String>(u => u.StartsWith(showinfo)), null))
.Returns(new FileStream(@".\Files\TVRage\SeriesInfo_one.xml", FileMode.Open, FileAccess.Read, FileShare.Read));
}
[Test]
public void should_be_null_when_no_showinfo_is_returned()
{
WithEmptyResults();
Mocker.Resolve<TvRageProvider>().GetSeries(100).Should().BeNull();
ExceptionVerification.ExpectedWarns(1);
}
[Test]
public void should_return_series_when_showinfo_is_valid()
{
WithOneResult();
var result = Mocker.Resolve<TvRageProvider>().GetSeries(29999);
result.ShowId.Should().Be(29999);
result.Name.Should().Be("Anger Management");
}
}
}

View File

@ -0,0 +1,50 @@
// ReSharper disable RedundantUsingDirective
using System;
using System.Collections.Generic;
using System.Linq;
using FluentAssertions;
using NUnit.Framework;
using Ninject;
using NzbDrone.Common;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common;
using TvdbLib.Data;
using TvdbLib.Exceptions;
namespace NzbDrone.Core.Test.ProviderTests.TvRageProviderTests
{
[TestFixture]
// ReSharper disable InconsistentNaming
public class GetUtcOffsetFixture : CoreTest
{
[Test]
public void should_return_zero_if_timeZone_is_empty()
{
Mocker.Resolve<TvRageProvider>().GetUtcOffset("").Should().Be(0);
}
[Test]
public void should_return_zero_if_cannot_be_coverted_to_int()
{
Mocker.Resolve<TvRageProvider>().GetUtcOffset("adfhadfhdjaf").Should().Be(0);
}
[TestCase("GMT-5", -5)]
[TestCase("GMT+0", 0)]
[TestCase("GMT+8", 8)]
public void should_return_offset_when_not_dst(string timezone, int expected)
{
Mocker.Resolve<TvRageProvider>().GetUtcOffset(timezone).Should().Be(expected);
}
[TestCase("GMT-5 +DST", -4)]
[TestCase("GMT+0 +DST", 1)]
[TestCase("GMT+8 +DST", 9)]
public void should_return_offset_plus_one_when_dst(string timezone, int expected)
{
Mocker.Resolve<TvRageProvider>().GetUtcOffset(timezone).Should().Be(expected);
}
}
}

View File

@ -0,0 +1,65 @@
// ReSharper disable RedundantUsingDirective
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using FluentAssertions;
using NUnit.Framework;
using Ninject;
using NzbDrone.Common;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common;
using TvdbLib.Data;
using TvdbLib.Exceptions;
namespace NzbDrone.Core.Test.ProviderTests.TvRageProviderTests
{
[TestFixture]
// ReSharper disable InconsistentNaming
public class ParseDayOfWeekFixture : CoreTest
{
[Test]
public void should_return_null_if_xelement_is_null()
{
Mocker.Resolve<TvRageProvider>().ParseDayOfWeek(null).Should().Be(null);
}
[Test]
public void should_return_null_if_value_is_null()
{
Mocker.Resolve<TvRageProvider>().ParseDayOfWeek(new XElement("airday", null)).Should().Be(null);
}
[Test]
public void should_return_null_if_value_is_empty()
{
Mocker.Resolve<TvRageProvider>().ParseDayOfWeek(new XElement("airday", "")).Should().Be(null);
}
[Test]
public void should_return_null_if_value_is_daily()
{
Mocker.Resolve<TvRageProvider>().ParseDayOfWeek(new XElement("airday", "Daily")).Should().Be(null);
}
[Test]
public void should_return_null_if_value_is_weekdays()
{
Mocker.Resolve<TvRageProvider>().ParseDayOfWeek(new XElement("airday", "Weekdays")).Should().Be(null);
}
[TestCase("Sunday", DayOfWeek.Sunday)]
[TestCase("Monday", DayOfWeek.Monday)]
[TestCase("Tuesday", DayOfWeek.Tuesday)]
[TestCase("Wednesday", DayOfWeek.Wednesday)]
[TestCase("Thursday", DayOfWeek.Thursday)]
[TestCase("Friday", DayOfWeek.Friday)]
[TestCase("Saturday", DayOfWeek.Saturday)]
public void should_return_dayOfWeek_when_it_is_valid(string value, DayOfWeek expected)
{
Mocker.Resolve<TvRageProvider>().ParseDayOfWeek(new XElement("airday", value)).Should().Be(expected);
}
}
}

View File

@ -0,0 +1,82 @@
// ReSharper disable RedundantUsingDirective
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using Ninject;
using NzbDrone.Common;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common;
using TvdbLib.Data;
using TvdbLib.Exceptions;
namespace NzbDrone.Core.Test.ProviderTests.TvRageProviderTests
{
[TestFixture]
// ReSharper disable InconsistentNaming
public class SearchSeriesFixture : CoreTest
{
private const string search = "http://services.tvrage.com/feeds/full_search.php?show=";
private void WithEmptyResults()
{
Mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadStream(It.Is<String>(u => u.StartsWith(search)), null))
.Returns(new FileStream(@".\Files\TVRage\SearchResults_empty.xml", FileMode.Open, FileAccess.Read, FileShare.Read));
}
private void WithManyResults()
{
Mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadStream(It.Is<String>(u => u.StartsWith(search)), null))
.Returns(new FileStream(@".\Files\TVRage\SearchResults_many.xml", FileMode.Open, FileAccess.Read, FileShare.Read));
}
private void WithOneResult()
{
Mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadStream(It.Is<String>(u => u.StartsWith(search)), null))
.Returns(new FileStream(@".\Files\TVRage\SearchResults_one.xml", FileMode.Open, FileAccess.Read, FileShare.Read));
}
[Test]
public void should_be_empty_when_no_results_are_found()
{
WithEmptyResults();
Mocker.Resolve<TvRageProvider>().SearchSeries("asdasdasdasdas").Should().BeEmpty();
}
[Test]
public void should_be_have_more_than_one_when_multiple_results_are_returned()
{
WithManyResults();
Mocker.Resolve<TvRageProvider>().SearchSeries("top+gear").Should().NotBeEmpty();
}
[Test]
public void should_have_one_when_only_one_result_is_found()
{
WithOneResult();
Mocker.Resolve<TvRageProvider>().SearchSeries("suits").Should().HaveCount(1);
}
[Test]
public void ended_should_not_have_a_value_when_series_has_not_ended()
{
WithOneResult();
Mocker.Resolve<TvRageProvider>().SearchSeries("suits").First().Ended.HasValue.Should().BeFalse();
}
[Test]
public void started_should_match_series()
{
WithOneResult();
Mocker.Resolve<TvRageProvider>().SearchSeries("suits").First().Started.Should().Be(new DateTime(2011, 6, 23));
}
}
}

View File

@ -0,0 +1,18 @@
using System;
using System.Data;
using Migrator.Framework;
using NzbDrone.Common;
namespace NzbDrone.Core.Datastore.Migrations
{
[Migration(20121218)]
public class Migration20121218 : NzbDroneMigration
{
protected override void MainDbUpgrade()
{
Database.AddColumn("Series", new Column("TvRageId", DbType.Int32, ColumnProperty.Null));
Database.AddColumn("Series", new Column("TvRageTitle", DbType.String, ColumnProperty.Null));
Database.AddColumn("Series", new Column("UtcOffset", DbType.Int32, ColumnProperty.Null));
}
}
}

View File

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NzbDrone.Core.Model.TvRage
{
public class TvRageEpisode
{
public int EpisodeNumber { get; set; }
public int SeasonNumber { get; set; }
public string ProductionCode { get; set; }
public DateTime AirDate { get; set; }
public string Link { get; set; }
public string Title { get; set; }
}
}

View File

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NzbDrone.Core.Model.TvRage
{
public class TvRageSearchResult
{
public int ShowId { get; set; }
public string Name { get; set; }
public string Link { get; set; }
public string Country { get; set; }
public DateTime Started { get; set; }
public DateTime? Ended { get; set; }
public int Seasons { get; set; }
public string Status { get; set; }
public int RunTime { get; set; }
public DateTime AirTime { get; set; }
public DayOfWeek? AirDay { get; set; }
}
}

View File

@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NzbDrone.Core.Model.TvRage
{
public class TvRageSeries
{
public int ShowId { get; set; }
public string Name { get; set; }
public string Link { get; set; }
public int Seasons { get; set; }
public int Started { get; set; }
public DateTime StartDate { get; set; }
public DateTime Ended { get; set; }
public string OriginCountry { get; set; }
public string Status { get; set; }
public int RunTime { get; set; }
public string Network { get; set; }
public DateTime AirTime { get; set; }
public DayOfWeek? AirDay { get; set; }
public int UtcOffset { get; set; }
}
}

View File

@ -228,6 +228,7 @@
<Compile Include="Datastore\MigrationLogger.cs" />
<Compile Include="Datastore\MigrationsHelper.cs" />
<Compile Include="Datastore\CustomeMapper.cs" />
<Compile Include="Datastore\Migrations\Migration20121218.cs" />
<Compile Include="Datastore\Migrations\Migration20121209.cs" />
<Compile Include="Datastore\Migrations\Migration20121202.cs" />
<Compile Include="Datastore\Migrations\Migration20121122.cs" />
@ -291,6 +292,9 @@
<Compile Include="Model\Sabnzbd\SabQueueItem.cs" />
<Compile Include="Model\Sabnzbd\SabVersionModel.cs" />
<Compile Include="Model\StatsModel.cs" />
<Compile Include="Model\TvRage\TvRageEpisode.cs" />
<Compile Include="Model\TvRage\TvRageSearchResult.cs" />
<Compile Include="Model\TvRage\TvRageSeries.cs" />
<Compile Include="Model\Twitter\TwitterAuthorizationModel.cs" />
<Compile Include="Model\UpdatePackage.cs" />
<Compile Include="Model\Xbmc\ActionType.cs" />
@ -343,6 +347,8 @@
<Compile Include="Jobs\RssSyncJob.cs" />
<Compile Include="Jobs\UpdateInfoJob.cs" />
<Compile Include="Providers\StatsProvider.cs" />
<Compile Include="Providers\TvRageMappingProvider.cs" />
<Compile Include="Providers\TvRageProvider.cs" />
<Compile Include="Providers\XemCommunicationProvider.cs" />
<Compile Include="Providers\XemProvider.cs" />
<Compile Include="Repository\MetadataDefinition.cs" />

View File

@ -99,5 +99,15 @@ namespace NzbDrone.Core.Providers
return false;
}
public virtual string GetCleanName(int seriesId)
{
var item = _database.FirstOrDefault<SceneMapping>("WHERE SeriesId = @0", seriesId);
if (item == null)
return null;
return item.CleanTitle;
}
}
}

View File

@ -14,18 +14,23 @@ namespace NzbDrone.Core.Providers
{
public class SeriesProvider
{
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
private readonly ConfigProvider _configProvider;
private readonly TvDbProvider _tvDbProvider;
private readonly IDatabase _database;
private readonly SceneMappingProvider _sceneNameMappingProvider;
private readonly BannerProvider _bannerProvider;
private readonly MetadataProvider _metadataProvider;
private readonly TvRageMappingProvider _tvRageMappingProvider;
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
private static readonly Regex TimeRegex = new Regex(@"^(?<time>\d+:?\d*)\W*(?<meridiem>am|pm)?", RegexOptions.IgnoreCase | RegexOptions.Compiled);
public SeriesProvider(IDatabase database, ConfigProvider configProviderProvider,
TvDbProvider tvDbProviderProvider, SceneMappingProvider sceneNameMappingProvider,
BannerProvider bannerProvider, MetadataProvider metadataProvider)
BannerProvider bannerProvider, MetadataProvider metadataProvider,
TvRageMappingProvider tvRageMappingProvider)
{
_database = database;
_configProvider = configProviderProvider;
@ -33,6 +38,7 @@ namespace NzbDrone.Core.Providers
_sceneNameMappingProvider = sceneNameMappingProvider;
_bannerProvider = bannerProvider;
_metadataProvider = metadataProvider;
_tvRageMappingProvider = tvRageMappingProvider;
}
public SeriesProvider()
@ -104,6 +110,17 @@ namespace NzbDrone.Core.Providers
series.BannerUrl = tvDbSeries.BannerPath;
series.Network = tvDbSeries.Network;
try
{
if(series.TvRageId == 0)
series = _tvRageMappingProvider.FindMatchingTvRageSeries(series);
}
catch(Exception ex)
{
logger.ErrorException("Error getting TvRage information for series: " + series.Title, ex);
}
UpdateSeries(series);
_metadataProvider.CreateForSeries(series, tvDbSeries);
@ -112,7 +129,7 @@ namespace NzbDrone.Core.Providers
public virtual void AddSeries(string title, string path, int tvDbSeriesId, int qualityProfileId, DateTime? airedAfter)
{
Logger.Info("Adding Series [{0}] Path: [{1}]", tvDbSeriesId, path);
logger.Info("Adding Series [{0}] Path: [{1}]", tvDbSeriesId, path);
if (tvDbSeriesId <=0)
{
@ -173,33 +190,33 @@ namespace NzbDrone.Core.Providers
public virtual void DeleteSeries(int seriesId)
{
var series = GetSeries(seriesId);
Logger.Warn("Deleting Series [{0}]", series.Title);
logger.Warn("Deleting Series [{0}]", series.Title);
using (var tran = _database.GetTransaction())
{
//Delete History, Files, Episodes, Seasons then the Series
Logger.Debug("Deleting History Items from DB for Series: {0}", series.Title);
logger.Debug("Deleting History Items from DB for Series: {0}", series.Title);
_database.Delete<History>("WHERE SeriesId=@0", seriesId);
Logger.Debug("Deleting EpisodeFiles from DB for Series: {0}", series.Title);
logger.Debug("Deleting EpisodeFiles from DB for Series: {0}", series.Title);
_database.Delete<EpisodeFile>("WHERE SeriesId=@0", seriesId);
Logger.Debug("Deleting Seasons from DB for Series: {0}", series.Title);
logger.Debug("Deleting Seasons from DB for Series: {0}", series.Title);
_database.Delete<Season>("WHERE SeriesId=@0", seriesId);
Logger.Debug("Deleting Episodes from DB for Series: {0}", series.Title);
logger.Debug("Deleting Episodes from DB for Series: {0}", series.Title);
_database.Delete<Episode>("WHERE SeriesId=@0", seriesId);
Logger.Debug("Deleting Series from DB {0}", series.Title);
logger.Debug("Deleting Series from DB {0}", series.Title);
_database.Delete<Series>("WHERE SeriesId=@0", seriesId);
Logger.Info("Successfully deleted Series [{0}]", series.Title);
logger.Info("Successfully deleted Series [{0}]", series.Title);
tran.Complete();
}
Logger.Trace("Beginning deletion of banner for SeriesID: ", seriesId);
logger.Trace("Beginning deletion of banner for SeriesID: ", seriesId);
_bannerProvider.Delete(seriesId);
}

View File

@ -0,0 +1,69 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NLog;
using Ninject;
using NzbDrone.Core.Model.TvRage;
using NzbDrone.Core.Repository;
namespace NzbDrone.Core.Providers
{
public class TvRageMappingProvider
{
private readonly SceneMappingProvider _sceneMappingProvider;
private readonly TvRageProvider _tvRageProvider;
private readonly EpisodeProvider _episodeProvider;
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
[Inject]
public TvRageMappingProvider(SceneMappingProvider sceneMappingProvider,
TvRageProvider tvRageProvider, EpisodeProvider episodeProvider)
{
_sceneMappingProvider = sceneMappingProvider;
_tvRageProvider = tvRageProvider;
_episodeProvider = episodeProvider;
}
public TvRageMappingProvider()
{
}
public Series FindMatchingTvRageSeries(Series series)
{
var firstEpisode = _episodeProvider.GetEpisode(series.SeriesId, 1, 1);
var cleanName = _sceneMappingProvider.GetCleanName(series.SeriesId);
var results = _tvRageProvider.SearchSeries(series.Title);
var result = ProcessResults(results, series, cleanName, firstEpisode);
if (result != null)
{
logger.Trace("TV Rage: {0} matches TVDB: {1}", result.Name, series.Title);
series.TvRageId = result.ShowId;
series.TvRageTitle = result.Name;
series.UtcOffset = _tvRageProvider.GetSeries(result.ShowId).UtcOffset;
}
return series;
}
public TvRageSearchResult ProcessResults(IList<TvRageSearchResult> searchResults, Series series, string sceneCleanName, Episode firstEpisode)
{
foreach (var result in searchResults)
{
if (Parser.NormalizeTitle(result.Name).Equals(series.CleanTitle))
return result;
if (!String.IsNullOrWhiteSpace(sceneCleanName) && Parser.NormalizeTitle(result.Name).Equals(sceneCleanName))
return result;
if (firstEpisode.AirDate.HasValue && result.Started == firstEpisode.AirDate.Value)
return result;
}
return null;
}
}
}

View File

@ -0,0 +1,197 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using NLog;
using Ninject;
using NzbDrone.Common;
using NzbDrone.Core.Model.TvRage;
namespace NzbDrone.Core.Providers
{
public class TvRageProvider
{
private readonly HttpProvider _httpProvider;
private const string TVRAGE_APIKEY = "NW4v0PSmQIoVmpbASLdD";
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
[Inject]
public TvRageProvider(HttpProvider httpProvider)
{
_httpProvider = httpProvider;
}
public TvRageProvider()
{
}
public virtual IList<TvRageSearchResult> SearchSeries(string title)
{
var searchResults = new List<TvRageSearchResult>();
var xmlStream = _httpProvider.DownloadStream("http://services.tvrage.com/feeds/full_search.php?show=" + title, null);
var xml = XDocument.Load(xmlStream);
var shows = xml.Descendants("Results").Descendants("show");
foreach (var s in shows)
{
try
{
var show = new TvRageSearchResult();
show.ShowId = Int32.Parse(s.Element("showid").Value);
show.Name = s.Element("name").Value;
show.Link = s.Element("link").Value;
show.Country = s.Element("country").Value;
DateTime started;
if (DateTime.TryParse(s.Element("started").Value, out started)) ;
show.Started = started;
DateTime ended;
if (DateTime.TryParse(s.Element("ended").Value, out ended)) ;
show.Ended = ended;
if (show.Ended < new DateTime(1900, 1, 1))
show.Ended = null;
show.Seasons = Int32.Parse(s.Element("seasons").Value);
show.Status = s.Element("status").Value;
show.RunTime = Int32.Parse(s.Element("runtime").Value);
show.AirTime = DateTime.Parse(s.Element("airtime").Value);
show.AirDay = ParseDayOfWeek(s.Element("airday"));
searchResults.Add(show);
}
catch (Exception ex)
{
logger.DebugException("Failed to parse TvRage Search Result. Search Term : " + title, ex);
}
}
return searchResults;
}
public virtual TvRageSeries GetSeries(int id)
{
var url = string.Format("http://services.tvrage.com/feeds/showinfo.php?key={0}&sid={1}", TVRAGE_APIKEY, id);
var xmlStream = _httpProvider.DownloadStream(url, null);
var xml = XDocument.Load(xmlStream);
var s = xml.Descendants("Showinfo").First();
try
{
if(s.Element("showid") == null)
{
logger.Warn("TvRage did not return valid series info for id: {0}", id);
return null;
}
var show = new TvRageSeries();
show.ShowId = Int32.Parse(s.Element("showid").Value);
show.Name = s.Element("showname").Value;
show.Link = s.Element("showlink").Value;
show.Seasons = Int32.Parse(s.Element("seasons").Value);
show.Started = Int32.Parse(s.Element("started").Value);
DateTime startDate;
if (DateTime.TryParse(s.Element("startdate").Value, out startDate)) ;
show.StartDate = startDate;
DateTime ended;
if (DateTime.TryParse(s.Element("ended").Value, out ended)) ;
show.Ended = ended;
show.OriginCountry = s.Element("origin_country").Value;
show.Status = s.Element("status").Value;
show.RunTime = Int32.Parse(s.Element("runtime").Value);
show.Network = s.Element("network").Value;
show.AirTime = DateTime.Parse(s.Element("airtime").Value);
show.AirDay = ParseDayOfWeek(s.Element("airday"));
show.UtcOffset = GetUtcOffset(s.Element("timezone").Value);
return show;
}
catch (Exception ex)
{
logger.DebugException("Failed to parse ShowInfo for ID: " + id, ex);
return null;
}
}
public virtual List<TvRageEpisode> GetEpisodes(int id)
{
var url = String.Format("http://services.tvrage.com/feeds/episode_list.php?key={0}&sid={1}", TVRAGE_APIKEY, id);
var xmlStream = _httpProvider.DownloadStream(url, null);
var xml = XDocument.Load(xmlStream);
var show = xml.Descendants("Show");
var seasons = show.Descendants("Season");
var episodes = new List<TvRageEpisode>();
foreach (var season in seasons)
{
var eps = season.Descendants("episode");
foreach (var e in eps)
{
try
{
var episode = new TvRageEpisode();
episode.EpisodeNumber = Int32.Parse(e.Element("epnum").Value);
episode.SeasonNumber = Int32.Parse(e.Element("seasonnum").Value);
episode.ProductionCode = e.Element("prodnum").Value;
episode.AirDate = DateTime.Parse(e.Element("airdate").Value);
episode.Link = e.Element("link").Value;
episode.Title = e.Element("title").Value;
episodes.Add(episode);
}
catch (Exception ex)
{
logger.DebugException("Failed to parse TV Rage episode", ex);
}
}
}
return episodes;
}
internal int GetUtcOffset(string timeZone)
{
if (String.IsNullOrWhiteSpace(timeZone))
return 0;
var offsetString = timeZone.Substring(3, 2);
int offset;
if (!Int32.TryParse(offsetString, out offset))
return 0;
if (timeZone.IndexOf("+DST", StringComparison.CurrentCultureIgnoreCase) > 0)
offset++;
return offset;
}
internal DayOfWeek? ParseDayOfWeek(XElement element)
{
if(element == null)
return null;
if(String.IsNullOrWhiteSpace(element.Value))
return null;
try
{
return (DayOfWeek)Enum.Parse(typeof(DayOfWeek), element.Value);
}
catch(Exception)
{
}
return null;
}
}
}

View File

@ -52,6 +52,12 @@ namespace NzbDrone.Core.Repository
public bool UseSceneNumbering { get; set; }
public int TvRageId { get; set; }
public string TvRageTitle { get; set; }
public int UtcOffset { get; set; }
/// <summary>
/// Gets or sets a value indicating whether this <see cref="Series"/> is hidden.
/// </summary>