Added tests for Roksbox and Wdtv metadata

Fixed: Detecting metadata files for Roksbox and WDTV inside of Specials folders
This commit is contained in:
Mark McDowall 2014-06-19 07:18:50 -07:00
parent 32e6b7db48
commit 2fd3c354fd
5 changed files with 167 additions and 21 deletions

View File

@ -0,0 +1,78 @@
using System.IO;
using FizzWare.NBuilder;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.Metadata;
using NzbDrone.Core.Metadata.Consumers.Roksbox;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.Tv;
using NzbDrone.Test.Common;
namespace NzbDrone.Core.Test.Metadata.Consumers.Roksbox
{
[TestFixture]
public class FindMetadataFileFixture : CoreTest<RoksboxMetadata>
{
private Series _series;
[SetUp]
public void Setup()
{
_series = Builder<Series>.CreateNew()
.With(s => s.Path = @"C:\Test\TV\The.Series".AsOsAgnostic())
.Build();
}
[Test]
public void should_return_null_if_filename_is_not_handled()
{
var path = Path.Combine(_series.Path, "file.jpg");
Subject.FindMetadataFile(_series, path).Should().BeNull();
}
[TestCase("Specials")]
[TestCase("specials")]
[TestCase("Season 1")]
public void should_return_season_image(string folder)
{
var path = Path.Combine(_series.Path, folder, folder + ".jpg");
Subject.FindMetadataFile(_series, path).Type.Should().Be(MetadataType.SeasonImage);
}
[TestCase(".xml", MetadataType.EpisodeMetadata)]
[TestCase(".jpg", MetadataType.EpisodeImage)]
public void should_return_metadata_for_episode_if_valid_file_for_episode(string extension, MetadataType type)
{
var path = Path.Combine(_series.Path, "the.series.s01e01.episode" + extension);
Subject.FindMetadataFile(_series, path).Type.Should().Be(type);
}
[TestCase(".xml")]
[TestCase(".jpg")]
public void should_return_null_if_not_valid_file_for_episode(string extension)
{
var path = Path.Combine(_series.Path, "the.series.episode" + extension);
Subject.FindMetadataFile(_series, path).Should().BeNull();
}
[Test]
public void should_not_return_metadata_if_image_file_is_a_thumb()
{
var path = Path.Combine(_series.Path, "the.series.s01e01.episode-thumb.jpg");
Subject.FindMetadataFile(_series, path).Should().BeNull();
}
[Test]
public void should_return_series_image_for_folder_jpg_in_series_folder()
{
var path = Path.Combine(_series.Path, new DirectoryInfo(_series.Path).Name + ".jpg");
Subject.FindMetadataFile(_series, path).Type.Should().Be(MetadataType.SeriesImage);
}
}
}

View File

@ -0,0 +1,74 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using FizzWare.NBuilder;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.Metadata;
using NzbDrone.Core.Metadata.Consumers.Wdtv;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.Tv;
using NzbDrone.Test.Common;
namespace NzbDrone.Core.Test.Metadata.Consumers.Wdtv
{
[TestFixture]
public class FindMetadataFileFixture : CoreTest<WdtvMetadata>
{
private Series _series;
[SetUp]
public void Setup()
{
_series = Builder<Series>.CreateNew()
.With(s => s.Path = @"C:\Test\TV\The.Series".AsOsAgnostic())
.Build();
}
[Test]
public void should_return_null_if_filename_is_not_handled()
{
var path = Path.Combine(_series.Path, "file.jpg");
Subject.FindMetadataFile(_series, path).Should().BeNull();
}
[TestCase("Specials")]
[TestCase("specials")]
[TestCase("Season 1")]
public void should_return_season_image(string folder)
{
var path = Path.Combine(_series.Path, folder, "folder.jpg");
Subject.FindMetadataFile(_series, path).Type.Should().Be(MetadataType.SeasonImage);
}
[TestCase(".xml", MetadataType.EpisodeMetadata)]
[TestCase(".metathumb", MetadataType.EpisodeImage)]
public void should_return_metadata_for_episode_if_valid_file_for_episode(string extension, MetadataType type)
{
var path = Path.Combine(_series.Path, "the.series.s01e01.episode" + extension);
Subject.FindMetadataFile(_series, path).Type.Should().Be(type);
}
[TestCase(".xml")]
[TestCase(".metathumb")]
public void should_return_null_if_not_valid_file_for_episode(string extension)
{
var path = Path.Combine(_series.Path, "the.series.episode" + extension);
Subject.FindMetadataFile(_series, path).Should().BeNull();
}
[Test]
public void should_return_series_image_for_folder_jpg_in_series_folder()
{
var path = Path.Combine(_series.Path, "folder.jpg");
Subject.FindMetadataFile(_series, path).Type.Should().Be(MetadataType.SeriesImage);
}
}
}

View File

@ -174,6 +174,8 @@
<Compile Include="Messaging\Commands\CommandFixture.cs" />
<Compile Include="Messaging\Events\EventAggregatorFixture.cs" />
<Compile Include="MetadataSourceTests\TraktProxyFixture.cs" />
<Compile Include="Metadata\Consumers\Roksbox\FindMetadataFileFixture.cs" />
<Compile Include="Metadata\Consumers\Wdtv\FindMetadataFileFixture.cs" />
<Compile Include="NotificationTests\Xbmc\GetJsonVersionFixture.cs" />
<Compile Include="NotificationTests\Xbmc\Http\ActivePlayersFixture.cs" />
<Compile Include="NotificationTests\Xbmc\Http\CheckForErrorFixture.cs" />

View File

@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Remoting.Messaging;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml;
@ -10,11 +9,8 @@ using System.Xml.Linq;
using NLog;
using NzbDrone.Common;
using NzbDrone.Common.Disk;
using NzbDrone.Common.Http;
using NzbDrone.Core.Datastore;
using NzbDrone.Core.MediaCover;
using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.Messaging.Events;
using NzbDrone.Core.Metadata.Files;
using NzbDrone.Core.Tv;
@ -36,7 +32,7 @@ namespace NzbDrone.Core.Metadata.Consumers.Roksbox
}
private static List<string> ValidCertification = new List<string> { "G", "NC-17", "PG", "PG-13", "R", "UR", "UNRATED", "NR", "TV-Y", "TV-Y7", "TV-Y7-FV", "TV-G", "TV-PG", "TV-14", "TV-MA" };
private static readonly Regex SeasonImagesRegex = new Regex(@"^(season (?<season>\d+))|(?<season>specials)", RegexOptions.Compiled | RegexOptions.IgnoreCase);
private static readonly Regex SeasonImagesRegex = new Regex(@"^(season (?<season>\d+))|(?<specials>specials)", RegexOptions.Compiled | RegexOptions.IgnoreCase);
public override List<MetadataFile> AfterRename(Series series, List<MetadataFile> existingMetadataFiles, List<EpisodeFile> episodeFiles)
{
@ -97,26 +93,27 @@ namespace NzbDrone.Core.Metadata.Consumers.Roksbox
};
//Series and season images are both named folder.jpg, only season ones sit in season folders
if (String.Compare(filename, parentdir.Name, StringComparison.InvariantCultureIgnoreCase) == 0)
if (Path.GetFileNameWithoutExtension(filename).Equals(parentdir.Name, StringComparison.InvariantCultureIgnoreCase))
{
var seasonMatch = SeasonImagesRegex.Match(parentdir.Name);
if (seasonMatch.Success)
{
metadata.Type = MetadataType.SeasonImage;
var seasonNumber = seasonMatch.Groups["season"].Value;
if (seasonNumber.Contains("specials"))
if (seasonMatch.Groups["specials"].Success)
{
metadata.SeasonNumber = 0;
}
else
{
metadata.SeasonNumber = Convert.ToInt32(seasonNumber);
metadata.SeasonNumber = Convert.ToInt32(seasonMatch.Groups["season"].Value);
}
return metadata;
}
else
{
metadata.Type = MetadataType.SeriesImage;

View File

@ -1,9 +1,7 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Runtime.Remoting.Messaging;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml;
@ -11,11 +9,8 @@ using System.Xml.Linq;
using NLog;
using NzbDrone.Common;
using NzbDrone.Common.Disk;
using NzbDrone.Common.Http;
using NzbDrone.Core.Datastore;
using NzbDrone.Core.MediaCover;
using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.Messaging.Events;
using NzbDrone.Core.Metadata.Files;
using NzbDrone.Core.Tv;
@ -36,7 +31,7 @@ namespace NzbDrone.Core.Metadata.Consumers.Wdtv
_logger = logger;
}
private static readonly Regex SeasonImagesRegex = new Regex(@"^(season (?<season>\d+))|(?<season>specials)", RegexOptions.Compiled | RegexOptions.IgnoreCase);
private static readonly Regex SeasonImagesRegex = new Regex(@"^(season (?<season>\d+))|(?<specials>specials)", RegexOptions.Compiled | RegexOptions.IgnoreCase);
public override List<MetadataFile> AfterRename(Series series, List<MetadataFile> existingMetadataFiles, List<EpisodeFile> episodeFiles)
{
@ -95,7 +90,7 @@ namespace NzbDrone.Core.Metadata.Consumers.Wdtv
};
//Series and season images are both named folder.jpg, only season ones sit in season folders
if (String.Compare(filename, "folder.jpg", true) == 0)
if (Path.GetFileName(filename).Equals("folder.jpg", StringComparison.InvariantCultureIgnoreCase))
{
var parentdir = Directory.GetParent(path);
var seasonMatch = SeasonImagesRegex.Match(parentdir.Name);
@ -103,19 +98,19 @@ namespace NzbDrone.Core.Metadata.Consumers.Wdtv
{
metadata.Type = MetadataType.SeasonImage;
var seasonNumber = seasonMatch.Groups["season"].Value;
if (seasonNumber.Contains("specials"))
if (seasonMatch.Groups["specials"].Success)
{
metadata.SeasonNumber = 0;
}
else
{
metadata.SeasonNumber = Convert.ToInt32(seasonNumber);
metadata.SeasonNumber = Convert.ToInt32(seasonMatch.Groups["season"].Value);
}
return metadata;
}
else
{
metadata.Type = MetadataType.SeriesImage;