示例#1
0
        public async Task <UserInfoModel> GetMyUserInfo()
        {
            if (IsLogin())
            {
                try
                {
                    string url = string.Format("http://account.bilibili.com/api/myinfo?access_key={0}&appkey={1}&platform=wp&type=json", BiliApiHelper.access_key, BiliApiHelper._appKey_IOS);
                    url += "&sign=" + BiliApiHelper.GetSign(url);
                    string results = await BiliInterface.GetHtmlAsync(url);

                    UserInfoModel model = JsonConvert.DeserializeObject <UserInfoModel>(results);
                    //AttentionList = model.attentions;
                    return(model);
                }
                catch (Exception)
                {
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }
示例#2
0
        public static async Task <BiliInterfaceInfo> GetInfoAsync(string AVnum, ScoreType stype = ScoreType.Guichu, bool useKanb = false)
        {
            string avnum = GetAVdenum(AVnum);

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

            string uri = string.Empty;

            if (useKanb)
            {
                uri = string.Format("https://kanbilibili.com/api/video/{0}", avnum);
            }
            else
            {
                uri = string.Format("https://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.GetTimeSpan);
                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
                {
                    if (!useKanb)
                    {
                        //基础信息
                        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.mid          = Convert.ToUInt32(UpModel.mid);
                        info.face         = UpModel.face;
                        info.cid          = Convert.ToUInt32(info.pagesn[0].cid);
                        info.play         = Convert.ToInt32(DataModel.view);
                        info.video_review = Convert.ToInt32(DataModel.danmaku);
                        info.review       = Convert.ToInt32(DataModel.reply);
                        info.coins        = Convert.ToInt32(DataModel.coin);
                        info.share        = Convert.ToInt32(DataModel.share);
                        info.favorites    = Convert.ToInt32(DataModel.favorite);
                        info.like         = Convert.ToInt32(DataModel.like);
                        info.his_rank     = Convert.ToInt32(DataModel.his_rank);
                        info.now_rank     = Convert.ToInt32(DataModel.now_rank);
                        info.tag          = "";
                        if (InfoModel.tag != null) //注意有的视频竟然会没有tag
                        {
                            (from a in ((JArray)InfoModel.tag) select a["tag_name"]).ToList().ForEach(b =>
                            {
                                info.tag += "," + b.ToString();
                            });

                            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;", "\"");
                    }
                    else
                    {
                        info     = JsonConvert.DeserializeObject <BiliInterfaceInfo>(model.data.ToString());
                        info.aid = int.Parse(avnum);
                        BiliVideoModel InfoModel = JsonConvert.DeserializeObject <BiliVideoModel>(model.data.ToString());
                        info.pagesn = JsonConvert.DeserializeObject <List <BiliVideoModel> >(InfoModel.list.ToString()); //这里的list是B站接口的pages
                        info.cid    = Convert.ToUInt32(info.pagesn[0].cid);
                    }
                    switch (stype)
                    {
                    case ScoreType.None:
                        break;

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

                    case ScoreType.VC211:
                        CalScoreVC211(ref info);
                        break;

                    case ScoreType.CSVEP:
                        CalScoreCVSEP(ref info);
                        break;

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

            return(info);
        }