Esempio n. 1
0
        public List <PlayListItem> GetPlayListItems(List <string> Folders, SearchOption searchOptions)
        {
            playListItems.Clear();

            // Filter folders here. The IgnoreFolders appsetting allows folders to be entered to be ignored/added

            string[] folders = new string[] { "" };
            if (AppSettings.Default.IgnoreFolders.Length > 0)
            {
                folders = AppSettings.Default.IgnoreFolders.Split(",");
            }

            foreach (string folderException in folders)
            {
                Folders = Folders.Except(Folders.Where(f => new DirectoryInfo(f).Name.StartsWith(folderException))).ToList();
            }


            foreach (string Folder in Folders)
            {
                if (!Directory.Exists(Folder))
                {
                    Logger.LogComment("ERROR: Selected Playlist Folder Missing: " + Folder);
                    continue;
                }

                try
                {
                    IEnumerable <string> files = PlayListEngineHelper.GetFilesByExtensions(new DirectoryInfo(Folder), searchOptions, PlayListEngineHelper.GetSupportedExtensions());

                    // Filter here
                    // Filter 1: MAC Computers create files that end in .jpg that start with "._"
                    files = files.Except(files.Where(f => new FileInfo(f).Name.StartsWith("._")));

                    files = files.Except(files.Where(f => new FileInfo(f).Name.StartsWith("._")));
                    foreach (string file in files)
                    {
                        PlayListItem item = new PlayListItem();
                        item.Path     = file;
                        item.ItemType = PlayListEngineHelper.GetPlayListItemTypeFromPath(file);

                        playListItems.Add(item);
                    }
                }
                catch (Exception exc)
                {
                    Logger.LogComment("WARNING: Unable to load file or files from Folder " + Folder + " Exception: " + exc.ToString());
                }
            }

            CurrentPlayListItems.AddRange(playListItems);

            if (CurrentPlayListItems.Count > 0)
            {
                CurrentPlayListItem = CurrentPlayListItems.First();
            }

            return(playListItems);
        }
Esempio n. 2
0
        public List <PlayListItem> GetPlayListItems(List <string> Folders, SearchOption searchOptions)
        {
            playListItems.Clear();

            foreach (string Folder in Folders)
            {
                if (!Directory.Exists(Folder))
                {
                    Logger.LogComment("ERROR: Selected Playlist Folder Missing: " + Folder);
                    continue;
                }

                try
                {
                    IEnumerable <string> files = PlayListEngineHelper.GetFilesByExtensions(new DirectoryInfo(Folder), searchOptions, PlayListEngineHelper.GetSupportedExtensions());
                    foreach (string file in files)
                    {
                        PlayListItem item = new PlayListItem();
                        item.Path     = file;
                        item.ItemType = PlayListEngineHelper.GetPlayListItemTypeFromPath(file);

                        playListItems.Add(item);
                    }
                }
                catch (Exception exc)
                {
                    Logger.LogComment("WARNING: Unable to load file or files from Folder " + Folder + " Exception: " + exc.ToString());
                }
            }

            if (AppSettings.Default.Shuffle)
            {
                Random r = new Random((int)DateTime.Now.Ticks);
                playListItems = Helpers.Shuffle <PlayListItem> (playListItems, r).ToList();
            }

            CurrentPlayListItems.AddRange(playListItems);
            Logger.LogComment("New List generated! Contains: " + CurrentPlayListItems.Count + " items.");
            // extra logging for now
            Logger.LogComment("----------------------Begin Playlist Dump----------------");
            try
            {
                for (int i = 0; i < CurrentPlayListItems.Count; i++)
                {
                    Logger.LogComment(CurrentPlayListItems[i].ItemType + ":" + CurrentPlayListItems[i].Path);
                }
            }
            catch (Exception)
            {
                // Collection was modified, basically timing issue. ignore.
            }

            Logger.LogComment("------------------- END PLAYLIST DUMP-------------------");
            // Return it in case we want to use this for the UI for future work.

            if (CurrentPlayListItems.Count > 0)
            {
                CurrentPlayListItem = CurrentPlayListItems.First();
            }

            return(playListItems);
        }