Ejemplo n.º 1
0
        public static void RefreshUserInfo()
        {
            SESSDATA = Other.TextGetCenter("SESSDATA=", ";", cookie);
            WebClient MyWebClient = new WebClient();

            MyWebClient.Credentials = CredentialCache.DefaultCredentials;//获取或设置用于向Internet资源的请求进行身份验证的网络凭据
            MyWebClient.Headers.Add("Cookie", cookie);
            try
            {
                UserDataRaw = Encoding.UTF8.GetString(MyWebClient.DownloadData("https://api.bilibili.com/x/space/myinfo?jsonp=jsonp")); //如果获取网站页面采用的是UTF-8,则使用这句
            }
            catch (WebException e)
            {
                Dialog.Show("用户信息获取错误" + e.Message);
            }
            MyWebClient.Dispose();
            UserJson = JsonConvert.DeserializeObject <JSONCallback.User.User>(UserDataRaw);
            if (UserJson.code != 0)
            {
                islogin = false;
                return;
            }
            islogin = true;
            face    = UserJson.data.face;
            uid     = UserJson.data.mid;
            name    = UserJson.data.name;
        }
Ejemplo n.º 2
0
        private bool ProcessMD(string vlink)
        {
            string callback = Other.GetHtml("https://www.bilibili.com/bangumi/media/md" + vlink);
            string ssid     = Other.TextGetCenter("\"season_id\":", ",", callback);

            Type = VideoType.SS;
            ProcessSS(ssid);
            return(true);
        }
Ejemplo n.º 3
0
        private string ProcessBV(string v)
        {
            //https://api.bilibili.com/x/web-interface/view?bvid=BV187411m7eL
            WebClient wc  = new WebClient();
            string    ret = Encoding.UTF8.GetString(wc.DownloadData("https://api.bilibili.com/x/web-interface/view?bvid=" + v));
            string    aid = Other.TextGetCenter("\"aid\":", ",", ret);

            return("av" + aid);
        }
Ejemplo n.º 4
0
        public Video(string vlink)
        {
            //第一步,bilibili网址转换
            //注意垃圾spm!
            //例如 https://www.bilibili.com/bangumi/play/ss28615/?spm=3.0212

            vlink = Other.TextGetCenter("//", "/?", vlink);
            if (vlink.EndsWith("/"))
            {
                vlink.Substring(0, vlink.Length - 1);
            }
            vlink = Other.TextGetCenter("/", "?", vlink);


            //第二步判断格式
            if (vlink.Contains("BV"))
            {
                Type  = VideoType.AV;
                vlink = ProcessBV(vlink);
            }
            vlink = vlink.ToLower();
            if (vlink.Contains("av"))
            {
                Type = VideoType.AV;
                ProcessAV(vlink.Replace("av", ""));
            }
            else if (vlink.Contains("ep"))
            {
                Type = VideoType.SS;
                ProcessEP(vlink.Replace("ep", ""));
            }
            else if (vlink.Contains("ss"))
            {
                Type = VideoType.SS;
                ProcessSS(vlink.Replace("ss", ""));
            }
            else if (vlink.Contains("md"))
            {
                ProcessMD(vlink.Replace("md", ""));
            }
            else if (vlink.Contains("ml"))
            {
                ProcessML(vlink.Replace("ml", ""));
            }
            else
            {
                Dialog.Show("不是可以获取的格式,请检查格式是否正确");
            }
        }
Ejemplo n.º 5
0
 private bool ProcessAV(string avid)
 {
     VideoClass.AV nav = new VideoClass.AV(avid);
     if (nav.isbangumi)
     {
         string vlink = nav.bangumiurl;
         vlink = Other.TextGetCenter("play/", "/", vlink, vlink);
         if (vlink.Contains("ep"))
         {
             Type = VideoType.SS;
             ProcessEP(vlink.Replace("ep", ""));
             return(true);
         }
     }
     av.Add(nav);
     return(true);
 }
Ejemplo n.º 6
0
 private bool GetDownloadUrls()
 {
     if (quality < VideoQuality.Q4K)
     {
         //下载链接api为 https://api.bilibili.com/x/player/playurl?avid=44743619&cid=78328965&qn=32 cid为上面获取到的 avid为输入的av号 qn为视频质量
         //https://www.biliplus.com/BPplayurl.php?otype=json&cid=29892777&module=bangumi&qn=16
         WebClient MyWebClient = new WebClient();
         MyWebClient.Credentials = CredentialCache.DefaultCredentials;//获取或设置用于向Internet资源的请求进行身份验证的网络凭据
         string callback = "";
         try
         {
             if (!Settings.outland)
             {
                 MyWebClient.Headers.Add("Cookie", User.cookie);
                 callback = Encoding.UTF8.GetString(MyWebClient.DownloadData(string.Format("https://api.bilibili.com/x/player/playurl?avid={0}&cid={1}&qn={2}", aid, cid, quality.ToString()))); //如果获取网站页面采用的是UTF-8,则使用这句
             }
             else
             {
                 System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;                                                                                                                          //加上这一句
                 callback = Encoding.UTF8.GetString(MyWebClient.DownloadData(string.Format("https://www.biliplus.com/BPplayurl.php?otype=json&module=bangumi&avid={0}&cid={1}&qn={2}", aid, cid, quality.ToString()))); //如果获取网站页面采用的是UTF-8,则使用这句
             }
         }
         catch (WebException e)
         {
             Dialog.Show("无法下载," + e.Message);
             return(false);
         }
         MyWebClient.Dispose();
         if (!Settings.outland)
         {
             JSONCallback.Player.Player player = JsonConvert.DeserializeObject <JSONCallback.Player.Player>(callback);
             if (player.code == -404)
             {
                 Dialog.Show(string.Format("无法下载 {0}({1}), 该视频需要大会员登录下载,请先登录", player.code, player.message), "获取错误");
                 return(false);
             }
             else if (player.code != 0)
             {
                 Dialog.Show(string.Format("无法下载 {0}({1})", player.code, player.message), "获取错误");
                 return(false);
             }
             if (!player.data.accept_quality.Contains(quality))
             {
                 Console.WriteLine(string.Format("没有指定的画质 {0} ,最高画质为 {1}, 自动下载最高画质{1}", VideoQuality.Name(quality), VideoQuality.Name(player.data.accept_quality[0])));
                 quality = player.data.accept_quality[0];
                 return(GetDownloadUrls());//我太懒了,直接递归吧
             }
             foreach (JSONCallback.Player.DurlItem Item in player.data.durl)
             {
                 DownloadUrl du = new DownloadUrl();
                 du.url  = Item.url;
                 du.size = Item.size;
                 urls.Add(du);
             }
             return(true);
         }
         else
         {
             if (callback == "")
             {
                 Dialog.Show(string.Format("使用BiliPlus API出错!"), "获取错误");
                 return(false);
             }
             JSONCallback.BiliPlus.Player player = JsonConvert.DeserializeObject <JSONCallback.BiliPlus.Player>(callback);
             if (!player.accept_quality.Contains(quality))
             {
                 Console.WriteLine(string.Format("没有指定的画质 {0} ,最高画质为 {1}, 自动下载最高画质{1}", VideoQuality.Name(quality), VideoQuality.Name(player.accept_quality[0])));
                 quality = player.accept_quality[0];
                 return(GetDownloadUrls());//我太懒了,直接递归吧
             }
             foreach (JSONCallback.BiliPlus.DurlItem Item in player.durl)
             {
                 DownloadUrl du = new DownloadUrl();
                 du.url  = Item.url;
                 du.size = Item.size;
                 urls.Add(du);
             }
             return(true);
         }
     }
     else
     {
         string callback = Other.GetHtml("https://www.bilibili.com/video/av" + aid, true);
         string json     = Other.TextGetCenter("window.__playinfo__=", "</script>", callback);
         Console.WriteLine(json);
         try
         {
             JSONCallback.FourKPlayer.FourKPlayer player = JsonConvert.DeserializeObject <JSONCallback.FourKPlayer.FourKPlayer>(json);
             if (player.code == -404)
             {
                 Dialog.Show(string.Format("无法下载 {0}({1}), 该视频需要大会员登录下载,请先登录", player.code, player.message), "获取错误");
                 return(false);
             }
             else if (player.code != 0)
             {
                 Dialog.Show(string.Format("无法下载 {0}({1})", player.code, player.message), "获取错误");
                 return(false);
             }
             if (!player.data.accept_quality.Contains(quality))
             {
                 Console.WriteLine(string.Format("没有指定的画质 {0} ,最高画质为 {1}, 自动下载最高画质{1}", VideoQuality.Name(quality), VideoQuality.Name(player.data.accept_quality[0])));
                 quality = player.data.accept_quality[0];
                 return(GetDownloadUrls());//我太懒了,直接递归吧
             }
             foreach (JSONCallback.FourKPlayer.VideoItem Item in player.data.dash.video)
             {
                 if (Item.id != quality)
                 {
                     continue;
                 }
                 DownloadUrl du = new DownloadUrl();
                 du.type = Item.mimeType.Replace("video/", "");
                 du.url  = Item.baseUrl;
                 du.size = -1;//暂不支持检测大小
                 urls.Add(du);
                 du      = new DownloadUrl();
                 du.type = "mp3";
                 du.url  = player.data.dash.audio[1].baseUrl;
                 du.size = -1;//暂不支持检测大小
                 urls.Add(du);
                 return(true);
             }
             return(false);
         }
         catch (Exception e)
         {
             Console.WriteLine("4K获取出错,正在尝试降级后重试.");
             quality = VideoQuality.Q1080P60;
             return(GetDownloadUrls());
         }
     }
 }
Ejemplo n.º 7
0
        public Video(string vlink)
        {
            //第一步,bilibili网址转换
            //注意垃圾spm!
            //例如 https://www.bilibili.com/bangumi/play/ss28615/?spm=3.0212
            if (vlink.IndexOf("?") != -1)
            {//去除后置参数
                vlink = vlink.Substring(0, vlink.IndexOf("?"));
            }

            if (vlink.Contains("space.bilibili.com"))
            {
                //https://space.bilibili.com/341151171

                string uid = vlink.Substring(vlink.LastIndexOf("/") + 1, vlink.Length - 1 - vlink.LastIndexOf("/"));
                ProcessUid(uid);
                return;
            }

            vlink = Other.TextGetCenter("/", "/?", vlink);
            if (vlink.EndsWith("/"))
            {
                vlink = vlink.Substring(0, vlink.Length - 1);
            }
            vlink = Other.TextGetCenter("/", "?", vlink);


            //第二步判断格式
            if (vlink.Contains("BV"))
            {
                Type  = VideoType.AV;
                vlink = "av" + Video.ProcessBV(vlink);
            }
            vlink = vlink.ToLower();
            if (vlink.Contains("av"))
            {
                Type = VideoType.AV;
                ProcessAV(vlink.Replace("av", ""));
            }
            else if (vlink.Contains("ep"))
            {
                Type = VideoType.SS;
                ProcessEP(vlink.Replace("ep", ""));
            }
            else if (vlink.Contains("ss"))
            {
                Type = VideoType.SS;
                ProcessSS(vlink.Replace("ss", ""));
            }
            else if (vlink.Contains("md"))
            {
                ProcessMD(vlink.Replace("md", ""));
            }
            else if (vlink.Contains("ml"))
            {
                ProcessML(vlink.Replace("ml", ""));
            }
            else if (vlink.Contains("uid"))
            {
                ProcessUid(vlink.Replace("uid", ""));
            }
            else
            {
                Dialog.Show("不是可以获取的格式,请检查格式是否正确");
            }
        }