Exemple #1
0
        public static async void GetTagSort(int tid, string tags, int page = 1, int pagesize = 30, string order = "default")
        {
            string uri = string.Format($"http://api.bilibili.cn/tags?appkey=4ebafd7c4951b366&tid={tid}&tags={tags}&page={page}&pagesize={pagesize}&order={order}&ts={BiliApiHelper.GetTimeSpen}");

            uri += "&sign=" + BiliApiHelper.GetSign(uri, "8cb98205e9b2ad3669aad0fce12a4c13");

            string html = await GetHtmlAsync(uri);

            Console.ReadKey();
        }
Exemple #2
0
        public static async Task <BiliVideoDataModel> GetInfoNewAsync(string AVnum, ScoreType stype = ScoreType.Guichu)
        {
            string avnum = GetAVdenum(AVnum);

            log.Info("正在通过API获取数据 - AV" + avnum);

            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}",
                                       BiliApiHelper.access_key, avnum, BiliApiHelper.GetTimeSpen);

            uri += "&sign=" + BiliApiHelper.GetSign(uri);

            Stopwatch sw = new Stopwatch();

            sw.Restart();
            string html = await GetHtmlAsync(uri);

            log.Info($"获取数据完成 - AV{avnum} 用时:{sw.ElapsedMilliseconds}ms");
            sw.Stop();

            BiliInterfaceInfo info = new BiliInterfaceInfo();

            info.AVNUM = "AV" + avnum;
            try
            {
                BiliVideoModel model = JsonConvert.DeserializeObject <BiliVideoModel>(html);

                if (model.code == -403)
                {
                    if (model.data.ToString().Contains("no perm"))
                    {
                        log.Error("没有数据!(正在补档或被删除?)"); //TODO: 在新版API中还需要吗?
                    }
                    else
                    {
                        log.Error("本视频为会员独享,或账号方面错误!");
                    }
                }
                else if (model.code == -404)
                {
                    log.Error("视频不存在!");
                }
                else if (model.code == -500)
                {
                    log.Error("服务器错误,代码-500,请稍后再试");
                }
                else if (model.code == -502)
                {
                    log.Error("网关错误,代码-502,请稍后再试");
                }
                else
                {
                    BiliVideoDataModel InfoModel = JsonConvert.DeserializeObject <BiliVideoDataModel>(model.data.ToString());
                    return(InfoModel);
                }
            }
            catch (Exception e)
            {
                log.Error("AV" + avnum + "的数据发生错误,请稍后重试!" + e.Message);
                //return null; //TODO: 出错时返回后的检查方式需要变更
            }

            return(null);
        }
Exemple #3
0
        public static async Task <BiliInterfaceInfo> GetInfoAsync(string AVnum, ScoreType stype = ScoreType.Guichu)
        {
            string avnum = GetAVdenum(AVnum);

            log.Info("正在通过API获取数据 - AV" + avnum);

            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}",
                                       BiliApiHelper.access_key, avnum, BiliApiHelper.GetTimeSpen);

            uri += "&sign=" + BiliApiHelper.GetSign(uri);

            Stopwatch sw = new Stopwatch();

            sw.Restart();
            string html = await GetHtmlAsync(uri);

            log.Info($"获取数据完成 - AV{avnum} 用时:{sw.ElapsedMilliseconds}ms");
            sw.Stop();

            BiliInterfaceInfo info = new BiliInterfaceInfo();

            info.AVNUM = "AV" + avnum;
            try
            {
                BiliVideoModel model = JsonConvert.DeserializeObject <BiliVideoModel>(html);

                if (model.code == -403)
                {
                    if (model.data.ToString().Contains("no perm"))
                    {
                        log.Error("没有数据!(正在补档或被删除?)"); //TODO: 在新版API中还需要吗?
                    }
                    else
                    {
                        log.Error("本视频为会员独享,或账号方面错误!");
                    }
                }
                else if (model.code == -404)
                {
                    log.Error("视频不存在!");
                }
                else if (model.code == -500)
                {
                    log.Error("服务器错误,代码-500,请稍后再试");
                }
                else if (model.code == -502)
                {
                    log.Error("网关错误,代码-502,请稍后再试");
                }
                else
                {
                    //基础信息
                    BiliVideoModel InfoModel = JsonConvert.DeserializeObject <BiliVideoModel>(model.data.ToString());
                    //UP信息
                    BiliVideoModel UpModel = JsonConvert.DeserializeObject <BiliVideoModel>(InfoModel.owner.ToString());
                    //数据信息
                    BiliVideoModel DataModel = JsonConvert.DeserializeObject <BiliVideoModel>(InfoModel.stat.ToString());
                    //关注信息
                    BiliVideoModel AttentionModel = JsonConvert.DeserializeObject <BiliVideoModel>(InfoModel.req_user.ToString());
                    //分P信息
                    info.pagesn = JsonConvert.DeserializeObject <List <BiliVideoModel> >(InfoModel.pages.ToString());
                    //--数据转换开始--
                    info.title        = InfoModel.title;
                    info.created_at   = InfoModel.Created_at;
                    info.typename     = InfoModel.tname;
                    info.pic          = InfoModel.pic;
                    info.author       = UpModel.name;
                    info.cid          = Convert.ToUInt32(info.pagesn[0].cid);
                    info.play         = Convert.ToUInt32(DataModel.view);
                    info.video_review = Convert.ToUInt32(DataModel.danmaku);
                    info.review       = Convert.ToUInt32(DataModel.reply);
                    info.coins        = Convert.ToUInt32(DataModel.coin);
                    info.favorites    = Convert.ToUInt32(DataModel.favorite);
                    info.tag          = "";
                    if (InfoModel.tags != null) //注意有的视频竟然会没有tag
                    {
                        string[] pretags = ((JArray)InfoModel.tags).ToObject <string[]>();

                        foreach (string pretag in pretags)
                        {
                            info.tag += "," + pretag;
                        }
                        info.tag = info.tag.Substring(1);
                    }
                    info.description = InfoModel.desc;
                    //--数据转换结束--
                    //info.title = HttpUtility.HtmlDecode(info.title);
                    //--or
                    info.title = info.title.Replace("&amp;", "&");
                    info.title = info.title.Replace("&lt;", "<");
                    info.title = info.title.Replace("&gt;", ">");
                    info.title = info.title.Replace("&quot;", "\"");
                    switch (stype)
                    {
                    case ScoreType.None:
                        break;

                    case ScoreType.Guichu:
                        CalScoreGuichu(ref info);
                        break;

                    case ScoreType.VC211:
                        CalScoreVC211(ref info);
                        break;
                    }
                }
            }
            catch (Exception e)
            {
                log.Error("AV" + avnum + "的数据发生错误,请稍后重试!" + e.Message);
                //return null; //TODO: 出错时返回后的检查方式需要变更
            }

            return(info);
        }