示例#1
0
文件: Video.cs 项目: zhonng/BiliDuang
        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);
        }
示例#2
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());
         }
     }
 }