示例#1
0
        public bool Play(VideoInfo videoInfo, VideoItemFile videoItemFile)
        {
            bool ret = false;
            // if playing video, mark video item as played/watched
            // TODO btr way to normalize if a file is a video file
            string fileExt = videoItemFile.Extension.TrimStart('.');

            switch (fileExt)
            {
            case "avi":
            case "m4v":
            case "mov":
            case "mpg":
            case "mkv":
            case "mp4":
            case "mpeg":
                // run as background so can wait w/o blocking ui
                // after X secs timeout, mark as played/watched
                // .. but requires UseShellEx = false which requires more config/settings to specify video player
                // so for now, meh runs as background thread w/o wait
                VideoItemFileInfo videoItemFileInfo = new VideoItemFileInfo();
                videoItemFileInfo.videoInfo     = videoInfo;
                videoItemFileInfo.videoItemFile = videoItemFile;
                backgroundWorkerOpenFile.Run(videoItemFileInfo);
                break;

            default:
                string   fullName = videoInfo.GetFullName(videoItemFile);
                FileInfo fileInfo = MyFile.FileInfo(fullName);
                if (fileInfo == null)
                {
                    // MessageBox.Show("Error trying to open file\n"+fullName+"\nView log for details");
                    ret = false;
                }
                else
                {
                    ret = MyFile.RunFile(fileInfo);
                }
                break;
            }

            return(ret);
        }
示例#2
0
        private void buttonPlay_Click(object sender, EventArgs e)
        {
            Button button = (Button)sender;

            if (selectedVideoInfo != null && selectedVideoInfo.files != null && selectedVideoInfo.files.video != null)
            {
                button.Enabled = false;
                button.Text    = "Playing..";

                PlayFile playFile = new PlayFile();
                playFile.playFile_Completed += (senderPlay, eventPlay) => PlayFile_Completed(senderPlay, eventPlay, selectedVideoInfo);
                playFile.AddAccessToSubForms(this, subFormProgress);
                string   videoFullName = selectedVideoInfo.GetFullName(selectedVideoInfo.files.video);
                FileInfo fileInfo      = MyFile.FileInfo(videoFullName);
                if (fileInfo == null)
                {
                    MessageBox.Show("Error trying to play video [" + selectedVideoInfo.files.video.Name + "]");
                    return;
                }
                playFile.Play(selectedVideoInfo, selectedVideoInfo.files.video);

                MyFormField.DelayButtonClick(button, "Play");
            }
        }
示例#3
0
        public bool SetImages(VideoInfo videoInfo)
        {
            // nothing to see
            if (videoInfo.files == null || videoInfo.files.images == null)
            {
                return(false);
            }

            // set big picture box to poster, if avail
            if (videoInfo.files != null && videoInfo.files.poster != null)
            {
                Image posterImage = MyImage.GetImageFromFile(videoInfo.GetFullName(videoInfo.files.poster));
                pictureBoxImage.Image = posterImage;
            }
            else
            {
                if (pictureBoxImage.Image != null)
                {
                    pictureBoxImage.Image.Dispose();
                }
                pictureBoxImage.Image = null;
            }


            flowLayoutPanelImages.SuspendLayout();

            // remove prior images, for memory management funz

            /*
             * http://msdn.microsoft.com/en-us/library/system.windows.forms.control.controlcollection.clear%28v=vs.110%29.aspx
             * Calling the Clear method does not remove control handles from memory.
             */
            // flowLayoutPanelImages.Controls.Clear();
            foreach (PictureBox priorPictureImage in flowLayoutPanelImages.Controls.OfType <PictureBox>())
            {
                if (priorPictureImage.Image != null)
                {
                    priorPictureImage.Image.Dispose();
                }
                priorPictureImage.Image = null;
            }
            while (flowLayoutPanelImages.Controls.Count > 0)
            {
                flowLayoutPanelImages.Controls.RemoveAt(0);
            }



            PictureBox pictureBox;

            foreach (VideoItemFile videoItemFile in videoInfo.files.images)
            {
                string imageFullName = videoInfo.GetFullName(videoItemFile);
                // skip images smaller than y or larger than x
                if (videoItemFile.Length < 100)
                {
                    MyLog.Add("SetImages: Skipping " + imageFullName + " " + MyFile.FormatSize(videoItemFile.Length));
                    continue;
                }
                if (videoItemFile.Length > 5 * 1048576)
                {
                    MyLog.Add("SetImages: Skipping " + imageFullName + " " + MyFile.FormatSize(videoItemFile.Length));
                    continue;
                }

                Image image = MyImage.GetImageFromFile(imageFullName);

                try
                {
                    pictureBox          = new PictureBox();
                    pictureBox.Size     = new Size(75, 75);
                    pictureBox.Image    = image;
                    pictureBox.SizeMode = PictureBoxSizeMode.Zoom; // keep aspect ratio
                    pictureBox.Cursor   = Cursors.Hand;
                    pictureBox.Click   += this.imageList_Click;

                    flowLayoutPanelImages.Controls.Add(pictureBox);
                }
                catch (Exception e)
                {
                    // skip
                    MyLog.Add("SetImages: " + imageFullName + "\n" + e.ToString());
                }
            }

            flowLayoutPanelImages.ResumeLayout();

            return(true);
        }
        /// <summary>
        /// update the XBMC .nfo file
        /// </summary>
        /// <param name="videoItemFile"></param>
        /// <param name="videoItem"></param>
        /// <returns></returns>
        public bool UpdateXBMC(VideoInfo videoInfo)
        {
            // MyLog.Add("UpdateXBMC");

            string videoFullName = null;
            string fileContents  = null;

            if (videoInfo.files == null || videoInfo.files.xbmc == null)
            {
                if (Config.settings.createXBMC)
                {
                    videoFullName = videoInfo.videoDirectory + @"\movie.nfo";
                    fileContents  = GetDefaultXBMCxml();
                }
                else
                {
                    return(false);
                }
            }
            else if (!Config.settings.updateXBMC)
            {
                return(false);
            }
            else
            {
                videoFullName = videoInfo.GetFullName(videoInfo.files.xbmc);
                fileContents  = MyFile.ReadAllText(videoFullName);
            }
            if (fileContents == null || videoFullName == null)
            {
                return(false);
            }

            VideoItem videoItem = videoInfo.videoItem;


            XmlDocument doc = MyXMLDoc.LoadXml(fileContents);

            if (doc == null)
            {
                return(false);
            }

            MyXMLDoc.SetSingleNodeString(doc, "/movie/title", videoItem.title);
            MyXMLDoc.SetSingleNodeString(doc, "/movie/plot", videoItem.plot);
            MyXMLDoc.SetSingleNodeString(doc, "/movie/set", videoItem.movieset);
            MyXMLDoc.SetSingleNodeString(doc, "/movie/tagline", videoItem.tagline);
            MyXMLDoc.SetSingleNodeString(doc, "/movie/id", videoItem.imdbId);
            MyXMLDoc.SetSingleNodeString(doc, "/movie/tmdbId", videoItem.tmdbId);
            MyXMLDoc.SetSingleNodeString(doc, "/movie/mpaa", videoItem.mpaa);

            MyXMLDoc.SetSingleNodeDecimal(doc, "/movie/rating", videoItem.imdbRating);

            MyXMLDoc.SetSingleNodeInt(doc, "/movie/year", videoItem.year);
            MyXMLDoc.SetSingleNodeInt(doc, "/movie/runtime", videoItem.runtime);
            MyXMLDoc.SetSingleNodeInt(doc, "/movie/playcount", videoItem.playCount);
            int watched = VideoFileEnums.watched.GetValueByKey(videoItem.watched);

            // either watched or not
            if (watched != 0 && watched != 1)
            {
                watched = 0;
            }
            MyXMLDoc.SetSingleNodeInt(doc, "/movie/watched", watched);

            bool ret = MyXMLDoc.SaveXML(doc, videoFullName);

            if (ret)
            {
                MyLog.Add("wrote " + videoFullName);
            }
            else
            {
                MyLog.Add("error writing to " + videoFullName);
            }
            return(ret);
        }
        /// <summary>
        /// update the MB .xml file
        /// </summary>
        /// <param name="videoItemFile"></param>
        /// <param name="videoItem"></param>
        /// <returns></returns>
        public bool UpdateMB(VideoInfo videoInfo)
        {
            string videoFullName = null;
            string fileContents  = null;

            if (videoInfo.files == null || videoInfo.files.mb == null)
            {
                if (Config.settings.createMB)
                {
                    videoFullName = videoInfo.videoDirectory + @"\movie.xml";
                    fileContents  = GetDefaultMBxml();
                }
                else
                {
                    return(false);
                }
            }
            else if (!Config.settings.updateMB)
            {
                return(false);
            }
            else
            {
                videoFullName = videoInfo.GetFullName(videoInfo.files.mb);
                fileContents  = MyFile.ReadAllText(videoFullName);
            }
            if (fileContents == null || videoFullName == null)
            {
                return(false);
            }
            VideoItem videoItem = videoInfo.videoItem;

            XmlDocument doc = MyXMLDoc.LoadXml(fileContents);

            if (doc == null)
            {
                return(false);
            }

            MyXMLDoc.SetSingleNodeString(doc, "/Title/LocalTitle", videoItem.title);
            MyXMLDoc.SetSingleNodeString(doc, "/Title/Overview", videoItem.plot);
            MyXMLDoc.SetSingleNodeString(doc, "/Title/set", videoItem.movieset);
            MyXMLDoc.SetSingleNodeString(doc, "/Title/tagline", videoItem.tagline);
            MyXMLDoc.SetSingleNodeString(doc, "/Title/IMDB", videoItem.imdbId);
            MyXMLDoc.SetSingleNodeString(doc, "/Title/TMDbId", videoItem.tmdbId);
            MyXMLDoc.SetSingleNodeString(doc, "/Title/ContentRating", videoItem.mpaa);

            MyXMLDoc.SetSingleNodeDecimal(doc, "/Title/Rating", videoItem.imdbRating);

            MyXMLDoc.SetSingleNodeInt(doc, "/Title/ProductionYear", videoItem.year);
            MyXMLDoc.SetSingleNodeInt(doc, "/Title/RunningTime", videoItem.runtime);

            bool ret = MyXMLDoc.SaveXML(doc, videoFullName);

            if (ret)
            {
                MyLog.Add("wrote " + videoFullName);
            }
            else
            {
                MyLog.Add("error writing to " + videoFullName);
            }
            return(ret);
        }
示例#6
0
        public static GalleryImageThumbnailInfo GetCachedThumbnail(VideoInfo videoInfo)
        {
            GalleryImageThumbnailInfo galleryImageThumbnailInfo = new GalleryImageThumbnailInfo();

            galleryImageThumbnailInfo.fromCache    = false;
            galleryImageThumbnailInfo.createdCache = false;
            galleryImageThumbnailInfo.thumbnail    = null;

            Image  thumbnail = null;
            string cachedThumbnailFullName = MyFile.EnsureDataFile("poster_" + videoInfo.hash, "jpg", @"cache\gallery");

            if (Config.settings.gallery.cachePosterThumbnails && File.Exists(cachedThumbnailFullName))
            {
                // use file stream so files not locked
                FileStream fileStream = new FileStream(cachedThumbnailFullName, FileMode.Open, FileAccess.Read);
                thumbnail = Image.FromStream(fileStream);
                fileStream.Close();
                // thumbnail = Image.FromFile(cachedThumbnailFile); // locks file

                galleryImageThumbnailInfo.fromCache = true;
            }
            else if (videoInfo.files.poster == null)
            {
                thumbnail = null;
            }
            else
            {
                VideoItemFile videoItemFile  = videoInfo.files.poster;
                string        posterFullName = videoInfo.GetFullName(videoItemFile);

                // skip images smaller than y or larger than x
                if (videoItemFile.Length < 100)
                {
                    MyLog.Add("Get Thumbnail: Skipping " + posterFullName + " " + MyFile.FormatSize(videoItemFile.Length));
                    thumbnail = null;
                }
                if (videoItemFile.Length > 5 * 1048576)
                {
                    MyLog.Add("Get Thumbnail: Skipping " + posterFullName + " " + MyFile.FormatSize(videoItemFile.Length));
                    thumbnail = null;
                }

                try
                {
                    if (!File.Exists(posterFullName))
                    {
                        thumbnail = null;
                    }
                    else
                    {
                        // size of thumbails .. TODO make a config setting
                        thumbnail = MyImage.GetThumbnail(posterFullName, 165, 250, Color.Black);
                        if (Config.settings.gallery.cachePosterThumbnails && thumbnail != null)
                        {
                            // clone image so files not locked
                            if (MyImage.SaveJpgImage((Image)thumbnail.Clone(), cachedThumbnailFullName))
                            {
                                galleryImageThumbnailInfo.createdCache = true;
                            }
                        }
                    }
                }
                catch (OutOfMemoryException)
                {
                    // Image.FromFile will throw this if file is invalid/corrupted; Don't ask me why
                    MyLog.Add("Invalid Image; Unable to read " + posterFullName + " " + MyFile.FormatSize(videoItemFile.Length));
                    thumbnail = null;
                }
                catch (Exception ei)
                {
                    MyLog.Add(ei.ToString());
                    thumbnail = null;
                }
            }

            galleryImageThumbnailInfo.thumbnail = thumbnail;
            return(galleryImageThumbnailInfo);
        }
示例#7
0
        /// <summary>
        /// read the video directory and try to parse video info
        /// such as XBMC, MB
        /// </summary>
        /// <param name="directory"></param>
        /// <returns></returns>
        public VideoInfo ReadDirectory(string directory)
        {
            bool      parsedFile = false;
            VideoInfo videoInfo  = new VideoInfo();

            videoInfo.Initialize();
            videoInfo.videoDirectory = directory;
            VideoInfo parsedVideoInfo = new VideoInfo();

            parsedVideoInfo.Initialize();
            parsedVideoInfo.videoDirectory = directory;

            IEnumerable <string> files = MyFile.EnumerateFiles(directory);

            if (files.Count() == 0)
            {
                // empty folder .. maybe a category folder, or movie placeholder
                return(videoInfo);
            }


            // MyLog.Add("ReadDirectory: " + files.Count() + " files");
            foreach (string file in files)
            {
                FileInfo fileInfo = MyFile.FileInfo(file);

                if (fileInfo == null)
                {
                    continue;
                }
                VideoItemFile videoItemFile = new VideoItemFile();
                videoItemFile.Set(directory, fileInfo);

                // parse nfo/xml/file to get file info

                videoInfo.files.qty += 1;

                string fileExt = fileInfo.Extension.TrimStart('.');
                switch (fileExt)
                {
                case "avi":
                case "m4v":
                case "mov":
                case "mpg":
                case "mkv":
                case "mp4":
                case "mpeg":
                    videoInfo.files.video = videoItemFile;

                    //if (videoInfo.videoItem.encoding == null)
                    //{
                    string encoding = RunFFprobe(videoInfo.GetFullName(videoInfo.files.video));
                    if (encoding != null)
                    {
                        videoInfo.videoItem.encoding = ParseFFprobe(encoding);
                    }
                    //}
                    break;

                case "jpg":
                case "jpeg":
                case "png":
                    if (fileInfo.Name == "poster.jpg")
                    {
                        videoInfo.files.poster = videoItemFile;
                    }
                    else if (fileInfo.Name == "fanart.jpg")
                    {
                        videoInfo.files.fanart = videoItemFile;
                    }
                    videoInfo.files.images.Add(videoItemFile);
                    break;

                case "mve":
                case "nfo":
                case "xml":
                    // TODO btr way to ensure which type parsing

                    string fileContents = MyFile.ReadAllText(fileInfo.FullName);
                    fileContents = fileContents.Trim();
                    if (String.IsNullOrEmpty(fileContents))
                    {
                        continue;
                    }
                    if (fileContents.StartsWith("<?xml"))
                    {
                        XmlDocument doc = MyXMLDoc.LoadXml(fileContents);
                        if (doc == null)
                        {
                            continue;
                        }



                        if (fileContents.Contains("<VideoInfo>"))
                        {
                            //if (parsedFile == false)
                            {
                                parsedVideoInfo = ParseMVE(fileInfo.FullName);
                                videoInfo.MergeVideoItemWith(parsedVideoInfo);
                                // videoInfo.videoItem = parsedVideoInfo.videoItem;
                            }
                            videoInfo.files.mve = videoItemFile;

                            parsedFile = true;
                        }
                        if (fileContents.Contains("<Title>"))
                        {
                            //if (parsedFile == false)
                            {
                                parsedVideoInfo = ParseMB(doc);
                                videoInfo.MergeVideoItemWith(parsedVideoInfo);
                                //videoInfo.videoItem = parsedVideoInfo.videoItem;
                            }
                            videoInfo.files.mb = videoItemFile;

                            parsedFile = true;
                        }
                        if (fileContents.Contains("<movie>"))
                        {
                            //if (parsedFile == false)
                            {
                                parsedVideoInfo = ParseXBMC(doc);
                                videoInfo.MergeVideoItemWith(parsedVideoInfo);
                                //videoInfo.videoItem = parsedVideoInfo.videoItem;
                            }
                            videoInfo.files.xbmc = videoItemFile;

                            parsedFile = true;
                        }
                    }
                    else if (fileContents.StartsWith("{"))
                    {
                        //if (parsedFile == false)
                        {
                            parsedVideoInfo = ParseMVE(fileInfo.FullName);
                            videoInfo.MergeVideoItemWith(parsedVideoInfo);
                            // videoInfo.videoItem = parsedVideoInfo.videoItem;
                        }
                        videoInfo.files.mve = videoItemFile;

                        parsedFile = true;
                    }

                    break;

                case "txt":
                    if (videoItemFile.Name.StartsWith("handbrake"))
                    {
                        parsedVideoInfo = ParseOtherHandrake(videoInfo.GetFullName(videoItemFile), videoItemFile);
                        videoInfo.MergeVideoItemWith(parsedVideoInfo);
                    }
                    else
                    {
                        parsedVideoInfo = ParseOtherFileName(videoInfo.GetFullName(videoItemFile), videoItemFile);
                        videoInfo.MergeVideoItemWith(parsedVideoInfo);
                    }

                    videoInfo.files.others.Add(videoItemFile);
                    break;

                default:
                    videoInfo.files.others.Add(videoItemFile);
                    break;
                } // end switch ext
            }     // end foreach file


            // couldnt parse nfo/xml and have video file in dir, so use video file for some basic info
            if (!parsedFile && videoInfo.files != null && videoInfo.files.video != null)
            {
                parsedVideoInfo = ParseVideoFile(videoInfo.files.video);
                videoInfo.MergeVideoItemWith(parsedVideoInfo);

                parsedFile = true;
            }

            /* .. no video file .. so skip
             * // couldnt parse nfo/xml and have files in dir, so use dir for some basic info
             * else if (!parsedFile && files.Count() > 0)
             * {
             *  DirectoryInfo directoryInfo = new DirectoryInfo(directory);
             *  parsedVideoInfo = ParseDirectory(directoryInfo);
             *  videoInfo.MergeVideoItemWith(parsedVideoInfo);
             *
             *  parsedFile = true;
             * }
             */

            if (videoInfo.videoItem.title == null || videoInfo.files == null || videoInfo.files.video == null)
            {
                videoInfo = null;
            }
            else
            {
                // sanitize some data

                // remove (year) from title .. bad prior parse mb, xbmc
                videoInfo.videoItem.title = Regex.Replace(videoInfo.videoItem.title, @"\([0-9]{4}\)$", "");
            }

            return(videoInfo);
        }