Matching TvRage to TvDb

#ND-15 In Progress
This commit is contained in:
Mark McDowall 2012-12-19 08:41:51 -08:00
parent f00b17ac47
commit 253426873c
17 changed files with 753 additions and 7 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,7 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="ProviderTests\TvRageProviderTests\ParseDayOfWeekFixture.cs" />
<Compile Include="ProviderTests\TvRageProviderTests\GetUtcOffsetFixture.cs" />
<Compile Include="ProviderTests\TvRageProviderTests\SearchSeriesFixture.cs" />
<Compile Include="QualityTypesTest.cs" />
@ -330,6 +331,15 @@
<SubType>Designer</SubType>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<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,57 @@
// 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();
}
[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,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,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

@ -17,6 +17,6 @@ namespace NzbDrone.Core.Model.TvRage
public string Status { get; set; }
public int RunTime { get; set; }
public DateTime AirTime { get; set; }
public DayOfWeek AirDay { get; set; }
public DayOfWeek? AirDay { get; set; }
}
}

View File

@ -19,7 +19,7 @@ namespace NzbDrone.Core.Model.TvRage
public int RunTime { get; set; }
public string Network { get; set; }
public DateTime AirTime { get; set; }
public DayOfWeek AirDay { 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" />
@ -346,6 +347,7 @@
<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" />

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

@ -21,11 +21,13 @@ namespace NzbDrone.Core.Providers
private readonly SceneMappingProvider _sceneNameMappingProvider;
private readonly BannerProvider _bannerProvider;
private readonly MetadataProvider _metadataProvider;
private readonly TvRageMappingProvider _tvRageMappingProvider;
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 +35,7 @@ namespace NzbDrone.Core.Providers
_sceneNameMappingProvider = sceneNameMappingProvider;
_bannerProvider = bannerProvider;
_metadataProvider = metadataProvider;
_tvRageMappingProvider = tvRageMappingProvider;
}
public SeriesProvider()
@ -104,6 +107,9 @@ namespace NzbDrone.Core.Providers
series.BannerUrl = tvDbSeries.BannerPath;
series.Network = tvDbSeries.Network;
if (series.TvRageId == 0)
series = _tvRageMappingProvider.FindMatchingTvRageSeries(series);
UpdateSeries(series);
_metadataProvider.CreateForSeries(series, tvDbSeries);

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

@ -22,6 +22,10 @@ namespace NzbDrone.Core.Providers
_httpProvider = httpProvider;
}
public TvRageProvider()
{
}
public virtual IList<TvRageSearchResult> SearchSeries(string title)
{
var searchResults = new List<TvRageSearchResult>();
@ -56,7 +60,7 @@ namespace NzbDrone.Core.Providers
show.Status = s.Element("status").Value;
show.RunTime = Int32.Parse(s.Element("runtime").Value);
show.AirTime = DateTime.Parse(s.Element("airtime").Value);
show.AirDay = (DayOfWeek)Enum.Parse(typeof(DayOfWeek), s.Element("airday").Value);
show.AirDay = ParseDayOfWeek(s.Element("airday"));
searchResults.Add(show);
}
@ -72,12 +76,18 @@ namespace NzbDrone.Core.Providers
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 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;
@ -98,7 +108,7 @@ namespace NzbDrone.Core.Providers
show.RunTime = Int32.Parse(s.Element("runtime").Value);
show.Network = s.Element("network").Value;
show.AirTime = DateTime.Parse(s.Element("airtime").Value);
show.AirDay = (DayOfWeek)Enum.Parse(typeof(DayOfWeek), s.Element("airday").Value);
show.AirDay = ParseDayOfWeek(s.Element("airday"));
show.UtcOffset = GetUtcOffset(s.Element("timezone").Value);
return show;
}
@ -112,7 +122,7 @@ namespace NzbDrone.Core.Providers
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 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");
@ -164,5 +174,24 @@ namespace NzbDrone.Core.Providers
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>