Esempio n. 1
0
        public Dictionary <string, string> getPlaybackOptions(VideoInfo video)
        {
            DoLogin();
            var             docStr   = "";
            MatchCollection matchCID = null;

            for (int i = 0; i <= 10; i++)
            {
                docStr   = _browserSession.LoadAsStr(Resources.AmazonMovieUrl(video.Other.ToString()));
                matchCID = Regex.Matches(docStr, "\"customerID\":\"(.+?)\"", RegexOptions.None);
                if (matchCID.Count > 0)
                {
                    break;
                }
            }
            Log.Info("matchCID" + matchCID[0].Groups[1].ToString());
            MatchCollection matchToken = Regex.Matches(docStr, "\"csrfToken\":\"(.+?)\"", RegexOptions.None);

            Log.Info("matchToken" + matchToken[0].Groups[1].ToString());
            MatchCollection matchMID = Regex.Matches(docStr, "\"marketplaceID\":\"(.+?)\"", RegexOptions.None);

            Log.Info("matchMID" + matchMID[0].Groups[1].ToString());
            // need to do extra url call...
            string          deviceTypeID = "A35LWR0L7KC0TJ"; //"A324MFXUEZFF7B";
            MatchCollection matchSWFUrl  = Regex.Matches(docStr, "\\<script.*?type.*?=.*?\"text\\/javascript\".+?src.*?=.*?\"(.+?webplayer[^\"]+?)\"", RegexOptions.None);

            if (matchSWFUrl.Count > 0)
            {
                var swfStr = _browserSession.LoadAsStr(matchSWFUrl[0].Groups[1].ToString());
                Log.Info("matchSwfJS" + matchSWFUrl[0].Groups[1].ToString());
                MatchCollection matchSwf = Regex.Matches(swfStr, "LEGACY_FLASH_SWF=\"(.+?)\"", RegexOptions.None);
                Log.Info("matchSwf" + matchSwf[0].Groups[1].ToString());
                MatchCollection matchDID = Regex.Matches(swfStr, "FLASH_GOOGLE_TV=\"(.+?)\"", RegexOptions.None);
                Log.Info("matchDID" + matchDID[0].Groups[1].ToString());
                //deviceTypeID = matchDID[0].Groups[1].ToString(); //"A324MFXUEZFF7B";
            }

            long milliseconds = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
            var  urlMainS     = Resources.AmazonRootUrl.Replace("http", "https");

            if (docStr.Contains("parental-controls-on"))
            {
                Log.Info("Parental control on, try to send pin");
                var pinUrl      = urlMainS + "/gp/video/streaming/player-pin-validation.json/ref=dp_pct_pin_cont?callback=__jpcb1422536298130&pin=" + ((AmazonPrimeSiteUtil)_siteUtil).AmznAdultPin + "&csrftoken=" + Uri.EscapeDataString(matchToken[0].Groups[1].ToString()) + "&_=" + milliseconds;
                var pinResponse = _browserSession.LoadAsStr(pinUrl);
                Log.Info(pinResponse);
            }

            var jsonUrl = urlMainS + "/gp/video/streaming/player-token.json?callback=jQuery16406641344620746118_" + milliseconds + "&csrftoken=" + Uri.EscapeDataString(matchToken[0].Groups[1].ToString()) + "&_=" + milliseconds;

            Log.Info(jsonUrl);
            var tokenResponse = _browserSession.LoadAsStr(jsonUrl);

            Log.Info(tokenResponse);
            matchToken = Regex.Matches(tokenResponse, "\"token\":\"(.+?)\"", RegexOptions.None);
            Log.Info("matchToken" + matchToken[0].Groups[1].ToString());
            string token = matchToken[0].Groups[1].ToString();

            jsonUrl = "https://atv-ps-eu.amazon.com/cdp/catalog/GetStreamingUrlSets?version=1&format=json&firmware=WIN%2011,7,700,224%20PlugIn&marketplaceID=" + matchMID[0].Groups[1].ToString() + "&token=" + token + "&deviceTypeID=" + deviceTypeID + "&asin=" + video.Other.ToString() + "&customerID=" + matchCID[0].Groups[1].ToString() + "&deviceID=" + matchCID[0].Groups[1].ToString() + milliseconds + video.Other.ToString();

            var streamingUrls = _browserSession.LoadAsJSON(jsonUrl);
            //Log.Info(streamingUrls);
            var urlInfos = streamingUrls["message"]["body"]["urlSets"]["streamingURLInfoSet"][0]["streamingURLInfo"];
            Dictionary <string, string> PlaybackOptions = new Dictionary <string, string>();

            Log.Info(urlInfos.ToString());
            foreach (var urlInfo in urlInfos)
            {
                Log.Info(urlInfo.ToString());
                string theUrl = (string)urlInfo["url"];
                theUrl = theUrl.Replace("rtmpe", "rtmp");
                //var theUrl = matchUrl[0].Groups[1].ToString().Replace("rtmpe", "rtmp");

                string videoID  = video.Other.ToString();
                string rtmpMain = "azeufms";

                MatchCollection matchPlaypath = Regex.Matches(theUrl, "(mp4:.+)", RegexOptions.None);
                string          playpath      = matchPlaypath[0].Groups[1].ToString();
                Log.Info(theUrl);
                string resultUrl = "http://azeufms-vodfs.fplive.net/" + playpath.Substring(4);

                /*Log.Info(theUrl + " swfVfy=1 swfUrl=" + matchSwf[0].Groups[1].ToString() + " pageUrl=" + Properties.Resources.AmazonRootUrl + "/dp/" + videoID + " app=" + rtmpMain + "-vod playpath=" + playpath + " tcUrl=rtmpe://" + rtmpMain + "-vodfs.fplive.net:1935/" + rtmpMain + "-vod/");
                 * //theUrl = theUrl + " swfVfy=1 swfUrl=" + matchSwf[0].Groups[1].ToString() + " pageUrl=" + Properties.Resources.AmazonRootUrl + "/dp/" + videoID + " app=" + rtmpMain + "-vod playpath=" + playpath + " tcUrl=rtmpe://" + rtmpMain + "-vodfs.fplive.net:1935/" + rtmpMain + "-vod/";
                 * string resultUrl = new MPUrlSourceFilter.RtmpUrl(theUrl)
                 * {
                 *  App = rtmpMain + "-vod",
                 *  PlayPath = playpath,
                 *  SwfUrl = matchSwf[0].Groups[1].ToString(),
                 *  SwfVerify = true,
                 *  PageUrl = Properties.Resources.AmazonMovieUrl(video.Other.ToString()),
                 *  TcUrl = "rtmpe://" + rtmpMain + "-vodfs.fplive.net:1935/" + rtmpMain + "-vod/"
                 *
                 * }.ToString();*/

                //if (theUrl.Contains("$"))
                //{
                //}

                Log.Info(resultUrl);
                PlaybackOptions.Add(urlInfo["contentQuality"].ToString() + " (" + urlInfo["bitrate"].ToString() + " kbps)", resultUrl);
            }

            return(PlaybackOptions);
        }