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
@@ -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;
@@ -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;