private bool RemoveUri(string uri)
        {
            lock (_thisLock)
            {
                lock (_amoebaManager.ThisLock)
                {
                    var baseNode = _amoebaManager.BaseNode;

                    var uris = new List<string>(baseNode.Uris);
                    if (!uris.Remove(uri)) return false;

                    _amoebaManager.SetBaseNode(new Node(baseNode.Id, uris));
                }
            }

            return true;
        }
        public bool PlayMovie()
        {
            _info = _source.DVDDiskInfo;

            string videoFile = FindMPeg(_source);
            if (videoFile == null && _info != null)
            {
                OMLApplication.DebugLine("[MoviePlayerExtenderDVD] PlayMovie: DVD Disk info: '{0}'", _info);
                DVDTitle dvdTitle = _source.DVDTitle;
                if (dvdTitle != null)
                {
                    string videoTSDir = _source.VIDEO_TS;
                    int fileID = int.Parse(dvdTitle.File.Substring(4));
                    OMLApplication.DebugLine("[MoviePlayerExtenderDVD] PlayMovie: main title fileID={1} found for '{0}'", _source, fileID);
                    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"));

                    if (vobs.Count < 1)
                    {
                        OMLApplication.DebugLine("[MoviePlayerExtenderDVD] PlayMovie: no VOB files found for '{0}'", _source);
                        return false;
                    }

                    string mpegFolder = Path.Combine(FileSystemWalker.ExtenderCacheDirectory, Guid.NewGuid().ToString());
                    if (Directory.Exists(mpegFolder) == false)
                    {
                        OMLApplication.DebugLine("[MoviePlayerExtenderDVD] PlayMovie: creating folder '{0}'", mpegFolder);
                        Directory.CreateDirectory(mpegFolder);
                    }

                    if (vobs.Count == 1)
                    {
                        OMLApplication.DebugLine("[MoviePlayerExtenderDVD] Single VOB file, trying to use a hard-link approach and direct playback");
                        OMLApplication.DebugLine("[MoviePlayerExtenderDVD] Calling MakeMPEGLink on WCF Transcoder Service");
                        string mpegFile = transcoder.MakeMPEGLink(mpegFolder, vobs[0]);
                        if (File.Exists(mpegFile))
                        {
                            OMLApplication.DebugLine("[MoviePlayerExtenderDVD] directly use MPEG");
                            videoFile = mpegFile;
                        }
                    }
                    else if (OMLSettings.Extender_MergeVOB)
                    {
                        OMLApplication.DebugLine("[MoviePlayerExtenderDVD] Multiple VOB files, and Extender_MergeVOB == true, trying to use a hard-link and auto-merge into single large .VOB file approach ");
                        OMLApplication.DebugLine("[MoviePlayerExtenderDVD] Calling MakeMPEGLink on WCF Transcoder Service");
                        string mpegFile = transcoder.MakeMPEGLink(mpegFolder, vobs[0]);
                        OMLApplication.DebugLine("[MoviePlayerExtenderDVD] Merge VOB's, use first VOB to play and merge into");

                        if (File.Exists(mpegFile) == false)
                            return false;

                        videoFile = mpegFile;

                        Microsoft.MediaCenter.UI.Application.DeferredInvokeOnWorkerThread(delegate
                        {
                            FileStream writer = null;
                            try
                            {
                                writer = File.Open(vobs[0], FileMode.Append, FileAccess.Write, FileShare.Read);
                                for (int i = 1; i < vobs.Count; ++i)
                                    MergeFile(writer, vobs[0], vobs[i]);

                                for (int i = 1; i < vobs.Count; ++i)
                                {
                                    OMLApplication.DebugLine("[MoviePlayerExtenderDVD] Deleting '{0}'", vobs[i]);
                                    File.Delete(vobs[i]);
                                }
                            }
                            finally
                            {
                                if (writer != null)
                                {
                                    OMLApplication.DebugLine("[MoviePlayerExtenderDVD] Done merging into '{0}'", vobs[0]);
                                    writer.Close();
                                }
                            }
                        }, delegate
                        {
                            Utilities.DebugLine("[MoviePlayerExtenderDVD] Merging done, restart play, and reset posision");
                            if (AddInHost.Current.MediaCenterEnvironment.MediaExperience != null)
                            {
                                TimeSpan cur = AddInHost.Current.MediaCenterEnvironment.MediaExperience.Transport.Position;
                                Utilities.DebugLine("[MoviePlayerExtenderDVD] Current position: {0}", cur);
                                if (AddInHost.Current.MediaCenterEnvironment.PlayMedia(MediaType.Video, videoFile, false))
                                {
                                    AddInHost.Current.MediaCenterEnvironment.MediaExperience.Transport.Position = cur;
                                    Utilities.DebugLine("[MoviePlayerExtenderDVD] Done starting over, resetting position: {0}", cur);
                                }
                            }
                        }, null);
                    }
                    //else if (OMLSettings.Extender_UseAsx)
                    else
                    {
                        OMLApplication.DebugLine("[MoviePlayerExtenderDVD] Multiple VOB files, and Extender_UseAsx == true, trying to use a hard-link and asx playlist approach ");
                        foreach (string vob in vobs) {
                            OMLApplication.DebugLine("[MoviePlayerExtenderDVD] Calling MakeMPEGLink on WCF Transcoder Service");
                            transcoder.MakeMPEGLink(mpegFolder, vob);
                        }

                        if (File.Exists(GetMPEGName(mpegFolder, vobs[0])))
                            videoFile = CreateASX(mpegFolder, vts, _source.Name, vobs);
                    }
                }
                else
                    OMLApplication.DebugLine("[MoviePlayerExtenderDVD] PlayMovie: no main title found for {0}", _source);
            }
            else
                OMLApplication.DebugLine("[MoviePlayerExtenderDVD] PlayMovie: no DVD-DiskInfo found for {0}", _source);

            if (videoFile == null)
                videoFile = GetAsxFile();

            if (videoFile != null && AddInHost.Current.MediaCenterEnvironment.PlayMedia(MediaType.Video, videoFile, false))
            {
                if (AddInHost.Current.MediaCenterEnvironment.MediaExperience != null)
                {
                    Utilities.DebugLine("[MoviePlayerExtenderDVD] PlayMovie: movie '{0}', Playing file '{1}'", _source.Name, videoFile);
                    OMLApplication.Current.NowPlayingMovieName = _source.Name;
                    OMLApplication.Current.NowPlayingStatus = PlayState.Playing;
                    if (_source.ResumeTime != null)
                    {
                        Utilities.DebugLine("[MoviePlayerExtenderDVD] PlayMovie: set resume time to: {0}", _source.ResumeTime);
                        AddInHost.Current.MediaCenterEnvironment.MediaExperience.Transport.Position = _source.ResumeTime.Value;
                    }
                    //AddInHost.Current.MediaCenterEnvironment.MediaExperience.Transport.PropertyChanged -= MoviePlayerFactory.Transport_PropertyChanged;
                    //AddInHost.Current.MediaCenterEnvironment.MediaExperience.Transport.PropertyChanged += MoviePlayerFactory.Transport_PropertyChanged;
                    //AddInHost.Current.MediaCenterEnvironment.MediaExperience.Transport.PropertyChanged -= this.Transport_PropertyChanged;
                    //AddInHost.Current.MediaCenterEnvironment.MediaExperience.Transport.PropertyChanged += this.Transport_PropertyChanged;
                    AddInHost.Current.MediaCenterEnvironment.MediaExperience.GoToFullScreen();
                }
                return true;
            }
            else
            {
                return false;
            }
        }
        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;
        }
예제 #4
0
        private void DownloadLiveStream(Broadcast broadcast, AccessPublic accessPublic)
        {
            List<string> chunklist = new List<string>();
            Uri httpsHlsUrl = new Uri(accessPublic.https_hls_url);
            string baseUrl = httpsHlsUrl.Scheme + "://" + httpsHlsUrl.DnsSafeHost + httpsHlsUrl.Segments[0] + httpsHlsUrl.Segments[1] + httpsHlsUrl.Segments[2] + httpsHlsUrl.Segments[3];
            bool liveStream = true;
            while (liveStream)
            {
                UpdateChunklist(broadcast, baseUrl, ref chunklist, ref liveStream);

                foreach (var chunk in chunklist.ToList())
                {
                    string message;
                    chunklist.Remove(chunk);
                    DownloadChunk(broadcast, baseUrl, chunk, out message);
                    Console.WriteLine(message);
                }
            }

            var pDownload = new PDownload
            {
                User = broadcast.username,
                Broadcast = broadcast.id,
                DownloadLiveStream = false
            };
            DownloadVideos(pDownload);
        }