Exemplo 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);
        }
Exemplo n.º 2
0
        /// <summary>
        /// This is for playlist syncing. This gets called when a playlist is handed in on the
        /// command via setfile. It' checks to find a file that is as close as possible on this unit.
        /// </summary>
        /// <param name="path">Remote machine path which was passed in</param>
        /// <returns>a full path to a file</returns>
        public string ConvertFileNameToLocal(string path)
        {
            // Note: Path is from a remote machine
            // Formula is:
            // 1) If an exact match is found..return that.
            // 2) If the root folder and file name is found, return that (probably common case)
            // 3) If the file name is found...return that
            // 4) If folder is found, return random file from that folder
            // 5) If nothing is found, return a random file (Not sure what to do here)
            // Sample for below uses:
            //          passed in: c:\geektoolkit\pictures\scifi\mandalorian.jpg
            //

            // Test 1: Full path found on this machine: c:\geektoolkit\pictures\scifi\mandalorian.jpg
            var testpath = CurrentPlayListItems.Where(p => p.Path.ToUpper() == path.ToUpper()).FirstOrDefault();

            if (testpath != null)
            {
                Logger.LogComment("SYNC: (case 1) Full path found! Returning: " + testpath);
                return(testpath.Path);
            }

            // case 2: Match from just the directory name, and a matching image was found: scifi\mandalorian.jpg
            // Note: this is 'golden path' and how I expect this to be used.
            testpath = CurrentPlayListItems.Where(p => p.Path.Contains(new FileInfo(path).Directory.Name.ToUpper()) && new FileInfo(p.Path).Name.ToUpper() == new FileInfo(path).Name.ToUpper()).FirstOrDefault();
            if (testpath != null)
            {
                Logger.LogComment("SYNC: (case 2) Folder/Filename found! Returning: " + testpath);
                return(testpath.Path);
            }

            // case 3: Match any file in the playlist against mandalorian.jpg
            testpath = CurrentPlayListItems.Where(p => new FileInfo(p.Path).Name.ToUpper() == new FileInfo(path).Name.ToUpper()).FirstOrDefault();
            if (testpath != null)
            {
                Logger.LogComment("SYNC: (case 3) Filename only found! Returning: " + testpath);
                return(testpath.Path);
            }

            // case 4: Match a folder with the same name as the subfolder/playlist:  scifi
            testpath = CurrentPlayListItems.Where(p => new FileInfo(p.Path).Directory.Name.ToUpper() == new FileInfo(path).Directory.Name.ToUpper()).FirstOrDefault();
            if (testpath != null)
            {
                // note: in this case, the testpath is likely just a foldername.  We have to get a file out of it.
                Logger.LogComment("SYNC: (case 4) - Found folder!");
                string file = PlayListEngineHelper.GetRandomFileFromFolder(testpath.Path);
                Logger.LogComment("SYNC: (case 4) Folder only found! Returning: " + file);
                return(file);
            }

            // case 5: just return something to show
            Logger.LogComment("SYNC: (case 5) - NO matches found for path, DirectoryName, Filename, continuing on with current playlist..returning" + CurrentPlayListItem.Path);
            return(CurrentPlayListItem.Path);


            return("");
        }
Exemplo n.º 3
0
        public void PlayFile(string path)
        {
            // Externally exposed API to allow for frame syncing or automation scenarios.
            // note: The file that we try to play may not exist, if not, we should look at the folder and try to
            // find it, if that doesn't exist then show randome file from playlist
            //
            // Future use from Avalonia Gitter: How to load an image from network path..
            // var response = await httpClient.GetAsync(bitmapPath, HttpCompletionOption.ResponseContentRead);
            // var stream = await response.Content.ReadAsStreamAsync();
            // bitmap = new Bitmap(stream);
            //
            //


            PlayListItemType type = PlayListEngineHelper.GetPlayListItemTypeFromPath(path);

            try
            {
                // TODO: Try to 'peek' at next file, if video, then slow down more
                if (type == PlayListItemType.Video)
                {
                    KillVideoPlayer();
                    PlayVideoFile(path);
                }
                else
                {
                    PlayImageFile(false, path);
                    KillVideoPlayer(); // if a video is playing, get rid of it now that we've swapped images
                }
            }
            catch (InvalidOperationException)
            {
                // We expect this if a process is no longer around
            }
            catch (Exception exc)
            {
                Logger.LogComment("ERROR: PlayFile: Exception processing file.." + exc.ToString());
            }
        }
Exemplo n.º 4
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);
        }