Exemple #1
0
        private async void LoadVideo()
        {
            try
            {
                isMovie = false;
                tag.Children.Clear();
                pr_Load.Visibility = Visibility.Visible;
                string uri = string.Format("http://app.bilibili.com/x/view?_device=wp&_ulv=10000&access_key={0}&aid={1}&appkey=422fd9d7289a1dd9&build=411005&plat=4&platform=android&ts={2}", ApiHelper.access_key, _aid, ApiHelper.GetTimeSpan);
                uri += "&sign=" + ApiHelper.GetSign(uri);
                string results = "";
                if (SettingHelper.Get_UseCN() || SettingHelper.Get_UseHK() || SettingHelper.Get_UseTW())
                {
                    results = await WebClientClass.GetResults_Proxy(uri);
                }
                else
                {
                    results = await WebClientClass.GetResults(new Uri(uri));
                }

                VideoInfoModels m = JsonConvert.DeserializeObject <VideoInfoModels>(results);
                if (m.code == 0)
                {
                    this.DataContext = m.data;

                    if (m.data.movie != null)
                    {
                        //isMovie = true;

                        grid_Movie.Visibility = Visibility.Visible;
                        if (m.data.movie.movie_status == 1)
                        {
                            if (m.data.movie.pay_user.status == 0)
                            {
                                movie_pay.Visibility = Visibility.Visible;
                                txt_PayMonery.Text   = m.data.movie.payment.price.ToString("0.00");
                            }
                            else
                            {
                                isMovie = true;
                                movie_pay.Visibility = Visibility.Collapsed;
                            }
                        }
                        else
                        {
                            movie_pay.Visibility = Visibility.Collapsed;
                        }
                    }
                    else
                    {
                        grid_Movie.Visibility = Visibility.Collapsed;
                        movie_pay.Visibility  = Visibility.Collapsed;
                    }

                    //m.data.pages
                    gv_Play.SelectedIndex = 0;
                    if (m.data.req_user.attention != 1)
                    {
                        btn_AttUp.Visibility       = Visibility.Visible;
                        btn_CancelAttUp.Visibility = Visibility.Collapsed;
                    }
                    else
                    {
                        btn_AttUp.Visibility       = Visibility.Collapsed;
                        btn_CancelAttUp.Visibility = Visibility.Visible;
                    }
                    if (m.data.season != null)
                    {
                        grid_season.Visibility = Visibility.Visible;
                    }
                    else
                    {
                        grid_season.Visibility = Visibility.Collapsed;
                    }
                    if (m.data.tag != null)
                    {
                        grid_tag.Visibility = Visibility.Visible;
                    }
                    else
                    {
                        grid_tag.Visibility = Visibility.Collapsed;
                    }

                    if (m.data.elec != null)
                    {
                        grid_elec.Visibility  = Visibility.Visible;
                        txt_NotCb.Visibility  = Visibility.Collapsed;
                        grid_elec.DataContext = m.data.elec;
                    }
                    else
                    {
                        grid_elec.Visibility = Visibility.Collapsed;
                        txt_NotCb.Visibility = Visibility.Visible;
                    }
                    list_About.ItemsSource = null;
                    if (m.data.relates != null)
                    {
                        list_About.ItemsSource = m.data.relates;
                    }

                    if (m.data.tag != null)
                    {
                        foreach (var item in m.data.tag)
                        {
                            HyperlinkButton hy = new HyperlinkButton();
                            hy.Content    = item.tag_name;
                            hy.Margin     = new Thickness(0, 0, 10, 0);
                            hy.Foreground = App.Current.Resources["Bili-ForeColor"] as SolidColorBrush;
                            hy.Click     += Hy_Click;;
                            tag.Children.Add(hy);
                        }
                    }
                }
                else
                {
                    if (m.code == -403)
                    {
                        error.Visibility = Visibility.Visible;
                        txt_error.Text   = "您的权限不足或者不支持你所在地区";
                        return;
                    }
                    if (m.code == -404)
                    {
                        error.Visibility = Visibility.Visible;
                        txt_error.Text   = "视频不存在或已被删除";
                        return;
                    }

                    messShow.Show(m.message, 3000);
                }
            }
            catch (Exception ex)
            {
                if (ex.HResult == -2147012867 || ex.HResult == -2147012889)
                {
                    messShow.Show("无法连接服务器,请检查你的网络连接", 3000);
                }
                else
                {
                    messShow.Show("更新数据失败了", 3000);
                }
            }
            finally
            {
                btn_HideAll_Click(null, null);
                pr_Load.Visibility = Visibility.Collapsed;
            }
        }
        private async void GetInfo()
        {
            try
            {
                pr_Load.Visibility = Visibility.Visible;
                string uri = string.Format("http://bangumi.bilibili.com/api/season_v3?_device=wp&access_key={2}&_ulv=10000&build=411005&platform=android&appkey=422fd9d7289a1dd9&ts={0}000&type=bangumi&season_id={1}", ApiHelper.GetTimeSpan, _banId, ApiHelper.access_key);
                uri += "&sign=" + ApiHelper.GetSign(uri);
                string results = "";
                if (SettingHelper.Get_UseCN() || SettingHelper.Get_UseHK() || SettingHelper.Get_UseTW())
                {
                    results = await WebClientClass.GetResults_Proxy(uri);
                }
                else
                {
                    results = await WebClientClass.GetResults(new Uri(uri));
                }

                // string results = await WebClientClass.GetResults(new Uri(uri));
                BangumiInfoModel model = JsonConvert.DeserializeObject <BangumiInfoModel>(results);

                if (model.code == 0)
                {
                    int i = 0;

                    model.result.episodes.ForEach(x => { x.orderindex = i; i++; });
                    model.result.episodes = model.result.episodes.OrderByDescending(x => x.orderindex).ToList();

                    this.DataContext = model.result;


                    gv_Play.ItemsSource = model.result.episodes;

                    if (model.result.user_season.attention == 0)
                    {
                        btn_Like.Visibility       = Visibility.Visible;
                        btn_CancelLike.Visibility = Visibility.Collapsed;
                    }
                    else
                    {
                        btn_Like.Visibility       = Visibility.Collapsed;
                        btn_CancelLike.Visibility = Visibility.Visible;
                    }
                    if (model.result.rank != null)
                    {
                        BangumiInfoModel rank = JsonConvert.DeserializeObject <BangumiInfoModel>(model.result.rank.ToString());
                        grid_Cb.DataContext  = rank;
                        grid_Cb.Visibility   = Visibility.Visible;
                        txt_NotCb.Visibility = Visibility.Collapsed;
                        GetRankInfo();
                    }
                    else
                    {
                        txt_NotCb.Visibility = Visibility.Visible;
                        grid_Cb.Visibility   = Visibility.Collapsed;
                    }

                    if (model.result.seasons != null)
                    {
                        Grid_About.Visibility = Visibility.Visible;

                        WrapPanel_About.Children.Clear();
                        if (model.result.seasons.Count == 1)
                        {
                            Grid_About.Visibility = Visibility.Collapsed;
                        }
                        else
                        {
                            foreach (BangumiInfoModel item in model.result.seasons)
                            {
                                HyperlinkButton btn = new HyperlinkButton();
                                btn.DataContext = item;
                                btn.Margin      = new Thickness(0, 0, 10, 0);
                                btn.Content     = item.title;
                                btn.Foreground  = App.Current.Resources["Bili-ForeColor"] as SolidColorBrush;
                                if (item.season_id == _banId)
                                {
                                    btn.IsEnabled = false;
                                }
                                btn.Click += Btn_Click;;
                                WrapPanel_About.Children.Add(btn);
                            }
                        }

                        //Grid_About
                    }
                    else
                    {
                        Grid_About.Visibility = Visibility.Collapsed;
                    }


                    if (model.result.tags != null)
                    {
                        WrapPanel_tag.Children.Clear();
                        foreach (var item in model.result.tags)
                        {
                            HyperlinkButton btn = new HyperlinkButton();
                            btn.DataContext = item;
                            btn.Margin      = new Thickness(0, 0, 10, 0);
                            btn.Content     = item.tag_name;
                            btn.Foreground  = App.Current.Resources["Bili-ForeColor"] as SolidColorBrush;
                            btn.Click      += Btn_Click1;;
                            WrapPanel_tag.Children.Add(btn);
                        }
                    }

                    if (gv_Play.Items.Count != 0)
                    {
                        cb_H.SelectedIndex    = cb_H.Items.Count - 1;
                        gv_Play.SelectedIndex = 0;
                    }
                    else
                    {
                        messShow.Show("尚未开播或不支持你所在地区", 3000);
                    }
                }
                else
                {
                    messShow.Show(model.message, 3000);
                }
            }
            catch (Exception ex)
            {
                if (ex.HResult == -2147012867)
                {
                    messShow.Show("检查你的网络连接!", 3000);
                }
                else
                {
                    messShow.Show("发生错误\r\n" + ex.Message, 3000);
                }
            }
            finally
            {
                Page_SizeChanged(null, null);
                btn_HideAll_Click(null, null);

                pr_Load.Visibility = Visibility.Collapsed;
            }
        }