예제 #1
0
 private void Change_Quality(object sender, SelectionChangedEventArgs e)
 {
     if (Media.IsOpen)
     {
         P_data p_data = bilibili_Video.Get_Video_Stream(video_Info.aid, video_Info.pages[0].cid, (int)((ComboBoxItem)Choose_Quality.SelectedItem).Uid.ToInt32(), IsLogin, biliCookie);
         if (p_data.Success)
         {
             Play_Video(p_data.url);
         }
     }
 }
예제 #2
0
        public P_data Get_Video_Stream(string avid, string cid, int clarity, bool Islogin, Bilibili_Account.BiliCookie biliCookie)
        {
            P_data p_Data = new P_data();
            var    client = new RestClient("http://api.bilibili.com/x/player/playurl?cid=" + cid + "&avid=" + avid + "&qn=" + clarity);

            client.Timeout = -1;
            var request = new RestRequest(Method.GET);

            if (Islogin)
            {
                request.AddCookie("SESSDATA", biliCookie.SESSDATA);
            }
            IRestResponse response  = client.Execute(request);
            JObject       recommend = (JObject)JsonConvert.DeserializeObject(response.Content);

            if ((int)recommend["code"] == 0)
            {
                p_Data.Success = true;
                JToken data = recommend["data"];
                p_Data.url = data["durl"][0]["url"].ToString();
                p_Data.accept_description = new string[data["accept_description"].Count()];
                p_Data.accept_quality     = new int[data["accept_description"].Count()];
                for (int i = 0; i < data["accept_description"].Count(); i++)
                {
                    p_Data.accept_description[i] = data["accept_description"][i].ToString();
                    p_Data.accept_quality[i]     = (int)data["accept_quality"][i];
                }

                client   = null;
                request  = null;
                response = null;

                return(p_Data);
            }
            else
            {
                p_Data.Success = false;
                MessageBox.Show("视频加载失败");
                client   = null;
                request  = null;
                response = null;
                return(p_Data);
            }
        }
예제 #3
0
        //这里没整好
        public void Open_New_Video(string avid, MainWindow MainWindow)
        {
            // foreach(string str in )



            Thread Open_New_Video_Thread = new Thread(() =>
            {
                mainWindow    = MainWindow;
                video_Info    = bilibili_Video.gets_video_info(avid);
                P_data p_data = bilibili_Video.Get_Video_Stream(avid, video_Info.pages[0].cid, 16, IsLogin, biliCookie);

                int i = 0;
                List <Choose_Quality_Item> choose_Quality_Items = new List <Choose_Quality_Item>();

                int clarity = 16;
                if (mainWindow.IsLogin)
                {
                    biliCookie = mainWindow.BiliCookie;
                    IsLogin    = true;

                    /* clarity = p_data.accept_quality[0];
                     * foreach (string str in p_data.accept_description)
                     * {
                     *
                     *   choose_Quality_Items.Add(new Choose_Quality_Item(str, p_data.accept_quality[i]));
                     *   i++;
                     *
                     * }
                     * this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (ThreadStart)delegate ()
                     * {
                     *   //Choose_Quality.ItemsSource = choose_Quality_Items;
                     *   Choose_Quality.Items.Add(choose_Quality_Items);
                     *   Choose_Quality.SelectedIndex = 0;
                     * });*/
                }
                else
                {
                    /* foreach (string str in p_data.accept_description)
                     * {
                     *   if (p_data.accept_quality[i] > 32)
                     *   {
                     *       i++;
                     *       continue;
                     *   }
                     *   choose_Quality_Items.Add(new Choose_Quality_Item(str, p_data.accept_quality[i]));
                     * }
                     * this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (ThreadStart)delegate ()
                     * {
                     *   // Choose_Quality.ItemsSource = choose_Quality_Items;
                     *   Choose_Quality.Items.Add(choose_Quality_Items);
                     *   Choose_Quality.SelectedIndex = Choose_Quality.Items.Count - 1;
                     *
                     * });*/
                }
                if (video_Info.Success)
                {
                    if (p_data.Success)
                    {
                        Play_Video(bilibili_Video.Get_Video_Stream(avid, video_Info.pages[0].cid, clarity, IsLogin, biliCookie).url);
                    }
                }
            });

            Open_New_Video_Thread.Name = "Open_New_Video_Thread";
            Open_New_Video_Thread.Start();
        }