2013-04-07 21:01:24 +02:00
|
|
|
|
using System;
|
2012-08-03 09:01:34 +02:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
using NLog;
|
|
|
|
|
using NzbDrone.Common;
|
2013-04-15 03:41:39 +02:00
|
|
|
|
using NzbDrone.Core.Parser.Model;
|
2013-04-07 21:01:24 +02:00
|
|
|
|
using NzbDrone.Core.Qualities;
|
|
|
|
|
using NzbDrone.Core.Tv;
|
2012-08-03 09:01:34 +02:00
|
|
|
|
|
2013-04-15 03:41:39 +02:00
|
|
|
|
namespace NzbDrone.Core.Parser
|
2012-08-03 09:01:34 +02:00
|
|
|
|
{
|
|
|
|
|
public static class Parser
|
|
|
|
|
{
|
|
|
|
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
|
|
|
|
|
|
|
|
|
private static readonly Regex[] ReportTitleRegex = new[]
|
2013-04-15 03:41:39 +02:00
|
|
|
|
{
|
|
|
|
|
//Episodes with airdate
|
2013-04-29 05:11:43 +02:00
|
|
|
|
new Regex(@"^(?<title>.+?)?\W*(?<airyear>\d{4})\W+(?<airmonth>[0-1][0-9])\W+(?<airday>[0-3][0-9])(\W+|_|$)(?!\\)",
|
2013-04-15 03:41:39 +02:00
|
|
|
|
RegexOptions.IgnoreCase | RegexOptions.Compiled),
|
2012-08-03 09:01:34 +02:00
|
|
|
|
|
2013-04-15 03:41:39 +02:00
|
|
|
|
//Multi-Part episodes without a title (S01E05.S01E06)
|
2013-08-18 07:40:39 +02:00
|
|
|
|
new Regex(@"^(?:\W*S?(?<season>(?<!\d+)\d{1,2}(?!\d+))(?:(?:[ex]){1,2}(?<episode>\d{1,3}(?!\d+)))+){2,}(\W+|_|$)(?!\\)",
|
2013-04-15 03:41:39 +02:00
|
|
|
|
RegexOptions.IgnoreCase | RegexOptions.Compiled),
|
2012-08-03 09:01:34 +02:00
|
|
|
|
|
2013-04-15 03:41:39 +02:00
|
|
|
|
//Multi-episode Repeated (S01E05 - S01E06, 1x05 - 1x06, etc)
|
2013-08-18 07:40:39 +02:00
|
|
|
|
new Regex(@"^(?<title>.+?)(?:(\W|_)+S?(?<season>(?<!\d+)\d{1,2}(?!\d+))(?:(?:[ex]){1,2}(?<episode>\d{1,3}(?!\d+)))+){2,}(\W+|_|$)(?!\\)",
|
2013-04-15 03:41:39 +02:00
|
|
|
|
RegexOptions.IgnoreCase | RegexOptions.Compiled),
|
2012-08-03 09:01:34 +02:00
|
|
|
|
|
2013-04-15 03:41:39 +02:00
|
|
|
|
//Episodes without a title, Single (S01E05, 1x05) AND Multi (S01E04E05, 1x04x05, etc)
|
2013-08-18 07:40:39 +02:00
|
|
|
|
new Regex(@"^(?:S?(?<season>(?<!\d+)\d{1,2}(?!\d+))(?:(?:\-|[ex]|\W[ex]|_){1,2}(?<episode>\d{2,3}(?!\d+)))+)(\W+|_|$)(?!\\)",
|
2013-04-15 03:41:39 +02:00
|
|
|
|
RegexOptions.IgnoreCase | RegexOptions.Compiled),
|
2012-08-03 09:01:34 +02:00
|
|
|
|
|
2013-04-15 03:41:39 +02:00
|
|
|
|
//Episodes with a title, Single episodes (S01E05, 1x05, etc) & Multi-episode (S01E05E06, S01E05-06, S01E05 E06, etc)
|
2013-08-18 07:40:39 +02:00
|
|
|
|
new Regex(@"^(?<title>.+?)(?:(\W|_)+S?(?<season>(?<!\d+)\d{1,2}(?!\d+))(?:(?:\-|[ex]|\W[ex]|_){1,2}(?<episode>\d{2,3}(?!\d+)))+)\W?(?!\\)",
|
2013-04-15 03:41:39 +02:00
|
|
|
|
RegexOptions.IgnoreCase | RegexOptions.Compiled),
|
2012-08-03 09:01:34 +02:00
|
|
|
|
|
2013-04-15 03:41:39 +02:00
|
|
|
|
//Episodes with a title, Single episodes (S01E05, 1x05, etc) & Multi-episode (S01E05E06, S01E05-06, S01E05 E06, etc)
|
2013-08-18 07:40:39 +02:00
|
|
|
|
new Regex(@"^(?<title>.+?)(?:\W+S?(?<season>(?<!\d+)(?:\d{1,2}|\d{4})(?!\d+))(?:(?:\-|[ex]|\W[ex]){1,2}(?<episode>\d{2,3}(?!\d+)))+)(\W+|_|$)(?!\\)",
|
2013-04-29 05:11:43 +02:00
|
|
|
|
RegexOptions.IgnoreCase | RegexOptions.Compiled),
|
|
|
|
|
|
|
|
|
|
//Episodes with single digit episode number (S01E1, S01E5E6, etc)
|
|
|
|
|
new Regex(@"^(?<title>.*?)(?:\W?S?(?<season>(?<!\d+)\d{1,2}(?!\d+))(?:(?:\-|[ex]){1,2}(?<episode>\d{1}))+)+(\W+|_|$)(?!\\)",
|
2013-04-15 03:41:39 +02:00
|
|
|
|
RegexOptions.IgnoreCase | RegexOptions.Compiled),
|
2012-08-03 09:01:34 +02:00
|
|
|
|
|
2013-04-15 03:41:39 +02:00
|
|
|
|
//Supports 103/113 naming
|
2013-04-29 05:11:43 +02:00
|
|
|
|
new Regex(@"^(?<title>.+?)?(?:\W?(?<season>(?<!\d+)\d{1})(?<episode>\d{2}(?!p|i|\d+)))+(\W+|_|$)(?!\\)",
|
2013-04-15 03:41:39 +02:00
|
|
|
|
RegexOptions.IgnoreCase | RegexOptions.Compiled),
|
2012-08-03 09:01:34 +02:00
|
|
|
|
|
2013-04-15 03:41:39 +02:00
|
|
|
|
//Mini-Series, treated as season 1, episodes are labelled as Part01, Part 01, Part.1
|
2013-04-29 05:11:43 +02:00
|
|
|
|
new Regex(@"^(?<title>.+?)(?:\W+(?:(?:Part\W?|(?<!\d+\W+)e)(?<episode>\d{1,2}(?!\d+)))+)(\W+|_|$)(?!\\)",
|
2013-04-15 03:41:39 +02:00
|
|
|
|
RegexOptions.IgnoreCase | RegexOptions.Compiled),
|
2012-08-03 09:01:34 +02:00
|
|
|
|
|
2013-04-15 03:41:39 +02:00
|
|
|
|
//Supports 1103/1113 naming
|
2013-04-29 05:11:43 +02:00
|
|
|
|
new Regex(@"^(?<title>.+?)?(?:\W?(?<season>(?<!\d+|\(|\[)\d{2})(?<episode>\d{2}(?!p|i|\d+|\)|\]|\W\d+)))+(\W+|_|$)(?!\\)",
|
2013-04-15 03:41:39 +02:00
|
|
|
|
RegexOptions.IgnoreCase | RegexOptions.Compiled),
|
2012-08-03 09:01:34 +02:00
|
|
|
|
|
2013-06-19 17:44:41 +02:00
|
|
|
|
//Supports Season 01 Episode 03
|
|
|
|
|
new Regex(@"(?:.*(?:\""|^))(?<title>.*?)(?:\W?Season\W?)(?<season>(?<!\d+)\d{1,2}(?!\d+))(?:\W|_)(?:Episode\W)(?<episode>(?<!\d+)\d{1,2}(?!\d+))",
|
|
|
|
|
RegexOptions.IgnoreCase | RegexOptions.Compiled),
|
|
|
|
|
|
2013-04-15 03:41:39 +02:00
|
|
|
|
//Supports Season only releases
|
2013-04-29 05:11:43 +02:00
|
|
|
|
new Regex(@"^(?<title>.+?)\W(?:S|Season)\W?(?<season>\d{1,2}(?!\d+))(\W+|_|$)(?<extras>EXTRAS|SUBPACK)?(?!\\)",
|
2013-04-15 03:41:39 +02:00
|
|
|
|
RegexOptions.IgnoreCase | RegexOptions.Compiled)
|
|
|
|
|
};
|
2012-08-03 09:01:34 +02:00
|
|
|
|
|
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);
|
|
|
|
|
|
2013-06-19 17:44:41 +02:00
|
|
|
|
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|\<|\>|\?|\*|\:|\|",
|
2013-04-15 03:41:39 +02:00
|
|
|
|
RegexOptions.IgnoreCase | RegexOptions.Compiled);
|
2012-08-03 09:01:34 +02:00
|
|
|
|
|
2012-10-15 07:52:12 +02:00
|
|
|
|
private static readonly Regex MultiPartCleanupRegex = new Regex(@"\(\d+\)$", RegexOptions.Compiled);
|
|
|
|
|
|
2013-09-01 05:01:46 +02:00
|
|
|
|
private static readonly Regex LanguageRegex = new Regex(@"(?:\W|_)(?<italian>ita|italian)|(?<german>german\b)|(?<flemish>flemish)|(?<greek>greek)|(?<french>(?:\W|_)FR)(?:\W|_)",
|
|
|
|
|
RegexOptions.IgnoreCase | RegexOptions.Compiled);
|
2012-12-31 20:27:45 +01:00
|
|
|
|
|
2013-04-15 03:41:39 +02:00
|
|
|
|
public static ParsedEpisodeInfo ParsePath(string path)
|
2012-08-03 09:01:34 +02:00
|
|
|
|
{
|
|
|
|
|
var fileInfo = new FileInfo(path);
|
|
|
|
|
|
2013-04-15 03:41:39 +02:00
|
|
|
|
var result = ParseTitle(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-15 03:41:39 +02:00
|
|
|
|
result = ParseTitle(fileInfo.FullName);
|
2012-08-03 09:01:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-04-28 21:46:13 +02:00
|
|
|
|
if (result == null)
|
2012-08-03 09:01:34 +02:00
|
|
|
|
{
|
|
|
|
|
Logger.Warn("Unable to parse episode info from path {0}", path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-15 03:41:39 +02:00
|
|
|
|
public static ParsedEpisodeInfo ParseTitle(string title)
|
2012-08-03 09:01:34 +02:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2013-04-29 05:11:43 +02:00
|
|
|
|
if (!ValidateBeforeParsing(title)) return null;
|
|
|
|
|
|
2012-08-03 09:01:34 +02:00
|
|
|
|
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-15 03:41:39 +02:00
|
|
|
|
var result = ParseMatchCollection(match);
|
2012-08-03 09:01:34 +02:00
|
|
|
|
if (result != null)
|
|
|
|
|
{
|
2013-06-09 22:50:57 +02:00
|
|
|
|
//Check if episode is in the future (most likely a parse error)
|
2013-04-29 05:11:43 +02:00
|
|
|
|
if (result.AirDate > DateTime.Now.AddDays(1).Date || result.AirDate < new DateTime(1970, 1, 1))
|
2012-08-03 09:01:34 +02:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
result.Language = ParseLanguage(title);
|
2013-09-01 04:44:55 +02:00
|
|
|
|
result.Quality = QualityParser.ParseQuality(title);
|
2012-08-03 09:01:34 +02:00
|
|
|
|
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);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-15 03:41:39 +02:00
|
|
|
|
private static ParsedEpisodeInfo ParseMatchCollection(MatchCollection matchCollection)
|
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-15 03:41:39 +02:00
|
|
|
|
ParsedEpisodeInfo 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-15 03:41:39 +02:00
|
|
|
|
result = new ParsedEpisodeInfo
|
|
|
|
|
{
|
|
|
|
|
SeasonNumber = seasons.First(),
|
2013-04-28 21:46:13 +02:00
|
|
|
|
EpisodeNumbers = new int[0],
|
2013-04-15 03:41:39 +02:00
|
|
|
|
};
|
2012-08-03 09:01:34 +02:00
|
|
|
|
|
|
|
|
|
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-07-02 21:51:16 +02:00
|
|
|
|
|
|
|
|
|
if (first > last)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var count = last - first + 1;
|
|
|
|
|
result.EpisodeNumbers = Enumerable.Range(first, count).ToArray();
|
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-15 03:41:39 +02:00
|
|
|
|
result = new ParsedEpisodeInfo
|
|
|
|
|
{
|
|
|
|
|
AirDate = new DateTime(airYear, airmonth, airday).Date,
|
|
|
|
|
};
|
2012-08-03 09:01:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-08 21:14:52 +02:00
|
|
|
|
result.SeriesTitle = CleanSeriesTitle(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-15 03:41:39 +02:00
|
|
|
|
var parseResult = ParseTitle(title);
|
2012-08-03 09:01:34 +02:00
|
|
|
|
|
2013-04-07 21:01:24 +02:00
|
|
|
|
if (parseResult == null)
|
2013-04-15 03:41:39 +02:00
|
|
|
|
{
|
2013-06-08 21:14:52 +02:00
|
|
|
|
return CleanSeriesTitle(title);
|
2013-04-15 03:41:39 +02:00
|
|
|
|
}
|
2012-08-03 09:01:34 +02:00
|
|
|
|
|
2013-04-15 03:41:39 +02:00
|
|
|
|
return parseResult.SeriesTitle;
|
2012-08-03 09:01:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-04-15 03:41:39 +02:00
|
|
|
|
private static Language ParseLanguage(string title)
|
2012-08-03 09:01:34 +02:00
|
|
|
|
{
|
|
|
|
|
var lowerTitle = title.ToLower();
|
|
|
|
|
|
|
|
|
|
if (lowerTitle.Contains("english"))
|
2013-04-15 03:41:39 +02:00
|
|
|
|
return Language.English;
|
2012-08-03 09:01:34 +02:00
|
|
|
|
|
|
|
|
|
if (lowerTitle.Contains("french"))
|
2013-04-15 03:41:39 +02:00
|
|
|
|
return Language.French;
|
2012-08-03 09:01:34 +02:00
|
|
|
|
|
|
|
|
|
if (lowerTitle.Contains("spanish"))
|
2013-04-15 03:41:39 +02:00
|
|
|
|
return Language.Spanish;
|
2012-08-03 09:01:34 +02:00
|
|
|
|
|
|
|
|
|
if (lowerTitle.Contains("danish"))
|
2013-04-15 03:41:39 +02:00
|
|
|
|
return Language.Danish;
|
2012-08-03 09:01:34 +02:00
|
|
|
|
|
|
|
|
|
if (lowerTitle.Contains("dutch"))
|
2013-04-15 03:41:39 +02:00
|
|
|
|
return Language.Dutch;
|
2012-08-03 09:01:34 +02:00
|
|
|
|
|
|
|
|
|
if (lowerTitle.Contains("japanese"))
|
2013-04-15 03:41:39 +02:00
|
|
|
|
return Language.Japanese;
|
2012-08-03 09:01:34 +02:00
|
|
|
|
|
|
|
|
|
if (lowerTitle.Contains("cantonese"))
|
2013-04-15 03:41:39 +02:00
|
|
|
|
return Language.Cantonese;
|
2012-08-03 09:01:34 +02:00
|
|
|
|
|
|
|
|
|
if (lowerTitle.Contains("mandarin"))
|
2013-04-15 03:41:39 +02:00
|
|
|
|
return Language.Mandarin;
|
2012-08-03 09:01:34 +02:00
|
|
|
|
|
|
|
|
|
if (lowerTitle.Contains("korean"))
|
2013-04-15 03:41:39 +02:00
|
|
|
|
return Language.Korean;
|
2012-08-03 09:01:34 +02:00
|
|
|
|
|
|
|
|
|
if (lowerTitle.Contains("russian"))
|
2013-04-15 03:41:39 +02:00
|
|
|
|
return Language.Russian;
|
2012-08-03 09:01:34 +02:00
|
|
|
|
|
|
|
|
|
if (lowerTitle.Contains("polish"))
|
2013-04-15 03:41:39 +02:00
|
|
|
|
return Language.Polish;
|
2012-08-03 09:01:34 +02:00
|
|
|
|
|
|
|
|
|
if (lowerTitle.Contains("vietnamese"))
|
2013-04-15 03:41:39 +02:00
|
|
|
|
return Language.Vietnamese;
|
2012-08-03 09:01:34 +02:00
|
|
|
|
|
|
|
|
|
if (lowerTitle.Contains("swedish"))
|
2013-04-15 03:41:39 +02:00
|
|
|
|
return Language.Swedish;
|
2012-08-03 09:01:34 +02:00
|
|
|
|
|
|
|
|
|
if (lowerTitle.Contains("norwegian"))
|
2013-04-15 03:41:39 +02:00
|
|
|
|
return Language.Norwegian;
|
2012-08-03 09:01:34 +02:00
|
|
|
|
|
|
|
|
|
if (lowerTitle.Contains("finnish"))
|
2013-04-15 03:41:39 +02:00
|
|
|
|
return Language.Finnish;
|
2012-08-03 09:01:34 +02:00
|
|
|
|
|
|
|
|
|
if (lowerTitle.Contains("turkish"))
|
2013-04-15 03:41:39 +02:00
|
|
|
|
return Language.Turkish;
|
2012-08-03 09:01:34 +02:00
|
|
|
|
|
|
|
|
|
if (lowerTitle.Contains("portuguese"))
|
2013-04-15 03:41:39 +02:00
|
|
|
|
return Language.Portuguese;
|
2012-08-03 09:01:34 +02:00
|
|
|
|
|
2013-07-17 02:51:05 +02:00
|
|
|
|
if (lowerTitle.Contains("nlsub"))
|
|
|
|
|
return Language.Norwegian;
|
|
|
|
|
|
2012-12-31 20:27:45 +01:00
|
|
|
|
var match = LanguageRegex.Match(title);
|
|
|
|
|
|
|
|
|
|
if (match.Groups["italian"].Captures.Cast<Capture>().Any())
|
2013-04-15 03:41:39 +02:00
|
|
|
|
return Language.Italian;
|
2012-12-31 20:27:45 +01:00
|
|
|
|
|
|
|
|
|
if (match.Groups["german"].Captures.Cast<Capture>().Any())
|
2013-04-15 03:41:39 +02:00
|
|
|
|
return Language.German;
|
2012-12-31 20:27:45 +01:00
|
|
|
|
|
|
|
|
|
if (match.Groups["flemish"].Captures.Cast<Capture>().Any())
|
2013-04-15 03:41:39 +02:00
|
|
|
|
return Language.Flemish;
|
2012-12-31 20:27:45 +01:00
|
|
|
|
|
|
|
|
|
if (match.Groups["greek"].Captures.Cast<Capture>().Any())
|
2013-04-15 03:41:39 +02:00
|
|
|
|
return Language.Greek;
|
2012-12-31 20:27:45 +01:00
|
|
|
|
|
2013-09-01 05:01:46 +02:00
|
|
|
|
if (match.Groups["french"].Success)
|
|
|
|
|
return Language.French;
|
|
|
|
|
|
2013-04-15 03:41:39 +02:00
|
|
|
|
return Language.English;
|
2012-08-03 09:01:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-04-29 05:11:43 +02:00
|
|
|
|
private static bool ValidateBeforeParsing(string title)
|
|
|
|
|
{
|
|
|
|
|
if (title.ToLower().Contains("password") && title.ToLower().Contains("yenc"))
|
|
|
|
|
{
|
|
|
|
|
Logger.Trace("");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!title.Any(Char.IsLetterOrDigit) || (!title.Any(Char.IsPunctuation) && !title.Any(Char.IsWhiteSpace)))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-08 21:14:52 +02:00
|
|
|
|
public static string CleanSeriesTitle(this string title)
|
2012-08-03 09:01:34 +02:00
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|