示例#1
0
        public static async Task <string> GetBiliUrl(PlayerModel model, int quality)
        {
            try
            {
                string url = "http://interface.bilibili.com/playurl?_device=uwp&cid=" + model.Mid + "&otype=xml&quality=" + quality + "&appkey=" + ApiHelper._appKey + "&access_key=" + ApiHelper.access_key + "&type=mp4&mid=" + "" + "&_buvid=" + ApiHelper._buvid + "&_hwid=" + ApiHelper._hwid + "&platform=uwp_desktop" + "&ts=" + ApiHelper.GetTimeSpan;
                url += "&sign=" + ApiHelper.GetSign(url);

                string re = "";
                if (SettingHelper.Get_UseCN() || SettingHelper.Get_UseHK() || SettingHelper.Get_UseTW())
                {
                    re = await WebClientClass.GetResults_Proxy(url);
                }
                else
                {
                    re = await WebClientClass.GetResults_Phone(new Uri(url));
                }


                // re = await WebClientClass.GetResults_Phone(new Uri(url));
                string playUrl = Regex.Match(re, "<url>(.*?)</url>").Groups[1].Value;
                playUrl = playUrl.Replace("<![CDATA[", "");
                playUrl = playUrl.Replace("]]>", "");
                return(playUrl);
            }
            catch (Exception)
            {
                return("");
            }

            // mediaElement.Source = new Uri(playUrl);
        }
示例#2
0
        public static async Task <string> GetResults_Proxy(string url)
        {
            string area = "cn";

            if (SettingHelper.Get_UseCN())
            {
                area = "cn";
            }
            if (SettingHelper.Get_UseHK())
            {
                area = "hk";
            }
            if (SettingHelper.Get_UseTW())
            {
                area = "tw";
            }

            HttpBaseProtocolFilter fiter = new HttpBaseProtocolFilter();

            fiter.IgnorableServerCertificateErrors.Add(Windows.Security.Cryptography.Certificates.ChainValidationResult.Expired);

            using (HttpClient hc = new HttpClient(fiter))
            {
                //url
                Uri uri = new Uri(string.Format("http://52uwp.com/api/BiliBili?area={0}&url={1}", area, Uri.EscapeDataString(url)));
                HttpResponseMessage hr = await hc.GetAsync(uri);

                hr.EnsureSuccessStatusCode();
                string results = await hr.Content.ReadAsStringAsync();

                JObject obj = JObject.Parse(results);
                if ((int)obj["code"] == 0)
                {
                    return(obj["message"].ToString());
                }
                else
                {
                    throw new NotSupportedException(obj["message"].ToString());
                }
            }
        }