예제 #1
0
        private async Task <ChannelPageParser> GetChannelPageParserAsync(string channelId)
        {
            var url = $"https://www.youtube.com/channel/{channelId}";
            var raw = await _httpClient.GetStringAsync(url).ConfigureAwait(false);

            return(ChannelPageParser.Initialize(raw));
        }
예제 #2
0
        private async Task <ChannelPageParser> GetChannelPageParserByUsernameAsync(string username)
        {
            username = username.UrlEncode();

            var url = $"https://www.youtube.com/user/{username}?hl=en";

            // Retry up to 5 times because sometimes the response has random errors
            for (var retry = 0; retry < 5; retry++)
            {
                var raw = await _httpClient.GetStringAsync(url);

                var parser = ChannelPageParser.Initialize(raw);

                // If successful - return
                if (parser.ParseIsAvailable())
                {
                    return(parser);
                }

                // Otherwise put a delay before trying again
                await Task.Delay(150);
            }

            // Throw exception
            throw new InvalidDataException("Could not get channel page.");
        }
예제 #3
0
        private async Task <ChannelPageParser> GetChannelPageParserByUsernameAsync(string username)
        {
            username = username.UrlEncode();

            var url = $"https://www.youtube.com/user/{username}";
            var raw = await _httpClient.GetStringAsync(url).ConfigureAwait(false);

            return(ChannelPageParser.Initialize(raw));
        }