예제 #1
0
        public static string FindMPeg(MediaSource source)
        {
            DVDTitle dvdTitle = source.DVDTitle;

            if (dvdTitle == null)
            {
                return(null);
            }

            // ensure DVD's with DTS audio get transcoded, since extenders don't support DTS audio playback
            if (dvdTitle.AudioTracks.Count > 0 && dvdTitle.AudioTracks[0].Format == AudioEncoding.DTS)
            {
                return(null);
            }

            string        videoTSDir = source.VIDEO_TS;
            int           fileID     = int.Parse(dvdTitle.File.Substring(4));
            string        vts        = string.Format("VTS_{0:D2}_", fileID);
            List <string> vobs       = new List <string>(Directory.GetFiles(videoTSDir, vts + "*.VOB"));

            vobs.Remove(Path.Combine(videoTSDir, vts + "0.VOB"));

            // don't direct play unmerged .VOB files
            if (vobs.Count < 1 || vobs.Count > 1)
            {
                return(null);
            }

            if (IsNTFS(videoTSDir))
            {
                string mpegFolder = Path.Combine(FileSystemWalker.ExtenderCacheDirectory, Guid.NewGuid().ToString());

                if (Directory.Exists(mpegFolder) == false)
                {
                    Directory.CreateDirectory(mpegFolder);
                }
                if (Directory.Exists(mpegFolder) == false)
                {
                    return(null);
                }

                OMLApplication.DebugLine("[MoviePlayerExtenderDVD] Attempting to connect to WCF Transcoder Service");
                TranscodingAPI transcoder = new TranscodingAPI(source, null);
                OMLApplication.DebugLine("[MoviePlayerExtenderDVD] Calling MakeMPEGLink on WCF Transcoder Service");
                string mpegFile = transcoder.MakeMPEGLink(mpegFolder, vobs[0]);
                if (File.Exists(mpegFile))
                {
                    return(mpegFile);
                }
            }
            else if (videoTSDir.StartsWith("\\\\"))
            {
                string mpegFile = Path.ChangeExtension(source.GetTranscodingFileName(), ".MPEG");
                if (File.Exists(mpegFile))
                {
                    OMLApplication.DebugLine("[MoviePlayerExtenderDVD] Found '{0}' as pre-existing .MPEG soft-link", mpegFile);
                    return(mpegFile);
                }

                string vob = Path.Combine(videoTSDir, vobs[0]);
                OMLApplication.DebugLine("[MoviePlayerExtenderDVD] Trying to create '{0}' soft-link to '{1}'", mpegFile, vob);

                OMLApplication.DebugLine("[MoviePlayerExtenderDVD] Attempting to connect to WCF Transcoder Service");
                TranscodingAPI transcoder = new TranscodingAPI(source, null);
                OMLApplication.DebugLine("[MoviePlayerExtenderDVD] Calling CreateSymbolicLink on WCF Transcoder Service");
                bool   ret    = transcoder.CreateSymbolicLink(mpegFile, vob);
                string retMsg = ret ? "success" : "Sym-Link failed: " + new Win32Exception(Marshal.GetLastWin32Error()).Message;

                if (File.Exists(mpegFile))
                {
                    return(mpegFile);
                }
                OMLApplication.DebugLine("[MoviePlayerExtenderDVD] Soft-link creation failed! {0}", retMsg);
            }
            else
            {
                OMLApplication.DebugLine("[MoviePlayerExtenderDVD] Media not on a network drive nor on a NTFS compatible drive, no supported");
            }

            return(null);
        }