Exemple #1
0
        private void checkIfIsLive()
        {
            Task.Run(() =>
            {
                try
                {
                    var req =
                        WebRequest.Create(
                            //$"https://api.twitch.tv/kraken/streams/{Name}?client_id={IrcManager.DefaultClientID}");
                            $"https://api.twitch.tv/helix/streams?user_login={Name}")
                        .AuthorizeHelix();

                    if (AppSettings.IgnoreSystemProxy)
                    {
                        req.Proxy = null;
                    }
                    using (var res = req.GetResponse())
                    {
                        using (var resStream = res.GetResponseStream())
                        {
                            var parser = new JsonParser();

                            dynamic json  = parser.Parse(resStream);
                            var tmpIsLive = IsLive;

                            IsLive = json["data"]?.Count > 0 ?? false;

                            if (!IsLive)
                            {
                                StreamViewerCount = 0;
                                StreamStatus      = null;
                                StreamGame        = null;

                                if (tmpIsLive)
                                {
                                    LiveStatusUpdated?.Invoke(this, EventArgs.Empty);
                                }
                            }
                            else
                            {
                                dynamic stream = json["data"][0];
                                //dynamic channel = stream["channel"];

                                StreamViewerCount = int.Parse(stream["viewer_count"]);
                                StreamStatus      = stream["title"];
                                //StreamGame = channel["game"];
                                StreamStart = DateTime.Parse(stream["started_at"]);

                                LiveStatusUpdated?.Invoke(this, EventArgs.Empty);
                            }
                        }
                    }
                }
                catch
                {
                }
            });
        }
Exemple #2
0
        private void checkIfIsLive()
        {
            Task.Run(() =>
            {
                try
                {
                    var req =
                        WebRequest.Create(
                            $"https://api.twitch.tv/kraken/streams/{Name}?client_id={IrcManager.DefaultClientID}");

                    using (var res = req.GetResponse())
                        using (var resStream = res.GetResponseStream())
                        {
                            var parser = new JsonParser();

                            dynamic json = parser.Parse(resStream);

                            var tmpIsLive = IsLive;

                            IsLive = json["stream"] != null;

                            if (!IsLive)
                            {
                                StreamViewerCount = 0;
                                StreamStatus      = null;
                                StreamGame        = null;

                                if (tmpIsLive)
                                {
                                    LiveStatusUpdated?.Invoke(this, EventArgs.Empty);
                                }
                            }
                            else
                            {
                                dynamic stream  = json["stream"];
                                dynamic channel = stream["channel"];

                                StreamViewerCount = int.Parse(stream["viewers"]);
                                StreamStatus      = channel["status"];
                                StreamGame        = channel["game"];
                                StreamStart       = DateTime.Parse(stream["created_at"]);

                                LiveStatusUpdated?.Invoke(this, EventArgs.Empty);
                            }
                        }
                }
                catch
                {
                }
            });
        }