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
        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.º 3
0
        protected AMFArray GetResultsFromFindByMediaId(Match m)
        {
            AMFSerializer ser = new AMFSerializer();

            object[] values = new object[4];
            values[0] = hashValue;
            values[1] = Convert.ToDouble(playerId);
            values[2] = Convert.ToDouble(m.Groups["mediaId"].Value);
            values[3] = Convert.ToDouble(array4);
            byte[] data = ser.Serialize2("com.brightcove.player.runtime.PlayerMediaFacade.findMediaById", values);
            lastResponse = AMFObject.GetResponse(requestUrl, data);
            return(lastResponse.GetArray("renditions"));
        }
Exemplo n.º 4
0
        protected AMFArray GetResultsFromFindByMediaId(Match m, string videoUrl)
        {
            AMFSerializer ser = new AMFSerializer();

            object[] values = new object[4];
            values[0] = hashValue;
            values[1] = Convert.ToDouble(m.Groups["experienceId"].Value);
            values[2] = Convert.ToDouble(videoUrl.Substring(videoUrl.LastIndexOf("/") + 1));
            values[3] = Convert.ToDouble(array4);
            byte[]    data = ser.Serialize2("com.brightcove.player.runtime.PlayerMediaFacade.findMediaById", values, AMFVersion.AMF3);
            AMFObject obj  = AMFObject.GetResponse(requestUrl + m.Groups["playerKey"].Value, data);

            return(obj.GetArray("renditions"));
        }
 protected AMFArray GetResultsFromFindByMediaId(Match m)
 {
     AMFSerializer ser = new AMFSerializer();
     object[] values = new object[4];
     values[0] = hashValue;
     values[1] = Convert.ToDouble(playerId);
     values[2] = Convert.ToDouble(m.Groups["mediaId"].Value);
     values[3] = Convert.ToDouble(array4);
     byte[] data = ser.Serialize2("com.brightcove.player.runtime.PlayerMediaFacade.findMediaById", values);
     AMFObject obj = AMFObject.GetResponse(requestUrl, data);
     return obj.GetArray("renditions");
 }
Exemplo n.º 6
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);
        }
        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;
        }
        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);
        }
Exemplo n.º 9
0
 protected AMFArray GetResultsFromFindByMediaId(Match m, string videoUrl)
 {
     AMFSerializer ser = new AMFSerializer();
     object[] values = new object[4];
     values[0] = hashValue;
     values[1] = Convert.ToDouble(m.Groups["experienceId"].Value);
     values[2] = Convert.ToDouble(videoUrl.Substring(videoUrl.LastIndexOf("/") + 1));
     values[3] = Convert.ToDouble(array4);
     byte[] data = ser.Serialize2("com.brightcove.player.runtime.PlayerMediaFacade.findMediaById", values, AMFVersion.AMF3);
     AMFObject obj = AMFObject.GetResponse(requestUrl + m.Groups["playerKey"].Value, data);
     return obj.GetArray("renditions");
 }