protected AMFArray GetResultsFromViewerExperienceRequest(Match m, string videoUrl) { AMFObject contentOverride = new AMFObject("com.brightcove.experience.ContentOverride"); System.Text.RegularExpressions.Group g; if ((g = m.Groups["contentId"]).Success) { Log.Debug("param contentId=" + g.Value); contentOverride.Add("contentId", (double)Int64.Parse(g.Value)); } else contentOverride.Add("contentId", double.NaN); contentOverride.Add("target", "videoPlayer"); if ((g = m.Groups["contentRefId"]).Success) { Log.Debug("param contentRefId=" + g.Value); contentOverride.Add("contentRefId", g.Value); } else contentOverride.Add("contentRefId", null); contentOverride.Add("featuredRefId", null); contentOverride.Add("contentRefIds", null); contentOverride.Add("featuredId", double.NaN); contentOverride.Add("contentIds", null); contentOverride.Add("contentType", 0); AMFArray array = new AMFArray(); array.Add(contentOverride); AMFObject ViewerExperienceRequest = new AMFObject("com.brightcove.experience.ViewerExperienceRequest"); ViewerExperienceRequest.Add("TTLToken", String.Empty); if ((g = m.Groups["playerKey"]).Success) { Log.Debug("param playerKey=" + g.Value); ViewerExperienceRequest.Add("playerKey", g.Value); } else ViewerExperienceRequest.Add("playerKey", playerKey); ViewerExperienceRequest.Add("deliveryType", double.NaN); ViewerExperienceRequest.Add("contentOverrides", array); ViewerExperienceRequest.Add("URL", videoUrl); Log.Debug("param URL=" + videoUrl); if ((g = m.Groups["experienceId"]).Success) { Log.Debug("param experienceId=" + g.Value); ViewerExperienceRequest.Add("experienceId", (double)Int64.Parse(g.Value)); } else ViewerExperienceRequest.Add("experienceId", double.NaN); AMFSerializer ser = new AMFSerializer(); byte[] data = ser.Serialize(ViewerExperienceRequest, "com.brightcove.experience.ExperienceRuntimeFacade.getDataForExperience", hashValue); AMFObject response = AMFObject.GetResponse(requestUrl, data); return response.GetArray("programmedContent").GetObject("videoPlayer").GetObject("mediaDTO").GetArray("renditions"); }
AMFObject getViewerExperience(string contentRefId, string videoUrl) { AMFObject contentOverride = new AMFObject("com.brightcove.experience.ContentOverride"); contentOverride.Add("contentId", double.NaN); contentOverride.Add("target", "videoPlayer"); contentOverride.Add("contentRefId", contentRefId); contentOverride.Add("featuredRefId", null); contentOverride.Add("contentRefIds", null); contentOverride.Add("featuredId", double.NaN); contentOverride.Add("contentIds", null); contentOverride.Add("contentType", 0); AMFArray array = new AMFArray(); array.Add(contentOverride); AMFObject ViewerExperienceRequest = new AMFObject("com.brightcove.experience.ViewerExperienceRequest"); ViewerExperienceRequest.Add("TTLToken", String.Empty); ViewerExperienceRequest.Add("playerKey", String.Empty); ViewerExperienceRequest.Add("deliveryType", double.NaN); ViewerExperienceRequest.Add("contentOverrides", array); ViewerExperienceRequest.Add("URL", videoUrl); ViewerExperienceRequest.Add("experienceId", playerId); AMFSerializer ser = new AMFSerializer(); byte[] data = ser.Serialize(ViewerExperienceRequest, hashValue); string requestUrl = "http://c.brightcove.com/services/messagebroker/amf?playerid=" + playerId; return(GetResponse(requestUrl, data)); }
protected AMFArray GetResultsFromViewerExperienceRequest(Match m, string videoUrl) { AMFObject contentOverride = new AMFObject("com.brightcove.experience.ContentOverride"); System.Text.RegularExpressions.Group g; if ((g = m.Groups["contentId"]).Success) { Log.Debug("param contentId=" + g.Value); contentOverride.Add("contentId", (double)Int64.Parse(g.Value)); } else { contentOverride.Add("contentId", double.NaN); } contentOverride.Add("target", "videoPlayer"); if ((g = m.Groups["contentRefId"]).Success) { Log.Debug("param contentRefId=" + g.Value); contentOverride.Add("contentRefId", g.Value); } else { contentOverride.Add("contentRefId", null); } contentOverride.Add("featuredRefId", null); contentOverride.Add("contentRefIds", null); contentOverride.Add("featuredId", double.NaN); contentOverride.Add("contentIds", null); contentOverride.Add("contentType", 0); AMFArray array = new AMFArray(); array.Add(contentOverride); AMFObject ViewerExperienceRequest = new AMFObject("com.brightcove.experience.ViewerExperienceRequest"); ViewerExperienceRequest.Add("TTLToken", String.Empty); if ((g = m.Groups["playerKey"]).Success) { Log.Debug("param playerKey=" + g.Value); ViewerExperienceRequest.Add("playerKey", g.Value); } else { ViewerExperienceRequest.Add("playerKey", playerKey); } ViewerExperienceRequest.Add("deliveryType", double.NaN); ViewerExperienceRequest.Add("contentOverrides", array); ViewerExperienceRequest.Add("URL", videoUrl); Log.Debug("param URL=" + videoUrl); if ((g = m.Groups["experienceId"]).Success) { Log.Debug("param experienceId=" + g.Value); ViewerExperienceRequest.Add("experienceId", (double)Int64.Parse(g.Value)); } else { ViewerExperienceRequest.Add("experienceId", double.NaN); } AMFSerializer ser = new AMFSerializer(); byte[] data = ser.Serialize(ViewerExperienceRequest, "com.brightcove.experience.ExperienceRuntimeFacade.getDataForExperience", hashValue); lastResponse = AMFObject.GetResponse(requestUrl, data); return(lastResponse.GetArray("programmedContent").GetObject("videoPlayer").GetObject("mediaDTO").GetArray("renditions")); }
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); }
AMFObject getViewerExperience(string contentRefId, string videoUrl) { AMFObject contentOverride = new AMFObject("com.brightcove.experience.ContentOverride"); contentOverride.Add("contentId", double.NaN); contentOverride.Add("target", "videoPlayer"); contentOverride.Add("contentRefId", contentRefId); contentOverride.Add("featuredRefId", null); contentOverride.Add("contentRefIds", null); contentOverride.Add("featuredId", double.NaN); contentOverride.Add("contentIds", null); contentOverride.Add("contentType", 0); AMFArray array = new AMFArray(); array.Add(contentOverride); AMFObject ViewerExperienceRequest = new AMFObject("com.brightcove.experience.ViewerExperienceRequest"); ViewerExperienceRequest.Add("TTLToken", String.Empty); ViewerExperienceRequest.Add("playerKey", String.Empty); ViewerExperienceRequest.Add("deliveryType", double.NaN); ViewerExperienceRequest.Add("contentOverrides", array); ViewerExperienceRequest.Add("URL", videoUrl); ViewerExperienceRequest.Add("experienceId", playerId); AMFSerializer ser = new AMFSerializer(); byte[] data = ser.Serialize(ViewerExperienceRequest, hashValue); string requestUrl = "http://c.brightcove.com/services/messagebroker/amf?playerid=" + playerId; return GetResponse(requestUrl, data); }