Exemplo n.º 1
0
        public override Dictionary <string, string> GetPlaybackOptions(string url)
        {
            Log.Info("!!" + url);
            url = url.TrimEnd('/');
            int    ii      = url.LastIndexOf('/');
            int    p       = url.IndexOf('&', ii);
            string videoId = url.Substring(ii + 1, p - ii - 1);

            Dictionary <string, string> options = new Dictionary <string, string>();

            AMFSerializer ser = new AMFSerializer();

            object[] values = new object[4];
            values[0] = videoId;
            values[1] = null;
            values[2] = null;
            values[3] = "false";
            byte[]    data = ser.Serialize2("viddlerGateway.getVideoInfo", values);
            AMFObject obj  = AMFObject.GetResponse(@"http://www.viddler.com/amfgateway.action", data);

            AMFArray files = obj.GetArray("files");

            for (int i = 0; i < files.Count; i++)
            {
                AMFObject file = files.GetObject(i);
                string    nm   = String.Format("{0}x{1} {2}K",
                                               file.GetDoubleProperty("width"), file.GetDoubleProperty("height"),
                                               file.GetDoubleProperty("bitrate"));
                string filename = file.GetStringProperty("filename");
                string path     = file.GetStringProperty("path");
                options.Add(nm, decryptPath(path));
            }
            return(options);
        }
Exemplo n.º 2
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));
        }
Exemplo n.º 3
0
        public override string GetVideoUrl(VideoInfo video)
        {
            string   result     = string.Empty;
            string   videoId    = string.Empty;
            AMFArray renditions = null;

            if (RequestType.Equals(BrightCoveType.FindMediaById))
            {
                /*
                 * sample AMF input (expressed as JSON)
                 * ["466faf0229239e70a6df8fe66fc04f25f50e6fa7",48543011001,1401332946001,15364602001]
                 */
                videoId = video.VideoUrl;

                object[] values = new object[4];
                values[0] = hashValue;
                values[1] = Convert.ToDouble(playerId);
                values[2] = Convert.ToDouble(videoId);
                values[3] = Convert.ToDouble(publisherId);

                AMFSerializer serializer = new AMFSerializer();
                AMFObject     response   = AMFObject.GetResponse(brightcoveUrl, serializer.Serialize2("com.brightcove.player.runtime.PlayerMediaFacade.findMediaById", values, AMFVersion.AMF3));
                //Log.Debug("AMF Response: {0}", response.ToString());

                renditions = response.GetArray("renditions");
            }
            else
            {
                /*
                 * sample AMF input for ViewerExperience (expressed in pretty-printed JSON for clarity - captured using Flashbug in Firebug)
                 * [
                 *  {"targetURI":"com.brightcove.experience.ExperienceRuntimeFacade.getDataForExperience",
                 *   "responseURI":"/1",
                 *   "length":"461 B",
                 *   "data":["82c0aa70e540000aa934812f3573fd475d131a63",
                 *      {"contentOverrides":[
                 *          {"contentType":0,
                 *           "target":"videoPlayer",
                 *           "featuredId":null,
                 *           "contentId":1411956407001,
                 *           "featuredRefId":null,
                 *           "contentIds":null,
                 *           "contentRefId":null,
                 *           "contentRefIds":null,
                 *           "__traits":
                 *              {"type":"com.brightcove.experience.ContentOverride",
                 *               "members":["contentType","target","featuredId","contentId","featuredRefId","contentIds","contentRefId","contentRefIds"],
                 *               "count":8,
                 *               "externalizable":false,
                 *               "dynamic":false}}],
                 *        "TTLToken":"",
                 *        "deliveryType":null,
                 *        "playerKey":"AQ~~,AAAABDk7A3E~,xYAUE9lVY9-LlLNVmcdybcRZ8v_nIl00",
                 *        "URL":"http://ww3.tvo.org/video/171480/safe-houses",
                 *        "experienceId":756015080001,
                 *        "__traits":
                 *          {"type":"com.brightcove.experience.ViewerExperienceRequest",
                 *           "members":["contentOverrides","TTLToken","deliveryType","playerKey","URL","experienceId"],
                 *           "count":6,
                 *           "externalizable":false,
                 *           "dynamic":false}}]}]
                 */
                videoId = getBrightCoveVideoIdForViewerExperienceRequest(video.VideoUrl);
                if (!string.IsNullOrEmpty(videoId))
                {
                    // content override
                    AMFObject contentOverride = new AMFObject(@"com.brightcove.experience.ContentOverride");
                    contentOverride.Add("contentId", videoId);
                    contentOverride.Add("contentIds", null);
                    contentOverride.Add("contentRefId", null);
                    contentOverride.Add("contentRefIds", null);
                    contentOverride.Add("contentType", 0);
                    contentOverride.Add("featuredId", double.NaN);
                    contentOverride.Add("featuredRefId", null);
                    contentOverride.Add("target", "videoPlayer");
                    AMFArray contentOverrideArray = new AMFArray();
                    contentOverrideArray.Add(contentOverride);

                    // viewer experience request
                    AMFObject viewerExperenceRequest = new AMFObject(@"com.brightcove.experience.ViewerExperienceRequest");
                    viewerExperenceRequest.Add("contentOverrides", contentOverrideArray);
                    viewerExperenceRequest.Add("experienceId", Convert.ToDouble(playerId));
                    viewerExperenceRequest.Add("deliveryType", null);
                    viewerExperenceRequest.Add("playerKey", string.Empty);
                    viewerExperenceRequest.Add("URL", video.VideoUrl);
                    viewerExperenceRequest.Add("TTLToken", string.Empty);

                    //Log.Debug("About to make AMF call: {0}", viewerExperenceRequest.ToString());
                    AMFSerializer serializer = new AMFSerializer();
                    AMFObject     response   = AMFObject.GetResponse(brightcoveUrl, serializer.Serialize(viewerExperenceRequest, "com.brightcove.experience.ExperienceRuntimeFacade.getDataForExperience", hashValue));
                    //Log.Debug("AMF Response: {0}", response.ToString());

                    renditions = response.GetArray("programmedContent").GetObject("videoPlayer").GetObject("mediaDTO").GetArray("renditions");
                }
            }

            if (renditions == null)
            {
                return(result);
            }

            video.PlaybackOptions = new Dictionary <string, string>();
            // keep track of bitrates and URLs
            Dictionary <string, string> urlsDictionary = new Dictionary <string, string>();

            for (int i = 0; i < renditions.Count; i++)
            {
                AMFObject rendition = renditions.GetObject(i);
                int       bitrate   = rendition.GetIntProperty("encodingRate");
                string    optionKey = String.Format("{0}x{1} {2}K",
                                                    rendition.GetIntProperty("frameWidth"),
                                                    rendition.GetIntProperty("frameHeight"),
                                                    bitrate / 1024);
                string url = HttpUtility.UrlDecode(rendition.GetStringProperty("defaultURL"));
                Log.Debug("Option: {0} URL: {1}", optionKey, url);

                // typical rtmp url from "defaultURL" is:
                // rtmp://brightcove.fcod.llnwd.net/a500/d20/&mp4:media/1351824783/1351824783_1411974095001_109856X-640x360-1500k.mp4&1330020000000&1b163106256f448754aff72969869479
                //
                // following rtmpdump style command works
                // rtmpdump
                // --app 'a500/d20/?videoId=1411956407001&lineUpId=&pubId=18140038001&playerId=756015080001&playerTag=&affiliateId='
                // --auth 'mp4:media/1351824783/1351824783_1411974097001_109856X-400x224-300k.mp4&1330027200000&23498dd8f4659cd07ad1b6c4ee5a013d'
                // --rtmp 'rtmp://brightcove.fcod.llnwd.net/a500/d20/?videoId=1411956407001&lineUpId=&pubId=18140038001&playerId=756015080001&playerTag=&affiliateId='
                // --flv 'TVO_org_-_Safe_as_Houses.flv'
                // --playpath 'mp4:media/1351824783/1351824783_1411974097001_109856X-400x224-300k.mp4'

                Match rtmpUrlMatch = rtmpUrlRegex.Match(url);

                if (rtmpUrlMatch.Success)
                {
                    string leftover = rtmpUrlMatch.Groups["leftover"].Value;
                    string query    = string.Format(@"videoId={0}&lineUpId=&pubId={1}&playerId={2}&playerTag=&affiliateId=",
                                                    videoId, publisherId, playerId);

                    int questionMarkPosition = leftover.IndexOf('?');
                    // use existing query (if present) in the new query string
                    if (questionMarkPosition != -1)
                    {
                        query = string.Format(@"{0}{1}", leftover.Substring(questionMarkPosition + 1, leftover.Length - questionMarkPosition - 1), query);
                    }

                    string app     = String.Format("{0}?{1}", rtmpUrlMatch.Groups["app"], query);
                    string auth    = leftover;
                    string rtmpUrl = String.Format("{0}://{1}/{2}?{3}",
                                                   rtmpUrlMatch.Groups["rtmp"].Value,
                                                   rtmpUrlMatch.Groups["host"].Value,
                                                   rtmpUrlMatch.Groups["app"].Value,
                                                   query);
                    int    ampersandPosition = leftover.IndexOf('&');
                    string playPath          = ampersandPosition == -1 ? leftover : leftover.Substring(0, ampersandPosition);
                    Log.Debug(@"rtmpUrl: {0}, PlayPath: {1}, App: {2}, Auth: {3}", rtmpUrl, playPath, app, auth);
                    urlsDictionary.Add(optionKey, new RtmpUrl(rtmpUrl)
                    {
                        PlayPath = playPath,
                        App      = app,
                        Auth     = auth
                    }.ToString());
                }
            }

            // sort the URLs ascending by bitrate
            foreach (var item in urlsDictionary.OrderBy(u => u.Key, new BitrateComparer()))
            {
                video.PlaybackOptions.Add(item.Key, item.Value);
                // return last URL as the default (will be the highest bitrate)
                result = item.Value;
            }
            return(result);
        }
Exemplo n.º 4
0
        public override string GetVideoUrl(VideoInfo video)
        {
            string webdata = GetWebData(video.VideoUrl);
            //Match m = new Regex(@"playerID=(\d+).*?videoPlayer=ref:(C\d+)").Match(webdata);
            EpisodeInfo info = new EpisodeInfo();
            Match       m;

            if ((m = Regex.Match(webdata, @"<div class=""secondary_nav_header"".*?>.*?<h\d><span.*?>(.*?)<", RegexOptions.Singleline)).Success)
            {
                info.SeriesTitle = m.Groups[1].Value;
            }
            if ((m = Regex.Match(webdata, @"<h3 class=""episode_header""><span.*?>(.*?)<")).Success)
            {
                string result = m.Groups[1].Value;
                if ((m = Regex.Match(result, @"Series (\d+)")).Success)
                {
                    info.SeriesNumber = m.Groups[1].Value;
                }
                if ((m = Regex.Match(result, @"Episode (\d+)")).Success)
                {
                    info.EpisodeNumber = m.Groups[1].Value;
                }
            }
            if ((m = Regex.Match(webdata, @"<p>First broadcast at (.*?)</p>")).Success)
            {
                DateTime airDate;
                if (DateTime.TryParse(m.Groups[1].Value, out airDate))
                {
                    info.AirDate = airDate.ToString("d MMMM");
                    if (string.IsNullOrEmpty(info.SeriesNumber))
                    {
                        info.SeriesNumber = airDate.Year.ToString();
                    }
                }
            }

            video.Other = info;

            m = new Regex(@"videoPlayer=ref:(C\d+)").Match(webdata);
            if (!m.Success)
            {
                return(String.Empty);
            }

            AMFObject viewerExperience = getViewerExperience(m.Groups[1].Value, video.VideoUrl);
            AMFObject mediaDTO         = viewerExperience.GetArray("programmedContent").GetObject("videoPlayer").GetObject("mediaDTO");

            if (!string.IsNullOrEmpty(mediaDTO.GetStringProperty("drmMetadataURL")))
            {
                video.PlaybackOptions = YouTubeShowHandler.GetYouTubePlaybackOptions(video.Other as EpisodeInfo);
                if (video.PlaybackOptions != null && video.PlaybackOptions.Count > 0)
                {
                    return(video.PlaybackOptions.Last().Value);
                }
                return(null);
            }

            AMFArray renditions = mediaDTO.GetArray("renditions");

            return(FillPlaybackOptions(video, renditions));
        }
        public override List <VideoInfo> GetVideos(Category category)
        {
            List <VideoInfo> result = new List <VideoInfo>();

            /*
             * sample AMF input for findPagingMediaCollectionByReferenceId (expressed in pretty-printed JSON for clarity - captured using Firebug)
             *
             *  ["1ddf0ed58803c0533b0f82a8ff68ae50e0e12f52",1706768404001,"cn-johnny-test-playlist-clip",0,50,1873145815]
             */

            object[] amfInput = new object[6];
            amfInput[0] = hashValue;
            amfInput[1] = Convert.ToDouble(playerId);
            amfInput[2] = string.Format(@"cn-{0}-playlist-clip", ((RssLink)category).Url);
            amfInput[3] = Convert.ToDouble(@"0");
            amfInput[4] = Convert.ToDouble(@"50");
            amfInput[5] = Convert.ToDouble(publisherId);

            AMFSerializer serializer = new AMFSerializer();
            AMFObject     response   = AMFObject.GetResponse(brightcoveUrl, serializer.Serialize2("com.brightcove.player.runtime.PlayerMediaFacade.findPagingMediaCollectionByReferenceId", amfInput));

            //Log.Debug("AMF Response: {0}", response.ToString());
            string lineUpId = response.GetDoubleProperty("id").ToString();

            Log.Debug("LineUpId: {0}", lineUpId);

            AMFArray videoDTOs = response.GetArray("videoDTOs");

            if (videoDTOs != null)
            {
                for (int i = 0; i < videoDTOs.Count; i++)
                {
                    AMFObject videoDTO = videoDTOs.GetObject(i);

                    string url = videoDTO.GetStringProperty("FLVFullLengthURL");

                    // typical URL from FLVFullLengthURL
                    // rtmpe://cp102794.edgefcs.net/ondemand/&tv/johnnyTest/video/johnnyTest_clip2_eps19_en
                    //
                    // following rtmpdump style command works
                    // rtmpdump
                    // --rtmp 'rtmpe://cp102794.edgefcs.net:1935/ondemand?videoId=3066558001&lineUpId=1664607936001&pubId=1873145815&playerId=1706768404001&affiliateId='
                    // --flv 'johnnyTest_clip2_eps19_en.mp4'
                    // --playpath 'tv/johnnyTest/video/johnnyTest_clip2_eps19_en?videoId=3066558001&lineUpId=1664607936001&pubId=1873145815&playerId=1706768404001&affiliateId='

                    Match rtmpUrlMatch = rtmpUrlRegex.Match(url);

                    if (rtmpUrlMatch.Success)
                    {
                        string videoId = videoDTO.GetDoubleProperty("id").ToString();
                        string query   = string.Format(@"videoId={0}&lineUpId={1}&pubId={2}&playerId={3}&affiliateId=",
                                                       videoId, lineUpId, publisherId, playerId);
                        string rtmpUrl = String.Format("{0}://{1}/{2}?{3}",
                                                       rtmpUrlMatch.Groups["rtmp"].Value,
                                                       rtmpUrlMatch.Groups["host"].Value,
                                                       rtmpUrlMatch.Groups["app"].Value,
                                                       query);
                        string playPath = string.Format(@"{0}?{1}", rtmpUrlMatch.Groups["leftover"].Value, query);
                        Log.Debug(@"RTMP URL: {0}, playPath: {1}", rtmpUrl, playPath);

                        VideoInfo video = new VideoInfo()
                        {
                            Title       = videoDTO.GetStringProperty("displayName"),
                            Thumb       = videoDTO.GetStringProperty("thumbnailURL"),
                            Description = videoDTO.GetStringProperty("longDescription"),
                            Length      = TimeSpan.FromSeconds(videoDTO.GetDoubleProperty("length") / 1000).ToString(),
                            VideoUrl    = new RtmpUrl(rtmpUrl)
                            {
                                PlayPath = playPath
                            }.ToString()
                        };

                        result.Add(video);
                    }
                }
            }
            else
            {
                Log.Error(@"No videos found for {0}", category.Name);
            }
            return(result);
        }