コード例 #1
0
        /// <summary>
        /// 根据uid返回该用户所有的视频数据
        /// </summary>
        /// <param name="uid">用户id</param>
        /// <param name="count">视频总数</param>
        /// <returns></returns>
        public static List <UpMessage> GetUP(int uid, int PageNum)
        {
            //请求第二次,根据获取到的总数和uid一页显示所有的视频数据
            //注意:该API地址最多请求的每页条数是100,如果超过100则会返回参数错误,需分开加载
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create($"https://space.bilibili.com/ajax/member/getSubmitVideos?mid={uid}&pagesize=100&page={PageNum}");

            //伪造浏览器(UserAgent是IE的)
            request.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 10.0; WOW64; Trident/7.0; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.30729; .NET CLR 3.5.30729)";
            WebResponse  response = request.GetResponse();                                         //获取response
            StreamReader reader   = new StreamReader(response.GetResponseStream(), Encoding.UTF8); //获取输入流,实际为json
            string       JsonStr  = reader.ReadToEnd();

            reader.Close();   //关闭流
            response.Close(); //关闭响应

            JObject json = JObject.Parse(JsonStr);

            //如果请求没问题,返回的json中状态这个键的值会为true
            if (json["status"].Value <bool>())
            {
                //所有的视频数据在data对象的vlist数组里
                var data  = json["data"];
                var vlist = (JArray)data["vlist"];//vlist为对象数组
                List <UpMessage> vedios = new List <UpMessage>();
                foreach (var item in vlist)
                {
                    //单个视频赋值
                    UpMessage v = new UpMessage
                    {
                        aid         = "av" + item["aid"].Value <string>(),
                        title       = item["title"].Value <string>(),
                        length      = item["length"].Value <string>(),
                        created     = timeToString(item["created"].Value <string>()),
                        description = item["description"].Value <string>(),
                        play        = item["play"].Value <string>() == "--" ? -1 : item["play"].Value <int>(),//遇到了播放数有问题,B站上显示“--”的情况
                        pic         = item["pic"].Value <string>()
                    };
                    vedios.Add(v);
                }
                return(vedios);
            }
            else
            {
                return(new List <UpMessage>());
            }
        }
コード例 #2
0
        private async void Reciever()
        {
            StringBuilder builder = new StringBuilder();
            var           stream  = tcpClient.GetStream();

            while (true)
            {
                List <byte> data  = new List <byte>();
                int         count = 0;
                byte[]      buff;
                do
                {
                    buff   = new byte[4096];
                    count += await stream.ReadAsync(buff, 0, buff.Length);

                    data.AddRange(buff);
                } while (stream.DataAvailable);
                byte[] tmp = data.ToArray();
                Array.Resize(ref tmp, count);
                var m = CreateMessage(Encoding.UTF8.GetString(tmp));

                switch (m.MsgType)
                {
                case Message.Type.All:
                    if (!m.From.Equals(nick))
                    {
                        UpMessage?.Invoke(m);
                    }
                    break;

                case Message.Type.Private:
                    UpMessage?.Invoke(m);
                    break;

                case Message.Type.ClientList:
                    List <Info> list = JsonConvert.DeserializeObject <List <Info> >(m.Msg);
                    UpClientList?.Invoke(list);
                    break;

                default:
                    break;
                }
            }
        }
コード例 #3
0
 /// <summary>
 /// 双击列表会根据选中行显示该视频的详细信息,并且获取封面
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void ReaderView_MouseDoubleClick(object sender, MouseButtonEventArgs e)
 {
     if (ReaderView.SelectedValue != null)
     {
         UpMessage vedio = (UpMessage)ReaderView.SelectedValue;
         VedioView vv    = new VedioView();
         vv.Title = $"{vedio.aid}详细信息";
         vv.TitleLabel.Content   = vedio.title;
         vv.descriptionBox.Text  = vedio.description;
         vv.aidLabel.Content     = $"av号:{vedio.aid}";
         vv.playLabel.Content    = $"播放数:{vedio.play}";
         vv.lengthLabel.Content  = $"视频长度:{vedio.length}";
         vv.createdLabel.Content = $"审核通过时间:{vedio.created}";
         ImageSourceConverter imageSourceConverter = new ImageSourceConverter();
         vv.titlePic.Source = (ImageSource)imageSourceConverter.ConvertFrom(BiliBiliReader.getPic(vedio.pic));
         VedioView.Pic_Name = vedio.pic;
         vv.Show();
     }
 }