Example #1
0
        private static void Data_Changed(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if (e.NewValue != null && e.NewValue is BangumiResponse data)
            {
                var instance = d as BangumiCard;
                var cover    = data.cover;

                ThreadPool.QueueUserWorkItem(async(callback) =>
                {
                    var path = await BiliClient.GetFileAsCacheAsync(cover);
                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        instance.CoverPicture.Source = new BitmapImage(new Uri(path, UriKind.RelativeOrAbsolute));
                        instance.NameText.Text       = data.title;
                        instance.NewEpText.Text      = $"更新至: {data.newest_ep_index}";
                        instance.Param = data.param;
                    });
                });
            }
        }
Example #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("请将 B站直播 cookie 保存到 程序目录/Data/cookie.txt");
            string cookieFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Data/cookie.txt");

            _cookie     = File.ReadAllText(cookieFilePath).Trim();
            _biliClient = new BiliClient(new CookieModel(_cookie));

            InitRoomIds();
            StartListen();


            while (true)
            {
                var key = Console.ReadKey().Key;
                if (key == ConsoleKey.E)
                {
                    return;
                }
            }
        }
        public PageRoot()
        {
            InitializeComponent();

            BiliClient.Account.MeUpdate += (sender, args) =>
            {
                var data = BiliClient.Account.Me;

                Task.Run(async() =>
                {
                    string path    = await BiliClient.GetFileAsCacheAsync(data.face);
                    data.face_path = path;

                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        imageUserFace.Source = new BitmapImage(new Uri(path, UriKind.RelativeOrAbsolute));
                    });
                });
            };
            RenderOptions.SetBitmapScalingMode(imageUserFace, BitmapScalingMode.Fant);
            contentFrame.Navigated += (sender, args) => contentFramePgRing.Visibility = Visibility.Collapsed;
        }
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            int uid = (int)e.ExtraData;

            Controls.WindowCaption.Captions[Application.Current.MainWindow].ShowBackground = true;
            ThreadPool.QueueUserWorkItem(async delegate
            {
                var response = await BiliClient.Account.GetUserSpaceAsync(uid);
                Application.Current.Dispatcher.Invoke(() =>
                {
                    NameText.Text = response.card.name;
                    SignText.Text = response.card.sign;
                    UidText.Text  = $"Uid:{response.card.mid}";

                    var tabClass = response.tab;

                    {
                        switch (response.card.sex)
                        {
                        case "男": SexText.Text = "\u2642"; SexText.Foreground = new SolidColorBrush(Colors.DodgerBlue); break;

                        case "女": SexText.Text = "\u2640"; SexText.Foreground = new SolidColorBrush(Colors.Lavender); break;

                        default: SexText.Text = "\u2642\u00BF\u003F\u2640"; SexText.Foreground = new SolidColorBrush(Colors.Gray); break;
                        }
                    }

                    {
                        var level      = response.card.level_info;
                        LevelPath.Fill = FindResource($"Level{level.current_level}Color") as SolidColorBrush;
                        LevelPath.Data = FindResource($"Level{level.current_level}Icon") as StreamGeometry;
                        ExpText.Text   = $"{level.current_exp}/{level.next_exp}";
                        if (Regex.Match(level.next_exp, "[0-9](1-5)").Success)
                        {
                            ExpBar.Value = level.current_exp * 1.0d / int.Parse(level.next_exp);
                        }
                        else
                        {
                            ExpBar.ShowError = true;
                        }
                    }

                    {
                        FansText.Text   = response.card.fans.ToString();
                        FollowText.Text = response.card.attention.ToString();
                        LikeText.Text   = response.card.likes.like_num.ToString();
                    }

                    {
                        Vip vipData = response.card.vip;
                        if (vipData.vipStatus == 1)
                        {
                            BigVipElement.Visibility = Visibility.Visible;
                            BigVipText.Text          = vipData.label.text;
                        }
                        else
                        {
                            BigVipElement.Visibility = Visibility.Collapsed;
                        }
                    }

                    {
                        var live = response.live;
                        LiveRoomElement.Visibility = live.liveStatus == 1 ? Visibility.Visible : Visibility.Collapsed;
                    }

                    {
                        var archive = response.archive;
                        if (tabClass.archive)
                        {
                            ArchiveElement.Init(response.archive, response.card.mid);
                        }
                        else
                        {
                            ArchiveElement.Visibility = Visibility.Collapsed;
                        }
                    }

                    {
                        var article = response.article;
                        if (tabClass.article)
                        {
                        }
                        else
                        {
                            ArticleElement.Visibility = Visibility.Collapsed;
                        }
                    }

                    {
                        var season = response.season;
                        if (tabClass.bangumi)
                        {
                            SeasonElement.Init(season.item, response.card.mid);
                        }
                        else
                        {
                            SeasonElement.Visibility = Visibility.Collapsed;
                        }
                    }

                    FollowUserButton.SetResourceReference(ContentProperty, "User.FollowUser");
                });

                if (response.images != null)
                {
                    var topPhotoPath = await BiliClient.GetFileAsCacheAsync(response.images.imgUrl);
                    Application.Current.Dispatcher.Invoke(() => TopPhotoComponent.Source = new BitmapImage(new Uri(topPhotoPath, UriKind.RelativeOrAbsolute)));
                }

                var facePath = await BiliClient.GetFileAsCacheAsync(response.card.face);
                Application.Current.Dispatcher.Invoke(() => FaceComponent.Source = new BitmapImage(new Uri(facePath, UriKind.RelativeOrAbsolute)));
            });
        }