コード例 #1
0
ファイル: BiliInterface.cs プロジェクト: SkiTiSu/BiliRanking
 public static int sortt(BiliInterfaceInfo x, BiliInterfaceInfo y)
 {
     int res = 0;
     if (x.Fdefen > y.Fdefen)
         res = -1;
     else
         res = 1;
     return res;
 }
コード例 #2
0
ファイル: BiliInterface.cs プロジェクト: SkiTiSu/BiliRanking
        //TODO: 加入P2、Pn的信息获取
        public static BiliInterfaceInfo GetInfo(string AVnum)
        {
            string avnum = AVnum.ToUpper();
            if (avnum.Contains("AV"))
            {
                avnum = avnum.Substring(2, avnum.Length - 2);
            }

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

            string html = GetHtml(InterfaceUrl + avnum);
            JavaScriptSerializer j = new JavaScriptSerializer();
            BiliInterfaceInfo info = new BiliInterfaceInfo();
            try
            {
                info = j.Deserialize<BiliInterfaceInfo>(html);

                if (info.code == -403)
                {
                    if (info.error == "no perm error")
                        Log.Error("没有数据!(正在补档或被删除?)");
                    else
                        Log.Error("本视频为会员独享,需要Cookie!");
                }
                else if (info.code == -503)
                {
                    Log.Warn("到达连续获取上限,延时两秒");
                    System.Threading.Thread.Sleep(2000);
                    return GetInfo(AVnum);
                }
                else if (info.code == -404)
                {
                    Log.Error("视频不存在!");
                }
                else if (info.code != 0)
                {
                    Log.Error("返回未知错误:" + info.code);
                }
                else
                {
                    info.aid = avnum;
                    info.AVNUM = "AV" + avnum;
                    info.title = info.title.Replace("&amp;", "&");
                    info.title = info.title.Replace("&lt;", "<");
                    info.title = info.title.Replace("&gt;", ">");
                    info.title = info.title.Replace("&quot;", "\"");

                    //算分
                    double xiuzheng = 0;

                    //收藏
                    xiuzheng = ((double)info.favorites / (double)info.play) * 1500;
                    if (xiuzheng > 55)
                        xiuzheng = 55;
                    info.Ffavorites = Convert.ToUInt32(info.favorites * xiuzheng);

                    //硬币
                    xiuzheng = ((double)info.coins / (double)info.play) * 5000;
                    if (xiuzheng > 25)
                        xiuzheng = 25;
                    info.Fcoins = Convert.ToUInt32(info.coins * xiuzheng);

                    //评论
                    xiuzheng = ((double)(info.review + info.favorites + info.coins) / (double)(info.play + info.review + info.video_review * 5)) * 800;
                    if (xiuzheng > 30)
                        xiuzheng = 30;
                    info.Freview = Convert.ToUInt32(info.review * xiuzheng);

                    //播放
                    info.Fplay = info.Ffavorites + info.Fcoins;
                    if (info.play <= info.Fplay)
                        info.Fplay = info.play;
                    else
                        info.Fplay = info.Fplay + (info.play - info.Fplay) / 2;

                    //得分
                    info.Fdefen = info.Ffavorites + info.Fcoins + info.Freview + info.Fplay;

                }
            }
            catch (Exception e)
            {
                Log.Error("AV" + avnum + "的数据发生错误,请稍后重试!" + e.Message);
            }

            return info;
        }