예제 #1
0
 public object Create(object parent, object configContext, System.Xml.XmlNode section)
 {
     Hashtable pathCollection = new Hashtable();
     MoviePathInfo moviePathInfo;
     LogWrapper.LogInfo("Retrieving movie folders from configuration for scanning.");
     try
     {
         XmlNode xNode;
         XmlElement rootElement = (XmlElement)section;
         XmlNodeList xmlNodes = rootElement.SelectNodes("//Path");
         foreach (XmlNode nodeLog in xmlNodes)
         {
             moviePathInfo = new MoviePathInfo();
             xNode = nodeLog.SelectSingleNode("MoviePath");
             moviePathInfo.MoviePath = xNode.InnerText.ToString().Trim();
             xNode = nodeLog.SelectSingleNode("MovieLanguage");
             moviePathInfo.MovieLanguage = xNode.InnerText.ToString().Trim();
             xNode = nodeLog.SelectSingleNode("Order");
             moviePathInfo.Order = Convert.ToInt32(xNode.InnerText);
             pathCollection.Add(moviePathInfo.Order, moviePathInfo);
             LogWrapper.LogInfo(string.Format("Added path to ScanList. Details are:: Order : {0} Path : '{1}' Language : {2}", moviePathInfo.Order, moviePathInfo.MoviePath, moviePathInfo.MovieLanguage));
         }
     }
     catch (Exception ex)
     {
         LogWrapper.LogError(ex);
     }
     return pathCollection;
 }
예제 #2
0
        public List<Movie> getMoviesForFolder(string folderPath, string language)
        {
            movies.Clear();
            MoviePathInfo mPathInfo = new MoviePathInfo();
            mPathInfo.MoviePath = folderPath;
            mPathInfo.MovieLanguage = language;
            getMoviesForPath(mPathInfo);
            List<string> CDRoms = new List<string>();
            foreach (DriveInfo drive in DriveInfo.GetDrives())
            {
                if (drive.DriveType == DriveType.CDRom)
                    CDRoms.Add(drive.Name);
            }
            if (CDRoms.Contains(Path.GetPathRoot(folderPath)))
            {
                IEnumerable<FileInfo> movieFilesOnCDRom = from fileinf in
                                                              from file in Directory.GetFiles(folderPath)
                                                              select new FileInfo(file)
                                                          orderby fileinf.LastWriteTime descending
                                                          select fileinf;

                foreach (FileInfo moviefile in movieFilesOnCDRom)
                {
                    Movie mov = new Movie();
                    mov.Name = removeStopwordsFromMovName(Regex.Replace(moviefile.Name, moviefile.Extension, ""));
                    mov.Language = language;
                    mov.Location = moviefile.FullName;
                    mov.Size = (float)moviefile.Length / (1024 * 1024);
                    mov.Year = GetYearForMovie(mov.Name);
                    if (mov.Size >= 100)
                        movies.Add(mov);
                }
            }
            return movies;
        }
예제 #3
0
 private bool getMoviePaths()
 {
     Hashtable configCollection = (Hashtable)(System.Configuration.ConfigurationManager.GetSection("MoviePaths"));
     IDictionaryEnumerator index = configCollection.GetEnumerator();
     MoviePathInfo moviePathInfo = new MoviePathInfo();
     // List<MoviePathInfo> moviePaths = new List<MoviePathInfo>();
     try
     {
         while (index.MoveNext())
         {
             moviePaths.Add((MoviePathInfo)index.Value);
             //string strMoviePath = moviePathInfo.MoviePath;
             //string strMovieLanguage = moviePathInfo.MovieLanguage;
             //int order = moviePathInfo.Order;
         }
     }
     catch (Exception ex)
     {
         //if (log.IsErrorEnabled)
         //{
         //    log.Error("Page Load failed : " + ex.Message);
         //}
     }
     moviePaths.Reverse();
     return true;
 }
예제 #4
0
        public bool getMoviesForPath(MoviePathInfo moviePath)
        {
            bool success = false;
            try
            {
                if (Directory.Exists(moviePath.MoviePath))
                {
                    //string[] moviesInCurrentDirArray = Directory.GetDirectories(moviePath.MoviePath);
                    //DateTime[] modificationTimes = new DateTime[moviesInCurrentDirArray.Length];
                    //for (int i = 0; i < moviesInCurrentDirArray.Length; i++)
                    //    modificationTimes[i] = new DirectoryInfo(moviesInCurrentDirArray[i]).LastWriteTime;
                    //Array.Sort(modificationTimes, moviesInCurrentDirArray);
                    //List<string> moviesInCurrentDir = moviesInCurrentDirArray.Reverse().ToList();

                    List<string> moviesInCurrentDir = (from dir in
                                                           from e in Directory.GetDirectories(moviePath.MoviePath)
                                                           select new DirectoryInfo(e)
                                                       orderby dir.LastWriteTime descending
                                                       select dir.FullName).ToList();

                    moviesInCurrentDir.RemoveAll(ContainsSubDir);
                    foreach (string movieDir in moviesInCurrentDir)
                    {
                        try
                        {
                            Movie mov = new Movie();
                            mov.Name = removeStopwordsFromMovName(movieDir);
                            mov.Language = moviePath.MovieLanguage;
                            mov.Location = movieDir;
                            //mov.Checksum = GetMD5HashFromFile(movieDir);
                            mov.Size = (float)GetSizeForMovie(movieDir) / (1024 * 1024);
                            mov.Year = GetYearForMovie(mov.Name);
                            movies.Add(mov);
                            string[] CollectionWords = Configuration.GetConfigurationValues("CollectionGroupWords");
                            foreach (string collectionWord in CollectionWords)
                            {
                                if (mov.Name.Contains(collectionWord))
                                {
                                    Random rand = new Random();
                                    MoviePathInfo CollectionPath = new MoviePathInfo();
                                    CollectionPath.MoviePath = movieDir;
                                    CollectionPath.MovieLanguage = moviePath.MovieLanguage;
                                    CollectionPath.Order = rand.Next(1000, 2000);
                                    getMoviesForPath(CollectionPath);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            LogWrapper.LogError(ex);
                        }
                    }
                    success = true;
                }
            }
            catch (Exception ex)
            {
                LogWrapper.LogError(ex);
            }
            return success;
        }