2013-04-07 21:01:24 +02:00
|
|
|
|
using System;
|
2012-08-03 09:01:34 +02:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
using NLog;
|
|
|
|
|
using NzbDrone.Common;
|
2013-04-07 21:01:24 +02:00
|
|
|
|
using NzbDrone.Core.Qualities;
|
|
|
|
|
using NzbDrone.Core.Tv;
|
|
|
|
|
using NzbDrone.Core.Model;
|
2012-08-03 09:01:34 +02:00
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core
|
|
|
|
|
{
|
|
|
|
|
public static class Parser
|
|
|
|
|
{
|
|
|
|
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
|
|
|
|
|
|
|
|
|
private static readonly Regex[] ReportTitleRegex = new[]
|
|
|
|
|
{
|
|
|
|
|
//Episodes with airdate
|
|
|
|
|
new Regex(@"^(?<title>.+?)?\W*(?<airyear>\d{4})\W+(?<airmonth>[0-1][0-9])\W+(?<airday>[0-3][0-9])\W?(?!\\)",
|
|
|
|
|
RegexOptions.IgnoreCase | RegexOptions.Compiled),
|
|
|
|
|
|
|
|
|
|
//Multi-Part episodes without a title (S01E05.S01E06)
|
|
|
|
|
new Regex(@"^(?:\W*S?(?<season>(?<!\d+)\d{1,2}(?!\d+))(?:(?:[ex]){1,2}(?<episode>\d{1,2}(?!\d+)))+){2,}\W?(?!\\)",
|
|
|
|
|
RegexOptions.IgnoreCase | RegexOptions.Compiled),
|
|
|
|
|
|
|
|
|
|
//Multi-episode Repeated (S01E05 - S01E06, 1x05 - 1x06, etc)
|
|
|
|
|
new Regex(@"^(?<title>.+?)(?:\W+S?(?<season>(?<!\d+)\d{1,2}(?!\d+))(?:(?:[ex]){1,2}(?<episode>\d{1,2}(?!\d+)))+){2,}\W?(?!\\)",
|
|
|
|
|
RegexOptions.IgnoreCase | RegexOptions.Compiled),
|
|
|
|
|
|
|
|
|
|
//Episodes without a title, Single (S01E05, 1x05) AND Multi (S01E04E05, 1x04x05, etc)
|
2012-12-21 02:38:54 +01:00
|
|
|
|
new Regex(@"^(?:S?(?<season>(?<!\d+)\d{1,2}(?!\d+))(?:(?:\-|[ex]|\W[ex]){1,2}(?<episode>\d{2}(?!\d+)))+)\W?(?!\\)",
|
2012-08-03 09:01:34 +02:00
|
|
|
|
RegexOptions.IgnoreCase | RegexOptions.Compiled),
|
|
|
|
|
|
|
|
|
|
//Episodes with a title, Single episodes (S01E05, 1x05, etc) & Multi-episode (S01E05E06, S01E05-06, S01E05 E06, etc)
|
|
|
|
|
new Regex(@"^(?<title>.+?)(?:\W+S?(?<season>(?<!\d+)\d{1,2}(?!\d+))(?:(?:\-|[ex]|\W[ex]){1,2}(?<episode>\d{2}(?!\d+)))+)\W?(?!\\)",
|
|
|
|
|
RegexOptions.IgnoreCase | RegexOptions.Compiled),
|
|
|
|
|
|
|
|
|
|
//Episodes over 99 (3-digits or more) (S01E105, S01E105E106, etc)
|
|
|
|
|
new Regex(@"^(?<title>.*?)(?:\W?S?(?<season>(?<!\d+)\d{1,2}(?!\d+))(?:(?:\-|[ex]){1,2}(?<episode>\d+))+)+\W?(?!\\)",
|
|
|
|
|
RegexOptions.IgnoreCase | RegexOptions.Compiled),
|
|
|
|
|
|
|
|
|
|
new Regex(@"^(?:S?(?<season>(?<!\d+)(?:\d{1,2}|\d{4})(?!\d+))(?:(?:\-|[ex]|\W[ex])(?<episode>\d{2}(?!\d+)))+\W*)+\W?(?!\\)",
|
|
|
|
|
RegexOptions.IgnoreCase | RegexOptions.Compiled),
|
|
|
|
|
|
|
|
|
|
//Episodes with a title, Single episodes (S01E05, 1x05, etc) & Multi-episode (S01E05E06, S01E05-06, S01E05 E06, etc)
|
|
|
|
|
new Regex(@"^(?<title>.+?)(?:\W+S?(?<season>(?<!\d+)(?:\d{1,2}|\d{4})(?!\d+))(?:(?:\-|[ex]|\W[ex]){1,2}(?<episode>\d{2}(?!\d+)))+)\W?(?!\\)",
|
|
|
|
|
RegexOptions.IgnoreCase | RegexOptions.Compiled),
|
|
|
|
|
|
|
|
|
|
//Supports 103/113 naming
|
|
|
|
|
new Regex(@"^(?<title>.+?)?(?:\W?(?<season>(?<!\d+)\d{1})(?<episode>\d{2}(?!p|i|\d+)))+\W?(?!\\)",
|
|
|
|
|
RegexOptions.IgnoreCase | RegexOptions.Compiled),
|
|
|
|
|
|
2013-04-08 00:40:13 +02:00
|
|
|
|
//Mini-Series, treated as season 1, episodes are labelled as Part01, Part 01, Part.1
|
2012-08-03 09:01:34 +02:00
|
|
|
|
new Regex(@"^(?<title>.+?)(?:\W+(?:(?:Part\W?|(?<!\d+\W+)e)(?<episode>\d{1,2}(?!\d+)))+)\W?(?!\\)",
|
|
|
|
|
RegexOptions.IgnoreCase | RegexOptions.Compiled),
|
|
|
|
|
|
|
|
|
|
//Supports 1103/1113 naming
|
|
|
|
|
new Regex(@"^(?<title>.+?)?(?:\W?(?<season>(?<!\d+|\(|\[)\d{2})(?<episode>\d{2}(?!p|i|\d+|\)|\])))+\W?(?!\\)",
|
|
|
|
|
RegexOptions.IgnoreCase | RegexOptions.Compiled),
|
|
|
|
|
|
|
|
|
|
//Supports Season only releases
|
|
|
|
|
new Regex(@"^(?<title>.+?)\W(?:S|Season)\W?(?<season>\d{1,2}(?!\d+))\W?(?<extras>EXTRAS|SUBPACK)?(?!\\)",
|
|
|
|
|
RegexOptions.IgnoreCase | RegexOptions.Compiled)
|
|
|
|
|
};
|
|
|
|
|
|
2013-01-06 22:13:46 +01:00
|
|
|
|
private static readonly Regex NormalizeRegex = new Regex(@"((^|\W)(a|an|the|and|or|of)($|\W|_))|\W|_|(?:(?<=[^0-9]+)|\b)(?!(?:19\d{2}|20\d{2}))\d+(?=[^0-9ip]+|\b)",
|
2012-08-03 09:01:34 +02:00
|
|
|
|
RegexOptions.IgnoreCase | RegexOptions.Compiled);
|
|
|
|
|
|
|
|
|
|
private static readonly Regex SimpleTitleRegex = new Regex(@"480[i|p]|720[i|p]|1080[i|p]|[x|h|x\s|h\s]264|DD\W?5\W1|\<|\>|\?|\*|\:|\||""",
|
|
|
|
|
RegexOptions.IgnoreCase | RegexOptions.Compiled);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-10-15 07:52:12 +02:00
|
|
|
|
private static readonly Regex MultiPartCleanupRegex = new Regex(@"\(\d+\)$", RegexOptions.Compiled);
|
|
|
|
|
|
2012-12-31 20:27:45 +01:00
|
|
|
|
private static readonly Regex LanguageRegex = new Regex(@"(?:\W|_)(?<italian>ita|italian)|(?<german>german\b)|(?<flemish>flemish)|(?<greek>greek)(?:\W|_)", RegexOptions.IgnoreCase | RegexOptions.Compiled);
|
|
|
|
|
|
2013-04-08 00:40:13 +02:00
|
|
|
|
public static FileNameParseResult ParsePath(string path)
|
2012-08-03 09:01:34 +02:00
|
|
|
|
{
|
|
|
|
|
var fileInfo = new FileInfo(path);
|
|
|
|
|
|
2013-04-07 21:01:24 +02:00
|
|
|
|
var result = ParseTitle<FileNameParseResult>(fileInfo.Name);
|
2012-08-03 09:01:34 +02:00
|
|
|
|
|
|
|
|
|
if (result == null)
|
|
|
|
|
{
|
|
|
|
|
Logger.Trace("Attempting to parse episode info using full path. {0}", fileInfo.FullName);
|
2013-04-07 21:01:24 +02:00
|
|
|
|
result = ParseTitle<FileNameParseResult>(fileInfo.FullName);
|
2012-08-03 09:01:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (result != null)
|
|
|
|
|
{
|
|
|
|
|
result.OriginalString = path;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Logger.Warn("Unable to parse episode info from path {0}", path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-08 00:40:13 +02:00
|
|
|
|
public static T ParseTitle<T>(string title) where T : ParseResult, new()
|
2012-08-03 09:01:34 +02:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Logger.Trace("Parsing string '{0}'", title);
|
|
|
|
|
var simpleTitle = SimpleTitleRegex.Replace(title, String.Empty);
|
|
|
|
|
|
|
|
|
|
foreach (var regex in ReportTitleRegex)
|
|
|
|
|
{
|
|
|
|
|
var match = regex.Matches(simpleTitle);
|
|
|
|
|
|
|
|
|
|
if (match.Count != 0)
|
|
|
|
|
{
|
2013-04-07 21:01:24 +02:00
|
|
|
|
var result = ParseMatchCollection<T>(match);
|
2012-08-03 09:01:34 +02:00
|
|
|
|
if (result != null)
|
|
|
|
|
{
|
|
|
|
|
//Check if episode is in the future (most likley a parse error)
|
|
|
|
|
if (result.AirDate > DateTime.Now.AddDays(1).Date)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
result.Language = ParseLanguage(title);
|
|
|
|
|
result.Quality = ParseQuality(title);
|
|
|
|
|
result.OriginalString = title;
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
2012-12-21 00:29:14 +01:00
|
|
|
|
if (!title.ToLower().Contains("password") && !title.ToLower().Contains("yenc"))
|
|
|
|
|
Logger.ErrorException("An error has occurred while trying to parse " + title, e);
|
2012-08-03 09:01:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Logger.Trace("Unable to parse {0}", title);
|
|
|
|
|
ReportingService.ReportParseError(title);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-07 21:01:24 +02:00
|
|
|
|
private static T ParseMatchCollection<T>(MatchCollection matchCollection) where T : ParseResult, new()
|
2012-08-03 09:01:34 +02:00
|
|
|
|
{
|
2012-12-20 07:49:13 +01:00
|
|
|
|
var seriesName = matchCollection[0].Groups["title"].Value.Replace('.', ' ');
|
2012-08-03 09:01:34 +02:00
|
|
|
|
|
2013-04-08 00:40:13 +02:00
|
|
|
|
int airYear;
|
|
|
|
|
Int32.TryParse(matchCollection[0].Groups["airyear"].Value, out airYear);
|
2012-08-03 09:01:34 +02:00
|
|
|
|
|
2013-04-08 00:40:13 +02:00
|
|
|
|
T result;
|
2012-08-03 09:01:34 +02:00
|
|
|
|
|
2013-04-08 00:40:13 +02:00
|
|
|
|
if (airYear < 1900)
|
2012-08-03 09:01:34 +02:00
|
|
|
|
{
|
|
|
|
|
var seasons = new List<int>();
|
|
|
|
|
|
|
|
|
|
foreach (Capture seasonCapture in matchCollection[0].Groups["season"].Captures)
|
|
|
|
|
{
|
|
|
|
|
int parsedSeason;
|
|
|
|
|
if (Int32.TryParse(seasonCapture.Value, out parsedSeason))
|
|
|
|
|
seasons.Add(parsedSeason);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//If no season was found it should be treated as a mini series and season 1
|
|
|
|
|
if (seasons.Count == 0)
|
|
|
|
|
seasons.Add(1);
|
|
|
|
|
|
|
|
|
|
//If more than 1 season was parsed go to the next REGEX (A multi-season release is unlikely)
|
|
|
|
|
if (seasons.Distinct().Count() > 1)
|
|
|
|
|
return null;
|
|
|
|
|
|
2013-04-08 00:40:13 +02:00
|
|
|
|
result = new T
|
2012-08-03 09:01:34 +02:00
|
|
|
|
{
|
|
|
|
|
SeasonNumber = seasons.First(),
|
|
|
|
|
EpisodeNumbers = new List<int>()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
foreach (Match matchGroup in matchCollection)
|
|
|
|
|
{
|
|
|
|
|
var episodeCaptures = matchGroup.Groups["episode"].Captures.Cast<Capture>().ToList();
|
|
|
|
|
|
|
|
|
|
//Allows use to return a list of 0 episodes (We can handle that as a full season release)
|
|
|
|
|
if (episodeCaptures.Any())
|
|
|
|
|
{
|
|
|
|
|
var first = Convert.ToInt32(episodeCaptures.First().Value);
|
|
|
|
|
var last = Convert.ToInt32(episodeCaptures.Last().Value);
|
2013-04-08 00:40:13 +02:00
|
|
|
|
result.EpisodeNumbers = Enumerable.Range(first, last - first + 1).ToList();
|
2012-08-03 09:01:34 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//Check to see if this is an "Extras" or "SUBPACK" release, if it is, return NULL
|
|
|
|
|
//Todo: Set a "Extras" flag in EpisodeParseResult if we want to download them ever
|
|
|
|
|
if (!String.IsNullOrWhiteSpace(matchCollection[0].Groups["extras"].Value))
|
|
|
|
|
return null;
|
|
|
|
|
|
2013-04-08 00:40:13 +02:00
|
|
|
|
result.FullSeason = true;
|
2012-08-03 09:01:34 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//Try to Parse as a daily show
|
|
|
|
|
var airmonth = Convert.ToInt32(matchCollection[0].Groups["airmonth"].Value);
|
|
|
|
|
var airday = Convert.ToInt32(matchCollection[0].Groups["airday"].Value);
|
|
|
|
|
|
|
|
|
|
//Swap day and month if month is bigger than 12 (scene fail)
|
|
|
|
|
if (airmonth > 12)
|
|
|
|
|
{
|
|
|
|
|
var tempDay = airday;
|
|
|
|
|
airday = airmonth;
|
|
|
|
|
airmonth = tempDay;
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-08 00:40:13 +02:00
|
|
|
|
result = new T
|
2013-04-07 21:01:24 +02:00
|
|
|
|
{
|
2013-04-08 00:40:13 +02:00
|
|
|
|
AirDate = new DateTime(airYear, airmonth, airday).Date,
|
2012-08-03 09:01:34 +02:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-08 00:40:13 +02:00
|
|
|
|
result.SeriesTitle = seriesName;
|
2012-08-03 09:01:34 +02:00
|
|
|
|
|
2013-04-08 00:40:13 +02:00
|
|
|
|
Logger.Trace("Episode Parsed. {0}", result);
|
2012-08-03 09:01:34 +02:00
|
|
|
|
|
2013-04-08 00:40:13 +02:00
|
|
|
|
return result;
|
2012-08-03 09:01:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string ParseSeriesName(string title)
|
|
|
|
|
{
|
|
|
|
|
Logger.Trace("Parsing string '{0}'", title);
|
|
|
|
|
|
2013-04-07 21:01:24 +02:00
|
|
|
|
var parseResult = ParseTitle<ParseResult>(title);
|
2012-08-03 09:01:34 +02:00
|
|
|
|
|
2013-04-07 21:01:24 +02:00
|
|
|
|
if (parseResult == null)
|
2012-11-26 08:13:55 +01:00
|
|
|
|
return NormalizeTitle(title);
|
2012-08-03 09:01:34 +02:00
|
|
|
|
|
2012-11-26 08:13:55 +01:00
|
|
|
|
return parseResult.CleanTitle;
|
2012-08-03 09:01:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-04-08 00:40:13 +02:00
|
|
|
|
private static QualityModel ParseQuality(string name)
|
2012-08-03 09:01:34 +02:00
|
|
|
|
{
|
|
|
|
|
Logger.Trace("Trying to parse quality for {0}", name);
|
|
|
|
|
|
|
|
|
|
name = name.Trim();
|
|
|
|
|
var normalizedName = NormalizeTitle(name);
|
2013-02-27 04:19:22 +01:00
|
|
|
|
var result = new QualityModel { Quality = Quality.Unknown };
|
2012-08-03 09:01:34 +02:00
|
|
|
|
result.Proper = (normalizedName.Contains("proper") || normalizedName.Contains("repack"));
|
|
|
|
|
|
|
|
|
|
if (normalizedName.Contains("dvd") || normalizedName.Contains("bdrip") || normalizedName.Contains("brrip"))
|
|
|
|
|
{
|
2013-02-27 04:19:22 +01:00
|
|
|
|
result.Quality = Quality.DVD;
|
2012-08-03 09:01:34 +02:00
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (normalizedName.Contains("xvid") || normalizedName.Contains("divx") || normalizedName.Contains("dsr"))
|
|
|
|
|
{
|
|
|
|
|
if (normalizedName.Contains("bluray"))
|
|
|
|
|
{
|
2013-02-27 04:19:22 +01:00
|
|
|
|
result.Quality = Quality.DVD;
|
2012-08-03 09:01:34 +02:00
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-27 04:19:22 +01:00
|
|
|
|
result.Quality = Quality.SDTV;
|
2012-08-03 09:01:34 +02:00
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (normalizedName.Contains("bluray"))
|
|
|
|
|
{
|
|
|
|
|
if (normalizedName.Contains("720p"))
|
|
|
|
|
{
|
2013-02-27 04:19:22 +01:00
|
|
|
|
result.Quality = Quality.Bluray720p;
|
2012-08-03 09:01:34 +02:00
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (normalizedName.Contains("1080p"))
|
|
|
|
|
{
|
2013-02-27 04:19:22 +01:00
|
|
|
|
result.Quality = Quality.Bluray1080p;
|
2012-08-03 09:01:34 +02:00
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-27 04:19:22 +01:00
|
|
|
|
result.Quality = Quality.Bluray720p;
|
2012-08-03 09:01:34 +02:00
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
if (normalizedName.Contains("webdl"))
|
|
|
|
|
{
|
2012-10-15 06:30:07 +02:00
|
|
|
|
if (normalizedName.Contains("1080p"))
|
|
|
|
|
{
|
2013-02-27 04:19:22 +01:00
|
|
|
|
result.Quality = Quality.WEBDL1080p;
|
2012-10-15 06:30:07 +02:00
|
|
|
|
return result;
|
|
|
|
|
}
|
2012-12-16 10:08:02 +01:00
|
|
|
|
|
|
|
|
|
if (normalizedName.Contains("720p"))
|
|
|
|
|
{
|
2013-02-27 04:19:22 +01:00
|
|
|
|
result.Quality = Quality.WEBDL720p;
|
2012-12-16 10:08:02 +01:00
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-07 21:01:24 +02:00
|
|
|
|
if (name.Contains("[WEBDL]"))
|
2012-12-16 10:08:02 +01:00
|
|
|
|
{
|
2013-02-27 04:19:22 +01:00
|
|
|
|
result.Quality = Quality.WEBDL720p;
|
2012-12-16 10:08:02 +01:00
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-27 04:19:22 +01:00
|
|
|
|
result.Quality = Quality.WEBDL480p;
|
2012-08-03 09:01:34 +02:00
|
|
|
|
return result;
|
|
|
|
|
}
|
2013-01-01 04:45:57 +01:00
|
|
|
|
|
2013-01-09 09:15:06 +01:00
|
|
|
|
if (normalizedName.Contains("trollhd") || normalizedName.Contains("rawhd"))
|
|
|
|
|
{
|
2013-02-27 04:19:22 +01:00
|
|
|
|
result.Quality = Quality.RAWHD;
|
2013-01-09 09:15:06 +01:00
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-03 09:01:34 +02:00
|
|
|
|
if (normalizedName.Contains("x264") || normalizedName.Contains("h264") || normalizedName.Contains("720p"))
|
|
|
|
|
{
|
2013-04-07 21:01:24 +02:00
|
|
|
|
if (normalizedName.Contains("1080p"))
|
2013-01-01 04:45:57 +01:00
|
|
|
|
{
|
2013-02-27 04:19:22 +01:00
|
|
|
|
result.Quality = Quality.HDTV1080p;
|
2013-01-01 04:45:57 +01:00
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-27 04:19:22 +01:00
|
|
|
|
result.Quality = Quality.HDTV720p;
|
2012-08-03 09:01:34 +02:00
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
//Based on extension
|
|
|
|
|
|
2013-02-27 04:19:22 +01:00
|
|
|
|
if (result.Quality == Quality.Unknown)
|
2012-08-03 09:01:34 +02:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
switch (Path.GetExtension(name).ToLower())
|
|
|
|
|
{
|
|
|
|
|
case ".avi":
|
|
|
|
|
case ".xvid":
|
|
|
|
|
case ".divx":
|
|
|
|
|
case ".wmv":
|
|
|
|
|
case ".mp4":
|
|
|
|
|
case ".mpg":
|
|
|
|
|
case ".mpeg":
|
|
|
|
|
case ".mov":
|
|
|
|
|
case ".rm":
|
|
|
|
|
case ".rmvb":
|
|
|
|
|
case ".flv":
|
|
|
|
|
case ".dvr-ms":
|
|
|
|
|
case ".ogm":
|
|
|
|
|
case ".strm":
|
|
|
|
|
{
|
2013-02-27 04:19:22 +01:00
|
|
|
|
result.Quality = Quality.SDTV;
|
2012-08-03 09:01:34 +02:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case ".mkv":
|
|
|
|
|
case ".ts":
|
|
|
|
|
{
|
2013-02-27 04:19:22 +01:00
|
|
|
|
result.Quality = Quality.HDTV720p;
|
2012-08-03 09:01:34 +02:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (ArgumentException)
|
|
|
|
|
{
|
|
|
|
|
//Swallow exception for cases where string contains illegal
|
|
|
|
|
//path characters.
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (name.Contains("[HDTV]"))
|
|
|
|
|
{
|
2013-02-27 04:19:22 +01:00
|
|
|
|
result.Quality = Quality.HDTV720p;
|
2013-01-01 04:45:57 +01:00
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (normalizedName.Contains("hdtv") && normalizedName.Contains("1080p"))
|
|
|
|
|
{
|
2013-02-27 04:19:22 +01:00
|
|
|
|
result.Quality = Quality.HDTV1080p;
|
2012-08-03 09:01:34 +02:00
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((normalizedName.Contains("sdtv") || normalizedName.Contains("pdtv") ||
|
2013-02-27 04:19:22 +01:00
|
|
|
|
(result.Quality == Quality.Unknown && normalizedName.Contains("hdtv"))) &&
|
2012-08-03 09:01:34 +02:00
|
|
|
|
!normalizedName.Contains("mpeg"))
|
|
|
|
|
{
|
2013-02-27 04:19:22 +01:00
|
|
|
|
result.Quality = Quality.SDTV;
|
2012-08-03 09:01:34 +02:00
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-08 00:40:13 +02:00
|
|
|
|
private static LanguageType ParseLanguage(string title)
|
2012-08-03 09:01:34 +02:00
|
|
|
|
{
|
|
|
|
|
var lowerTitle = title.ToLower();
|
|
|
|
|
|
|
|
|
|
if (lowerTitle.Contains("english"))
|
|
|
|
|
return LanguageType.English;
|
|
|
|
|
|
|
|
|
|
if (lowerTitle.Contains("french"))
|
|
|
|
|
return LanguageType.French;
|
|
|
|
|
|
|
|
|
|
if (lowerTitle.Contains("spanish"))
|
|
|
|
|
return LanguageType.Spanish;
|
|
|
|
|
|
|
|
|
|
if (lowerTitle.Contains("danish"))
|
|
|
|
|
return LanguageType.Danish;
|
|
|
|
|
|
|
|
|
|
if (lowerTitle.Contains("dutch"))
|
|
|
|
|
return LanguageType.Dutch;
|
|
|
|
|
|
|
|
|
|
if (lowerTitle.Contains("japanese"))
|
|
|
|
|
return LanguageType.Japanese;
|
|
|
|
|
|
|
|
|
|
if (lowerTitle.Contains("cantonese"))
|
|
|
|
|
return LanguageType.Cantonese;
|
|
|
|
|
|
|
|
|
|
if (lowerTitle.Contains("mandarin"))
|
|
|
|
|
return LanguageType.Mandarin;
|
|
|
|
|
|
|
|
|
|
if (lowerTitle.Contains("korean"))
|
|
|
|
|
return LanguageType.Korean;
|
|
|
|
|
|
|
|
|
|
if (lowerTitle.Contains("russian"))
|
|
|
|
|
return LanguageType.Russian;
|
|
|
|
|
|
|
|
|
|
if (lowerTitle.Contains("polish"))
|
|
|
|
|
return LanguageType.Polish;
|
|
|
|
|
|
|
|
|
|
if (lowerTitle.Contains("vietnamese"))
|
|
|
|
|
return LanguageType.Vietnamese;
|
|
|
|
|
|
|
|
|
|
if (lowerTitle.Contains("swedish"))
|
|
|
|
|
return LanguageType.Swedish;
|
|
|
|
|
|
|
|
|
|
if (lowerTitle.Contains("norwegian"))
|
|
|
|
|
return LanguageType.Norwegian;
|
|
|
|
|
|
|
|
|
|
if (lowerTitle.Contains("finnish"))
|
|
|
|
|
return LanguageType.Finnish;
|
|
|
|
|
|
|
|
|
|
if (lowerTitle.Contains("turkish"))
|
|
|
|
|
return LanguageType.Turkish;
|
|
|
|
|
|
|
|
|
|
if (lowerTitle.Contains("portuguese"))
|
|
|
|
|
return LanguageType.Portuguese;
|
|
|
|
|
|
2012-12-31 20:27:45 +01:00
|
|
|
|
var match = LanguageRegex.Match(title);
|
|
|
|
|
|
|
|
|
|
if (match.Groups["italian"].Captures.Cast<Capture>().Any())
|
|
|
|
|
return LanguageType.Italian;
|
|
|
|
|
|
|
|
|
|
if (match.Groups["german"].Captures.Cast<Capture>().Any())
|
|
|
|
|
return LanguageType.German;
|
|
|
|
|
|
|
|
|
|
if (match.Groups["flemish"].Captures.Cast<Capture>().Any())
|
|
|
|
|
return LanguageType.Flemish;
|
|
|
|
|
|
|
|
|
|
if (match.Groups["greek"].Captures.Cast<Capture>().Any())
|
|
|
|
|
return LanguageType.Greek;
|
|
|
|
|
|
2012-08-03 09:01:34 +02:00
|
|
|
|
return LanguageType.English;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-06 08:33:07 +02:00
|
|
|
|
|
2012-08-03 09:01:34 +02:00
|
|
|
|
|
|
|
|
|
public static string NormalizeTitle(string title)
|
|
|
|
|
{
|
|
|
|
|
long number = 0;
|
|
|
|
|
|
|
|
|
|
//If Title only contains numbers return it as is.
|
|
|
|
|
if (Int64.TryParse(title, out number))
|
|
|
|
|
return title;
|
|
|
|
|
|
|
|
|
|
return NormalizeRegex.Replace(title, String.Empty).ToLower();
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-08 00:40:13 +02:00
|
|
|
|
public static string CleanupEpisodeTitle(string title)
|
2012-10-15 07:52:12 +02:00
|
|
|
|
{
|
|
|
|
|
//this will remove (1),(2) from the end of multi part episodes.
|
|
|
|
|
return MultiPartCleanupRegex.Replace(title, string.Empty).Trim();
|
|
|
|
|
}
|
2012-08-03 09:01:34 +02:00
|
|
|
|
}
|
|
|
|
|
}
|