Пример #1
0
        public void GetInfoAsyncTest()
        {
            BiliInterfaceInfo info = new BiliInterfaceInfo();
            info = AsyncHelper.RunSync(() => BiliInterface.GetInfoAsync("av2680512"));

            Assert.AreEqual(info.title, "【创刊号】哔哩哔哩月刊鬼畜排行榜#001");
        }
Пример #2
0
        public string DoReplace(string before, BiliInterfaceInfo info)
        {
            string after = before;

            after = after.Replace("<", "{");
            after = after.Replace(">", "}");

            after = after.Replace("{}", "\r\n");

            after = after.Replace("{huanhang}", "\r\n");
            after = after.Replace("{title}", info.title);
            after = after.Replace("{time}", info.created_at.Replace(" ", " ")); //半角换成全角
            after = after.Replace("{created_at}", info.created_at);
            after = after.Replace("{AVNUM}", info.AVNUM);
            after = after.Replace("{avnum}", info.avnum);
            after = after.Replace("{author}", info.author);
            after = after.Replace("{zongfen}", info.Fdefen.ToString());
            after = after.Replace("{paiming}", info.Fpaiming.Value.ToString("00"));
            after = after.Replace("{bofang}", info.play.ToString());
            after = after.Replace("{yingbi}", info.coins.ToString());
            after = after.Replace("{shoucang}", info.favorites.ToString());
            after = after.Replace("{danmu}", info.video_review.ToString());
            after = after.Replace("{pinglun}", info.review.ToString());
            after = after.Replace("{tag}", info.tag.ToString());
            after = after.Replace("{share}", info.share.ToString());

            return(after);
        }
Пример #3
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 / (int)info.pagesCount;
            if (info.Fplay > 10000)
            {
                info.Fplay = (int)(info.Fplay * 0.5) + 5000;
            }
            if (xiuzhengB < 10)
            {
                info.Fplay = (int)(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 = (int)(info.Fplay + (info.review * 25 + info.video_review) * xiuzhengA + info.favorites * xiuzhengB);
        }
Пример #4
0
        public void GetFlvInfoTest()
        {
            BiliInterfaceInfo info = new BiliInterfaceInfo();
            info = BiliInterface.GetFlvInfo("av3153761");
            //TestContext.WriteLine(info.flvurl);
            //Debug.WriteLine(info.flvurl);

            Assert.IsTrue(info.flvurl.Contains(".flv"));
        }
Пример #5
0
        public static BiliInterfaceInfo GetFlvInfo(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;

            try
            {
                info = GetInfo(avnum);
                if (page > 1)
                {
                    if (info.pagesn.Count >= page)
                    {
                        info.title  = info.title + $"_P{page}_{info.pagesn[page - 1].part}";
                        info.flvurl = GetFlvUrl(UInt32.Parse(info.avnum.Substring(2)), 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}";
                        }
                        info.flvurl = GetFlvUrl(UInt32.Parse(info.avnum.Substring(2)), info.cid);
                    }
                }
                else
                {
                    if (info.pagesn.Count > 1)
                    {
                        info.title = info.title + $"_P{page}_{info.pagesn[page - 1].part}";
                    }
                    info.flvurl = GetFlvUrl(UInt32.Parse(info.avnum.Substring(2)), info.cid);
                }
            }
            catch (Exception e)
            {
                Log.Error("AV" + avnum + "的数据发生错误,请稍后重试!" + e.Message);
            }

            return(info);
        }
Пример #6
0
        public static BiliInterfaceInfo GetMP4info(string AVnum, int page, bool isJJ = false)
        {
            BiliInterfaceInfo info = new BiliInterfaceInfo();

            info = GetInfo(AVnum, ScoreType.None);
            if (!string.IsNullOrEmpty(info.title))
            {
                info.mp4url = GetMP4UrlBackUp(uint.Parse(info.avnum));
            }
            return(info);
        }
Пример #7
0
 public static string GetFaceFilename(BiliInterfaceInfo info)
 {
     if (!string.IsNullOrEmpty(info.face))
     {
         return("uid" + info.mid + "-" + info.author + info.face.Substring(info.face.LastIndexOf(".")));
     }
     else
     {
         return("");
     }
 }
Пример #8
0
        public static void CalScoreStardust(ref BiliInterfaceInfo info)
        {
            /*
             * 总分=播放*0.8+评论*10+弹幕*转发*0.05+收藏*0.1*(硬币/2)
             *
             *  1-天数*0.018
             */
            int tianshu = (DateTime.Now - DateTime.Parse(info.created_at)).Days;

            info.Fdefen = Convert.ToInt32(
                (info.play * 0.8 + info.review * 10 + info.video_review * info.share * 0.05 + info.favorites * 0.1 * info.coins / 2)
                *
                (1 - tianshu * 0.018));
        }
Пример #9
0
        public void AddPic(BiliInterfaceInfo info, int n)
        {
            Log.Info("正在生成 - " + info.AVNUM);
            string picPath = Environment.CurrentDirectory + @"\pic\" + info.AVNUM + ".jpg";
            int    nn      = 190 + 292 * (n - 1);

            try
            {
                Image pic = Image.FromFile(picPath);
                g.DrawImage(pic, new Rectangle(250, nn - 15, 366, 218));
            }
            catch
            {
                Log.Error(info.AVNUM + " - 找不到封面文件,请在左侧窗格输入AV号尝试或手动获取!");
            }

            if (info.Fpaiming < 100)
            {
                g.DrawString(info.Fpaiming.ToString(), new Font("微软雅黑", 80, FontStyle.Bold), b, 110, nn - 30);
            }
            else
            {
                g.DrawString(info.Fpaiming.ToString(), new Font("微软雅黑", 60, FontStyle.Bold), b, 110, nn - 30);
            }


            g.DrawString(info.AVNUM.Substring(2), f, b, 725, nn);
            g.DrawString(info.Fdefen.ToString(), f, b, 1160, nn);
            if (info.author.Length <= 6)
            {
                g.DrawString(info.author, f, b, new RectangleF(1518, nn, 320, 320));
                //g.DrawString(info.up, f, b, 1518, nn);
            }
            else
            {
                g.DrawString(info.author, f, b, new RectangleF(1518, nn, 320, 320));
                //g.DrawString(info.up.Substring(0, 6), f, b, 1518, nn);
                //g.DrawString(info.up.Substring(6), f, b, 1518, nn + 74);
            }


            g.DrawString(info.created_at, f, b, 880, nn + 148);

            g.DrawString(info.title, new Font("微软雅黑", 32), b, 102, nn - 81);
        }
Пример #10
0
        public static void GetPic(BiliInterfaceInfo info)
        {
            string avnum = info.AVNUM;
            string file  = Environment.CurrentDirectory + @"\pic\" + avnum + ".jpg";

            if (File.Exists(file))
            {
                Log.Info("封面已存在 - " + avnum);
            }
            else
            {
                if (info.pic != null)
                {
                    string url = info.pic;
                    Log.Info("正在获取封面 - " + info.AVNUM + " | " + url + " -> " + file);
                    TSDownload tsd = new TSDownload(url, file);
                    tsd.StartWithoutThread();
                }
            }
        }
Пример #11
0
        public static void GetPic(string AVnum)
        {
            string avnum = GetAVdenum(AVnum);
            string file  = Environment.CurrentDirectory + @"\pic\AV" + avnum + ".jpg";

            if (File.Exists(file))
            {
                Log.Info("封面已存在 - AV" + avnum);
            }
            else
            {
                BiliInterfaceInfo info = GetInfo(AVnum);
                if (info.pic != null)
                {
                    string url = info.pic;
                    Log.Info("正在获取封面 - " + info.AVNUM + " | " + url + " -> " + file);
                    TSDownload tsd = new TSDownload(url, file);
                    tsd.Start();
                }
            }
        }
Пример #12
0
        public static string DoReplace(string before, BiliInterfaceInfo info)
        {
            string after = before;

            after = after.Replace("<", "{");
            after = after.Replace(">", "}");

            after = after.Replace("{}", "\r\n");

            after = after.Replace("{huanhang}", "\r\n");
            after = after.Replace("{title}", info.title);
            after = after.Replace("{time}", info.created_at.Replace(" ", " ")); //半角换成全角
            after = after.Replace("{created_at}", info.created_at);
            after = after.Replace("{AVNUM}", info.AVNUM);
            after = after.Replace("{avnum}", info.avnum);
            after = after.Replace("{author}", info.author);
            after = after.Replace("{zongfen}", info.Fdefen.ToString());
            after = after.Replace("{paiming}", info.Fpaiming.HasValue ? info.Fpaiming.Value.ToString("00") : "--");
            after = after.Replace("{bofang}", info.play.ToString());
            after = after.Replace("{yingbi}", info.coins.ToString());
            after = after.Replace("{shoucang}", info.favorites.ToString());
            after = after.Replace("{danmu}", info.video_review.ToString());
            after = after.Replace("{pinglun}", info.review.ToString());
            after = after.Replace("{tag}", info.tag);
            after = after.Replace("{share}", info.share.ToString());
            after = after.Replace("{pic}", "{pic}" + info.AVNUM);
            after = after.Replace("{face}", "{face}" + BiliInterface.GetFaceFilename(info));

            Type bitype = typeof(BiliInterfaceInfo);

            foreach (PropertyInfo pi in bitype.GetProperties(BindingFlags.Public | BindingFlags.Instance))
            {
                if (pi.CanRead && pi.Name != "pic" && pi.Name != "face")
                {
                    after = after.Replace($"{{{pi.Name}}}", pi.GetValue(info)?.ToString() ?? "");
                }
            }

            return(after);
        }
Пример #13
0
        public static List <Zhubang.TemplateInfo> ParseTemplate(BiliInterfaceInfo info, string template)
        {
            List <Zhubang.TemplateInfo> tis = new List <Zhubang.TemplateInfo>();
            var lines = Regex.Split(template, "\r\n|\r|\n");

            foreach (string line in lines)
            {
                if (string.IsNullOrEmpty(line))
                {
                    continue;
                }
                var cells = Regex.Split(line, "[|]");
                Zhubang.TemplateInfo ti = new Zhubang.TemplateInfo()
                {
                    text         = DoReplace(cells[0], info),
                    font         = new Font(cells[1], Convert.ToSingle(cells[2]), GraphicsUnit.Point),
                    brush        = new SolidBrush(ColorTranslator.FromHtml(cells[3])),
                    isRightAlign = bool.Parse(cells[4])
                };
                if (!ti.isRightAlign)
                {
                    ti.point = new PointF(Convert.ToSingle(cells[5]), Convert.ToSingle(cells[6]));
                }
                else
                {
                    ti.rectangle = new RectangleF(Convert.ToSingle(cells[7]), Convert.ToSingle(cells[8]), Convert.ToSingle(cells[9]), Convert.ToSingle(cells[10]));
                }
                if (cells.Length >= 12)
                {
                    ti.autoOffsetY = bool.Parse(cells[11]);
                }
                if (cells.Length >= 13)
                {
                    ti.maxWidth = Convert.ToSingle(cells[12]);
                }
                tis.Add(ti);
            }
            return(tis);
        }
Пример #14
0
 public static void GetFace(BiliInterfaceInfo info)
 {
     if (!string.IsNullOrEmpty(info.face))
     {
         string filename = GetFaceFilename(info);
         string file     = Environment.CurrentDirectory + @"\pic\" + filename;
         if (File.Exists(file))
         {
             Log.Info("头像已存在 - " + filename);
         }
         else
         {
             Log.Info("正在获取头像 - " + info.AVNUM + " | " + info.face + " -> " + file);
             TSDownload tsd = new TSDownload(info.face, file);
             tsd.StartWithoutThread();
         }
     }
     else
     {
         Log.Warn("没有头像地址,请重新获取 - " + info.AVNUM);
     }
 }
Пример #15
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.ToInt32(info.favorites * xiuzheng);
            //硬币
            xiuzheng = ((double)info.coins / (double)info.play) * 5000;
            if (xiuzheng > 25)
            {
                xiuzheng = 25;
            }
            info.Fcoins = Convert.ToInt32(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.ToInt32(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;
        }
Пример #16
0
        public void AddPic2(BiliInterfaceInfo info, int n)
        {
            Log.Info("正在生成 - " + info.AVNUM);
            string picPath = Environment.CurrentDirectory + @"\pic\" + info.AVNUM + ".jpg";
            int    x       = 36;
            int    y       = 37 + 233 * (n - 1);

            try
            {
                Image pic      = Image.FromFile(picPath);
                Image smallpic = resizeImage(pic, new Size(576, 360));
                //288 180
                Bitmap bmpFluffy = new Bitmap(smallpic);
                //bmpFluffy = new Bitmap(288, 180);
                Rectangle r = new Rectangle(Point.Empty, bmpFluffy.Size);

                using (Bitmap bmpMask = new Bitmap(r.Width, r.Height))
                    using (Graphics g = Graphics.FromImage(bmpMask))
                        using (GraphicsPath path = createRoundRect(
                                   r.X, r.Y,
                                   r.Width, r.Height,
                                   8))
                        {
                            g.FillRectangle(Brushes.Black, r);

                            g.InterpolationMode  = InterpolationMode.HighQualityBilinear;
                            g.CompositingQuality = CompositingQuality.HighQuality;
                            g.PixelOffsetMode    = PixelOffsetMode.HighQuality;
                            g.SmoothingMode      = SmoothingMode.AntiAlias;

                            g.FillPath(Brushes.White, path);

                            transferOneARGBChannelFromOneBitmapToAnother(
                                bmpMask,
                                bmpFluffy,
                                ChannelARGB.Blue,
                                ChannelARGB.Alpha);
                        }
                // bmpFluffy is now powered up and ready to be used



                //Image roundedpic = RoundCorners(smallpic, 10);

                //g.DrawImage(roundedpic, 36, y);
                //g.DrawImageUnscaled(roundedpic, 36, y);
                g.DrawImage(bmpFluffy, new Rectangle(x, y, 288, 180));
                //g.DrawImage(pic, new Rectangle(250, nn - 15, 366, 218));
            }
            catch (Exception e)
            {
                //throw e;
                Log.Error(info.AVNUM + " - 封面文件获取失败,请在左侧窗格输入AV号尝试或手动获取!");
            }
            //g.InterpolationMode = InterpolationMode.HighQualityBicubic;
            //Source Han Sans SC = 思源黑体
            g.DrawString(info.title.Replace('【', '[').Replace('】', ']'), new Font("思源黑体 Light", 42, GraphicsUnit.Pixel), b, 340, y - 2);
            g.DrawString($"分数: {info.Fdefen}   UP: {info.author}", new Font("思源黑体 Normal", 30, GraphicsUnit.Pixel), b, 340, y + 56);
            g.DrawString($"{info.avnum} 投稿时间: {info.created_at}", new Font("思源黑体 Regular", 25, GraphicsUnit.Pixel), b, 340, y + 142);

            if (info.Fpaiming < 100)
            {
                g.DrawString(info.Fpaiming.ToString(), new Font("思源黑体 ExtraLight", 72, GraphicsUnit.Pixel), b, 1152, y + 87);
            }
            else
            {
                g.DrawString(info.Fpaiming.ToString(), new Font("思源黑体 ExtraLight", 72, GraphicsUnit.Pixel), b, 1114, y + 87);
            }

            /*
             * if (info.Fpaiming < 100)
             * {
             *  g.DrawString(info.Fpaiming.ToString(), new Font("微软雅黑", 80, FontStyle.Bold), b, 110, nn - 30);
             * }
             * else
             * {
             *  g.DrawString(info.Fpaiming.ToString(), new Font("微软雅黑", 60, FontStyle.Bold), b, 110, nn - 30);
             * }
             *
             *
             * g.DrawString(info.AVNUM.Substring(2), f, b, 725, nn);
             * g.DrawString(info.Fdefen.ToString(), f, b, 1160, nn);
             * if (info.author.Length <= 6)
             * {
             *  g.DrawString(info.author, f, b, new RectangleF(1518, nn, 320, 320));
             *  //g.DrawString(info.up, f, b, 1518, nn);
             * }
             * else
             * {
             *  g.DrawString(info.author, f, b, new RectangleF(1518, nn, 320, 320));
             *  //g.DrawString(info.up.Substring(0, 6), f, b, 1518, nn);
             *  //g.DrawString(info.up.Substring(6), f, b, 1518, nn + 74);
             * }
             *
             *
             * g.DrawString(info.created_at, f, b, 880, nn + 148);
             *
             * g.DrawString(info.title, new Font("微软雅黑", 32), b, 102, nn - 81);
             */
        }
Пример #17
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);
        }
Пример #18
0
        public void AddPic2(BiliInterfaceInfo info, int n)
        {
            Log.Info("正在生成 - " + info.AVNUM);
            string picPath = Environment.CurrentDirectory + @"\pic\" + info.AVNUM + ".jpg";
            int x = 36;
            int y = 37 + 233 * (n - 1);
            try
            {
                Image pic = Image.FromFile(picPath);
                Image smallpic = resizeImage(pic, new Size(576, 360));
            //288 180
                Bitmap bmpFluffy = new Bitmap(smallpic);
                //bmpFluffy = new Bitmap(288, 180);
                Rectangle r = new Rectangle(Point.Empty, bmpFluffy.Size);

                using (Bitmap bmpMask = new Bitmap(r.Width, r.Height))
                using (Graphics g = Graphics.FromImage(bmpMask))
                using (GraphicsPath path = createRoundRect(
                    r.X, r.Y,
                    r.Width, r.Height,
                    8))
                {
                    g.FillRectangle(Brushes.Black, r);

                g.InterpolationMode = InterpolationMode.HighQualityBilinear;
                g.CompositingQuality = CompositingQuality.HighQuality;
                g.PixelOffsetMode = PixelOffsetMode.HighQuality;
                g.SmoothingMode = SmoothingMode.AntiAlias;

                g.FillPath(Brushes.White, path);

                    transferOneARGBChannelFromOneBitmapToAnother(
                        bmpMask,
                        bmpFluffy,
                        ChannelARGB.Blue,
                        ChannelARGB.Alpha);
                }
            // bmpFluffy is now powered up and ready to be used

            //Image roundedpic = RoundCorners(smallpic, 10);

            //g.DrawImage(roundedpic, 36, y);
            //g.DrawImageUnscaled(roundedpic, 36, y);
            g.DrawImage(bmpFluffy, new Rectangle(x, y, 288, 180));
                //g.DrawImage(pic, new Rectangle(250, nn - 15, 366, 218));
            }
            catch (Exception e)
            {
                //throw e;
                Log.Error(info.AVNUM + " - 封面文件获取失败,请在左侧窗格输入AV号尝试或手动获取!");
            }
            //g.InterpolationMode = InterpolationMode.HighQualityBicubic;
            //Source Han Sans SC = 思源黑体
            g.DrawString(info.title.Replace('【', '[').Replace('】',']'), new Font("思源黑体 Light", 42, GraphicsUnit.Pixel), b, 340, y - 2);
            g.DrawString($"分数: {info.Fdefen}   UP: {info.author}", new Font("思源黑体 Normal", 30, GraphicsUnit.Pixel), b, 340, y + 56);
            g.DrawString($"{info.avnum} 投稿时间: {info.created_at}", new Font("思源黑体 Regular", 25, GraphicsUnit.Pixel), b, 340, y + 142);

            if (info.Fpaiming < 100)
            {
                g.DrawString(info.Fpaiming.ToString(), new Font("思源黑体 ExtraLight", 72, GraphicsUnit.Pixel), b, 1152, y + 87);
            }
            else
            {
                g.DrawString(info.Fpaiming.ToString(), new Font("思源黑体 ExtraLight", 72, GraphicsUnit.Pixel), b, 1114, y + 87);
            }

            /*
            if (info.Fpaiming < 100)
            {
                g.DrawString(info.Fpaiming.ToString(), new Font("微软雅黑", 80, FontStyle.Bold), b, 110, nn - 30);
            }
            else
            {
                g.DrawString(info.Fpaiming.ToString(), new Font("微软雅黑", 60, FontStyle.Bold), b, 110, nn - 30);
            }

            g.DrawString(info.AVNUM.Substring(2), f, b, 725, nn);
            g.DrawString(info.Fdefen.ToString(), f, b, 1160, nn);
            if (info.author.Length <= 6)
            {
                g.DrawString(info.author, f, b, new RectangleF(1518, nn, 320, 320));
                //g.DrawString(info.up, f, b, 1518, nn);
            }
            else
            {
                g.DrawString(info.author, f, b, new RectangleF(1518, nn, 320, 320));
                //g.DrawString(info.up.Substring(0, 6), f, b, 1518, nn);
                //g.DrawString(info.up.Substring(6), f, b, 1518, nn + 74);
            }

            g.DrawString(info.created_at, f, b, 880, nn + 148);

            g.DrawString(info.title, new Font("微软雅黑", 32), b, 102, nn - 81);
            */
        }
Пример #19
0
        //TODO: 加入P2、Pn的信息获取
        public static BiliInterfaceInfo GetInfoOld(string AVnum)
        {
            string avnum = AVnum.ToUpper();
            if (avnum.Contains("AV"))
            {
                avnum = avnum.Substring(2, avnum.Length - 2);
            }

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

            SortedDictionary<string, string> parampairs = new SortedDictionary<string, string>();
            parampairs.Add("id", avnum);
            string param = GetSign(parampairs);

            string html = GetHtml("http://api.bilibili.com/view?" + param);

            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.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;
        }
Пример #20
0
        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;
        }
Пример #21
0
        public static void CalScoreCVSEP(ref BiliInterfaceInfo info)
        {
            /*
             * (1)基础函数:
             *  (播放得点+评论得点+其他得点)=基础得点(取小数点后2位有效数字)
             * (2)得点修正规则:
             *  ①播放得点:播放量<10000:播放量*1.5
             *       10000≤播放量<50000:播放量*5/3+15000
             *       播放量≥50000:播放量*7/3
             *  ②评论得点:评论数<1000:评论数*0.3
             *       1000≤评论数<3500:评论数*0.08+300
             *       评论数≥3500:评论数*0.175
             *  ③其他得点:收藏数+硬币数<1000:(收藏数+硬币数)*10
             *       1000≤收藏数+硬币数<5000:(收藏数+硬币数)*5+5000
             *       收藏数+硬币数≥5000:(收藏数+硬币数)*3+15000
             */
            //播放
            if (info.play < 10000)
            {
                info.Fplay = Convert.ToInt32(info.play * 1.5);
            }
            else if (info.play < 50000)
            {
                info.Fplay = info.play * 5 / 3 + 15000;
            }
            else
            {
                info.Fplay = info.play * 7 / 3;
            }
            //评论
            if (info.review < 1000)
            {
                info.Freview = Convert.ToInt32(info.review * 0.3);
            }
            else if (info.review < 3500)
            {
                info.Freview = Convert.ToInt32(info.review * 0.08) + 300;
            }
            else
            {
                info.Freview = Convert.ToInt32(info.review * 0.175);
            }
            //其他
            int linshi = info.favorites + info.coins;
            int qita;

            if (linshi < 1000)
            {
                qita = linshi * 10;
            }
            else if (linshi < 5000)
            {
                qita = linshi * 5 + 5000;
            }
            else
            {
                qita = linshi * 3 + 15000;
            }
            //基础得点(总分)
            info.Fdefen = info.Fplay + info.Freview + qita;
        }
Пример #22
0
 public static BiliInterfaceInfo GetMP4info(string AVnum, int page, bool isJJ = false)
 {
     BiliInterfaceInfo info = new BiliInterfaceInfo();
     info = GetInfo(AVnum, false);
     if (!string.IsNullOrEmpty(info.title))
     {
         info.mp4url = GetMP4UrlBackUp(uint.Parse(info.avnum));
     }
     return info;
 }
Пример #23
0
        public static BiliInterfaceInfo GetInfoOld(string AVnum)
        {
            string avnum = AVnum.ToUpper();

            if (avnum.Contains("AV"))
            {
                avnum = avnum.Substring(2, avnum.Length - 2);
            }

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

            SortedDictionary <string, string> parampairs = new SortedDictionary <string, string>();

            parampairs.Add("id", avnum);
            string param = GetSign(parampairs);

            string html = GetHtml("http://api.bilibili.com/view?" + param);

            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.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.ToInt32(info.favorites * xiuzheng);

                    //硬币
                    xiuzheng = ((double)info.coins / (double)info.play) * 5000;
                    if (xiuzheng > 25)
                    {
                        xiuzheng = 25;
                    }
                    info.Fcoins = Convert.ToInt32(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.ToInt32(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);
        }
Пример #24
0
 public static void CalScore(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;
 }
Пример #25
0
        public static IEnumerable <string> GetAVFlvUrl(string AVnum, out IEnumerable <string> renames, List <BiliInterfaceInfo> binfos = null) //TODO: 试试元组
        {
            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;
            List <string>        rrnames = new List <string>();

            try
            {
                info = GetInfo(avnum);
                if (page > 1)
                {
                    if (info.pagesn.Count >= page)
                    {
                        flvs = GetFlvUrls(uint.Parse(info.pagesn[page - 1].cid));
                    }
                    else
                    {
                        Log.Warn(AVnum + $" - 目标视频仅有{info.pagesn.Count}P,将下载P1");
                        flvs = GetFlvUrls(info.cid);
                    }
                }
                else
                {
                    flvs = GetFlvUrls(info.cid);
                }
                string topstring = "";
                try
                {
                    if (binfos != null)
                    {
                        int paiming = (from b in binfos where b.avnum == info.avnum select b.Fpaiming.Value).First();
                        if (paiming != 0 && paiming <= 20)
                        {
                            topstring = "TOP_" + paiming + "-";
                        }
                    }
                } catch { }
                info.title = $"{info.title}_{info.avnum}_P{page}_{info.pagesn[page - 1].part}";
                info.title = TSDownload.removeInvChrInPath(info.title);
                for (int i = 0; i < flvs.Count(); i++)
                {
                    string filename = Path.GetFileName(new Uri(flvs.ElementAt(i)).AbsolutePath);
                    rrnames.Add($"{filename}$///${topstring}{info.title}_{i + 1}.flv");
                }
            }
            catch (Exception e)
            {
                Log.Error("AV" + avnum + "的数据发生错误,请稍后重试!" + e.Message);
            }
            renames = rrnames;
            return(flvs);
        }
Пример #26
0
 public static void GetPic(BiliInterfaceInfo info)
 {
     string avnum = info.AVNUM;
     string file = Environment.CurrentDirectory + @"\pic\" + avnum + ".jpg";
     if (File.Exists(file))
     {
         Log.Info("封面已存在 - " + avnum);
     }
     else
     {
         if (info.pic != null)
         {
             string url = info.pic;
             Log.Info("正在获取封面 - " + info.AVNUM + " | " + url + " -> " + file);
             TSDownload tsd = new TSDownload(url, file);
             tsd.StartWithoutThread();
         }
     }
 }
Пример #27
0
        public void AddPic(BiliInterfaceInfo info, int n)
        {
            Log.Info("正在生成 - " + info.AVNUM);
            string picPath = Environment.CurrentDirectory + @"\pic\" + info.AVNUM + ".jpg";
            int nn = 190 + 292 * (n - 1);
            try
            {
                Image pic = Image.FromFile(picPath);
                g.DrawImage(pic, new Rectangle(250, nn - 15, 366, 218));
            }
            catch
            {
                Log.Error(info.AVNUM + " - 找不到封面文件,请在左侧窗格输入AV号尝试或手动获取!");
            }

            if(info.Fpaiming < 100)
            {
                g.DrawString(info.Fpaiming.ToString(), new Font("微软雅黑", 80, FontStyle.Bold), b, 110, nn - 30);
            }
            else
            {
                g.DrawString(info.Fpaiming.ToString(), new Font("微软雅黑", 60, FontStyle.Bold), b, 110, nn - 30);
            }

            g.DrawString(info.AVNUM.Substring(2), f, b, 725, nn);
            g.DrawString(info.Fdefen.ToString(), f, b, 1160, nn);
            if(info.author.Length <= 6)
            {
                g.DrawString(info.author, f, b, new RectangleF(1518, nn, 320, 320));
                //g.DrawString(info.up, f, b, 1518, nn);
            }
            else
            {
                g.DrawString(info.author, f, b, new RectangleF(1518, nn, 320, 320));
                //g.DrawString(info.up.Substring(0, 6), f, b, 1518, nn);
                //g.DrawString(info.up.Substring(6), f, b, 1518, nn + 74);
            }

            g.DrawString(info.created_at, f, b, 880, nn + 148);

            g.DrawString(info.title, new Font("微软雅黑", 32), b, 102, nn - 81);
        }