BiliRanking.Core.BiliInterface.GetInfoAsync C# (CSharp) Method

GetInfoAsync() public static method

public static GetInfoAsync ( string AVnum, bool needScore = true ) : Task
AVnum string
needScore bool
return Task
        public static async Task<BiliInterfaceInfo> GetInfoAsync(string AVnum, bool needScore = true)
        {
            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();

            JavaScriptSerializer j = new JavaScriptSerializer();
            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信息
                    List<BiliVideoModel> ban = 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(ban[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;
                    //--数据转换结束--
                    //新版API不存在此类问题
                    //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;", "\"");
                    if (needScore)
                    {
                        CalScore(ref info);
                    }
                }
            }
            catch (Exception e)
            {
                Log.Error("AV" + avnum + "的数据发生错误,请稍后重试!" + e.Message);
            }

            return info;
        }