public string GetLatestDownloadUrl() { while (true) { ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(string.Format("https://api.github.com/repos/{0}/releases/latest", RepoName)); 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 { string result; using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) using (Stream dataStream = response.GetResponseStream()) using (StreamReader reader = new StreamReader(dataStream)) result = reader.ReadToEnd(); Json.Value json = Json.Parser.Parse(result); string url = json["assets"][0]["browser_download_url"]; return(url); } catch (WebException) { Thread.Sleep(5000); } } }
public async Task <bool> AddRunePageAsync(Json.Value pageJson) { if (!await PrepareAsync()) { throw new NoClientException(); } HttpWebRequest request = Auth.CreateRequest("/lol-perks/v1/pages"); request.Method = "POST"; byte[] data = Encoding.UTF8.GetBytes(pageJson.ToString()); Stream newStream = request.GetRequestStream(); newStream.Write(data, 0, data.Length); newStream.Close(); try { HttpWebResponse response = (HttpWebResponse)await request.GetResponseAsync(); if (response.StatusCode == HttpStatusCode.OK) { return(true); } return(false); } catch (WebException ex) { return(false); } }
public static bool IsLatestVersion(out string description) { description = null; 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 { string result; using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) using (Stream stream = response.GetResponseStream()) using (StreamReader reader = new StreamReader(stream)) result = reader.ReadToEnd(); Json.Value json = Json.Parser.Parse(result); string latestTag = json["tag_name"]; if (Application.Current.FindResource("Version").ToString() == latestTag) { return(true); } description = ((string)json["body"]).Replace("\\r", "\r").Replace("\\n", "\n"); return(false); } catch { return(true); } }
public GiftCombo(Json.Value json) { Sender = new User(0, Regex.Unescape(json["data"]["uname"])); GiftName = Regex.Unescape(json["data"]["gift_name"]); Number = (uint)json["data"]["combo_num"]; TimeStamp = new DateTime(1970, 01, 01).AddSeconds(json["data"]["end_time"]); }
/// <summary> /// Get the result of the request in the form of IJson. /// </summary> /// <param name="url">Request url</param> /// <param name="paramsDic">Parameter dictionary</param> /// <param name="addVerification">Add verification sign for parameters</param> /// <returns>IJson result</returns> public static Json.Value GetJsonResult(string url, Dictionary <string, string> paramsDic, bool addVerification) { string result = GetTextResult(url, paramsDic, addVerification); Json.Value json = Json.Parser.Parse(result); return(json); }
public static IItem Parse(Json.Value json) { Console.WriteLine(json.ToString()); try { string[] cmd = ((string)json["cmd"]).Split(':'); switch (cmd[0]) { case "DANMU_MSG": return(new Danmaku(json)); case "SUPER_CHAT_MESSAGE": return(new SuperChat(json)); case "SEND_GIFT": return(new Gift(json)); case "COMBO_SEND": return(new ComboSend(json)); case "WELCOME": return(new Welcome(json)); case "WELCOME_GUARD": return(new WelcomeGuard(json)); case "GUARD_BUY": return(new GuardBuy(json)); case "INTERACT_WORD": return(new InteractWord(json)); case "ROOM_BLOCK_MSG": return(new RoomBlock(json)); case "LIVE": case "PREPARING": case "SPECIAL_GIFT": case "USER_TOAST_MSG": case "GUARD_MSG": case "GUARD_LOTTERY_START": case "ENTRY_EFFECT": case "SYS_MSG": case "ROOM_RANK": case "TV_START": case "NOTICE_MSG": case "SYS_GIFT": case "ROOM_REAL_TIME_MESSAGE_UPDATE": return(new Raw((Cmds)Enum.Parse(typeof(Cmds), json["cmd"]), json)); default: return(new Raw(Cmds.UNKNOW, json)); } } catch (Exception ex) { Console.WriteLine(ex); return(null); } }
public SeasonSuggest(Json.Value item) { Position = item["position"]; if (item.Contains("title")) { Title = item["title"]; } else { Title = null; } Keyword = item["keyword"]; // TODO: json response not contain following info any more Cover = "https:" + item["cover"]; Uri = item["uri"]; Ptime = item["ptime"]; SeasonTypeName = item["season_type_name"]; Area = item["area"]; if (item.Contains("label")) { Label = item["label"]; } else { Label = null; } }
private DanmakuServer GetDanmakuServer(long roomId) { roomId = GetRealRoomId(roomId); if (roomId < 0) { return(null); } try { HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://api.live.bilibili.com/room/v1/Danmu/getConf?room_id=" + roomId); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Json.Value json = Json.Parser.Parse(response.GetResponseStream()); if (json["code"] != 0) { Console.Error.WriteLine("Error occurs when resolving dm servers"); Console.Error.WriteLine(json.ToString()); return(null); } DanmakuServer danmakuServer = new DanmakuServer(); danmakuServer.RoomId = roomId; danmakuServer.Server = json["data"]["host_server_list"][0]["host"]; danmakuServer.Port = json["data"]["host_server_list"][0]["port"]; danmakuServer.WsPort = json["data"]["host_server_list"][0]["ws_port"]; danmakuServer.WssPort = json["data"]["host_server_list"][0]["wss_port"]; danmakuServer.Token = json["data"]["token"]; return(danmakuServer); } catch (WebException) { ConnectionFailed?.Invoke("直播间信息获取失败"); return(null); } }
public Page(string title, uint aid, Json.Value json, bool isSeason, string pic) { IsSeason = isSeason; if (!isSeason) { Title = title; Index = ((uint)json["page"]).ToString(); Aid = aid; Num = json["page"]; Cid = json["cid"]; Part = json["part"]; Duration = json["duration"]; Pic = pic; } else { Title = title; Index = json["index"]; Aid = json["aid"]; Num = json["page"]; Cid = json["cid"]; Part = json["index_title"]; Duration = json["duration"]; Pic = pic; } }
public VideoInfo(Json.Value json, bool isSeason) { if (!isSeason) { Aid = json["aid"]; Title = json["title"]; string pic = json["pic"]; pages = new List <Page>(); foreach (Json.Value p in json["pages"]) { pages.Add(new Page(Title, Aid, p, isSeason, pic)); } } else { Aid = json["season_id"]; Title = json["title"]; pages = new List <Page>(); foreach (Json.Value p in json["episodes"]) { string cover = (string)p["cover"]; pages.Add(new Page(Title, Aid, p, isSeason, cover)); } } }
/// <summary> /// Get the result of the request in the form of IJson. /// </summary> /// <param name="url">Request url</param> /// <param name="query">Parameter dictionary</param> /// <param name="sign">Add verification sign for parameters</param> /// <returns>IJson result</returns> public static Json.Value RequestJsonResult(string url, Dictionary <string, string> query, bool sign, string method = "GET") { string result = RequestTextResult(url, query, sign, method); Json.Value json = Json.Parser.Parse(result); return(json); }
/// <summary> /// Initialize a new login. /// </summary> /// <returns>Successful</returns> public bool Init() { try { HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://passport.bilibili.com/qrcode/getLoginUrl"); string result; using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) using (Stream stream = response.GetResponseStream()) using (StreamReader reader = new StreamReader(stream)) result = reader.ReadToEnd(); Json.Value getLoginUrl = Json.Parser.Parse(result); LoginUrlRecieved?.Invoke(this, getLoginUrl["data"]["url"]); Bitmap qrBitmap = RenderQrCode(getLoginUrl["data"]["url"]); QRImageLoaded?.Invoke(this, qrBitmap); oauthKey = getLoginUrl["data"]["oauthKey"]; return(true); } catch (WebException ex) { ConnectionFailed?.Invoke(this, ex); return(false); } }
public UserInfo(Json.Value json) { Face = json["data"]["face"]; Uname = json["data"]["uname"]; VipType = json["data"]["vipType"]; VipStatus = json["data"]["vipStatus"]; }
public HomepageRoomInfo(Json.Value value) { UId = value["uid"]; UName = value["uname"]; RoomId = value["roomid"]; Title = value["title"]; }
private Json.Value GetRoomLotteries(int roomId) { Json.Value lottery = BiliApi.GetJsonResult("https://api.live.bilibili.com/xlive/lottery-interface/v1/lottery/Check", new Dictionary <string, string> { { "roomid", roomId.ToString() } }, false); return(lottery); }
public GuardBuy(Json.Value json) { User = new User(json["data"]["uid"], Regex.Unescape(json["data"]["username"])); GuardLevel = json["data"]["guard_level"]; GiftName = json["data"]["gift_name"]; TimeStamp = new DateTime(1970, 01, 01).AddSeconds(json["data"]["start_time"]); }
public ComboSend(Json.Value json) { Sender = new User(json["data"]["uid"], Regex.Unescape(json["data"]["uname"])); GiftName = Regex.Unescape(json["data"]["gift_name"]); Number = (uint)json["data"]["total_num"]; GiftId = json["data"]["gift_id"]; Action = json["data"]["action"]; }
public GiftBag(Json.Value json) { BagId = json["bag_id"]; CornerMark = json["corner_mark"]; GiftId = json["gift_id"]; GiftName = json["gift_name"]; GiftNum = json["gift_num"]; }
public TopListRoomInfo(Json.Value value) { UId = value["uid"]; UName = value["uname"]; string link = value["link"]; RoomId = int.Parse(link.Substring(1)); }
static void Main(string[] args) { string text = System.IO.File.ReadAllText(@args[0]); Json.Value newValue = new Json.Value(); Console.WriteLine(newValue.Match(text).Success()); Console.Read(); }
/// <summary> /// Search a text asynchronously. /// </summary> /// <param name="text">text</param> public void SearchAsync(string text, int pagenum) { SearchText = text; long aid = FindAid(text); if (aid >= 0) { HistoryBox.Insert(text); VideoSelected?.Invoke("Av" + aid.ToString(), aid); return; } 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; NoMoreGrid.Visibility = Visibility.Collapsed; ContentViewer.Visibility = Visibility.Collapsed; Task task = new Task(() => { string type = NavType; Json.Value json = GetResult(text, type, pagenum); if (json != null) { Dispatcher.Invoke(new Action(() => { if (cancellationToken.IsCancellationRequested) { return; } ShowResult(json, type); PagesBox.SetPage((int)json["data"]["numPages"], (int)json["data"]["page"], false); PagesBox.Visibility = Visibility.Visible; LoadingPrompt.Visibility = Visibility.Hidden; })); } }); task.Start(); } else { HistoryBox.Visibility = Visibility.Visible; } }
public User(Json.Value json) { Mid = json["mid"]; Upic = "https:" + json["upic"]; Uname = json["uname"]; Videos = json["videos"]; Fans = json["fans"]; Usign = json["usign"]; }
public async Task <Json.Value> GetRunePages() { HttpWebRequest request = AuthRequest.CreateRequest("/lol-perks/v1/pages"); HttpWebResponse response = (HttpWebResponse)await request.GetResponseAsync(); string result = ReadStream(response.GetResponseStream()); Json.Value value = Json.Parser.Parse(result); return(value); }
// Listener recieved private void BiliLiveListener_JsonRecieved(Json.Value json) { Log += json.ToString() + "\r\n"; if (debugWindow != null) { debugWindow.AppendLog(json.ToString()); } BiliLiveJsonParser.Item item = BiliLiveJsonParser.Parse(json); AppendItem(item); AppendHistory(item); }
public UserSuggest(Json.Value item) { Position = item["position"]; Title = item["title"]; Keyword = item["keyword"]; Cover = "https:" + item["cover"]; Uri = item["uri"]; Level = item["level"]; Fans = item["fans"]; Archives = item["archives"]; }
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("ps", "30"); dic.Add("pn", page.ToString()); try { Json.Value json = BiliApi.GetJsonResult("https://api.bilibili.com/x/space/arc/search", dic, true); Dispatcher.Invoke(new Action(() => { foreach (Json.Value v in json["data"]["list"]["vlist"]) { ResultBox.Video video = new ResultBox.Video(v); ResultVideo resultVideo = new ResultVideo(video); resultVideo.PreviewMouseLeftButtonDown += ResultVideo_PreviewMouseLeftButtonDown; ContentPanel.Children.Add(resultVideo); } if (init) { int pages = (int)Math.Ceiling((double)json["data"]["page"]["count"] / json["data"]["page"]["ps"]); PagesBox.SetPage(pages, 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 static Item Parse(Json.Value json) { try { switch ((string)json["cmd"]) { case "DANMU_MSG": return(new Danmaku(json, new User((uint)json["info"][2][0], Regex.Unescape(json["info"][2][1])), Regex.Unescape(json["info"][1]), (uint)json["info"][0][9])); case "SEND_GIFT": return(new Gift(json, new User((uint)json["data"]["uid"], Regex.Unescape(json["data"]["uname"])), Regex.Unescape(json["data"]["giftName"]), (uint)json["data"]["num"])); case "COMBO_END": return(new GiftCombo(json, new User(0, Regex.Unescape(json["data"]["uname"])), Regex.Unescape(json["data"]["gift_name"]), (uint)json["data"]["combo_num"])); case "WELCOME": return(new Welcome(json, new User((uint)json["data"]["uid"], Regex.Unescape(json["data"]["uname"])))); case "WELCOME_GUARD": return(new WelcomeGuard(json, new User((uint)json["data"]["uid"], Regex.Unescape(json["data"]["username"])))); case "ROOM_BLOCK_MSG": return(new RoomBlock(json, new User((uint)json["data"]["uid"], Regex.Unescape(json["data"]["uname"])), (uint)json["data"]["operator"])); case "GUARD_BUY": return(new GuardBuy(json, new User((uint)json["data"]["uid"], Regex.Unescape(json["data"]["username"])), json["data"]["gift_name"])); case "LIVE": case "PREPARING": case "SPECIAL_GIFT": case "USER_TOAST_MSG": case "GUARD_MSG": case "GUARD_LOTTERY_START": case "ENTRY_EFFECT": case "SYS_MSG": case "COMBO_SEND": case "ROOM_RANK": case "TV_START": case "NOTICE_MSG": case "SYS_GIFT": case "ROOM_REAL_TIME_MESSAGE_UPDATE": return(new Item((Item.Cmds)Enum.Parse(typeof(Item.Cmds), (string)json["cmd"]), json)); default: return(new Item(Item.Cmds.UNKNOW, json)); } } catch (Exception) { Console.WriteLine(1); return(null); } }
public Gift(Json.Value json) { GiftName = Regex.Unescape(json["data"]["giftName"]); Number = json["data"]["num"]; Sender = new User(json["data"]["uid"], Regex.Unescape(json["data"]["uname"])); FaceUri = json["data"]["face"]; GiftId = json["data"]["giftId"]; Action = json["data"]["action"]; CoinType = json["data"]["coin_type"]; TimeStamp = new DateTime(1970, 01, 01).AddSeconds(json["data"]["timestamp"]); }
public void LoadAsync() { if (cancellationTokenSource != null) { cancellationTokenSource.Cancel(); } ContentViewer.ScrollToHome(); ContentPanel.Children.Clear(); cancellationTokenSource = new CancellationTokenSource(); CancellationToken cancellationToken = cancellationTokenSource.Token; LoadingPromptList.Visibility = Visibility.Visible; PagesBox.Visibility = Visibility.Hidden; Task task = new Task(() => { Json.Value userinfo = BiliApi.GetJsonResult("https://api.bilibili.com/x/web-interface/nav", null, false); if (cancellationToken.IsCancellationRequested) { return; } if (userinfo["code"] == 0) { Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("pn", "1"); dic.Add("ps", "100"); dic.Add("up_mid", ((uint)userinfo["data"]["mid"]).ToString()); dic.Add("is_space", "0"); Json.Value json = BiliApi.GetJsonResult("https://api.bilibili.com/medialist/gateway/base/created", dic, false); if (cancellationToken.IsCancellationRequested) { return; } if (json["code"] == 0) { Dispatcher.Invoke(new Action(() => { foreach (Json.Value folder in json["data"]["list"]) { AddFavFolder(new FavFolder(folder["title"], folder["media_count"], folder["id"])); } AddFavFolder(new FavFolder(FavFolder.SpecialFolder.ToView)); })); } } Dispatcher.Invoke(new Action(() => { LoadingPromptList.Visibility = Visibility.Hidden; })); }); task.Start(); }
public Season(Json.Value json, Json.Value cardsJson) { Cover = "https:" + Regex.Unescape(json["cover"]); Title = WebUtility.HtmlDecode(json["title"]); Styles = json["styles"]; Areas = json["areas"]; Pubtime = json["pubtime"]; Cv = json["cv"]; Description = json["desc"]; SeasonId = json["season_id"]; SeasonTypeName = cardsJson["result"][SeasonId.ToString()]["season_type_name"]; OrgTitle = WebUtility.HtmlDecode(json["org_title"]); }