Example #1
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);
        }