Пример #1
0
        /// <summary>
        /// 查询用户所有的投稿视频明细
        /// </summary>
        /// <param name="mid">用户id</param>
        /// <param name="order">排序</param>
        /// <param name="tid">视频分区</param>
        /// <param name="keyword">搜索关键词</param>
        /// <returns></returns>
        public List <SpacePublicationListVideo> GetAllPublication(long mid, PublicationOrder order = PublicationOrder.PUBDATE, int tid = 0, string keyword = "")
        {
            List <SpacePublicationListVideo> result = new List <SpacePublicationListVideo>();

            int i = 0;

            while (true)
            {
                i++;
                int ps = 100;

                var data = GetPublication(mid, i, ps, tid, order, keyword);
                //if (data == null) { continue; }

                if (data == null || data.Vlist == null || data.Vlist.Count == 0)
                {
                    break;
                }

                result.AddRange(data.Vlist);
            }
            return(result);
        }
Пример #2
0
        /// <summary>
        /// 查询用户投稿视频明细
        /// </summary>
        /// <param name="mid">用户id</param>
        /// <param name="pn">页码</param>
        /// <param name="ps">每页的视频数</param>
        /// <param name="order">排序</param>
        /// <param name="tid">视频分区</param>
        /// <param name="keyword">搜索关键词</param>
        /// <returns></returns>
        public SpacePublicationList GetPublication(long mid, int pn, int ps, int tid = 0, PublicationOrder order = PublicationOrder.PUBDATE, string keyword = "")
        {
            string url      = $"https://api.bilibili.com/x/space/arc/search?mid={mid}&pn={pn}&ps={ps}&order={order.ToString("G").ToLower()}&tid={tid}&keyword={keyword}";
            string referer  = "https://www.bilibili.com";
            string response = Utils.RequestWeb(url, referer);

            try
            {
                // 忽略play的值为“--”时的类型错误
                var settings = new JsonSerializerSettings
                {
                    Error = (sender, args) =>
                    {
                        if (Equals(args.ErrorContext.Member, "play") &&
                            args.ErrorContext.OriginalObject.GetType() == typeof(SpacePublicationListVideo))
                        {
                            args.ErrorContext.Handled = true;
                        }
                    }
                };

                var spacePublication = JsonConvert.DeserializeObject <SpacePublicationOrigin>(response, settings);
                if (spacePublication == null || spacePublication.Data == null)
                {
                    return(null);
                }
                return(spacePublication.Data.List);
            }
            catch (Exception e)
            {
                Console.WriteLine("GetPublication()发生异常: {0}", e);
                return(null);
            }
        }
Пример #3
0
        /// <summary>
        /// 查询用户投稿视频明细
        /// </summary>
        /// <param name="mid">用户id</param>
        /// <param name="pn">页码</param>
        /// <param name="ps">每页的视频数</param>
        /// <param name="order">排序</param>
        /// <param name="tid">视频分区</param>
        /// <param name="keyword">搜索关键词</param>
        /// <returns></returns>
        public SpacePublicationList GetPublication(long mid, int pn, int ps, int tid = 0, PublicationOrder order = PublicationOrder.PUBDATE, string keyword = "")
        {
            string url      = $"https://api.bilibili.com/x/space/arc/search?mid={mid}&pn={pn}&ps={ps}&order={order.ToString("G").ToLower()}&tid={tid}&keyword={keyword}";
            string referer  = "https://www.bilibili.com";
            string response = Utils.RequestWeb(url, referer);

            try
            {
                var spacePublication = JsonConvert.DeserializeObject <SpacePublicationOrigin>(response);
                if (spacePublication == null || spacePublication.Data == null)
                {
                    return(null);
                }
                return(spacePublication.Data.List);
            }
            catch (Exception e)
            {
                Console.WriteLine("GetPublication()发生异常: {0}", e);
                return(null);
            }
        }