Esempio n. 1
0
        /// <summary>
        /// parse the MB .xml file
        /// </summary>
        /// <param name="doc"></param>
        /// <returns></returns>
        public VideoInfo ParseMB(XmlDocument doc)
        {
            VideoInfo videoInfo = new VideoInfo();

            videoInfo.Initialize();

            videoInfo.videoItem.title = MyXMLDoc.GetSingleNodeString(doc, "/Title/LocalTitle");

            videoInfo.videoItem.plot = MyXMLDoc.GetSingleNodeString(doc, "/Title/Overview");

            videoInfo.videoItem.movieset = "";
            videoInfo.videoItem.tagline  = MyXMLDoc.GetSingleNodeString(doc, "/Title/tagline");

            videoInfo.videoItem.imdbId = MyXMLDoc.GetSingleNodeString(doc, "/Title/IMDB");
            videoInfo.videoItem.tmdbId = MyXMLDoc.GetSingleNodeString(doc, "/Title/TMDbId");
            videoInfo.videoItem.mpaa   = MyXMLDoc.GetSingleNodeString(doc, "/Title/ContentRating");

            videoInfo.videoItem.imdbRating = MyXMLDoc.GetSingleNodeDecimal(doc, "/Title/Rating");

            videoInfo.videoItem.year    = MyXMLDoc.GetSingleNodeInt(doc, "/Title/ProductionYear");
            videoInfo.videoItem.runtime = MyXMLDoc.GetSingleNodeInt(doc, "/Title/RunningTime");


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

            return(videoInfo);
        }
Esempio n. 2
0
        public VideoEncoding ParseFFprobe(string encoding)
        {
            VideoEncoding ffmprobe = new VideoEncoding();

            if (String.IsNullOrEmpty(encoding))
            {
                return(ffmprobe);
            }

            // MyLog.Add("FFMPEG: xml " + encoding);

            try
            {
                XmlDocument doc = MyXMLDoc.LoadXml(encoding);
                if (doc == null)
                {
                    return(ffmprobe);
                }

                string width = MyXMLDoc.GetSingleNodeString(doc, "/ffprobe/streams/stream[@codec_type='video']/@width");
                if (!String.IsNullOrEmpty(width))
                {
                    ffmprobe.width = Convert.ToInt32(width);
                }
                string height = MyXMLDoc.GetSingleNodeString(doc, "/ffprobe/streams/stream[@codec_type='video']/@height");
                if (!String.IsNullOrEmpty(height))
                {
                    ffmprobe.height = Convert.ToInt32(height);
                }
                string bitrate = MyXMLDoc.GetSingleNodeString(doc, "/ffprobe/format[@filename]/@bit_rate");
                if (!String.IsNullOrEmpty(bitrate))
                {
                    ffmprobe.bitrate = Convert.ToInt32(bitrate);
                }
                string codec = MyXMLDoc.GetSingleNodeString(doc, "/ffprobe/streams/stream[@codec_type='video']/@codec_name");
                if (!String.IsNullOrEmpty(codec))
                {
                    ffmprobe.codec = codec;
                }

                // MyLog.Add("FFMPEG: ffmprobe " + MySerialize.ToXML(ffmprobe));
            }
            catch (Exception e)
            {
                MyLog.Add("ParseFFprobe: " + e.ToString());
            }

            return(ffmprobe);
        }
        /// <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);
        }
Esempio n. 5
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);
        }
Esempio n. 6
0
        /// <summary>
        /// parse the XBMC .nfo file
        /// </summary>
        /// <param name="doc"></param>
        /// <returns></returns>
        public VideoInfo ParseXBMC(XmlDocument doc)
        {
            VideoInfo videoInfo = new VideoInfo();

            videoInfo.Initialize();

            List <string> innerTexts;

            videoInfo.videoItem.title = MyXMLDoc.GetSingleNodeString(doc, "/movie/title");

            videoInfo.videoItem.plot = MyXMLDoc.GetSingleNodeString(doc, "/movie/plot");

            videoInfo.videoItem.movieset = MyXMLDoc.GetSingleNodeString(doc, "/movie/set");
            videoInfo.videoItem.tagline  = MyXMLDoc.GetSingleNodeString(doc, "/movie/tagline");

            videoInfo.videoItem.imdbId = MyXMLDoc.GetSingleNodeString(doc, "/movie/id");
            videoInfo.videoItem.tmdbId = MyXMLDoc.GetSingleNodeString(doc, "/movie/tmdbId");
            videoInfo.videoItem.mpaa   = MyXMLDoc.GetSingleNodeString(doc, "/movie/mpaa");

            videoInfo.videoItem.imdbRating = MyXMLDoc.GetSingleNodeDecimal(doc, "/movie/rating");

            videoInfo.videoItem.year      = MyXMLDoc.GetSingleNodeInt(doc, "/movie/year");
            videoInfo.videoItem.runtime   = MyXMLDoc.GetSingleNodeInt(doc, "/movie/runtime");
            videoInfo.videoItem.playCount = MyXMLDoc.GetSingleNodeInt(doc, "/movie/playcount");
            int watched = MyXMLDoc.GetSingleNodeInt(doc, "/movie/watched");

            if (watched != 0 && watched != 1)
            {
                watched = 0;
            }
            videoInfo.videoItem.watched = VideoFileEnums.watched.GetKeyByValue(watched);

            videoInfo.videoItem.encoding        = new VideoEncoding();
            videoInfo.videoItem.encoding.codec  = MyXMLDoc.GetSingleNodeString(doc, "/movie/fileinfo/streamdetails/video/codec");
            videoInfo.videoItem.encoding.width  = MyXMLDoc.GetSingleNodeInt(doc, "/movie/fileinfo/streamdetails/video/width");
            videoInfo.videoItem.encoding.height = MyXMLDoc.GetSingleNodeInt(doc, "/movie/fileinfo/streamdetails/video/height");


            innerTexts = MyXMLDoc.GetMultipleNodeString(doc, "/movie/director");
            videoInfo.videoItem.directors = new List <VideoItemDirector <string> > {
            };
            foreach (string innerText in innerTexts)
            {
                videoInfo.videoItem.directors.Add(new VideoItemDirector <string>(innerText));
            }

            innerTexts = MyXMLDoc.GetMultipleNodeString(doc, "/movie/genre");
            videoInfo.videoItem.genres = new List <VideoItemGenre <string> > {
            };
            foreach (string innerText in innerTexts)
            {
                videoInfo.videoItem.genres.Add(new VideoItemGenre <string>(innerText));
            }

            innerTexts = MyXMLDoc.GetMultipleNodeString(doc, "/movie/tag");
            videoInfo.videoItem.tags = new List <VideoItemTag <string> > {
            };
            foreach (string innerText in innerTexts)
            {
                videoInfo.videoItem.tags.Add(new VideoItemTag <string>(innerText));
            }



            videoInfo.videoItem.actors = new List <VideoItemActor <string, string> >();
            List <Dictionary <string, string> > actorInfos = MyXMLDoc.GetMultipleNestedNodeString(doc, "/movie/actor");

            foreach (Dictionary <string, string> actorInfo in actorInfos)
            {
                VideoItemActor <string, string> videoItemActor = new VideoItemActor <string, string>();
                foreach (KeyValuePair <string, string> info in actorInfo)
                {
                    switch (info.Key)
                    {
                    case "name":
                        videoItemActor.name = info.Value;
                        break;

                    case "role":
                        videoItemActor.role = info.Value;
                        break;

                    case "thumb":
                        break;

                    default:
                        break;
                    }
                }
                if (!String.IsNullOrEmpty(videoItemActor.name))
                {
                    videoInfo.videoItem.actors.Add(videoItemActor);
                }
            }

            return(videoInfo);
        }