2011-04-27 02:47:29 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
2011-08-06 04:51:36 +00:00
|
|
|
|
using System.Linq;
|
2011-04-27 02:47:29 +00:00
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
using NLog;
|
|
|
|
|
using NzbDrone.Core.Model;
|
|
|
|
|
using NzbDrone.Core.Repository.Quality;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core
|
|
|
|
|
{
|
|
|
|
|
public static class Parser
|
|
|
|
|
{
|
|
|
|
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
|
|
|
|
|
|
|
|
|
private static readonly Regex[] ReportTitleRegex = new[]
|
|
|
|
|
{
|
2011-06-13 18:25:40 +00:00
|
|
|
|
//Episodes with airdate
|
2011-04-27 02:47:29 +00:00
|
|
|
|
new Regex(@"^(?<title>.+?)?\W*(?<airyear>\d{4})\W+(?<airmonth>\d{2})\W+(?<airday>\d{2})\W?(?!\\)",
|
|
|
|
|
RegexOptions.IgnoreCase | RegexOptions.Compiled),
|
2011-06-13 18:25:40 +00:00
|
|
|
|
|
|
|
|
|
//Multi-Part episodes without a title (S01E05.S01E06)
|
2011-09-07 06:43:10 +00:00
|
|
|
|
new Regex(@"^(?:\W*S?(?<season>\d{1,2}(?!\d+))(?:(?:\-|[ex]|\s){1,2}(?<episode>\d{1,2}(?!\d+)))+){2,}\W?(?!\\)",
|
2011-05-01 00:23:10 +00:00
|
|
|
|
RegexOptions.IgnoreCase | RegexOptions.Compiled),
|
2011-06-13 18:25:40 +00:00
|
|
|
|
|
2011-08-06 04:51:36 +00:00
|
|
|
|
//Multi-episode (S01E05E06, S01E05-06, etc)
|
2011-09-07 06:43:10 +00:00
|
|
|
|
new Regex(@"^(?<title>.+?)(?:\W+S?(?<season>\d{1,2}(?!\d+))(?:(?:\-|[ex]|\s){1,2}(?<episode>\d{1,2}(?!\d+)))+){2,}\W?(?!\\)",
|
2011-08-06 04:51:36 +00:00
|
|
|
|
RegexOptions.IgnoreCase | RegexOptions.Compiled),
|
|
|
|
|
|
|
|
|
|
//Single episodes (S01E05, 1x056, etc)
|
2011-09-07 06:43:10 +00:00
|
|
|
|
new Regex(@"^(?<title>.+?)(?:\W+S?(?<season>\d{1,2}(?!\d+))(?:(?:\-|[ex]|\s){1,2}(?<episode>\d{1,2}(?!\d+)))+)\W?(?!\\)",
|
2011-06-13 18:25:40 +00:00
|
|
|
|
RegexOptions.IgnoreCase | RegexOptions.Compiled),
|
|
|
|
|
|
|
|
|
|
//No Title - Single episodes or multi-episode (S01E05E06, S01E05-06, etc)
|
2011-09-07 06:43:10 +00:00
|
|
|
|
new Regex(@"^(?:\W?S?(?<season>\d{1,2}(?!\d+))(?:(?:\-|[ex]|\s){1,2}(?<episode>\d{1,2}(?!\d+)))+\W*)+\W?(?!\\)",
|
2011-06-13 18:25:40 +00:00
|
|
|
|
RegexOptions.IgnoreCase | RegexOptions.Compiled),
|
|
|
|
|
|
|
|
|
|
//Supports 103/113 naming
|
2011-04-27 02:47:29 +00:00
|
|
|
|
new Regex(@"^(?<title>.+?)?\W?(?:\W(?<season>\d+)(?<episode>\d{2}))+\W?(?!\\)",
|
|
|
|
|
RegexOptions.IgnoreCase | RegexOptions.Compiled),
|
2011-06-13 18:25:40 +00:00
|
|
|
|
|
|
|
|
|
//Episodes over 99 (3-digits or more)
|
2011-08-28 21:18:43 +00:00
|
|
|
|
new Regex(@"^(?<title>.*?)(?:\W?S?(?<season>\d{1,2}(?!\d+))(?:(?:\-|\.|[ex]|\s)+(?<episode>\d+))+)+\W?(?!\\)",
|
2011-06-13 18:25:40 +00:00
|
|
|
|
RegexOptions.IgnoreCase | RegexOptions.Compiled),
|
|
|
|
|
|
|
|
|
|
//Supports Season only releases
|
2011-08-27 04:37:24 +00:00
|
|
|
|
new Regex(@"^(?<title>.+?)\W(?:S|Season)\W?(?<season>\d{1,2}(?!\d+))+\W?(?!\\)",
|
2011-06-13 18:25:40 +00:00
|
|
|
|
RegexOptions.IgnoreCase | RegexOptions.Compiled)
|
2011-04-27 02:47:29 +00:00
|
|
|
|
};
|
|
|
|
|
|
2011-06-13 18:25:40 +00: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)",
|
2011-04-27 02:47:29 +00:00
|
|
|
|
RegexOptions.IgnoreCase | RegexOptions.Compiled);
|
|
|
|
|
|
2011-08-27 04:37:24 +00: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|\<|\>|\?|\*|\:|\||""",
|
2011-05-23 17:32:37 +00:00
|
|
|
|
RegexOptions.IgnoreCase | RegexOptions.Compiled);
|
|
|
|
|
|
2011-06-29 23:31:16 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Parses a file path into list of episodes it contains
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name = "path">Path of the file to parse</param>
|
|
|
|
|
/// <returns>List of episodes contained in the file</returns>
|
|
|
|
|
internal static EpisodeParseResult ParsePath(string path)
|
|
|
|
|
{
|
|
|
|
|
var fileInfo = new FileInfo(path);
|
|
|
|
|
return ParseTitle(fileInfo.Name);
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-27 02:47:29 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Parses a post title into list of episodes it contains
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name = "title">Title of the report</param>
|
2011-06-29 23:31:16 +00:00
|
|
|
|
/// <returns>List of episodes contained in the post</returns>
|
|
|
|
|
internal static EpisodeParseResult ParseTitle(string title)
|
2011-04-27 02:47:29 +00:00
|
|
|
|
{
|
|
|
|
|
Logger.Trace("Parsing string '{0}'", title);
|
2011-05-23 17:32:37 +00:00
|
|
|
|
var simpleTitle = SimpleTitleRegex.Replace(title, String.Empty);
|
2011-04-27 02:47:29 +00:00
|
|
|
|
|
|
|
|
|
foreach (var regex in ReportTitleRegex)
|
|
|
|
|
{
|
2011-04-30 23:25:35 +00:00
|
|
|
|
//Use only the filename, not the entire path
|
2011-06-29 23:31:16 +00:00
|
|
|
|
var match = regex.Matches(simpleTitle);
|
2011-04-27 02:47:29 +00:00
|
|
|
|
|
|
|
|
|
if (match.Count != 0)
|
|
|
|
|
{
|
|
|
|
|
var seriesName = NormalizeTitle(match[0].Groups["title"].Value);
|
|
|
|
|
|
2011-05-23 17:32:37 +00:00
|
|
|
|
int airyear;
|
2011-04-27 02:47:29 +00:00
|
|
|
|
Int32.TryParse(match[0].Groups["airyear"].Value, out airyear);
|
|
|
|
|
|
|
|
|
|
EpisodeParseResult parsedEpisode;
|
|
|
|
|
|
|
|
|
|
if (airyear < 1)
|
|
|
|
|
{
|
2011-08-06 04:51:36 +00:00
|
|
|
|
var seasons = new List<int>();
|
|
|
|
|
|
|
|
|
|
foreach (Capture seasonCapture in match[0].Groups["season"].Captures)
|
|
|
|
|
{
|
|
|
|
|
int s;
|
|
|
|
|
if (Int32.TryParse(seasonCapture.Value, out s))
|
|
|
|
|
seasons.Add(s);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//If more than 1 season was parsed go to the next REGEX (A multi-season release is unlikely)
|
|
|
|
|
if (seasons.Distinct().Count() != 1)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
var season = seasons[0];
|
2011-04-27 02:47:29 +00:00
|
|
|
|
|
|
|
|
|
parsedEpisode = new EpisodeParseResult
|
|
|
|
|
{
|
|
|
|
|
CleanTitle = seriesName,
|
|
|
|
|
SeasonNumber = season,
|
2011-05-24 04:12:54 +00:00
|
|
|
|
EpisodeNumbers = new List<int>()
|
2011-04-27 02:47:29 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
foreach (Match matchGroup in match)
|
|
|
|
|
{
|
2011-04-26 15:26:41 +00:00
|
|
|
|
var count = matchGroup.Groups["episode"].Captures.Count;
|
|
|
|
|
|
|
|
|
|
//Allows use to return a list of 0 episodes (We can handle that as a full season release)
|
|
|
|
|
if (count > 0)
|
|
|
|
|
{
|
|
|
|
|
var first = Convert.ToInt32(matchGroup.Groups["episode"].Captures[0].Value);
|
|
|
|
|
var last = Convert.ToInt32(matchGroup.Groups["episode"].Captures[count - 1].Value);
|
|
|
|
|
|
|
|
|
|
for (int i = first; i <= last; i++)
|
|
|
|
|
{
|
2011-05-24 04:12:54 +00:00
|
|
|
|
parsedEpisode.EpisodeNumbers.Add(i);
|
2011-04-26 15:26:41 +00:00
|
|
|
|
}
|
2011-04-27 02:47:29 +00:00
|
|
|
|
}
|
2011-08-27 04:37:24 +00:00
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
parsedEpisode.FullSeason = true;
|
|
|
|
|
}
|
2011-04-27 02:47:29 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//Try to Parse as a daily show
|
2011-06-23 01:17:42 +00:00
|
|
|
|
var airmonth = Convert.ToInt32(match[0].Groups["airmonth"].Value);
|
|
|
|
|
var airday = Convert.ToInt32(match[0].Groups["airday"].Value);
|
2011-04-27 02:47:29 +00:00
|
|
|
|
|
2011-06-23 01:17:42 +00:00
|
|
|
|
parsedEpisode = new EpisodeParseResult
|
|
|
|
|
{
|
|
|
|
|
CleanTitle = seriesName,
|
|
|
|
|
AirDate = new DateTime(airyear, airmonth, airday),
|
|
|
|
|
Language = ParseLanguage(simpleTitle)
|
|
|
|
|
};
|
2011-04-27 02:47:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
parsedEpisode.Quality = ParseQuality(title);
|
|
|
|
|
|
|
|
|
|
Logger.Trace("Episode Parsed. {0}", parsedEpisode);
|
|
|
|
|
|
|
|
|
|
return parsedEpisode;
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-07-06 06:17:21 +00:00
|
|
|
|
Logger.Warn("Unable to parse episode info. {0}", title);
|
2011-04-27 02:47:29 +00:00
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
Logger.Trace("Series Parsed. {0}", seriesName);
|
|
|
|
|
return seriesName;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return String.Empty;
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-28 19:23:35 +00:00
|
|
|
|
internal static Quality ParseQuality(string name)
|
2011-04-27 02:47:29 +00:00
|
|
|
|
{
|
|
|
|
|
Logger.Trace("Trying to parse quality for {0}", name);
|
|
|
|
|
|
2011-05-26 03:13:39 +00:00
|
|
|
|
name = name.Trim();
|
2011-06-13 18:25:40 +00:00
|
|
|
|
var normalizedName = NormalizeTitle(name);
|
2011-05-28 19:23:35 +00:00
|
|
|
|
var result = new Quality { QualityType = QualityTypes.Unknown };
|
2011-06-13 18:25:40 +00:00
|
|
|
|
result.Proper = normalizedName.Contains("proper");
|
2011-04-27 02:47:29 +00:00
|
|
|
|
|
2011-06-13 18:25:40 +00:00
|
|
|
|
if (normalizedName.Contains("dvd") || normalizedName.Contains("bdrip") || normalizedName.Contains("brrip"))
|
2011-04-27 02:47:29 +00:00
|
|
|
|
{
|
2011-05-28 19:23:35 +00:00
|
|
|
|
result.QualityType = QualityTypes.DVD;
|
|
|
|
|
return result;
|
2011-04-27 02:47:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-06-13 18:25:40 +00:00
|
|
|
|
if (normalizedName.Contains("xvid") || normalizedName.Contains("divx"))
|
2011-04-27 02:47:29 +00:00
|
|
|
|
{
|
2011-06-13 18:25:40 +00:00
|
|
|
|
if (normalizedName.Contains("bluray"))
|
2011-04-27 02:47:29 +00:00
|
|
|
|
{
|
2011-05-28 19:23:35 +00:00
|
|
|
|
result.QualityType = QualityTypes.DVD;
|
|
|
|
|
return result;
|
2011-04-27 02:47:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-05-28 19:23:35 +00:00
|
|
|
|
result.QualityType = QualityTypes.SDTV;
|
|
|
|
|
return result;
|
2011-04-27 02:47:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-06-13 18:25:40 +00:00
|
|
|
|
if (normalizedName.Contains("bluray"))
|
2011-04-27 02:47:29 +00:00
|
|
|
|
{
|
2011-06-13 18:25:40 +00:00
|
|
|
|
if (normalizedName.Contains("720p"))
|
2011-05-28 19:23:35 +00:00
|
|
|
|
{
|
|
|
|
|
result.QualityType = QualityTypes.Bluray720p;
|
|
|
|
|
return result;
|
|
|
|
|
}
|
2011-04-27 02:47:29 +00:00
|
|
|
|
|
2011-06-13 18:25:40 +00:00
|
|
|
|
if (normalizedName.Contains("1080p"))
|
2011-05-28 19:23:35 +00:00
|
|
|
|
{
|
|
|
|
|
result.QualityType = QualityTypes.Bluray1080p;
|
|
|
|
|
return result;
|
|
|
|
|
}
|
2011-04-27 02:47:29 +00:00
|
|
|
|
|
2011-05-28 19:23:35 +00:00
|
|
|
|
result.QualityType = QualityTypes.Bluray720p;
|
|
|
|
|
return result;
|
2011-04-27 02:47:29 +00:00
|
|
|
|
}
|
2011-06-13 18:25:40 +00:00
|
|
|
|
if (normalizedName.Contains("webdl"))
|
2011-05-28 19:23:35 +00:00
|
|
|
|
{
|
|
|
|
|
result.QualityType = QualityTypes.WEBDL;
|
|
|
|
|
return result;
|
|
|
|
|
}
|
2011-06-13 18:25:40 +00:00
|
|
|
|
if (normalizedName.Contains("x264") || normalizedName.Contains("h264") || normalizedName.Contains("720p"))
|
2011-05-28 19:23:35 +00:00
|
|
|
|
{
|
|
|
|
|
result.QualityType = QualityTypes.HDTV;
|
|
|
|
|
return result;
|
|
|
|
|
}
|
2011-04-27 02:47:29 +00:00
|
|
|
|
//Based on extension
|
2011-05-23 06:48:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-06-29 23:31:16 +00:00
|
|
|
|
if (result.QualityType == QualityTypes.Unknown)
|
2011-04-27 02:47:29 +00:00
|
|
|
|
{
|
2011-05-23 06:48:52 +00:00
|
|
|
|
try
|
2011-04-27 02:47:29 +00:00
|
|
|
|
{
|
2011-05-23 06:48:52 +00:00
|
|
|
|
switch (Path.GetExtension(name).ToLower())
|
|
|
|
|
{
|
|
|
|
|
case ".avi":
|
|
|
|
|
case ".xvid":
|
|
|
|
|
case ".wmv":
|
|
|
|
|
case ".mp4":
|
|
|
|
|
{
|
2011-05-28 19:23:35 +00:00
|
|
|
|
result.QualityType = QualityTypes.SDTV;
|
2011-05-23 06:48:52 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case ".mkv":
|
|
|
|
|
{
|
2011-05-28 19:23:35 +00:00
|
|
|
|
result.QualityType = QualityTypes.HDTV;
|
2011-05-23 06:48:52 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-04-27 02:47:29 +00:00
|
|
|
|
}
|
2011-05-23 06:48:52 +00:00
|
|
|
|
catch (ArgumentException)
|
|
|
|
|
{
|
|
|
|
|
//Swallow exception for cases where string contains illegal
|
|
|
|
|
//path characters.
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-05-24 04:41:57 +00:00
|
|
|
|
|
2011-08-25 23:58:24 +00:00
|
|
|
|
if ((normalizedName.Contains("sdtv") || (result.QualityType == QualityTypes.Unknown && normalizedName.Contains("hdtv"))) && !normalizedName.Contains("mpeg"))
|
2011-05-23 06:48:52 +00:00
|
|
|
|
{
|
2011-05-28 19:23:35 +00:00
|
|
|
|
result.QualityType = QualityTypes.SDTV;
|
|
|
|
|
return result;
|
2011-04-27 02:47:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-10 19:52:29 +00:00
|
|
|
|
public static LanguageType ParseLanguage(string title)
|
2011-05-09 06:16:26 +00:00
|
|
|
|
{
|
2011-06-23 00:19:19 +00:00
|
|
|
|
var lowerTitle = title.ToLower();
|
|
|
|
|
|
|
|
|
|
if (lowerTitle.Contains("english"))
|
2011-05-09 06:16:26 +00:00
|
|
|
|
return LanguageType.English;
|
|
|
|
|
|
2011-06-23 00:19:19 +00:00
|
|
|
|
if (lowerTitle.Contains("french"))
|
2011-05-09 06:16:26 +00:00
|
|
|
|
return LanguageType.French;
|
|
|
|
|
|
2011-06-23 00:19:19 +00:00
|
|
|
|
if (lowerTitle.Contains("spanish"))
|
2011-05-09 06:16:26 +00:00
|
|
|
|
return LanguageType.Spanish;
|
|
|
|
|
|
2011-06-23 00:19:19 +00:00
|
|
|
|
if (lowerTitle.Contains("german"))
|
2011-05-09 06:16:26 +00:00
|
|
|
|
{
|
|
|
|
|
//Make sure it doesn't contain Germany (Since we're not using REGEX for all this)
|
2011-06-23 00:19:19 +00:00
|
|
|
|
if (!lowerTitle.Contains("germany"))
|
2011-05-09 06:16:26 +00:00
|
|
|
|
return LanguageType.German;
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-23 00:19:19 +00:00
|
|
|
|
if (lowerTitle.Contains("italian"))
|
2011-05-09 06:16:26 +00:00
|
|
|
|
return LanguageType.Italian;
|
|
|
|
|
|
2011-06-23 00:19:19 +00:00
|
|
|
|
if (lowerTitle.Contains("danish"))
|
2011-05-09 06:16:26 +00:00
|
|
|
|
return LanguageType.Danish;
|
|
|
|
|
|
2011-06-23 00:19:19 +00:00
|
|
|
|
if (lowerTitle.Contains("dutch"))
|
2011-05-09 06:16:26 +00:00
|
|
|
|
return LanguageType.Dutch;
|
|
|
|
|
|
2011-06-23 00:19:19 +00:00
|
|
|
|
if (lowerTitle.Contains("japanese"))
|
2011-05-09 06:16:26 +00:00
|
|
|
|
return LanguageType.Japanese;
|
|
|
|
|
|
2011-06-23 00:19:19 +00:00
|
|
|
|
if (lowerTitle.Contains("cantonese"))
|
2011-05-09 06:16:26 +00:00
|
|
|
|
return LanguageType.Cantonese;
|
|
|
|
|
|
2011-06-23 00:19:19 +00:00
|
|
|
|
if (lowerTitle.Contains("mandarin"))
|
2011-05-09 06:16:26 +00:00
|
|
|
|
return LanguageType.Mandarin;
|
|
|
|
|
|
2011-06-23 00:19:19 +00:00
|
|
|
|
if (lowerTitle.Contains("korean"))
|
2011-05-09 06:16:26 +00:00
|
|
|
|
return LanguageType.Korean;
|
|
|
|
|
|
2011-06-23 00:19:19 +00:00
|
|
|
|
if (lowerTitle.Contains("russian"))
|
2011-05-09 06:16:26 +00:00
|
|
|
|
return LanguageType.Russian;
|
|
|
|
|
|
2011-06-23 00:19:19 +00:00
|
|
|
|
if (lowerTitle.Contains("polish"))
|
2011-05-09 06:16:26 +00:00
|
|
|
|
return LanguageType.Polish;
|
|
|
|
|
|
2011-06-23 00:19:19 +00:00
|
|
|
|
if (lowerTitle.Contains("vietnamese"))
|
2011-05-09 06:16:26 +00:00
|
|
|
|
return LanguageType.Vietnamese;
|
|
|
|
|
|
2011-06-23 00:19:19 +00:00
|
|
|
|
if (lowerTitle.Contains("swedish"))
|
2011-05-09 06:16:26 +00:00
|
|
|
|
return LanguageType.Swedish;
|
|
|
|
|
|
2011-06-23 00:19:19 +00:00
|
|
|
|
if (lowerTitle.Contains("norwegian"))
|
2011-05-09 06:16:26 +00:00
|
|
|
|
return LanguageType.Norwegian;
|
|
|
|
|
|
2011-06-23 00:19:19 +00:00
|
|
|
|
if (lowerTitle.Contains("finnish"))
|
2011-05-09 06:16:26 +00:00
|
|
|
|
return LanguageType.Finnish;
|
|
|
|
|
|
2011-06-23 00:19:19 +00:00
|
|
|
|
if (lowerTitle.Contains("turkish"))
|
2011-05-09 06:16:26 +00:00
|
|
|
|
return LanguageType.Turkish;
|
|
|
|
|
|
2011-06-23 00:19:19 +00:00
|
|
|
|
if (lowerTitle.Contains("portuguese"))
|
2011-05-09 06:16:26 +00:00
|
|
|
|
return LanguageType.Portuguese;
|
|
|
|
|
|
|
|
|
|
return LanguageType.English;
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-27 02:47:29 +00:00
|
|
|
|
/// <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>
|
|
|
|
|
public static string NormalizeTitle(string title)
|
|
|
|
|
{
|
2011-08-22 01:42:00 +00:00
|
|
|
|
long number = 0;
|
|
|
|
|
|
|
|
|
|
//If Title only contains numbers return it as is.
|
|
|
|
|
if (Int64.TryParse(title, out number))
|
2011-08-02 05:10:05 +00:00
|
|
|
|
return title;
|
2011-08-22 01:42:00 +00:00
|
|
|
|
|
2011-04-27 02:47:29 +00:00
|
|
|
|
return NormalizeRegex.Replace(title, String.Empty).ToLower();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string NormalizePath(string path)
|
|
|
|
|
{
|
|
|
|
|
if (String.IsNullOrWhiteSpace(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('/', '\\', ' ');
|
|
|
|
|
}
|
2011-07-27 22:59:48 +00:00
|
|
|
|
|
|
|
|
|
public static string UppercaseFirst(string s)
|
|
|
|
|
{
|
|
|
|
|
// Check for empty string.
|
|
|
|
|
if (string.IsNullOrEmpty(s))
|
|
|
|
|
{
|
|
|
|
|
return string.Empty;
|
|
|
|
|
}
|
|
|
|
|
// Return char and concat substring.
|
|
|
|
|
return char.ToUpper(s[0]) + s.Substring(1);
|
|
|
|
|
}
|
2011-04-27 02:47:29 +00:00
|
|
|
|
}
|
|
|
|
|
} |