Example #1
0
        public static void CalScoreVC211(ref BiliInterfaceInfo info)
        {
            //修正B
            double xiuzhengB = Math.Round((double)info.favorites / info.play * 250, 2);

            if (xiuzhengB > 50)
            {
                xiuzhengB = 50;
            }
            //播放得点
            info.Fplay = info.play / (uint)info.pagesCount;
            if (info.Fplay > 10000)
            {
                info.Fplay = (uint)(info.Fplay * 0.5) + 5000;
            }
            if (xiuzhengB < 10)
            {
                info.Fplay = (uint)(info.Fplay * xiuzhengB * 0.1);
            }
            //修正A
            double xiuzhengA = Math.Round((double)(info.Fplay + info.favorites) / (info.play + info.favorites + info.video_review * 10 + info.review * 20), 2);

            //总分
            info.Fdefen = (uint)(info.Fplay + (info.review * 25 + info.video_review) * xiuzhengA + info.favorites * xiuzhengB);
        }
Example #2
0
        public static IEnumerable <string> GetAVFlvUrl(string AVnum)
        {
            string[] avnp  = Regex.Split(AVnum, "_|-|#");
            string   avnum = GetAVdenum(avnp[0]);

            int page = 1;

            if (avnp.Length > 1)
            {
                try
                {
                    page = int.Parse(avnp[1]);
                }
                catch
                {
                    log.Warn(AVnum + " - 无法识别分P编号,将下载P1");
                }
            }

            BiliInterfaceInfo    info = null;
            IEnumerable <string> flvs = null;

            try
            {
                info = GetInfo(avnum);
                if (page > 1)
                {
                    if (info.pagesn.Count >= page)
                    {
                        info.title = info.title + $"_P{page}_{info.pagesn[page - 1].part}";
                        flvs       = GetFlvUrls(uint.Parse(info.pagesn[page - 1].cid));
                    }
                    else
                    {
                        log.Warn(AVnum + $" - 目标视频仅有{info.pagesn.Count}P,将下载P1");
                        if (info.pagesn.Count > 1)
                        {
                            info.title = info.title + $"_P{page}_{info.pagesn[page - 1].part}";
                        }
                        flvs = GetFlvUrls(info.cid);
                    }
                }
                else
                {
                    if (info.pagesn.Count > 1)
                    {
                        info.title = info.title + $"_P{page}_{info.pagesn[page - 1].part}";
                    }
                    flvs = GetFlvUrls(info.cid);
                }
            }
            catch (Exception e)
            {
                log.Error("AV" + avnum + "的数据发生错误,请稍后重试!" + e.Message);
            }

            return(flvs);
        }
Example #3
0
        public static void CalScoreGuichu(ref BiliInterfaceInfo info)
        {
            //算分
            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;
        }
Example #4
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);
        }
Example #5
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);
        }