/// <summary> /// Initialize a new login. /// </summary> /// <returns>Successful</returns> public bool Init() { try { HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://passport.bilibili.com/qrcode/getLoginUrl"); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Stream dataStream = response.GetResponseStream(); StreamReader reader = new StreamReader(dataStream); string result = reader.ReadToEnd(); reader.Close(); response.Close(); dataStream.Close(); IJson getLoginUrl = JsonParser.Parse(result); LoginUrlRecieved?.Invoke(this, getLoginUrl.GetValue("data").GetValue("url").ToString()); Bitmap qrBitmap = RenderQrCode(getLoginUrl.GetValue("data").GetValue("url").ToString()); QRImageLoaded?.Invoke(this, qrBitmap); oauthKey = getLoginUrl.GetValue("data").GetValue("oauthKey").ToString(); return(true); } catch (WebException ex) { ConnectionFailed?.Invoke(this, ex); return(false); } }
/// <summary> /// Get infos of a video/season. /// </summary> /// <param name="id">Aid/Season-id</param> /// <param name="isSeason">IsSeason</param> /// <returns>Video info</returns> public static VideoInfo GetInfo(uint id, bool isSeason) { if (!isSeason) { Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("aid", id.ToString()); try { IJson json = BiliApi.GetJsonResult("https://api.bilibili.com/x/web-interface/view", dic, false); return(new VideoInfo(json.GetValue("data"), isSeason)); } catch (System.Net.WebException) { return(null); } } else { Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("season_id", id.ToString()); try { IJson json = BiliApi.GetJsonResult("https://bangumi.bilibili.com/view/web_api/season", dic, false); if (json.GetValue("code").ToLong() == 0) { return(new VideoInfo(json.GetValue("result"), isSeason)); } return(null); } catch (System.Net.WebException) { return(null); } } }
public void LoadAsync() { if (cancellationTokenSource != null) { cancellationTokenSource.Cancel(); } ContentViewer.ScrollToHome(); ContentPanel.Children.Clear(); cancellationTokenSource = new CancellationTokenSource(); CancellationToken cancellationToken = cancellationTokenSource.Token; LoadingPrompt.Visibility = Visibility.Visible; PagesBox.Visibility = Visibility.Hidden; Task task = new Task(() => { IJson userinfo = BiliApi.GetJsonResult("https://api.bilibili.com/x/web-interface/nav", null, false); if (cancellationToken.IsCancellationRequested) { return; } if (userinfo.GetValue("code").ToLong() == 0) { Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("mid", userinfo.GetValue("data").GetValue("mid").ToLong().ToString()); IJson json = BiliApi.GetJsonResult("https://api.bilibili.com/x/space/fav/nav", dic, false); if (cancellationToken.IsCancellationRequested) { return; } if (json.GetValue("code").ToLong() == 0) { Dispatcher.Invoke(new Action(() => { foreach (IJson folder in json.GetValue("data").GetValue("archive")) { FavItem favItem; if (folder.GetValue("Cover").Contains(0)) { favItem = new FavItem(folder.GetValue("name").ToString(), folder.GetValue("cover").GetValue(0).GetValue("pic").ToString(), folder.GetValue("cur_count").ToLong(), folder.GetValue("media_id").ToLong(), true); } else { favItem = new FavItem(folder.GetValue("name").ToString(), null, folder.GetValue("cur_count").ToLong(), folder.GetValue("media_id").ToLong(), true); } favItem.PreviewMouseLeftButtonDown += FavItem_PreviewMouseLeftButtonDown; ContentPanel.Children.Add(favItem); } })); } } Dispatcher.Invoke(new Action(() => { LoadingPrompt.Visibility = Visibility.Hidden; })); }); task.Start(); }
private void ShowFolder(int mediaId, int pagenum, bool init) { if (cancellationTokenSource != null) { cancellationTokenSource.Cancel(); } ContentViewer.ScrollToHome(); ContentPanel.Children.Clear(); MediaId = mediaId; cancellationTokenSource = new CancellationTokenSource(); CancellationToken cancellationToken = cancellationTokenSource.Token; LoadingPrompt.Visibility = Visibility.Visible; PagesBox.Visibility = Visibility.Hidden; Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("media_id", mediaId.ToString()); dic.Add("pn", pagenum.ToString()); dic.Add("ps", "20"); dic.Add("keyword", ""); dic.Add("order", "mtime"); dic.Add("type", "0"); dic.Add("tid", "0"); dic.Add("jsonp", "jsonp"); Task task = new Task(() => { IJson json = BiliApi.GetJsonResult("https://api.bilibili.com/medialist/gateway/base/spaceDetail", dic, false); if (cancellationToken.IsCancellationRequested) { return; } if (json.GetValue("code").ToLong() == 0) { Dispatcher.Invoke(new Action(() => { foreach (IJson media in json.GetValue("data").GetValue("medias")) { FavItem favItem = new FavItem(media.GetValue("title").ToString(), media.GetValue("cover").ToString(), media.GetValue("fav_time").ToLong(), media.GetValue("id").ToLong(), false); favItem.PreviewMouseLeftButtonDown += FavItem_PreviewMouseLeftButtonDown; ContentPanel.Children.Add(favItem); } if (init) { PagesBox.SetPage((int)Math.Ceiling((double)json.GetValue("data").GetValue("info").GetValue("media_count").ToLong() / 20), 1, true); } PagesBox.Visibility = Visibility.Visible; })); } Dispatcher.Invoke(new Action(() => { LoadingPrompt.Visibility = Visibility.Hidden; })); }); task.Start(); }
private void FavItem_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { FavItem favItemSender = (FavItem)sender; if (favItemSender.IsFolder) { if (cancellationTokenSource != null) { cancellationTokenSource.Cancel(); } ContentViewer.ScrollToHome(); ContentPanel.Children.Clear(); cancellationTokenSource = new CancellationTokenSource(); CancellationToken cancellationToken = cancellationTokenSource.Token; LoadingPrompt.Visibility = Visibility.Visible; Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("media_id", favItemSender.Id.ToString()); dic.Add("pn", "1"); dic.Add("ps", "20"); dic.Add("keyword", ""); dic.Add("order", "mtime"); dic.Add("type", "0"); dic.Add("tid", "0"); dic.Add("jsonp", "jsonp"); Task task = new Task(() => { IJson json = BiliApi.GetJsonResult("https://api.bilibili.com/medialist/gateway/base/spaceDetail", dic, false); if (cancellationToken.IsCancellationRequested) { return; } if (json.GetValue("code").ToLong() == 0) { Dispatcher.Invoke(new Action(() => { foreach (IJson media in json.GetValue("data").GetValue("medias")) { FavItem favItem = new FavItem(media.GetValue("title").ToString(), media.GetValue("cover").ToString(), media.GetValue("fav_time").ToLong(), media.GetValue("id").ToLong(), false); favItem.PreviewMouseLeftButtonDown += FavItem_PreviewMouseLeftButtonDown; ContentPanel.Children.Add(favItem); } })); } Dispatcher.Invoke(new Action(() => { LoadingPrompt.Visibility = Visibility.Hidden; })); }); task.Start(); } else { VideoSelected?.Invoke(favItemSender.Title, favItemSender.Id); } }
private async void ShowDataAsync() { IJson json = JsonParser.Parse(await RequestJsonAsync(string.Format("https://api.tracker.gg/api/v1/bfv/profile/origin/{0}", Name))); Overview overview = new Overview(json.GetValue("data")); List <Overview> overviews = new List <Overview>(new Overview[] { overview }); DataGridOverview.ItemsSource = overviews; PlayTime.Text = overview.PlayedTime; LastPlayTime.Text = overview.LastPlayed; BitmapImage bitmapImage = new BitmapImage(); bitmapImage = new BitmapImage(); bitmapImage.BeginInit(); bitmapImage.UriSource = new Uri(Regex.Unescape(json.GetValue("data").GetValue("account").GetValue("avatarUrl").ToString())); bitmapImage.DecodePixelWidth = 320; bitmapImage.EndInit(); Img.Source = bitmapImage; List <Class> classes = new List <Class>(); foreach (IJson i in json.GetValue("data").GetValue("classes")) { Class @class = new Class(i); classes.Add(@class); } DataGridClasses.ItemsSource = classes; List <IHasCodeName> weapons = new List <IHasCodeName>(); foreach (IJson i in json.GetValue("data").GetValue("weapons")) { Weapon weapon = new Weapon(i); weapons.Add(weapon); } DataGridWeapons.ItemsSource = weapons; List <IHasCodeName> vehicles = new List <IHasCodeName>(); foreach (IJson i in json.GetValue("data").GetValue("vehicles")) { Vehicle vehicle = new Vehicle(i); vehicles.Add(vehicle); } DataGridVehicles.ItemsSource = vehicles; await CodeToNameAsync(weapons); DataGridWeapons.Items.Refresh(); await CodeToNameAsync(vehicles); DataGridVehicles.Items.Refresh(); }
public SeasonSuggest(IJson item) { Position = (uint)(item.GetValue("position").ToLong()); if (item.Contains("title")) { Title = item.GetValue("title").ToString(); } else { Title = null; } Keyword = item.GetValue("keyword").ToString(); Cover = Regex.Unescape("https:" + item.GetValue("Cover").ToString()); Uri = Regex.Unescape(item.GetValue("uri").ToString()); Ptime = item.GetValue("ptime").ToLong(); SeasonTypeName = item.GetValue("season_type_name").ToString(); Area = item.GetValue("area").ToString(); if (item.Contains("label")) { Label = item.GetValue("label").ToString(); } else { Label = null; } }
public void LoadAsync(int mid, int page, bool init) { Mid = mid; if (cancellationTokenSource != null) { cancellationTokenSource.Cancel(); } ContentViewer.ScrollToHome(); ContentPanel.Children.Clear(); PagesBox.Visibility = Visibility.Hidden; cancellationTokenSource = new CancellationTokenSource(); CancellationToken cancellationToken = cancellationTokenSource.Token; LoadingPrompt.Visibility = Visibility.Visible; Task task = new Task(() => { Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("mid", mid.ToString()); dic.Add("pagesize", "30"); dic.Add("page", page.ToString()); try { IJson json = BiliApi.GetJsonResult("https://space.bilibili.com/ajax/member/getSubmitVideos", dic, true); Dispatcher.Invoke(new Action(() => { foreach (IJson v in json.GetValue("data").GetValue("vlist")) { ResultBox.Video video = new ResultBox.Video(v); ResultVideo resultVideo = new ResultVideo(video); resultVideo.PreviewMouseLeftButtonDown += ResultVideo_PreviewMouseLeftButtonDown; ContentPanel.Children.Add(resultVideo); } if (init) { PagesBox.SetPage((int)json.GetValue("data").GetValue("pages").ToLong(), 1, true); } PagesBox.Visibility = Visibility.Visible; LoadingPrompt.Visibility = Visibility.Hidden; })); } catch (Exception) { } Dispatcher.Invoke(new Action(() => { LoadingPrompt.Visibility = Visibility.Hidden; })); }, cancellationTokenSource.Token); task.Start(); }
public bool IsLatestVersion() { ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://api.github.com/repos/xuan525/OriginReportTools/releases/latest"); request.Accept = "application/vnd.github.v3+json"; request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36"; try { HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Stream dataStream = response.GetResponseStream(); StreamReader reader = new StreamReader(dataStream); string result = reader.ReadToEnd(); reader.Close(); response.Close(); dataStream.Close(); IJson json = JsonParser.Parse(result); string latestTag = json.GetValue("tag_name").ToString(); return(Application.Current.FindResource("Version").ToString() == latestTag); } catch { return(true); } }
public string GetLatestDownloadUrl() { while (true) { ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://api.github.com/repos/xuan525/Bili-dl/releases/latest"); request.Accept = "application/vnd.github.v3+json"; request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36"; try { HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Stream dataStream = response.GetResponseStream(); StreamReader reader = new StreamReader(dataStream); string result = reader.ReadToEnd(); reader.Close(); response.Close(); dataStream.Close(); IJson json = JsonParser.Parse(result); string url = json.GetValue("assets").GetValue(0).GetValue("browser_download_url").ToString(); return(url); } catch (WebException) { Thread.Sleep(5000); } } }
public bool IsLatestVersion() { ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://api.github.com/repos/xuan525/Bili-dl/releases/latest"); request.Accept = "application/vnd.github.v3+json"; request.UserAgent = "Bili-dl"; try { HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Stream dataStream = response.GetResponseStream(); StreamReader reader = new StreamReader(dataStream); string result = reader.ReadToEnd(); reader.Close(); response.Close(); dataStream.Close(); IJson json = JsonParser.Parse(result); string latestTag = json.GetValue("tag_name").ToString(); return(Application.Current.FindResource("Version").ToString() == latestTag); } catch { return(true); } }
public Season(IJson json, IJson cardsJson) { Cover = "https:" + Regex.Unescape(json.GetValue("cover").ToString()); Title = System.Net.WebUtility.HtmlDecode(Regex.Unescape(json.GetValue("title").ToString())); Styles = Regex.Unescape(json.GetValue("styles").ToString()); Areas = Regex.Unescape(json.GetValue("areas").ToString()); Pubtime = json.GetValue("pubtime").ToLong(); Cv = Regex.Unescape(json.GetValue("cv").ToString()); Description = Regex.Unescape(json.GetValue("desc").ToString()); SeasonId = json.GetValue("season_id").ToLong(); SeasonTypeName = cardsJson.GetValue("result").GetValue(SeasonId.ToString()).GetValue("season_type_name").ToString(); OrgTitle = System.Net.WebUtility.HtmlDecode(Regex.Unescape(json.GetValue("org_title").ToString())); }
private List <Suggest> GetSuggest(string text) { Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("highlight", "1"); dic.Add("keyword", text); try { IJson json = BiliApi.GetJsonResult("https://app.bilibili.com/x/v2/search/suggest3", dic, true); if (json.GetValue("data").Contains("list")) { List <Suggest> suggests = new List <Suggest>(); foreach (IJson i in json.GetValue("data").GetValue("list")) { if (!i.Contains("sug_type")) { Suggest suggest = new Suggest(i); suggests.Add(suggest); } else if (i.GetValue("sug_type").ToString() == "pgc") { SeasonSuggest seasonSuggest = new SeasonSuggest(i); suggests.Add(seasonSuggest); } else if (i.GetValue("sug_type").ToString() == "user") { UserSuggest userSuggest = new UserSuggest(i); suggests.Add(userSuggest); } else { Suggest suggest = new Suggest(i); suggests.Add(suggest); } } suggests.Sort((x, y) => x.Position.CompareTo(y.Position)); return(suggests); } return(null); } catch (WebException) { return(null); } }
public UserSuggest(IJson item) { Position = (uint)item.GetValue("position").ToLong(); Title = item.GetValue("title").ToString(); Keyword = item.GetValue("keyword").ToString(); Cover = Regex.Unescape("https:" + item.GetValue("Cover").ToString()); Uri = Regex.Unescape(item.GetValue("uri").ToString()); Level = (uint)item.GetValue("level").ToLong(); Fans = item.GetValue("fans").ToLong(); Archives = item.GetValue("archives").ToLong(); }
public Weapon(IJson json) { ID = "weapons"; Code = ID + "." + json.GetValue("code").ToString(); Name = json.GetValue("code").ToString(); Kill = json.GetValue("kills").GetValue("displayValue").ToString(); KPM = json.GetValue("killsPerMinute").GetValue("displayValue").ToString(); TimePlayed = json.GetValue("timePlayed").GetValue("displayValue").ToString(); ShotsFired = json.GetValue("shotsFired").GetValue("displayValue").ToString(); ShotsHit = json.GetValue("shotsHit").GetValue("displayValue").ToString(); ShotsAccuracy = json.GetValue("ShotsAccuracy").GetValue("displayValue").ToString(); Headshots = json.GetValue("headshots").GetValue("displayValue").ToString(); TimePlayed = TimePlayed.Replace("h", "时").Replace("m", "分").Replace("s", "秒"); }
public Class(IJson json) { Name = json.GetValue("class").ToString(); Rank = json.GetValue("rank").GetValue("displayValue").ToString(); Score = json.GetValue("score").GetValue("displayValue").ToString(); ScoreMin = json.GetValue("scorePerMinute").GetValue("displayValue").ToString(); Kill = json.GetValue("kills").GetValue("displayValue").ToString(); KPM = json.GetValue("killsPerMinute").GetValue("displayValue").ToString(); KD = json.GetValue("kdRatio").GetValue("displayValue").ToString(); }
private bool Analysis() { StatusUpdate?.Invoke(ProgressPercentage, 0, Status.Analyzing); Segments = new List <Segment>(); Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("avid", Aid.ToString()); dic.Add("cid", Cid.ToString()); dic.Add("qn", Qn.ToString()); try { IJson json = BiliApi.GetJsonResult("https://api.bilibili.com/x/player/playurl", dic, false); if (json.GetValue("code").ToLong() == 0) { if (json.GetValue("data").GetValue("quality").ToLong() == Qn) { foreach (IJson v in json.GetValue("data").GetValue("durl")) { Segment segment = new Segment(Aid, Regex.Unescape(v.GetValue("url").ToString()), SegmentType.Mixed, v.GetValue("size").ToLong(), Threads); segment.Finished += Segment_Finished; Segments.Add(segment); } } else { return(false); } } else { json = BiliApi.GetJsonResult("http://api.bilibili.com/pgc/player/web/playurl", dic, false); if (json.GetValue("code").ToLong() == 0) { if (json.GetValue("result").GetValue("quality").ToLong() == Qn) { foreach (IJson v in json.GetValue("result").GetValue("durl")) { Segment segment = new Segment(Aid, Regex.Unescape(v.GetValue("url").ToString()), SegmentType.Mixed, v.GetValue("size").ToLong(), Threads); segment.Finished += Segment_Finished; Segments.Add(segment); } } else { return(false); } } else { return(false); } } return(true); } catch (WebException) { return(false); } }
public User(IJson json) { Mid = json.GetValue("mid").ToLong(); Upic = "https:" + Regex.Unescape(json.GetValue("upic").ToString()); Uname = Regex.Unescape(json.GetValue("uname").ToString()); Videos = json.GetValue("videos").ToLong(); Fans = json.GetValue("fans").ToLong(); Usign = Regex.Unescape(json.GetValue("usign").ToString()); }
/// <summary> /// Get qualities of the page/episode. /// </summary> /// <returns>A list of qualities</returns> public List <Quality> GetQualities() { Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("avid", Aid.ToString()); dic.Add("cid", Cid.ToString()); //dic.Add("fnval", "16"); try { IJson json = BiliApi.GetJsonResult("https://api.bilibili.com/x/player/playurl", dic, false); Qualities = new List <Quality>(); if (json.GetValue("code").ToLong() == 0) { for (int i = 0; i < ((JsonArray)json.GetValue("data").GetValue("accept_quality")).Count; i++) { Qualities.Add(new Quality(Title, Index, Num, Part, Aid, Cid, (uint)json.GetValue("data").GetValue("accept_quality").GetValue(i).ToLong(), json.GetValue("data").GetValue("accept_description").GetValue(i).ToString(), false)); } } else if (IsSeason) { json = BiliApi.GetJsonResult("http://api.bilibili.com/pgc/player/web/playurl", dic, false); if (json.GetValue("code").ToLong() == 0) { for (int i = 0; i < ((JsonArray)json.GetValue("result").GetValue("accept_quality")).Count; i++) { Qualities.Add(new Quality(Title, Index, Num, Part, Aid, Cid, (uint)json.GetValue("result").GetValue("accept_quality").GetValue(i).ToLong(), json.GetValue("result").GetValue("accept_description").GetValue(i).ToString(), true)); } } } return(Qualities); } catch (System.Net.WebException) { return(null); } }
public Suggest(IJson item) { Position = (uint)item.GetValue("position").ToLong(); if (item.Contains("title")) { Title = item.GetValue("title").ToString(); } else { Title = null; } Keyword = item.GetValue("keyword").ToString(); if (item.Contains("sug_type")) { Type = item.GetValue("sug_type").ToString(); } else { Type = null; } }
private async Task CodeToNameAsync(List <IHasCodeName> hasNames) { IJson json = JsonParser.Parse(await RequestJsonAsync(string.Format("https://api.tracker.gg/api/v1/bfv/profile/origin/{0}/{1}", Name, hasNames[0].ID))); Dictionary <string, string> codeDic = new Dictionary <string, string>(); foreach (IJson i in json.GetValue("data").GetValue("children")) { codeDic.Add(i.GetValue("id").ToString(), i.GetValue("metadata").GetValue("name").ToString()); } foreach (IHasCodeName i in hasNames) { i.Name = codeDic[i.Code]; } DataGridWeapons.Items.Refresh(); }
public Vehicle(IJson json) { ID = "vehicles"; Code = ID + "." + json.GetValue("code").ToString(); Name = json.GetValue("code").ToString(); Kill = json.GetValue("kills").GetValue("displayValue").ToString(); KPM = json.GetValue("killsPerMinute").GetValue("displayValue").ToString(); TimePlayed = json.GetValue("timePlayed").GetValue("displayValue").ToString(); Destroyed = json.GetValue("destroyed").GetValue("displayValue").ToString(); TimePlayed = TimePlayed.Replace("h", "时").Replace("m", "分").Replace("s", "秒"); }
/// <summary> /// Search a text asynchronously. /// </summary> /// <param name="text">text</param> public void SearchAsync(string text, int pagenum) { if (cancellationTokenSource != null) { cancellationTokenSource.Cancel(); } ContentViewer.ScrollToHome(); ContentPanel.Children.Clear(); PagesBox.Visibility = Visibility.Hidden; if (text != null && text.Trim() != string.Empty) { HistoryBox.Insert(text); HistoryBox.Visibility = Visibility.Hidden; TypeBtn.IsChecked = true; cancellationTokenSource = new CancellationTokenSource(); CancellationToken cancellationToken = cancellationTokenSource.Token; LoadingPrompt.Visibility = Visibility.Visible; Task task = new Task(() => { string type = NavType; IJson json = GetResult(text, type, pagenum); if (json != null) { Dispatcher.Invoke(new Action(() => { if (cancellationToken.IsCancellationRequested) { return; } ShowResult(json, type); PagesBox.SetPage((int)json.GetValue("data").GetValue("numpages").ToLong(), (int)json.GetValue("data").GetValue("page").ToLong(), false); PagesBox.Visibility = Visibility.Visible; LoadingPrompt.Visibility = Visibility.Hidden; })); } }); task.Start(); } else { HistoryBox.Visibility = Visibility.Visible; } }
public Video(IJson json) { Pic = "https:" + Regex.Unescape(json.GetValue("pic").ToString()); Title = System.Net.WebUtility.HtmlDecode(Regex.Unescape(json.GetValue("title").ToString())); Play = json.GetValue("play").ToLong(); if (json.Contains("pubdate")) { Pubdate = json.GetValue("pubdate").ToLong(); } else { Pubdate = json.GetValue("created").ToLong(); } Author = Regex.Unescape(json.GetValue("author").ToString()); Aid = json.GetValue("aid").ToLong(); }
public static UserInfo GetUserInfo(CookieCollection cookies) { try { IJson json = BiliApi.GetJsonResult("https://account.bilibili.com/home/userInfo", null, false); if (json.GetValue("code").ToLong() == 0) { return(new UserInfo(json)); } else { return(null); } } catch (WebException) { return(null); } }
private void ResultUser_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { TypeBtn.IsChecked = false; if (cancellationTokenSource != null) { cancellationTokenSource.Cancel(); } cancellationTokenSource = new CancellationTokenSource(); CancellationToken cancellationToken = cancellationTokenSource.Token; ContentPanel.Children.Clear(); LoadingPrompt.Visibility = Visibility.Visible; Task task = new Task(() => { Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("mid", ((ResultUser)sender).Mid.ToString()); dic.Add("pagesize", "30"); dic.Add("page", "1"); try { IJson json = BiliApi.GetJsonResult("https://space.bilibili.com/ajax/member/getSubmitVideos", dic, true); Dispatcher.Invoke(new Action(() => { foreach (IJson v in json.GetValue("data").GetValue("vlist")) { Video video = new Video(v); ResultVideo resultVideo = new ResultVideo(video); resultVideo.PreviewMouseLeftButtonDown += ResultVideo_PreviewMouseLeftButtonDown; ContentPanel.Children.Add(resultVideo); } LoadingPrompt.Visibility = Visibility.Hidden; })); } catch (Exception) { } }, cancellationTokenSource.Token); task.Start(); }
public Quality(string title, string index, uint num, string part, uint aid, uint cid, uint qn, string description, bool seasonApiOnly) { SeasonApiOnly = seasonApiOnly; Title = title; Index = index; Num = num; Part = part; Aid = aid; Cid = cid; Qn = qn; Description = description; Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("avid", Aid.ToString()); dic.Add("cid", Cid.ToString()); dic.Add("qn", Qn.ToString()); //dic.Add("fnval", "16"); try { if (!seasonApiOnly) { IJson json = BiliApi.GetJsonResult("https://api.bilibili.com/x/player/playurl", dic, false); IsAvaliable = json.GetValue("data").GetValue("quality").ToLong() == Qn; } else { IJson json = BiliApi.GetJsonResult("http://api.bilibili.com/pgc/player/web/playurl", dic, false); IsAvaliable = json.GetValue("result").GetValue("quality").ToLong() == Qn; } } catch (System.Net.WebException) { IsAvaliable = false; } }
public VideoInfo(IJson json, bool isSeason) { if (!isSeason) { Aid = (uint)json.GetValue("aid").ToLong(); Title = json.GetValue("title").ToString(); pages = new List <Page>(); foreach (IJson p in json.GetValue("pages")) { pages.Add(new Page(Title, Aid, p, isSeason)); } } else { Aid = (uint)json.GetValue("season_id").ToLong(); Title = json.GetValue("series_title").ToString(); pages = new List <Page>(); foreach (IJson p in json.GetValue("episodes")) { pages.Add(new Page(Title, Aid, p, isSeason)); } } }
public Page(string title, uint aid, IJson json, bool isSeason) { IsSeason = isSeason; if (!isSeason) { Title = title; Index = json.GetValue("page").ToLong().ToString(); Aid = aid; Num = (uint)json.GetValue("page").ToLong(); Cid = (uint)json.GetValue("cid").ToLong(); Part = json.GetValue("part").ToString(); Duration = (uint)json.GetValue("duration").ToLong(); } else { Title = title; Index = json.GetValue("index").ToString(); Aid = (uint)json.GetValue("aid").ToLong(); Num = (uint)json.GetValue("page").ToLong(); Cid = (uint)json.GetValue("cid").ToLong(); Part = json.GetValue("index_title").ToString(); Duration = (uint)json.GetValue("duration").ToLong(); } }
private async void ShowResult(IJson json, string type) { if (json.GetValue("code").ToLong() == 0 && json.GetValue("data").GetValue("numresults").ToLong() > 0) { switch (type) { case "video": foreach (IJson v in json.GetValue("data").GetValue("result")) { Video video = new Video(v); ResultVideo resultVideo = new ResultVideo(video); resultVideo.PreviewMouseLeftButtonDown += ResultVideo_PreviewMouseLeftButtonDown; ContentPanel.Children.Add(resultVideo); } break; case "media_bangumi": StringBuilder stringBuilderBangumi = new StringBuilder(); foreach (IJson v in json.GetValue("data").GetValue("result")) { stringBuilderBangumi.Append(','); stringBuilderBangumi.Append(v.GetValue("season_id").ToString()); } Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("season_ids", stringBuilderBangumi.ToString().Substring(1)); try { IJson cardsJson = await BiliApi.GetJsonResultAsync("https://api.bilibili.com/pgc/web/season/cards", dic, true); foreach (IJson v in json.GetValue("data").GetValue("result")) { Season season = new Season(v, cardsJson); ResultSeason resultSeason = new ResultSeason(season); resultSeason.PreviewMouseLeftButtonDown += ResultSeason_PreviewMouseLeftButtonDown; ContentPanel.Children.Add(resultSeason); } } catch (WebException) { } break; case "media_ft": StringBuilder stringBuilderFt = new StringBuilder(); foreach (IJson v in json.GetValue("data").GetValue("result")) { stringBuilderFt.Append(','); stringBuilderFt.Append(v.GetValue("season_id").ToString()); } Dictionary <string, string> dic1 = new Dictionary <string, string>(); dic1.Add("season_ids", stringBuilderFt.ToString().Substring(1)); try { IJson cardsJson1 = await BiliApi.GetJsonResultAsync("https://api.bilibili.com/pgc/web/season/cards", dic1, false); foreach (IJson v in json.GetValue("data").GetValue("result")) { Season season = new Season(v, cardsJson1); ResultSeason resultSeason = new ResultSeason(season); resultSeason.PreviewMouseLeftButtonDown += ResultSeason_PreviewMouseLeftButtonDown; ContentPanel.Children.Add(resultSeason); } } catch (WebException) { } break; case "bili_user": foreach (IJson v in json.GetValue("data").GetValue("result")) { User user = new User(v); ResultUser resultUser = new ResultUser(user); resultUser.PreviewMouseLeftButtonDown += ResultUser_PreviewMouseLeftButtonDown; ContentPanel.Children.Add(resultUser); } break; } } }