コード例 #1
0
        private void SetListItem(VideoInfo videoInfo, VideoItemFile videoItemFile, string fileType)
        {
            VideoItemFileInfo videoItemFileInfo = new VideoItemFileInfo();

            videoItemFileInfo.videoInfo     = videoInfo;
            videoItemFileInfo.videoItemFile = videoItemFile;

            // if not already in image list, add to it
            if (!smallImageList.Images.ContainsKey(videoItemFile.Extension))
            {
                Icon icon = MyFileTypeIcon.Get(videoItemFileInfo.GetFullName());
                if (icon != null)
                {
                    smallImageList.Images.Add(videoItemFile.Extension, icon);
                }
            }

            ListViewItem listViewItem = new ListViewItem(videoItemFile.Name);

            listViewItem.ImageKey = videoItemFile.Extension;
            listViewItem.SubItems.Add(fileType);
            string fileSize = Convert.ToString(MyFile.FormatSize(videoItemFile.Length));

            listViewItem.SubItems.Add(fileSize);


            listViewItem.Tag = videoItemFileInfo;

            listView.Items.Add(listViewItem);
        }
コード例 #2
0
        public VideoInfo ParseOtherHandrake(string fileFullName, VideoItemFile videoItemFile)
        {
            VideoInfo videoInfo = new VideoInfo();

            videoInfo.Initialize();

            string contents = MyFile.ReadAllText(fileFullName);

            if (String.IsNullOrEmpty(contents))
            {
                return(videoInfo);
            }

            Regex regexSize = new Regex(@"\+ Crop and Scale \(([0-9]{3,4}):([0-9]{3,4}):", RegexOptions.IgnoreCase);
            Match matchSize = regexSize.Match(contents);

            if (matchSize.Success && matchSize.Groups.Count == 3)
            {
                int width = 0;
                int.TryParse(matchSize.Groups[1].Value, out width);
                videoInfo.videoItem.encoding.width = width;
                int height = 0;
                int.TryParse(matchSize.Groups[2].Value, out height);
                videoInfo.videoItem.encoding.height = height;
            }

            if (contents.IndexOf("x264", StringComparison.OrdinalIgnoreCase) != -1)
            {
                videoInfo.videoItem.encoding.codec = "x264";
            }

            // hmm .. not alawys valid ..
            // Regex regexBitrate = new Regex(@"\+ bitrate ([0-9]{3,5}) kbps", RegexOptions.IgnoreCase);
            // so try summing all track instead
            int             bitrateVideoAudio = 0;
            Regex           regexBitrate      = new Regex(@"bytes, ([0-9]{3,5})\.[0-9]{2} kbps, fifo", RegexOptions.IgnoreCase);
            MatchCollection matchBitrates     = regexBitrate.Matches(contents);

            foreach (Match matchBitrate in matchBitrates)
            {
                if (matchBitrate.Success && matchBitrate.Groups.Count == 2)
                {
                    for (int index = matchBitrate.Groups.Count - 1; index >= 1; index--)
                    {
                        int bitrate = 0;
                        int.TryParse(matchBitrate.Groups[index].Value, out bitrate);
                        bitrateVideoAudio += bitrate;
                    }
                }
            }
            // MyLog.Add(videoItemFile.FullName + " bitrate : " + bitrateVideoAudio.ToString());
            if (bitrateVideoAudio > 100)
            {
                videoInfo.videoItem.encoding.bitrate = bitrateVideoAudio * 1024;
            }


            return(videoInfo);
        }
コード例 #3
0
        public VideoInfo ParseOtherFileName(string fileFullName, VideoItemFile videoItemFile)
        {
            VideoInfo videoInfo = new VideoInfo();

            videoInfo.Initialize();

            if (videoItemFile.Name.IndexOf("dvd", StringComparison.OrdinalIgnoreCase) != -1)
            {
                videoInfo.videoItem.source = "DVD";
            }
            else if (videoItemFile.Name.IndexOf("bluray", StringComparison.OrdinalIgnoreCase) != -1)
            {
                videoInfo.videoItem.source = "Bluray";
            }
            else if (videoItemFile.Name.IndexOf("amazon", StringComparison.OrdinalIgnoreCase) != -1 ||
                     videoItemFile.Name.IndexOf("hulu", StringComparison.OrdinalIgnoreCase) != -1 ||
                     videoItemFile.Name.IndexOf("crackle", StringComparison.OrdinalIgnoreCase) != -1)
            {
                videoInfo.videoItem.source = "Stream";
            }

            if (videoItemFile.Name.IndexOf("extended", StringComparison.OrdinalIgnoreCase) != -1)
            {
                videoInfo.videoItem.version = "Extended";
            }
            else if (videoItemFile.Name.IndexOf("director", StringComparison.OrdinalIgnoreCase) != -1)
            {
                videoInfo.videoItem.version = "Director";
            }
            else if (videoItemFile.Name.IndexOf("unrated", StringComparison.OrdinalIgnoreCase) != -1)
            {
                videoInfo.videoItem.version = "Unrated";
            }
            else if (videoItemFile.Name.IndexOf("theater", StringComparison.OrdinalIgnoreCase) != -1)
            {
                videoInfo.videoItem.version = "Theater";
            }

            if (videoItemFile.Name.IndexOf("review", StringComparison.OrdinalIgnoreCase) != -1)
            {
                videoInfo.videoItem.notes += videoItemFile.Name.Replace(".txt", "");
            }
            if (videoItemFile.Name.IndexOf("notes", StringComparison.OrdinalIgnoreCase) != -1)
            {
                videoInfo.videoItem.notes += videoItemFile.Name.Replace(".txt", "");
            }

            return(videoInfo);
        }
コード例 #4
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);
        }
コード例 #5
0
        public string GetFullName(VideoItemFile videoItemFile)
        {
            if (String.IsNullOrEmpty(videoDirectory))
            {
                return(null);
            }
            if (videoItemFile == null || String.IsNullOrEmpty(videoItemFile.Name))
            {
                return(null);
            }
            string fullName = videoDirectory;

            if (!String.IsNullOrEmpty(videoItemFile.SubDirectory))
            {
                fullName += @"\" + videoItemFile.SubDirectory;
            }
            fullName += @"\" + videoItemFile.Name;
            // MyLog.Add("VideoInfo GetFullName : " + fullName);
            return(fullName);
        }
コード例 #6
0
        public VideoInfo ParseVideoFile(VideoItemFile videoItemFile)
        {
            VideoInfo videoInfo = new VideoInfo();

            videoInfo.Initialize();

            string title;
            int    year        = 0;
            int    indexOfYear = videoItemFile.Name.IndexOf(" (");

            if (indexOfYear != -1)
            {
                title = videoItemFile.Name.Substring(0, indexOfYear);
                Match match = Regex.Match(videoItemFile.Name, @"\((\d+).?\)");
                try
                {
                    year = Convert.ToInt32(match.Groups[1].Value);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
            else
            {
                title = videoItemFile.Name;
                year  = 0;
            }
            videoInfo.videoItem       = new VideoItem();
            videoInfo.videoItem.title = title;

            videoInfo.videoItem.year = year;

            videoInfo.videoItem.playCount = 0;
            videoInfo.videoItem.watched   = "NO";

            // videoInfo.videoItem.plot = "(unknow) (from Video file)";

            return(videoInfo);
        }
コード例 #7
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);
        }
コード例 #8
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);
        }