private dynamic[] GetHitboxGameList(string partName, int count = 100) { var url = "https://www.hitbox.tv/api/games?q={0}&limit={1}"; return(this.With(x => loginWebClient.Download(String.Format(url, HttpUtility.UrlEncode(partName), count))) .With(x => JToken.Parse(x)) .With(x => x["categories"]) .With(x => x.ToArray <dynamic>())); }
private string GetProfileData() { loginWebClient.ContentType = ContentType.UrlEncodedUTF8; var content = loginWebClient.Download(String.Format(@"http://cybergame.tv/my_profile_edit/?rand={0}", Time.UnixTimestamp())); webGameList = Html.GetOptions(@"//select[@name='channel_game']/option", content); webChannelId = Html.GetAttribute(@"//input[@name='channel']", "value", content); profileFormParams = Html.FormParams(@"", content); return(content); }
public bool LoginWithToken() { var authToken = (string)Config.GetParameterValue("AuthToken"); var userName = Config.GetParameterValue("Username") as string; var password = Config.GetParameterValue("Password") as string; var tokenCredentials = Config.GetParameterValue("AuthTokenCredentials") as string; if (tokenCredentials != userName + password) { return(false); } if (String.IsNullOrEmpty(userName)) { IsAnonymous = true; return(true); } if (String.IsNullOrWhiteSpace(authToken)) { return(false); } SetCommonHeaders(); loginWebClient.Headers["Auth-Token"] = authToken; var response = this.With(x => loginWebClient.Download("https://api.gaminglive.tv/auth/me")) .With(x => String.IsNullOrWhiteSpace(x) ? null : x) .With(x => JToken.Parse(x)); if (response == null) { return(false); } var isOk = response.Value <bool>("ok"); NickName = (string)response.Value <dynamic>("user").login; if (isOk && !String.IsNullOrWhiteSpace(NickName)) { IsAnonymous = false; PollNotifications(); return(true); } Config.SetParameterValue("AuthToken", String.Empty); return(false); }
private void Connect() { var servers = JsonUtil.DeserializeUrl <HitboxServer[]>("https://www.hitbox.tv/api/chat/servers?redis=true"); if (servers == null) { return; } int port = 0; if (int.TryParse(webSocket.Port, out port)) { GetRandomIP(servers.Select(s => s.server_ip).ToArray(), int.Parse(webSocket.Port), (ip) => { if (!String.IsNullOrWhiteSpace(ip)) { using (var webClient = new WebClientBase()) { string pathHash = this.With(x => webClient.Download(String.Format("http://{0}/socket.io/1/{1}", ip, Time.UnixTimestamp()))) .With(x => new String(x.TakeWhile(c => !c.Equals(':')).ToArray())); webSocket.Path = String.Format("/socket.io/1/websocket/{0}", pathHash); webSocket.Host = ip; webSocket.Connect(); } } }); } }
private string GoodgameGet(string url) { var content = webClient.Download(url); if (content != null && content.Length < 1000 && content.Contains("location.href=")) { var cookieName = Re.GetSubString(content, @"\.cookie=\""(.*?)="); var cookieValue = Re.GetSubString(content, @"\.cookie=\"".*?=(.*?)"""); var newHref = Re.GetSubString(content, @"location\.href=""(.*?)"""); if (!String.IsNullOrWhiteSpace(cookieName) && !String.IsNullOrWhiteSpace(cookieValue) && !String.IsNullOrWhiteSpace(newHref)) { webClient.Encoding = System.Text.Encoding.UTF8; webClient.SetCookie(cookieName, cookieValue, "goodgame.ru"); content = webClient.Download(newHref); } } return(content); }
public void GetStreamId() { checkTimer = new Timer((obj) => { var youtubeChannel = obj as YoutubeChannel; if (String.IsNullOrWhiteSpace(ChannelName)) { return; } var channelUrl = webClient.GetRedirectUrl(String.Format(@"https://www.youtube.com/user/{0}/live", ChannelName.Replace("#", ""))); if (channelUrl == null || !channelUrl.Contains("v=")) { channelUrl = webClient.GetRedirectUrl(String.Format(@"https://www.youtube.com/channel/{0}/live", ChannelName.Replace("#", ""))); } youtubeChannel.checkTimer.Change(15000, 15000); if (String.IsNullOrWhiteSpace(channelUrl)) { return; } humanReadableChannelName = this.With(x => webClient.Download(channelUrl)) .With(x => Re.GetSubString(x, @"name=""title""\s*content=""(.*?)""")); youtubeChannel.checkTimer.Change(60000, 60000); var id = Re.GetSubString(channelUrl, @"v=([^&]+)"); if (!String.IsNullOrWhiteSpace(id) && videoId != id) { youtubeChannel.videoId = id; youtubeChannel.checkTimer.Change(Timeout.Infinite, Timeout.Infinite); if (chatPoller != null) { chatPoller.Stop(); } if (statsPoller != null) { statsPoller.Stop(); } youtubeChannel.SetupPollers(); } }, this, 0, 15000); }
public override void Join(Action <IChatChannel> callback, string channel) { ircClient = new IrcClient(); var safeConnectDelay = Chat.ChatChannels.Count * 100; Thread.Sleep(safeConnectDelay); ChannelName = "#" + channel.Replace("#", ""); pingTimer = new Timer((sender) => { TryIrc(() => ircClient.Ping()); (sender as TwitchChannel).disconnectTimer.Change(10000, Timeout.Infinite); }, this, Timeout.Infinite, Timeout.Infinite); disconnectTimer = new Timer((sender) => { Log.WriteError("{0} ping timeout", Chat.ChatName); TryIrc(() => Leave()); }, this, Timeout.Infinite, Timeout.Infinite); SetupStatsWatcher(); using (WebClientBase webClient = new WebClientBase()) { var badgesJson = this.With(x => webClient.Download(String.Format(@"https://api.twitch.tv/kraken/chat/{0}/badges", ChannelName.Replace("#", "")))) .With(x => JsonConvert.DeserializeObject <TwitchBadges>(x)); if (badgesJson != null) { channelBadges["admin"] = this.With(x => badgesJson.admin).With(x => x.image); channelBadges["broadcaster"] = this.With(x => badgesJson.broadcaster).With(x => x.image); channelBadges["mod"] = this.With(x => badgesJson.mod).With(x => x.image); channelBadges["staff"] = this.With(x => badgesJson.staff).With(x => x.image); channelBadges["turbo"] = this.With(x => badgesJson.turbo).With(x => x.image); channelBadges["subscriber"] = this.With(x => badgesJson.subscriber).With(x => x.image); } } SetUserBadge(ChannelName.ToLower().Replace("#", ""), "broadcaster"); JoinCallback = callback; var nickname = Chat.IsAnonymous ? (Chat as ChatBase).AnonymousNickName : Chat.NickName; var registrationInfo = new IrcUserRegistrationInfo() { UserName = nickname, NickName = nickname, RealName = nickname, Password = Chat.IsAnonymous ? "blah" : "oauth:" + Chat.Config.GetParameterValue("OAuthToken") as string, }; var host = Chat.Config.GetParameterValue("Host") as string; var portText = Chat.Config.GetParameterValue("Port") as string; int port = 6667; int.TryParse(portText, out port); if (TryIrc(() => { ircClient.Initialize(); ircClient.Disconnected += ircClient_Disconnected; ircClient.RawMessageReceived += ircClient_RawMessageReceived; ircClient.PongReceived += ircClient_PongReceived; if (Regex.IsMatch(host, @"\d+\.\d+\.\d+\.\d+")) { ircClient.Connect(host, port, false, registrationInfo); } else { Utils.Net.TestTCPPort(host, port, (hostList, error) => { if (hostList == null || hostList.AddressList.Count() <= 0) { Log.WriteError("All servers are down. Domain:" + host); Leave(); } else { ircClient.Connect(hostList.AddressList[random.Next(0, hostList.AddressList.Count())], port, false, registrationInfo); } }); } }) != null) { Leave(); } }
public bool LoginWithUsername() { var userName = Config.GetParameterValue("Username") as string; var password = Config.GetParameterValue("Password") as string; if (String.IsNullOrWhiteSpace(userName) || String.IsNullOrWhiteSpace(password) || userName.Equals(AnonymousNickName, StringComparison.InvariantCultureIgnoreCase)) { IsAnonymous = true; return(true); } if (Regex.IsMatch(userName, @"justinfan\d+")) { AnonymousNickName = userName; } NickName = userName; webClient.SetCookie("api_token", null, "twitch.tv"); webClient.SetCookie("csrf_token", null, "twitch.tv"); var csrfToken = this.With(x => webClient.Download("http://www.twitch.tv/login")) .With(x => Re.GetSubString(x, @"^.*authenticity_token.*?value=""(.*?)""")); if (csrfToken == null) { Log.WriteError("Twitch: Can't get CSRF token. Twitch web layout changed ?"); return(false); } string csrf_cookie = csrfToken; if (csrf_cookie.Substring(csrf_cookie.Length - 1).Equals("=")) { csrf_cookie = csrf_cookie.Substring(0, csrf_cookie.Length - 1) + "%3D"; } webClient.SetCookie("csrf_token", csrf_cookie, "twitch.tv"); webClient.ContentType = ContentType.UrlEncoded; webClient.Headers["X-Requested-With"] = "XMLHttpRequest"; webClient.Headers["X-CSRF-Token"] = csrfToken; webClient.Headers["Accept"] = "text/html, application/xhtml+xml, */*"; var apiToken = this.With(x => webClient.Upload("https://secure.twitch.tv/user/login", String.Format( "utf8=%E2%9C%93&authenticity_token={0}%3D&redirect_on_login=&embed_form=false&user%5Blogin%5D={1}&user%5Bpassword%5D={2}", csrfToken, userName, password))) .With(x => webClient.CookieValue("api_token", "http://twitch.tv")); if (String.IsNullOrWhiteSpace(apiToken)) { Log.WriteError("Twitch: Can't get API token"); return(false); } webClient.Headers["Twitch-Api-Token"] = apiToken; webClient.Headers["X-CSRF-Token"] = csrfToken; webClient.Headers["Accept"] = "*/*"; if (apiToken == null) { Log.WriteError("Login to twitch.tv failed. Joining anonymously"); IsAnonymous = true; return(false); } else { var oauthToken = this.With(x => webClient.Download("http://api.twitch.tv/api/me?on_site=1")) .With(x => JToken.Parse(x)) .With(x => x.Value <string>("chat_oauth_token")); if (String.IsNullOrWhiteSpace(oauthToken)) { Log.WriteError("Login to twitch.tv failed. Joining anonymously"); IsAnonymous = true; return(false); } IsAnonymous = false; Config.SetParameterValue("OAuthToken", oauthToken); Config.SetParameterValue("ApiToken", apiToken); Config.SetParameterValue("AuthTokenCredentials", userName + password); return(LoginWithToken()); } }
public override void Join(Action <IChatChannel> callback, string channel) { ChannelName = "#" + channel.Replace("#", ""); if (ChannelName.Contains("@")) { return; } string sid = String.Empty; using (WebClientBase webClient = new WebClientBase()) { webClient.Cookies = (Chat as ConnectcastChat).LoginWebClient.Cookies; channelToken = this.With(x => webClient.Download(String.Format("http://connectcast.tv/chat/{0}", ChannelName.Replace("#", "")))) .With(x => Re.GetSubString(x, "token[^']*'(.*?)'")); sid = this.With(x => webClient.Download( String.Format("https://chat.connectcast.tv:3000/socket.io/?EIO=3&transport=polling&t=", Time.UnixTimestamp()))) .With(x => Re.GetSubString(x, @"""sid"":""(.*?)""")); if (String.IsNullOrWhiteSpace(channelToken) || channelToken.Equals("NOTOKEN", StringComparison.InvariantCultureIgnoreCase)) { channelToken = "NOTOKEN"; } else { Chat.Status.IsLoggedIn = true; } } if (String.IsNullOrWhiteSpace(sid) && LeaveCallback != null) { LeaveCallback(this); return; } webSocket = new WebSocketBase(); webSocket.PingInterval = 0; JoinCallback = callback; webSocket.DisconnectHandler = () => { if (pingTimer != null) { pingTimer.Change(Timeout.Infinite, Timeout.Infinite); } Leave(); }; webSocket.ReceiveMessageHandler = ReadRawMessage; webSocket.Path = String.Format("/socket.io/?EIO=3&transport=websocket&sid={0}", sid); webSocket.Port = "3000"; webSocket.IsSecure = true; webSocket.Origin = "http://connectcast.tv"; webSocket.Cookies = new List <KeyValuePair <string, string> >() { new KeyValuePair <string, string>("io", sid) }; webSocket.Host = "chat.connectcast.tv"; webSocket.ConnectHandler = () => { if (pingTimer != null) { pingTimer.Change(PING_INTERVAL, PING_INTERVAL); } if (disconnectTimer != null) { disconnectTimer.Change(PING_INTERVAL * 2, Timeout.Infinite); } webSocket.Send("2probe"); }; SetupStatsWatcher(); webSocket.Connect(); }
public override void DownloadEmoticons(string url) { //image: ssl.gstatic.com/chat/emoji/emoji20png-61089cf406d77f75e149071e74d8f714.png lock (iconParseLock) { if (IsFallbackEmoticons && IsWebEmoticons) { return; } var list = new List <Emoticon>(); if (Emoticons == null) { Emoticons = new List <Emoticon>(); } var content = webClient.Download(url); if (String.IsNullOrWhiteSpace(content)) { return; } MatchCollection matches = Regex.Matches(content, @"yt-emoji-icon.yt-emoji-([0-9,a-z]+)\s*{(.*?)}", RegexOptions.IgnoreCase); if (matches.Count <= 0) { Log.WriteError("Unable to get Youtube emoticons!"); } else { string originalUrl = null; foreach (Match match in matches) { if (match.Groups.Count >= 2) { var smileName = match.Groups[1].Value; var cssClassDefinition = match.Groups[2].Value; var background = Css.GetBackground(cssClassDefinition); if (background != null && !String.IsNullOrWhiteSpace(background.url) && background.width > 0 && background.height > 0) { originalUrl = String.Format("http://{0}", background.url.Replace("//", "")); var modifiedUrl = String.Format(@"/ubiquitous/cache?ubx={0}&uby={1}&ubw={2}&ubh={3}&uburl={4}", background.x, background.y, background.width, background.height, HttpUtility.UrlEncode(originalUrl)); list.Add(new Emoticon(String.Format(@"\u{0}", smileName), modifiedUrl, background.width, background.height )); } } } if (list.Count > 0) { Uri uri; if (!String.IsNullOrWhiteSpace(originalUrl) && Uri.TryCreate(originalUrl, UriKind.Absolute, out uri)) { var imageDataService = SimpleIoc.Default.GetInstance <IImageDataSource>(); using (var memoryStream = webClient.DownloadToMemoryStream(originalUrl)) { if (memoryStream == null) { Log.WriteError("Web Youtube emoticons aren't available!"); using (var memStream = webClient.DownloadToMemoryStream(@"Content\youtubeemoji.png")) { if (memStream != null) { imageDataService.AddImage(uri, memStream); } } } } } Emoticons = list; if (IsFallbackEmoticons) { IsWebEmoticons = true; } IsFallbackEmoticons = true; } } } }