diff --git a/NzbDrone.Core.Test/ParserTest.cs.orig b/NzbDrone.Core.Test/ParserTest.cs.orig deleted file mode 100644 index 050d1b478..000000000 --- a/NzbDrone.Core.Test/ParserTest.cs.orig +++ /dev/null @@ -1,91 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using Gallio.Framework; -using MbUnit.Framework; -using MbUnit.Framework.ContractVerifiers; -using NzbDrone.Core.Repository.Quality; - -namespace NzbDrone.Core.Test -{ - [TestFixture] - // ReSharper disable InconsistentNaming - public class ParserTest - { - [Test] -<<<<<<< HEAD -======= - [Row("Sonny.With.a.Chance.S02E15", 2,15)] - [Row("WEEDS.S03E01-06.DUAL.BDRip.XviD.AC3.-HELLYWOOD", 3, 1)] ->>>>>>> 2d9285eee29d96b6eedee98e358aa76c32c2998f - [Row("Two.and.a.Half.Me.103.720p.HDTV.X264-DIMENSION", 1, 3)] - [Row("Two.and.a.Half.Me.113.720p.HDTV.X264-DIMENSION", 1, 13)] - [Row("Two.and.a.Half.Me.1013.720p.HDTV.X264-DIMENSION", 10, 13)] - [Row("Chuck.4x05.HDTV.XviD-LOL", 4, 5)] - [Row("The.Girls.Next.Door.S03E06.DVDRip.XviD-WiDE", 3, 6)] - [Row("Degrassi.S10E27.WS.DSR.XviD-2HD", 10, 27)] - [Row(@"z:\tv shows\battlestar galactica (2003)\Season 3\S03E05 - Collaborators.mkv", 3, 5)] - [Row(@"z:\tv shows\modern marvels\Season 16\S16E03 - The Potato.mkv", 16, 3)] - [Row(@"z:\tv shows\robot chicken\Specials\S00E16 - Dear Consumer - SD TV.avi", 0, 16)] - [Row(@"Parenthood.2010.S02E14.HDTV.XviD-LOL", 2, 14)] - [Row(@"Hawaii Five 0 S01E19 720p WEB DL DD5 1 H 264 NT", 1, 19)] - [Row(@"The Event S01E14 A Message Back 720p WEB DL DD5 1 H264 SURFER", 1, 14)] - [Row(@"Adam Hills In Gordon St Tonight S01E07 WS PDTV XviD FUtV", 1, 7)] - public void episode_parse(string path, int season, int episode) - { - var result = Parser.ParseEpisodeInfo(path); - Assert.AreEqual(season, result.SeasonNumber); - Assert.AreEqual(episode, result.Episodes[0]); - } - - [Test] - [Row("The.Office.US.S03E01E02.DUAL.BDRip.XviD.AC3.-HELLYWOOD", 3, 1, 2)] - [Row("WEEDS.S03E01-06.DUAL.BDRip.XviD.AC3.-HELLYWOOD", 3, 1, 6)] - public void episode_parse_multi(string path, int season, int episodeOne, int episodeTwo) - { - var result = Parser.ParseEpisodeInfo(path); - Assert.Count(2, result); - Assert.AreEqual(season, result[0].SeasonNumber); - Assert.AreEqual(episodeOne, result[0].EpisodeNumber); - Assert.AreEqual(episodeTwo, result[1].EpisodeNumber); - } - - [Test] - [Row("WEEDS.S03E01-06.DUAL.BDRip.XviD.AC3.-HELLYWOOD", QualityTypes.BDRip)] - [Row("WEEDS.S03E01-06.DUAL.BDRip.AC3.-HELLYWOOD", QualityTypes.BDRip)] - [Row("Two.and.a.Half.Men.S08E05.720p.HDTV.X264-DIMENSION", QualityTypes.HDTV)] - [Row("Chuck.S04E05.HDTV.XviD-LOL", QualityTypes.TV)] - [Row("The.Girls.Next.Door.S03E06.DVDRip.XviD-WiDE", QualityTypes.DVD)] - [Row("Degrassi.S10E27.WS.DSR.XviD-2HD", QualityTypes.TV)] - [Row("Sonny.With.a.Chance.S02E15.720p.WEB-DL.DD5.1.H.264-SURFER", QualityTypes.WEBDL)] - [Row("Sonny.With.a.Chance.S02E15.720p", QualityTypes.HDTV)] - [Row("Sonny.With.a.Chance.S02E15.mkv", QualityTypes.HDTV)] - [Row("Sonny.With.a.Chance.S02E15.avi", QualityTypes.TV)] - [Row("Sonny.With.a.Chance.S02E15.xvid", QualityTypes.TV)] - [Row("Sonny.With.a.Chance.S02E15.divx", QualityTypes.TV)] - [Row("Sonny.With.a.Chance.S02E15", QualityTypes.Unknown)] - [Row("Chuck - S01E04 - So Old - Playdate - 720p TV.mkv", QualityTypes.HDTV)] - [Row("Chuck - S22E03 - MoneyBART - HD TV.mkv", QualityTypes.HDTV)] - [Row("Chuck - S01E03 - Come Fly With Me - 720p BluRay.mkv", QualityTypes.Bluray720)] - [Row("Chuck - S01E03 - Come Fly With Me - 1080p BluRay.mkv", QualityTypes.Bluray1080)] - [Row("Chuck - S11E06 - D-Yikes! - 720p WEB-DL.mkv", QualityTypes.WEBDL)] - [Row("WEEDS.S03E01-06.DUAL.BDRip.XviD.AC3.-HELLYWOOD.avi", QualityTypes.BDRip)] - public void quality_parse(string path, object quality) - { - var result = Parser.ParseEpisodeInfo(path).Quality; - Assert.AreEqual(quality, result); - } - - [Test] - [Row(@"c:\test\", @"c:\test")] - [Row(@"c:\\test\\", @"c:\test")] - [Row(@"C:\\Test\\", @"C:\Test")] - [Row(@"C:\\Test\\Test\", @"C:\Test\Test")] - [Row(@"\\Testserver\Test\", @"\\Testserver\Test")] - public void Normalize_Path(string dirty, string clean) - { - var result = Parser.NormalizePath(dirty); - Assert.AreEqual(clean, result); - } - } -} diff --git a/NzbDrone.Core/Parser.cs.orig b/NzbDrone.Core/Parser.cs.orig deleted file mode 100644 index 856d9b8c4..000000000 --- a/NzbDrone.Core/Parser.cs.orig +++ /dev/null @@ -1,282 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Text.RegularExpressions; -using NLog; -using NzbDrone.Core.Model; -using NzbDrone.Core.Providers; -using NzbDrone.Core.Repository.Quality; - -namespace NzbDrone.Core -{ - internal static class Parser - { - private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - - private static readonly Regex[] ReportTitleRegex = new[] - { - new Regex(@"(?.+?)?\W?(?<year>\d+?)?\WS?(?<season>\d+)((?:\-|\.|[a-z])(?<episode>\d+))+\W(?!\\)", RegexOptions.IgnoreCase | RegexOptions.Compiled), - new Regex(@"(?<title>.+?)?\W?(?<year>\d+?)?\WS?(?<season>\d+)(?<episode>\d{2})\W(?!\\)", RegexOptions.IgnoreCase | RegexOptions.Compiled) //Supports 103/113 naming - }; - - private static readonly Regex[] SeasonReportTitleRegex = new[] - { - new Regex(@"(?<title>.+?)?\W?(?<year>\d{4}?)?\W(?:S|Season)?\W?(?<season>\d+)(?!\\)", RegexOptions.IgnoreCase | RegexOptions.Compiled), - }; - - private static readonly Regex NormalizeRegex = new Regex(@"((\s|^)the(\s|$))|((\s|^)and(\s|$))|[^a-z]", RegexOptions.IgnoreCase | RegexOptions.Compiled); - - /// <summary> - /// Parses a post title into list of episodes it contains - /// </summary> - /// <param name="title">Title of the report</param> - /// <returns>List of episodes contained to the post</returns> - internal static EpisodeParseResult ParseEpisodeInfo(string title) - { - Logger.Trace("Parsing string '{0}'", title); - - foreach (var regex in ReportTitleRegex) - { - var match = regex.Matches(title); - - if (match.Count != 0) - { - var seriesName = NormalizeTitle(match[0].Groups["title"].Value); - var year = 0; - Int32.TryParse(match[0].Groups["year"].Value, out year); - - if (year < 1900 || year > DateTime.Now.Year + 1) - { - year = 0; - } - - var parsedEpisode = new EpisodeParseResult - { - Proper = title.ToLower().Contains("proper"), - SeriesTitle = seriesName, - SeasonNumber = Convert.ToInt32(match[0].Groups["season"].Value), - Year = year, - Episodes = new List<int>() - }; - - foreach (Match matchGroup in match) - { - parsedEpisode.Episodes.Add(Convert.ToInt32(matchGroup.Groups["episode"].Value)); - -<<<<<<< HEAD - var seasonNumber = Convert.ToInt32(matchGroup.Groups["season"].Value); - - foreach (Capture episode in matchGroup.Groups["episode"].Captures) - { - var parsedEpisode = new EpisodeParseResult - { - SeriesTitle = seriesName, - SeasonNumber = seasonNumber, - EpisodeNumber = Convert.ToInt32(episode.Value), - Year = year - }; - - - result.Add(parsedEpisode); - Logger.Trace("Episode Parsed. {0}", parsedEpisode); - } - } - break; //Break out of the for loop, we don't want to process every REGEX for each item otherwise we'll get duplicates -======= - } - - parsedEpisode.Quality = ParseQuality(title); - - Logger.Trace("Episode Parsed. {0}", parsedEpisode); - - return parsedEpisode; ->>>>>>> 2d9285eee29d96b6eedee98e358aa76c32c2998f - } - } - - return null; - } - - /// <summary> - /// Parses a post title into season it contains - /// </summary> - /// <param name="title">Title of the report</param> - /// <returns>Season information contained in the post</returns> - internal static SeasonParseResult ParseSeasonInfo(string title) - { - Logger.Trace("Parsing string '{0}'", title); - - foreach (var regex in ReportTitleRegex) - { - var match = regex.Matches(title); - - if (match.Count != 0) - { - var seriesName = NormalizeTitle(match[0].Groups["title"].Value); - var year = 0; - Int32.TryParse(match[0].Groups["year"].Value, out year); - - if (year < 1900 || year > DateTime.Now.Year + 1) - { - year = 0; - } - - var seasonNumber = Convert.ToInt32(match[0].Groups["season"].Value); - - var result = new SeasonParseResult - { - SeriesTitle = seriesName, - SeasonNumber = seasonNumber, - Year = year - }; - - - result.Quality = ParseQuality(title); - - Logger.Trace("Season Parsed. {0}", result); - return result; - } - } - - return null; //Return null - } - - /// <summary> - /// Parses a post title to find the series that relates to it - /// </summary> - /// <param name="title">Title of the report</param> - /// <returns>Normalized Series Name</returns> - internal static string ParseSeriesName(string title) - { - Logger.Trace("Parsing string '{0}'", title); - - foreach (var regex in ReportTitleRegex) - { - var match = regex.Matches(title); - - if (match.Count != 0) - { - var seriesName = NormalizeTitle(match[0].Groups["title"].Value); - var year = 0; - Int32.TryParse(match[0].Groups["year"].Value, out year); - - if (year < 1900 || year > DateTime.Now.Year + 1) - { - year = 0; - } - - Logger.Trace("Series Parsed. {0}", seriesName); - return seriesName; - } - } - - return String.Empty; - } - - /// <summary> - /// Parses proper status out of a report title - /// </summary> - /// <param name="title">Title of the report</param> - /// <returns></returns> - internal static bool ParseProper(string title) - { - return title.ToLower().Contains("proper"); - } - - private static QualityTypes ParseQuality(string name) - { - Logger.Trace("Trying to parse quality for {0}", name); - - var result = QualityTypes.Unknown; - name = name.ToLowerInvariant(); - - if (name.Contains("dvd")) - return QualityTypes.DVD; - - if (name.Contains("bdrip") || name.Contains("brrip")) - { - return QualityTypes.BDRip; - } - - if (name.Contains("xvid") || name.Contains("divx")) - { - if (name.Contains("bluray")) - { - return QualityTypes.BDRip; - } - - return QualityTypes.TV; - } - - if (name.Contains("bluray")) - { - if (name.Contains("720p")) - return QualityTypes.Bluray720; - - if (name.Contains("1080p")) - return QualityTypes.Bluray1080; - - return QualityTypes.Bluray720; - } - if (name.Contains("web-dl")) - return QualityTypes.WEBDL; - if (name.Contains("x264") || name.Contains("h264") || name.Contains("720p")) - return QualityTypes.HDTV; - - //Based on extension - if (result == QualityTypes.Unknown) - { - switch (new FileInfo(name).Extension.ToLower()) - { - case ".avi": - case ".xvid": - case ".wmv": - { - result = QualityTypes.TV; - break; - } - case ".mkv": - { - result = QualityTypes.HDTV; - break; - } - } - } - - Logger.Trace("Quality Parsed:{0} Title:", result, name); - return result; - } - - /// <summary> - /// Normalizes the title. removing all non-word characters as well as common tokens - /// such as 'the' and 'and' - /// </summary> - /// <param name="title">title</param> - /// <returns></returns> - internal static string NormalizeTitle(string title) - { - return NormalizeRegex.Replace(title, String.Empty).ToLower(); - } - - //Note: changing case on path is a problem for running on mono/*nix - //Not going to change the casing any more... Looks Ugly in UI anyways :P - public static string NormalizePath(string path) - { - if (String.IsNullOrEmpty(path)) - throw new ArgumentException("Path can not be null or empty"); - - var info = new FileInfo(path); - - if (info.FullName.StartsWith(@"\\")) //UNC - { - return info.FullName.TrimEnd('/', '\\', ' '); - } - - return info.FullName.Trim('/', '\\', ' '); - } - - - } -}