Ejemplo n.º 1
0
        private string FillPlaybackOptions(VideoInfo video, AMFArray renditions)
        {
            SortedList <string, string> options = new SortedList <string, string>(new StreamComparer());

            for (int i = 0; i < renditions.Count; i++)
            {
                AMFObject rendition    = renditions.GetObject(i);
                int       encodingRate = rendition.GetIntProperty("encodingRate");
                string    nm           = String.Format("{0}x{1} | {2} kbps",
                                                       rendition.GetIntProperty("frameWidth"), rendition.GetIntProperty("frameHeight"),
                                                       encodingRate / 1000);
                string url = HttpUtility.UrlDecode(rendition.GetStringProperty("defaultURL"));
                if (url.StartsWith("rtmp"))
                {
                    string auth = String.Empty;
                    if (url.Contains('?'))
                    {
                        auth = '?' + url.Split('?')[1];
                    }
                    string[] parts = url.Split('&');

                    string rtmp     = parts[0] + auth;
                    string playpath = parts[1].Split('?')[0] + auth;

                    url = new MPUrlSourceFilter.RtmpUrl(rtmp)
                    {
                        PlayPath  = playpath,
                        SwfUrl    = "http://admin.brightcove.com/viewer/us20111207.0737/connection/ExternalConnection_2.swf",
                        SwfVerify = true
                    }.ToString();
                }
                if (!options.ContainsKey(nm))
                {
                    options.Add(nm, url);
                }
            }

            video.PlaybackOptions = new Dictionary <string, string>();
            foreach (KeyValuePair <string, string> key in options)
            {
                video.PlaybackOptions.Add(key.Key, key.Value);
            }

            return(StreamComparer.GetBestPlaybackUrl(video.PlaybackOptions, StreamQualityPref, AutoSelectStream));
        }
Ejemplo n.º 2
0
        string populateUrlsFromXml(VideoInfo video, XmlDocument streamPlaylist, bool live)
        {
            if (streamPlaylist == null)
            {
                Log.Warn("ITVPlayer: Stream playlist is null");
                return("");
            }

            XmlNode videoEntry = streamPlaylist.SelectSingleNode("//VideoEntries/Video");

            if (videoEntry == null)
            {
                Log.Warn("ITVPlayer: Could not find video entry");
                return("");
            }

            XmlNode node;

            node = videoEntry.SelectSingleNode("./MediaFiles");
            if (node == null || node.Attributes["base"] == null)
            {
                Log.Warn("ITVPlayer: Could not find base url");
                return("");
            }

            string rtmpUrl = node.Attributes["base"].Value;
            SortedList <string, string> options = new SortedList <string, string>(new StreamComparer());

            foreach (XmlNode mediaFile in node.SelectNodes("./MediaFile"))
            {
                if (mediaFile.Attributes["delivery"] == null || mediaFile.Attributes["delivery"].Value != "Streaming")
                {
                    continue;
                }

                string title = "";
                if (mediaFile.Attributes["bitrate"] != null)
                {
                    title = mediaFile.Attributes["bitrate"].Value;
                    int bitrate;
                    if (int.TryParse(title, out bitrate))
                    {
                        title = string.Format("{0} kbps", bitrate / 1000);
                    }
                }

                if (!options.ContainsKey(title))
                {
                    string url = new MPUrlSourceFilter.RtmpUrl(rtmpUrl)
                    {
                        PlayPath  = mediaFile.InnerText,
                        SwfUrl    = "http://www.itv.com/mediaplayer/ITVMediaPlayer.swf?v=12.18.4",
                        SwfVerify = true,
                        Live      = live
                    }.ToString();
                    options.Add(title, url);
                }
            }

            video.PlaybackOptions = new Dictionary <string, string>();
            foreach (KeyValuePair <string, string> key in options)
            {
                video.PlaybackOptions.Add(key.Key, key.Value);
            }

            if (RetrieveSubtitles)
            {
                node = videoEntry.SelectSingleNode("./ClosedCaptioningURIs");
                if (node != null && Helpers.UriUtils.IsValidUri(node.InnerText))
                {
                    video.SubtitleText = OnlineVideos.Sites.Utils.SubtitleReader.TimedText2SRT(GetWebData(node.InnerText));
                }
            }

            return(StreamComparer.GetBestPlaybackUrl(video.PlaybackOptions, StreamQualityPref, AutoSelectStream));
        }