Exemple #1
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();
        }
        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();
        }
Exemple #3
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();
        }
Exemple #4
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();
        }
Exemple #5
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();
        }
Exemple #6
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();
        }
Exemple #7
0
        private void PollNotifications()
        {
            if (notificationPoller != null)
            {
                notificationPoller.Stop();
            }

            if (!Status.IsLoggedIn)
            {
                return;
            }

            notificationPoller = new WebPoller()
            {
                Id       = "followersPoller",
                Interval = 5000,
                Uri      = new Uri(@"https://api.gaminglive.tv/notifications"),
            };
            notificationPoller.Headers["Auth-Token"] = Config.GetParameterValue("AuthToken") as string;

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

                using (stream)
                {
                    var notifications = JsonUtil.DeserializeStream <GamingLiveNotification[]>(stream);

                    long lastFollow = 0;
                    long.TryParse(Config.GetParameterValue("LastFollowerTime") as string, out lastFollow);

                    foreach (var notification in notifications)
                    {
                        if (notification.t.Equals("user:followed", StringComparison.InvariantCultureIgnoreCase))
                        {
                            if (notification.at > lastFollow)
                            {
                                if (currentFollowers.Any(n => n.from == notification.from))
                                {
                                    continue;
                                }

                                currentFollowers.Add(notification);
                                Config.SetParameterValue("LastFollowerTime", notification.at.ToString());
                                if (AddFollower != null)
                                {
                                    AddFollower(new ChatUser()
                                    {
                                        NickName = notification.from,
                                        ChatName = ChatName
                                    });
                                }
                            }
                        }
                    }
                }
            };

            notificationPoller.Start();
        }
Exemple #8
0
        public void SetupPollers()
        {
            if (!String.IsNullOrWhiteSpace(videoId))
            {
                #region Chatpoller
                int rc         = 0;
                int poll_delay = 30000;
                lastTime   = Time.UnixTimestamp().ToString();
                chatPoller = new WebPoller()
                {
                    Id  = ChannelName,
                    Uri = new Uri(String.Format(@"https://www.youtube.com/live_comments?action_get_comments=1&video_id={0}&lt={1}&rc={2}&pd={3}&format=json",
                                                videoId,
                                                lastTime,
                                                rc,
                                                poll_delay)),
                    IsLongPoll    = true,
                    Interval      = 30000,
                    TimeoutMs     = 30000,
                    IsAnonymous   = true,
                    KeepAlive     = false,
                    Delay         = poll_delay,
                    IsTimeStamped = false,
                };
                chatPoller.ReadString = (text) =>
                {
                    if (String.IsNullOrWhiteSpace(text))
                    {
                        return;
                    }

                    lock (chatLock)
                    {
                        rc++;
                        if (rc > 5)
                        {
                            rc = 0;
                        }

                        chatPoller.Uri = new Uri(String.Format(@"https://www.youtube.com/live_comments?action_get_comments=1&video_id={0}&lt={1}&rc={2}&pd={3}&format=json",
                                                               videoId,
                                                               lastTime,
                                                               rc,
                                                               poll_delay));

                        chatPoller.Interval  = random.Next(20000, 30000);
                        chatPoller.TimeoutMs = random.Next(30000, 35000);
                        chatPoller.Delay     = random.Next(20000, 30000);

                        if (String.IsNullOrWhiteSpace(text))
                        {
                            return;
                        }

                        string chatJson = this.With(x => XDocument.Parse(text))
                                          .With(x => x.Root.Element("html_content"))
                                          .With(x => (string)x.Value);

                        if (!String.IsNullOrWhiteSpace(chatJson))
                        {
                            var generalInfo = JObject.Parse(chatJson);
                            if (generalInfo != null)
                            {
                                if (String.IsNullOrEmpty(generalInfo["latest_time"].ToString()) ||
                                    (lastTime != null &&
                                     generalInfo["latest_time"].ToString() == lastTime))
                                {
                                    return;
                                }

                                long intLastTime;
                                long.TryParse(lastTime, out intLastTime);
                                lastTime = generalInfo["latest_time"].ToString();
                                var comments = JArray.Parse(generalInfo["comments"].ToString());

                                foreach (var comment in comments)
                                {
                                    var time_created = comment["time_created"].ToObject <long>();

                                    if (time_created <= intLastTime)
                                    {
                                        continue;
                                    }

                                    var author_name  = comment["author_name"].ToString();
                                    var comment_text = comment["comment"].ToString();


                                    if (String.IsNullOrEmpty(author_name) ||
                                        String.IsNullOrEmpty(comment_text))
                                    {
                                        return;
                                    }

                                    if (ReadMessage != null)
                                    {
                                        ReadMessage(new ChatMessage()
                                        {
                                            Channel         = String.IsNullOrWhiteSpace(humanReadableChannelName) ? ChannelName : "#" + humanReadableChannelName,
                                            ChatIconURL     = Chat.IconURL,
                                            ChatName        = Chat.ChatName,
                                            FromUserName    = author_name,
                                            HighlyImportant = false,
                                            IsSentByMe      = false,
                                            Text            = comment_text,
                                        });
                                    }


                                    Chat.UpdateStats();
                                    ChannelStats.MessagesCount++;
                                }
                            }
                        }
                    }
                };
                chatPoller.Start();
                #endregion
                #region Statspoller
                statsPoller = new WebPoller()
                {
                    Id         = ChannelName,
                    Uri        = new Uri(String.Format(@"http://www.youtube.com/live_stats?v={0}&t={1}", videoId, Time.UnixTimestamp().ToString())),
                    IsLongPoll = false,
                    Interval   = 60000,
                };

                statsPoller.ReadString = (text) =>
                {
                    if (String.IsNullOrWhiteSpace(text))
                    {
                        return;
                    }

                    lock (pollerLock)
                    {
                        Int32 viewers = 0;
                        Int32.TryParse(text, out viewers);
                        ChannelStats.ViewersCount = viewers;
                        Chat.UpdateStats();
                    }
                };
                statsPoller.Start();
                #endregion
                JoinCallback(this);
            }
        }