Ejemplo n.º 1
0
        public static IEnumerable<MovieScanResult> FindMovies(DirResult dir)
        {
            if (!dir.Files.Any(f => f.Name == "ignore"))
            {
                var movies = (from fn in dir.Files where fn.Size > MinimumMovieSize && IsValidMovieFileName(fn.Name, false) orderby fn.Name select fn).ToList();

                if (movies.Count > 0)
                {
                    var singleMovie = (movies.Count == 1) || movies.Select(m => m.Name).All(m => _numbers.Replace(m, "") == _numbers.Replace(movies[0].Name, ""));

                    if (singleMovie)
                    {
                        FileResult sampleFile;
                        if (dir.SubDirs.Count == 1 && dir.SubDirs[0].Name.ToLowerInvariant().Contains("sample"))
                            sampleFile = dir.SubDirs[0].Files.Where(f => IsValidMovieFileName(f.Name, null)).FirstOrDefault();
                        else
                            sampleFile = dir.Files.FirstOrDefault(file => IsValidMovieFileName(file.Name, true));

                        yield return MakeMovieResult(movies[0], true, sampleFile, true);
                    }
                    else
                    {
                        foreach (var movie in movies)
                            yield return MakeMovieResult(movie, false, null, false);
                    }
                }

                foreach (var subDir in dir.SubDirs.Where(sd => !sd.Name.ToLowerInvariant().Contains("sample")))
                    foreach (var result in FindMovies(subDir))
                        yield return result;
            }
        }
Ejemplo n.º 2
0
 public DirResult(DirResult parent, string name, string pathElementSeparator, string locallyAccessiblePath=null)
 {
     Parent = parent;
     PathElementSeparator = pathElementSeparator;
     Name = name;
     Files = new List<FileResult>();
     SubDirs = new List<DirResult>();
     _locallyAccessiblePath = locallyAccessiblePath;
 }
Ejemplo n.º 3
0
 private static DirResult Scan(DirResult parent, DirectoryInfo di)
 {
     try
     {
         var dirResult = new DirResult(parent, di.Name, @"\", di.FullName);
         dirResult.Files.AddRange(from fi in di.GetFiles() select new FileResult(dirResult, fi.Name, fi.Length, @"\"));
         dirResult.SubDirs.AddRange(from subDir in di.GetDirectories() let scanRes = Scan(dirResult, subDir) where scanRes != null select scanRes);
         return dirResult;
     }
     catch
     {
         return null;
     }
 }
Ejemplo n.º 4
0
 public FileResult(DirResult parent, string name, long size, string pathElementSeparator)
 {
     Parent = parent;
     Name = name;
     Size = size;
     _pathElementSeparator = pathElementSeparator;
 }