Exemplo n.º 1
0
        public static async Task <ReturnPlayModel> Get23MoeUrl(PlayerModel model, int qn)
        {
            try
            {
                var           playList = new SYEngine.Playlist(SYEngine.PlaylistTypes.NetworkHttp);
                List <string> urls     = new List <string>();
                string        rnd      = ApiHelper.GetTimeSpan.ToString();
                if (SettingHelper.Get_UseVIP())
                {
                    rnd = "true" + rnd;
                }
                var re3 = await WebClientClass.GetResults(new Uri(string.Format("https://moe.nsapps.cn/api/v1/BiliAnimeUrl?animeid={0}&cid={1}&epid={2}&rnd={3}", model.banId, model.Mid, model.banInfo.episode_id, rnd)));

                JObject obj = JObject.Parse(re3);
                if (Convert.ToInt32(obj["code"].ToString()) == 0)
                {
                    if (obj["mode"].ToString() == "mp4")
                    {
                        urls.Add(obj["data"][0]["url"].ToString());
                        return(new ReturnPlayModel()
                        {
                            usePlayMode = UsePlayMode.System,
                            url = obj["data"][0]["url"].ToString(),
                            urls = urls,
                            from = "server"
                        });
                    }
                    else
                    {
                        var returnPlayModel = new ReturnPlayModel()
                        {
                            usePlayMode = UsePlayMode.SYEngine,
                            from        = "server"
                        };
                        foreach (var item in obj["data"])
                        {
                            playList.Append(item["url"].ToString(), item["size"].ToInt32(), item["length"].ToInt32() / 1000);
                            urls.Add(item["url"].ToString());
                        }
                        playList.NetworkConfigs  = CreatePlaylistNetworkConfigs("https://www.bilibili.com/bangumi/play/ep" + model.episode_id);
                        returnPlayModel.playlist = playList;
                        returnPlayModel.urls     = urls;
                        return(returnPlayModel);
                    }
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception)
            {
                return(null);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 使用biliplus的接口,支持番剧/视频
        /// 需要授权
        /// </summary>
        /// <param name="model"></param>
        /// <param name="qn"></param>
        /// <returns></returns>
        public static async Task <ReturnPlayModel> GetBiliPlusUrl(string cid, int qn, string referer)
        {
            try
            {
                string url = "https://www.biliplus.com/BPplayurl.php?cid=" + cid + $"&otype=json&type=&quality={qn}&module=bangumi&season_type=1&qn={qn}&access_key={ApiHelper.access_key}";
                Dictionary <string, string> header = new Dictionary <string, string>();
                if (SettingHelper.Get_BiliplusCookie() != "")
                {
                    header.Add("Cookie", SettingHelper.Get_BiliplusCookie());
                }

                string re = await WebClientClass.GetResults(new Uri(url));

                FlvPlyaerUrlModel m = JsonConvert.DeserializeObject <FlvPlyaerUrlModel>(re);
                if (m.code == 0)
                {
                    List <string> urls     = new List <string>();
                    var           playList = new SYEngine.Playlist(SYEngine.PlaylistTypes.NetworkHttp);
                    foreach (var item in m.durl)
                    {
                        urls.Add(item.url);
                        playList.Append(item.url, item.size, item.length / 1000);
                    }
                    playList.NetworkConfigs = CreatePlaylistNetworkConfigs(referer);
                    return(new ReturnPlayModel()
                    {
                        playlist = playList,
                        usePlayMode = UsePlayMode.SYEngine,
                        urls = urls,
                        from = "biliplus"
                    });
                }
                else if (m.code == -403)
                {
                    if (ApiHelper.IsLogin())
                    {
                        ReturnPlayModel returnPlayModel = null;
                        MessageDialog   messageDialog   = new MessageDialog("读取视频地址失败了,是否授权Biliplus后再试一次?");
                        messageDialog.Commands.Add(new UICommand("授权", async(e) => {
                            var bp = await Account.AuthBiliPlus();
                            if (bp != "")
                            {
                                returnPlayModel = await GetBiliPlusUrl(cid, qn, referer);
                            }
                            else
                            {
                                Utils.ShowMessageToast("授权失败了");
                            }
                        }));
                        messageDialog.Commands.Add(new UICommand("取消"));
                        await messageDialog.ShowAsync();

                        return(returnPlayModel);
                    }
                    else
                    {
                        return(null);
                    }
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception)
            {
                return(null);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 读取番剧播放地址
        /// </summary>
        /// <param name="model"></param>
        /// <param name="quality"></param>
        /// <returns></returns>
        public static async Task <ReturnPlayModel> GetBangumiUrl(PlayerModel model, int qn)
        {
            try
            {
                if (qn < 10)
                {
                    switch (qn)
                    {
                    case 1:
                        qn = 32;
                        break;

                    case 2:
                        qn = 64;
                        break;

                    case 3:
                        qn = 80;
                        break;

                    case 4:
                        qn = 116;
                        break;

                    default:
                        qn = 64;
                        break;
                    }
                }


                List <string> urls = new List <string>();
                string        url  = string.Format("https://interface.bilibili.com/v2/playurl?cid={0}&player=1&quality={1}&qn={1}&ts={2}", model.Mid, qn, ApiHelper.GetTimeSpan);
                url += "&sign=" + ApiHelper.GetSign_PlayUrl(url);

                string re = await WebClientClass.GetResults(new Uri(url));

                var playList = new SYEngine.Playlist(SYEngine.PlaylistTypes.NetworkHttp);

                SYEngine.PlaylistNetworkConfigs config = new SYEngine.PlaylistNetworkConfigs();
                config.DownloadRetryOnFail = true;
                config.HttpCookie          = string.Empty;
                config.UniqueId            = string.Empty;
                config.HttpUserAgent       = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36";

                if (re.Contains("<code>"))
                {
                    //string url2 = string.Format("https://bangumi.bilibili.com/player/web_api/playurl/?access_key={3}&cid={0}&module=bangumi&player=1&otype=json&type=flv&quality={1}&ts={2}", model.Mid, quality, GetTimeSpan_2,access_key);
                    //url2 += "&sign=" + ApiHelper.GetSign_VIP(url2);
                    //
                    string url2 = string.Format(
                        "https://bangumi.bilibili.com/player/web_api/v2/playurl?cid={1}&appkey={0}&otype=json&type=&quality={2}&module=bangumi&season_type=1&qn={2}&ts={3}", ApiHelper._appKey_VIDEO, model.Mid, qn, ApiHelper.GetTimeSpan_2);
                    url2 += "&sign=" + ApiHelper.GetSign_VIDEO(url2);
                    re    = await WebClientClass.GetResultsUTF8Encode(new Uri(url2));

                    FlvPlyaerUrlModel m = JsonConvert.DeserializeObject <FlvPlyaerUrlModel>(re);
                    if (m.code == 0 && !re.Contains("8986943") && (m.status == 13 && m.vip_status != 0))
                    {
                        //if (m.durl.Count==1)
                        //{
                        //    return new ReturnPlayModel()
                        //    {
                        //        usePlayMode = UsePlayMode.System,
                        //        url = m.durl[0].url,
                        //        urls = urls
                        //    };
                        //}

                        foreach (var item in m.durl)
                        {
                            urls.Add(item.url);
                            playList.Append(item.url, item.size, item.length / 1000);
                        }
                    }
                    else
                    {
                        string rnd = ApiHelper.GetTimeSpan.ToString();
                        if (SettingHelper.Get_UseVIP())
                        {
                            rnd = "true" + rnd;
                        }
                        var re3 = await WebClientClass.GetResults(new Uri(string.Format("https://moe.nsapps.cn/api/v1/BiliAnimeUrl?animeid={0}&cid={1}&epid={2}&rnd={3}", model.banId, model.Mid, model.banInfo.episode_id, rnd)));

                        JObject obj = JObject.Parse(re3);
                        if (Convert.ToInt32(obj["code"].ToString()) == 0)
                        {
                            if (obj["mode"].ToString() == "mp4")
                            {
                                urls.Add(obj["data"][0]["url"].ToString());
                                return(new ReturnPlayModel()
                                {
                                    usePlayMode = UsePlayMode.System,
                                    url = obj["data"][0]["url"].ToString(),
                                    urls = urls,
                                    from = "server"
                                });
                            }
                            else
                            {
                                var returnPlayModel = new ReturnPlayModel()
                                {
                                    usePlayMode = UsePlayMode.SYEngine,
                                    from        = "server"
                                };
                                foreach (var item in obj["data"])
                                {
                                    playList.Append(item["url"].ToString(), item["size"].ToInt32(), item["length"].ToInt32() / 1000);
                                    urls.Add(item["url"].ToString());
                                }
                                returnPlayModel.playlist = playList;
                                returnPlayModel.urls     = urls;
                                return(returnPlayModel);
                            }
                        }

                        if (SettingHelper.Get_UseOtherSite())
                        {
                            var playurl = await _5DMHelper.GetUrl(model.banId, Convert.ToInt32(model.No));

                            if (playurl == "")
                            {
                                return(null);
                            }
                            else
                            {
                                urls.Add(playurl);
                                return(new ReturnPlayModel()
                                {
                                    usePlayMode = UsePlayMode.System,
                                    url = playurl,
                                    urls = urls,
                                    from = "other_site"
                                });
                            }
                        }
                        else
                        {
                            return(null);
                        }
                    }
                }
                else
                {
                    var mc = Regex.Matches(re, @"<length>(.*?)</length>.*?<size>(.*?)</size>.*?<url><!\[CDATA\[(.*?)\]\]></url>", RegexOptions.Singleline);

                    foreach (Match item in mc)
                    {
                        playList.Append(item.Groups[3].Value, Convert.ToInt32(item.Groups[2].Value), Convert.ToInt64(item.Groups[1].Value) / 1000);
                    }
                }
                config.HttpReferer = "https://www.bilibili.com/bangumi/play/ep" + model.episode_id;
                //config.HttpReferer = "";
                //config.HttpCookie = "sid=aj08qul1; pgv_pvi=2726422528; fts=1498031012; rpdid=ikxqxlpildoplqwkwlqw; buvid3=0916A88B-F02E-46E2-95B1-BEF35678E1EE37229infoc; LIVE_BUVID=9b2dbd17fe02c6e0b9a5f7cbfe182be2; LIVE_BUVID__ckMd5=54bf74d417f1dfe6; OUTFOX_SEARCH_USER_ID_NCOO=301070296.3442316; uTZ=-480; biliMzIsnew=1; biliMzTs=0; UM_distinctid=16072fe8c3138-01d5f1e1fd27a6-5d4e211f-1fa400-16072fe8c32d6; _ga=GA1.2.701916902.1513903771; im_notify_type_7251681=0; BANGUMI_SS_21728_REC=164986; finger=81df3ec0; 21680=183802; 22843=173309; BANGUMI_SS_22843_REC=173309; BANGUMI_SS_21680_REC=183802; balh_server=https://biliplus.ipcjs.win; purl_token=bilibili_1518001366; balh_season_21680=1; pgv_si=s8821510144; DedeUserID=7251681; DedeUserID__ckMd5=e2742b2aff29c1cf; SESSDATA=83ace795%2C1520595578%2Ca2c615ce; bili_jct=a0f037944a8423a37efb566011d0a84b; _dfcaptcha=42d9ae3eecffafaf47b08effeef54128";
                playList.NetworkConfigs = config;
                //FlvPlyaerUrlModel m = JsonConvert.DeserializeObject<FlvPlyaerUrlModel>(re);
                // var playList = new SYEngine.Playlist(SYEngine.PlaylistTypes.NetworkHttp);



                //foreach (var item in m.durl)
                //{
                //    playList.Append(item.url, item.size, item.length / 1000);
                //}


                // mediaPlay.Source = await playList.SaveAndGetFileUriAsync();
                return(new ReturnPlayModel()
                {
                    playlist = playList,
                    usePlayMode = UsePlayMode.SYEngine,
                    urls = urls,
                    from = "bilibili"
                });
            }
            catch (Exception)
            {
                return(null);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 读取视频播放地址
        /// </summary>
        /// <param name="model"></param>
        /// <param name="quality"></param>
        /// <returns></returns>
        public static async Task <ReturnPlayModel> GetVideoUrl(string aid, string cid, int qn)
        {
            try
            {
                if (qn < 10)
                {
                    switch (qn)
                    {
                    case 1:
                        qn = 32;
                        break;

                    case 2:
                        qn = 64;
                        break;

                    case 3:
                        qn = 80;
                        break;

                    case 4:
                        qn = 116;
                        break;

                    default:
                        qn = 64;
                        break;
                    }
                }
                List <string> urls = new List <string>();

                //https://interface.bilibili.com/v2/playurl?cid=31452468&appkey=84956560bc028eb7&otype=json&type=&quality=112&qn=112&sign=38b1355368ee65d055c12b57bdb26e3a

                string url = string.Format("https://interface.bilibili.com/v2/playurl?cid={1}&appkey={0}&otype=json&type=&quality={2}&qn={2}&ts={3}", ApiHelper._appKey_VIDEO, cid, qn, ApiHelper.GetTimeSpan_2);
                url += "&sign=" + ApiHelper.GetSign_VIDEO(url);


                string re = await WebClientClass.GetResults(new Uri(url));

                //var mc = Regex.Matches(re, @"<length>(.*?)</length>.*?<size>(.*?)</size>.*?<url><!\[CDATA\[(.*?)\]\]></url>", RegexOptions.Singleline);
                FlvPlyaerUrlModel m = JsonConvert.DeserializeObject <FlvPlyaerUrlModel>(re);
                // FlvPlyaerUrlModel m = JsonConvert.DeserializeObject<FlvPlyaerUrlModel>(re);
                var playList = new SYEngine.Playlist(SYEngine.PlaylistTypes.NetworkHttp);
                if (m.code == 0)
                {
                    foreach (var item in m.durl)
                    {
                        urls.Add(item.url);
                        playList.Append(item.url, item.size, item.length / 1000);
                    }
                }
                else
                {
                    var re3 = await WebClientClass.GetResults(new Uri(string.Format("https://moe.nsapps.cn/api/v1/BiliVideoUrl?cid={0}&qn={1}&rnd={2}", cid, qn, ApiHelper.GetTimeSpan)));

                    JObject obj = JObject.Parse(re3);
                    if (Convert.ToInt32(obj["code"].ToString()) == 0)
                    {
                        if (obj["mode"].ToString() == "mp4")
                        {
                            return(new ReturnPlayModel()
                            {
                                urls = new List <string>()
                                {
                                    obj["data"][0]["url"].ToString()
                                },
                                usePlayMode = UsePlayMode.System,
                                url = obj["data"][0]["url"].ToString(),
                                from = "server"
                            });
                        }
                        else
                        {
                            var returnPlayModel = new ReturnPlayModel()
                            {
                                usePlayMode = UsePlayMode.SYEngine,
                                from        = "server"
                            };
                            foreach (var item in obj["data"])
                            {
                                urls.Add(item["url"].ToString());
                                playList.Append(item["url"].ToString(), item["size"].ToInt32(), item["length"].ToInt32() / 1000);
                            }
                            returnPlayModel.playlist = playList;
                            returnPlayModel.urls     = urls;
                            return(returnPlayModel);
                        }
                    }
                }



                SYEngine.PlaylistNetworkConfigs config = new SYEngine.PlaylistNetworkConfigs();
                config.DownloadRetryOnFail = true;
                config.HttpCookie          = string.Empty;

                config.UniqueId      = string.Empty;
                config.HttpReferer   = "https://www.bilibili.com/video/av" + aid + "/";
                config.HttpUserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36";

                playList.NetworkConfigs = config;

                // mediaPlay.Source = await playList.SaveAndGetFileUriAsync();
                return(new ReturnPlayModel()
                {
                    usePlayMode = UsePlayMode.SYEngine,
                    playlist = playList,
                    urls = urls,
                    from = "bilibili"
                });
            }
            catch (Exception)
            {
                return(null);
            }
        }