public static async Task <string[]> LoginUseQRCodeAsync(Image qRCodeImage, CancellationToken token) { var getJson = JsonConvert.DeserializeObject <GetQRCodeJson>(await NetHelper.HttpGet("https://passport.bilibili.com/qrcode/getLoginUrl", null, null)); var QRcodeUrl = getJson.data.url; var key = getJson.data.oauthKey; var QRcode = await GetQRCodeImageAsync(QRcodeUrl); qRCodeImage.DispatcherQueue.TryEnqueue(() => qRCodeImage.Source = QRcode); while (true) { if (token.IsCancellationRequested) { return(null); } var postRaw = await NetHelper.HttpPostAsync ("http://passport.bilibili.com/qrcode/getLoginInfo", null, $"oauthKey={key}"); var postJson = JsonConvert.DeserializeObject <VerifyQRCodeJson>(postRaw.Item1); int.TryParse(postJson.data.ToString(), out int resultCode); if (resultCode == -2) { return(null); } if (postJson.status == true) { var sESSDATA = Regex.Match(postRaw.Item2.ToString(), "(?<=SESSDATA=)[%|a-z|A-Z|0-9|*]*")?.Value; var uid = Regex.Match(postRaw.Item2.ToString(), "(?<=DedeUserID=)[0-9]*")?.Value; return(new string[] { sESSDATA, uid }); } await Task.Delay(1000); } }
public static async Task <BiliUser> GetCurrentUserInfoAsync() { var sESSDATA = ApplicationData.Current.LocalSettings.Values["biliUserSESSDATA"] as string; if (sESSDATA == null) { return(null); } var cookies = new List <(string, string)>() { ("SESSDATA", sESSDATA) }; var json = JsonConvert.DeserializeObject <SelfInfoJson>(await NetHelper.HttpGet("http://api.bilibili.com/x/space/myinfo", cookies, null)); var user = new BiliUser(); //var file = await ApplicationData.Current.LocalCacheFolder.CreateFileAsync("avatar", CreationCollisionOption.ReplaceExisting); //var imgStream = await NetHelper.HttpGetStreamAsync(json.data.face, null, null); //var fileStream = await file.OpenStreamForWriteAsync(); //await imgStream.CopyToAsync(fileStream); //imgStream.Close(); //fileStream.Close(); //var imgSource = new BitmapImage(); //await imgSource.SetSourceAsync((await file.OpenStreamForReadAsync()).AsRandomAccessStream()); var imgSource = new BitmapImage(new Uri(json.data.face)); user.Uid = json.data.mid; user.Name = json.data.name; user.AvatarUrl = json.data.face; user.AvatarImg = imgSource; user.VipStatus = (VipStatus)json.data.vip.status; return(user); }
public static async Task <List <BiliBangumi> > GetBangumiListAsync(int page, long uid, string sESSDATA) { List <(string, string)> cookies = null; if (!string.IsNullOrWhiteSpace(sESSDATA)) { cookies = new List <(string, string)>(); cookies.Add(("SESSDATA", sESSDATA)); } var json = JsonConvert.DeserializeObject <BiliBangumiListJson>(await NetHelper.HttpGet ("https://api.bilibili.com/x/space/bangumi/follow/list", cookies, $"type=1&pn={page}&ps=15&vmid={uid}")); var list = new List <BiliBangumi>(); if (!(json.data.list?.Count > 0)) { return(null); } foreach (var bangumi in json.data.list) { list.Add(new BiliBangumi() { Title = bangumi.title + " - " + bangumi.season_title, SeasonId = bangumi.season_id, Cover = bangumi.cover }); } return(list); }
public static async Task <BiliFav> GetBiliFavAsync(int id, int pn, string sESSDATA) { List <(string, string)> cookies = null; if (!string.IsNullOrWhiteSpace(sESSDATA)) { cookies = new List <(string, string)>(); cookies.Add(("SESSDATA", sESSDATA)); } var json = JsonConvert.DeserializeObject <FavJson> (await NetHelper.HttpGet("https://api.bilibili.com/x/v3/fav/resource/list", cookies, $"media_id={id}", $"pn={pn}", "ps=20", "order=mtime")); if (json.data.medias == null) { return(null); } var fav = new BiliFav() { Id = json.data.info.id, Title = json.data.info.title, MediaCount = json.data.info.media_count, VideoList = json.data.medias.Select(m => new BiliVideoMaster() { Bv = m.bvid, Picture = m.cover, Title = m.title }).ToList() }; return(fav); }
public static async Task <BiliVideoMaster> GetVideoMasterInfoAsync(long av, string sESSDATA) { List <(string, string)> cookies = null; if (!string.IsNullOrWhiteSpace(sESSDATA)) { cookies = new List <(string, string)>(); cookies.Add(("SESSDATA", sESSDATA)); } var json = JsonConvert.DeserializeObject <VideoInfoJson>(await NetHelper.HttpGet("http://api.bilibili.com/x/web-interface/view", cookies, $"aid={av}")); var videoList = new List <BiliVideo>(); //此处并未请求视频流 json.data.pages.ForEach(v => { videoList.Add(new BiliVideo() { Bv = json.data.bvid, Cid = v.cid, Name = v.part, P = v.page, Title = json.data.title, Cover = json.data.pic }); }); var master = new BiliVideoMaster() { Bv = json.data.bvid, Picture = json.data.pic, Title = json.data.title, VideoList = videoList }; return(master); }
public static async Task <BiliVideoInfo> GetSingleVideoInfoAsync(string bv, long cid, int quality, string sESSDATA) { var master = await GetVideoMasterInfoAsync(bv, sESSDATA); List <(string, string)> cookies = null; if (!string.IsNullOrWhiteSpace(sESSDATA)) { cookies = new List <(string, string)>(); cookies.Add(("SESSDATA", sESSDATA)); } var json = JsonConvert.DeserializeObject <VideoStreamJson> (await NetHelper.HttpGet("http://api.bilibili.com/x/player/playurl", cookies, $"bvid={bv}", $"cid={cid}", $"qn={quality}", "fnval=16")); if (json.data == null) { throw new ParsingVideoException("视频解析失败,请检查是否缺少大会员权限"); } var info = new BiliVideoInfo() { Bv = master.Bv, Cid = cid, Name = master.Title + " " + master.VideoList.Where(v => v.Cid == cid)?.FirstOrDefault().Name, CoverUrl = master.VideoList.Where(v => v.Cid == cid)?.FirstOrDefault().Cover ?? master.Picture, QualityCodeList = json.data.accept_quality }; return(info); }
/// <summary> /// 获取番剧信息 /// </summary> /// <param name="eporss"></param> /// <param name="type">0是ep,其他随便一个数字是ss</param> /// <param name="sESSDATA"></param> /// <returns></returns> public static async Task <BiliBangumi> GetBangumiInfoAsync(int eporss, int type, string sESSDATA) { List <(string, string)> cookies = null; if (!string.IsNullOrWhiteSpace(sESSDATA)) { cookies = new List <(string, string)>(); cookies.Add(("SESSDATA", sESSDATA)); } BiliBangumiInfoJson json; if (type == 0) { json = JsonConvert.DeserializeObject <BiliBangumiInfoJson> (await NetHelper.HttpGet("http://api.bilibili.com/pgc/view/web/season", cookies, $"ep_id={eporss}")); } else { json = JsonConvert.DeserializeObject <BiliBangumiInfoJson> (await NetHelper.HttpGet("http://api.bilibili.com/pgc/view/web/season", cookies, $"season_id={eporss}")); } var videoList = new List <BiliVideo>(); json.result.episodes.ForEach(v => { videoList.Add(new BiliVideo() { Bv = v.bvid, Cid = v.cid, Name = v.long_title, Title = json.result.season_title, P = 1, Cover = v.cover }); }); var bangumi = new BiliBangumi() { Title = json.result.season_title, Cover = json.result.cover, MediaId = json.result.media_id, SeasonId = json.result.season_id, EpisodeList = videoList }; return(bangumi); }
public static async Task <(bool, string, long)> VerifySessDataAsync(string sESSDATA) { var cookies = new List <(string, string)>() { ("SESSDATA", sESSDATA) }; var json = JsonConvert.DeserializeObject <SelfInfoJson>(await NetHelper.HttpGet("http://api.bilibili.com/x/space/myinfo", cookies, null)); if (json.code == -101 || json.code != 0) { return(false, null, 0); } else { return(true, sESSDATA, json.data.mid); } }
public static async Task <List <BiliFav> > GetUserFavListInfoAsync(long uid, string sESSDATA) { List <(string, string)> cookies = null; if (!string.IsNullOrWhiteSpace(sESSDATA)) { cookies = new List <(string, string)>(); cookies.Add(("SESSDATA", sESSDATA)); } var json = JsonConvert.DeserializeObject <FavListJson> (await NetHelper.HttpGet("https://api.bilibili.com/x/v3/fav/folder/created/list-all", cookies, $"up_mid={uid}", "jsonp=jsonp")); var list = json.data.list.Select(l => new BiliFav() { Id = l.id, Title = l.title }).ToList(); return(list); }
public static async Task <BiliVideo> GetSingleVideoAsync(string bv, long cid, int quality, string sESSDATA) { var master = await GetVideoMasterInfoAsync(bv, sESSDATA); List <(string, string)> cookies = null; if (!string.IsNullOrWhiteSpace(sESSDATA)) { cookies = new List <(string, string)>(); cookies.Add(("SESSDATA", sESSDATA)); } if (quality == 0) { quality = 64; } var json = JsonConvert.DeserializeObject <VideoStreamJson> (await NetHelper.HttpGet("http://api.bilibili.com/x/player/playurl", cookies, $"bvid={bv}", $"cid={cid}", $"qn={quality}", "fnval=16")); if (json.data == null) { throw new ParsingVideoException("视频解析失败,请检查是否缺少大会员权限"); } var video = new BiliVideo(); video.Bv = bv; video.Cid = cid; video.Name = master.VideoList.Where(v => v.Cid == cid).FirstOrDefault().Name; video.P = master.VideoList.Where(v => v.Cid == cid).FirstOrDefault().P; video.Quality = (BiliVideoQuality)json.data.quality; video.Title = master.Title; if ((bool)ApplicationData.Current.LocalSettings.Values["HEVC"])//优先使用hevc { if (json.data.dash.video.Where(v => v.id == quality && v.codecs.Contains("hev")).Count() > 0) { video.VideoUrl = json.data.dash.video.Where(v => v.id == quality && v.codecs.Contains("hev")).FirstOrDefault().baseUrl; } else if (json.data.dash.video.Where(v => v.codecs.Contains("hev")).Count() > 0) { var list = json.data.dash.video.Where(v => v.codecs.Contains("hev")).OrderByDescending(v => v.id).ToList(); video.VideoUrl = list.First().baseUrl; } else if (json.data.dash.video.Where(v => v.id == quality && v.codecs.Contains("avc")).Count() > 0) { video.VideoUrl = json.data.dash.video.Where(v => v.id == quality && v.codecs.Contains("avc")).FirstOrDefault().baseUrl; } else { var list = json.data.dash.video.Where(v => v.codecs.Contains("avc")).OrderByDescending(v => v.id).ToList(); video.VideoUrl = list.First().baseUrl; } } else { if (json.data.dash.video.Where(v => v.id == quality && v.codecs.Contains("avc")).Count() > 0) { video.VideoUrl = json.data.dash.video.Where(v => v.id == quality && v.codecs.Contains("avc")).FirstOrDefault().baseUrl; } else { var list = json.data.dash.video.Where(v => v.codecs.Contains("avc")).OrderByDescending(v => v.id).ToList(); video.VideoUrl = list.First().baseUrl; } } if (json.data.dash.audio.Where(v => v.id == 30280).Count() > 0) { video.AudioUrl = json.data.dash.audio.Where(v => v.id == 30280).FirstOrDefault().baseUrl; } else { var list = json.data.dash.audio.OrderByDescending(v => v.id).ToList(); video.AudioUrl = list.First().baseUrl; } return(video); }