Esempio n. 1
0
        public override void SetupStatsWatcher()
        {
            statsPoller = new WebPoller()
            {
                Id  = ChannelName,
                Uri = new Uri(String.Format(@"http://api.hitbox.tv/media/live/{0}", ChannelName.Replace("#", ""))),
            };

            statsPoller.ReadStream = (stream) =>
            {
                if (stream == null)
                {
                    return;
                }

                lock (pollerLock)
                {
                    using (stream)
                    {
                        var channelInfo = this.With(x => stream)
                                          .With(x => JsonUtil.DeserializeStream <HitboxChannelStats>(stream))
                                          .With(x => x.livestream)
                                          .With(x => x.FirstOrDefault(livestream => livestream.media_name.Equals(ChannelName.Replace("#", ""), StringComparison.InvariantCultureIgnoreCase)));

                        statsPoller.LastValue = channelInfo;
                        if (channelInfo != null)
                        {
                            ChannelStats.ViewersCount = channelInfo.media_views;
                            Chat.UpdateStats();
                        }
                    }
                }
            };
            statsPoller.Start();
        }
Esempio n. 2
0
        public override void SetupStatsWatcher()
        {
            statsPoller = new WebPoller()
            {
                Id  = ChannelName,
                Uri = new Uri(String.Format(@"http://dummy.com/channel={0}", ChannelName.Replace("#", ""))),
            };

            statsPoller.ReadString = (stream) =>
            {
                if (stream == null)
                {
                    return;
                }

                lock (pollerLock)
                {
                    //var channelInfo = JsonConvert.DeserializeObject<ChannelStatus>(stream);
                    //statsPoller.LastValue = channelInfo;
                    //int viewers = 0;
                    //if (channelInfo != null && int.TryParse(channelInfo.spectators, out viewers))
                    //{
                    //    ChannelStats.ViewersCount = viewers;
                    //    Chat.UpdateStats();
                    //}
                }
            };
            statsPoller.Start();
        }
Esempio n. 3
0
        public override void SendMessage(ChatMessage message)
        {
            if (Chat.IsAnonymous || String.IsNullOrWhiteSpace(message.Channel) ||
                String.IsNullOrWhiteSpace(message.FromUserName) ||
                String.IsNullOrWhiteSpace(message.Text))
            {
                return;
            }

            if (webSocket == null)
            {
                return;
            }

            webSocket.Send(String.Format(
                               @"42[""send"",{{""room"":""{0}"",""msg"":""{1}"",""token"":""{2}""}}]",
                               ChannelName.Replace("#", ""),
                               message.Text,
                               channelToken
                               ));

            //Send message
        }
Esempio n. 4
0
        private void LoadInitialUserList()
        {
            Log.WriteInfo("Twitch initial user list loading for {0}...", ChannelName);
            lock ((Chat as TwitchChat).chatUsersLock)
            {
                var chatters = JsonUtil.DeserializeUrl <TwitchChattersHead>(String.Format("http://tmi.twitch.tv/group/user/{0}/chatters", ChannelName.Replace("#", "")))
                               .With(x => x.chatters);

                if (chatters == null)
                {
                    return;
                }

                var currentChannelUsers = new HashSet <string>();
                currentChannelUsers = new HashSet <string>((Chat as IChatUserList).ChatUsers
                                                           .Where(chatUser => chatUser != null && chatUser.NickName != null && chatUser.Channel.Equals(ChannelName))
                                                           .Select(chatUser => chatUser.NickName));

                var moderators = chatters.With(x => x.moderators);
                var admins     = chatters.With(x => x.admins);
                var staff      = chatters.With(x => x.staff);
                var viewers    = chatters.With(x => x.viewers);

                List <ChatUser> initialUserList = new List <ChatUser>();
                foreach (var pair in new Dictionary <string, List <string> > {
                    { "staff", staff },
                    { "admin", admins },
                    { "mod", moderators },
                    { "viewer", viewers }
                })
                {
                    if (pair.Key == null || pair.Value == null)
                    {
                        continue;
                    }

                    ObservableCollection <UserBadge> badges;
                    userBadges.TryGetValue(pair.Key, out badges);

                    initialUserList.AddRange(pair.Value.Select(x => new ChatUser()
                    {
                        Channel   = ChannelName,
                        ChatName  = Chat.ChatName,
                        GroupName = pair.Key,
                        NickName  = x,
                        Badges    = badges,
                    }));
                }

                lock ((Chat as TwitchChat).chatUsersLock)
                    (Chat as IChatUserList).ChatUsers.AddRange(
                        initialUserList.Where(x => !currentChannelUsers.Any(u => u.Equals(x.NickName)))
                        );
                Log.WriteInfo("Twitch initial user list loaded for {0}!", ChannelName);
            }
        }
Esempio n. 5
0
        public override void SetupStatsWatcher()
        {
            statsPoller = new WebPoller()
            {
                Id  = ChannelName,
                Uri = new Uri(String.Format(@"http://api.twitch.tv/kraken/streams/{0}?on_site=1", ChannelName.Replace("#", ""))),
            };

            statsPoller.ReadStream = (stream) =>
            {
                if (stream == null)
                {
                    return;
                }

                lock (pollerLock)
                {
                    using (stream)
                    {
                        var channelInfo = this.With(x => stream)
                                          .With(x => JsonUtil.DeserializeStream <dynamic>(stream));


                        statsPoller.LastValue = channelInfo;
                        if (channelInfo != null && channelInfo.stream != null)
                        {
                            ChannelStats.ViewersCount = channelInfo.stream.viewers;
                            Chat.UpdateStats();
                        }
                    }
                }
            };
            statsPoller.Start();
        }
Esempio n. 6
0
        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();
            }
        }
Esempio n. 7
0
        public override void SetupStatsWatcher()
        {
            if (ChannelName.Equals("#" + (Chat as ChatBase).AnonymousNickName, StringComparison.InvariantCultureIgnoreCase))
            {
                return;
            }

            statsPoller = new WebPoller()
            {
                Id  = ChannelName,
                Uri = new Uri(String.Format(@"http://api.gaminglive.tv/channels/{0}", ChannelName.Replace("#", ""))),
            };

            statsPoller.ReadStream = (stream) =>
            {
                if (stream == null)
                {
                    return;
                }

                lock (pollerLock)
                {
                    using ( stream )
                    {
                        var channelInfo = JsonUtil.DeserializeStream <GamingLiveChannelStats>(stream);
                        statsPoller.LastValue = channelInfo;
                        int viewers = 0;
                        if (channelInfo != null && channelInfo.state != null)
                        {
                            viewers = channelInfo.state.viewers;
                        }

                        ChannelStats.ViewersCount = viewers;
                        Chat.UpdateStats();
                    }
                }
            };
            statsPoller.Start();
        }
Esempio n. 8
0
        public override void Join(Action <IChatChannel> callback, string channel)
        {
            ChannelName = "#" + channel.Replace("#", "");

            SetupStatsWatcher();

            JoinCallback = callback;

            webSocket              = new WebSocketBase();
            webSocket.Host         = "api.gaminglive.tv";
            webSocket.PingInterval = 0;
            webSocket.Origin       = "http://www.gaminglive.tv";
            webSocket.Path         = String.Format("/chat/{0}?nick={1}&authToken={2}",
                                                   ChannelName.Replace("#", ""),
                                                   Chat.IsAnonymous ? (Chat as ChatBase).AnonymousNickName : Chat.NickName,
                                                   Chat.IsAnonymous ? (Chat as ChatBase).AnonymousNickName : Chat.Config.GetParameterValue("AuthToken").ToString());

            disconnectTimer = new Timer((sender) => {
                Log.WriteInfo("Gaminglive socket state: {0}", webSocket.State.ToString());
                Log.WriteInfo("Gaminglive got no ping reply. Disconnecting");
                Leave();
            }, this, Timeout.Infinite, Timeout.Infinite);

            pingTimer = new Timer((sender) =>
            {
                lock (pingLock)
                {
                    Log.WriteInfo("Gaminglive ping to {0}", ChannelName);
                    SendMessage(new ChatMessage()
                    {
                        Text = "!"
                    });
                    disconnectTimer.Change(5000, Timeout.Infinite);
                }
            }, this, Timeout.Infinite, Timeout.Infinite);

            webSocket.ConnectHandler = () =>
            {
                if (JoinCallback != null)
                {
                    JoinCallback(this);
                }
                Chat.Status.IsLoggedIn  = !Chat.IsAnonymous;
                Chat.Status.IsConnected = true;
                Chat.Status.IsStarting  = false;

                if (!Chat.IsAnonymous)
                {
                    pingTimer.Change(5000, pingInterval);
                }
                else
                {
                    pingTimer.Change(300000, Timeout.Infinite);
                }
            };

            webSocket.DisconnectHandler = () =>
            {
                if (LeaveCallback != null)
                {
                    LeaveCallback(this);
                }
            };
            webSocket.ReceiveMessageHandler = ReadRawMessage;
            webSocket.Connect();
        }
Esempio n. 9
0
        public override void SetupStatsWatcher()
        {
            statsPoller = new WebPoller()
            {
                Id     = ChannelName,
                Method = "POST",
                Uri    = new Uri(String.Format(@"http://connectcast.tv/channel/views?username={0}", ChannelName.Replace("#", ""))),
            };
            statsPoller.Headers["X-Requested-With"] = "XMLHttpRequest";
            statsPoller.ReadString = (stream) =>
            {
                lock (pollerLock)
                {
                    if (stream == null)
                    {
                        return;
                    }

                    var channelInfo = JsonUtil.FromJson <dynamic>(stream);

                    statsPoller.LastValue = channelInfo;
                    if (channelInfo != null && (int?)channelInfo["count"] != null)
                    {
                        ChannelStats.ViewersCount = (int)channelInfo["count"];
                        Chat.UpdateStats();
                    }
                }
            };
            statsPoller.Start();
        }
Esempio n. 10
0
        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();
        }
Esempio n. 11
0
        public override void SetupStatsWatcher()
        {
            statsPoller = new WebPoller()
            {
                Id  = ChannelName,
                Uri = new Uri(String.Format(@"http://api.cybergame.tv/p/statusv2/?channel={0}", ChannelName.Replace("#", ""))),
            };

            statsPoller.ReadString = (stream) =>
            {
                lock (pollerLock)
                {
                    if (stream == null)
                    {
                        return;
                    }

                    var channelInfo = JsonConvert.DeserializeObject <CybergameChannelStatus>(stream);
                    statsPoller.LastValue = channelInfo;
                    int viewers = 0;
                    if (channelInfo != null && int.TryParse(channelInfo.spectators, out viewers))
                    {
                        ChannelStats.ViewersCount = viewers;
                        Chat.UpdateStats();
                    }
                }
            };
            statsPoller.Start();
        }
Esempio n. 12
0
        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);
        }
Esempio n. 13
0
 public void GetStreamId()
 {
     using (WebClientBase webClient = new WebClientBase())
     {
         var channelPage = webClient.Download(String.Format("http://sc2tv.ru/channel/{0}", ChannelName.Replace("#", "")));
         channelId = Re.GetSubString(channelPage, @"channelId=(\d+)");
     }
 }