private static MovieScanResult MakeMovieResult(FileResult movie, bool isSingleMovieInParentFolder, FileResult sample, bool tryFindImdbData) { var msr = new MovieScanResult() { Path = movie.Path, ImdbId = tryFindImdbData ? TryFindImdbId(movie) : null, SamplePath = sample != null ? sample.Path : null, }; short? year; msr.CleanedName = CleanName(movie, isSingleMovieInParentFolder, out year); msr.Year = year; SetSeriesData(msr, movie); return msr; }
public string GetSanitizedName(FileResult movie, bool canUseParent, out short? year) { string name = movie.Name; int idxExt = name.LastIndexOf('.'); string tName = SantitizeName(name.Substring(0, idxExt)); string tPath = (canUseParent && movie.Parent.Parent != null) ? SantitizeName(movie.Parent.Name) : ""; var probable = tName.Length >= tPath.Length ? tName : tPath; //Find year year = null; var match = Regex.Match(probable, @"^(.*)\(([0-9]{4})\)\s*$", RegexOptions.CultureInvariant | RegexOptions.Singleline); if (!match.Success) match = Regex.Match(probable, @"^(.*)([0-9]{4})\s*$", RegexOptions.CultureInvariant | RegexOptions.Singleline); if (match.Success) { year = short.Parse(match.Groups[2].Value); probable = match.Groups[1].Value.Trim(); } return probable; }
private static void SetSeriesData(MovieScanResult msr, FileResult movie) { var m = _rexSeriesSeasonEpisode1.Match(movie.Name); if (!m.Success) m = _rexSeriesSeasonEpisode2.Match(movie.Name); if (m.Success) { msr.SeriesSeason = short.Parse(m.Groups[1].Value); msr.SeriesEpisode = short.Parse(m.Groups[2].Value); } else { m = _rexSeriesEpisode1.Match(movie.Name); if (m.Success) msr.SeriesEpisode = short.Parse(m.Groups[1].Value); } }
private static string CleanName(FileResult movie, bool canUseParent, out short? year) { return _nameSanitizer.GetSanitizedName(movie, canUseParent, out year); }
private static string TryFindImdbId(FileResult movie) { if (movie.Parent.LocallyAccessiblePath == null) return null; foreach (var fn in movie.Parent.Files.Where(f => _isInfoFile.IsMatch(f.Name))) { var filePath = Path.Combine(fn.Parent.LocallyAccessiblePath, fn.Name); try { using (var fileStream = new StreamReader(File.OpenRead(filePath), Encoding.Default)) { var match = _imdbTitle.Match(fileStream.ReadToEnd()); if (match.Success) return match.Groups[1].Value; } } catch (Exception ex) { _log.Warn("Failed to read nfo file ({0})! {1}", filePath, ex.Message); } } return null; }