public async Task <VideoRoot> GetLivestreamDetails(string videoId, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (IsNullOrWhiteSpace(videoId))
            {
                throw new ArgumentNullException(nameof(videoId));
            }

            var request           = $"{RequestConstants.VideoLivestreamDetails}&id={videoId}";
            var livestreamDetails = await HttpClientExtensions.ExecuteRequest <VideoRoot>(request, cancellationToken);

            request = $"{RequestConstants.VideoSnippet}&id={videoId}";
            var snippetDetails = await HttpClientExtensions.ExecuteRequest <VideoRoot>(request, cancellationToken);

            if (livestreamDetails?.Items?.Count > 0 && snippetDetails?.Items?.Count > 0)
            {
                livestreamDetails.Items[0].Snippet = snippetDetails.Items[0].Snippet;
            }
            else
            {
                // youtube just returns empty values when no stream was found
                throw new HttpRequestWithStatusException(HttpStatusCode.BadRequest, "Channel not found " + videoId);
            }

            return(livestreamDetails);
        }
Exemplo n.º 2
0
        public async Task <List <KnownGame> > GetKnownGames(KnownGamesPagedQuery query, CancellationToken cancellationToken = default(CancellationToken))
        {
            var request = RequestConstants.Types + "?order=viewersCurrent:DESC&limit=10";

            if (!string.IsNullOrEmpty(query.GameName))
            {
                request += $"&query={query.GameName}";
            }

            return(await HttpClientExtensions.ExecuteRequest <List <KnownGame> >(request, cancellationToken));
        }
Exemplo n.º 3
0
        public async Task <Channel> GetStreamDetails(string channelId, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (string.IsNullOrWhiteSpace(channelId))
            {
                throw new ArgumentNullException(nameof(channelId));
            }

            var request = RequestConstants.Channels + "/" + channelId;

            return(await HttpClientExtensions.ExecuteRequest <Channel>(request, cancellationToken));
        }
        public async Task <Livestream> GetChannelDetails(string channelName, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (IsNullOrWhiteSpace(channelName))
            {
                throw new ArgumentNullException(nameof(channelName));
            }

            var request        = RequestConstants.LiveChannel.Replace("{0}", channelName);
            var channelDetails = await HttpClientExtensions.ExecuteRequest <ChannelRoot>(request, cancellationToken);

            return(channelDetails?.Livestreams.FirstOrDefault());
        }
        public async Task <Mediainfo> GetStreamDetails(string streamId, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (IsNullOrWhiteSpace(streamId))
            {
                throw new ArgumentNullException(nameof(streamId));
            }

            var request    = $"{RequestConstants.Streams}/{streamId}";
            var streamRoot = await HttpClientExtensions.ExecuteRequest <StreamRoot>(request, cancellationToken);

            return(streamRoot?.Mediainfo);
        }
        public async Task <SearchLiveVideosRoot> GetLivestreamVideos(string channelId, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (IsNullOrWhiteSpace(channelId))
            {
                throw new ArgumentException("Argument is null or whitespace", nameof(channelId));
            }

            var request = RequestConstants.SearchChannelLiveVideos.Replace("{0}", channelId);
            var searchChannelLiveVideos = await HttpClientExtensions.ExecuteRequest <SearchLiveVideosRoot>(request, cancellationToken);

            return(searchChannelLiveVideos);
        }
        public async Task <List <Category> > GetTopGames(string gameName = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            var request = $"{RequestConstants.Games}?liveonly=true";

            if (gameName != null)
            {
                request += $"&q={gameName}";
            }

            var topGamesRoot = await HttpClientExtensions.ExecuteRequest <TopGamesRoot>(request, cancellationToken);

            return(topGamesRoot?.Categories);
        }
        public async Task <string> GetChannelIdFromUsername(string userName, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (IsNullOrWhiteSpace(userName))
            {
                throw new ArgumentException("Argument is null or whitespace", nameof(userName));
            }

            var request        = RequestConstants.GetChannelIdByUsername.Replace("{0}", userName);
            var channelDetails = await HttpClientExtensions.ExecuteRequest <GetChannelIdByNameRoot>(request, cancellationToken);

            if (channelDetails.Items == null || channelDetails.Items.Count == 0)
            {
                throw new HttpRequestWithStatusException(HttpStatusCode.BadRequest, "No channel found for username" + userName);
            }

            return(channelDetails.Items?.FirstOrDefault()?.Id);
        }
        public async Task <List <Livestream> > GetTopStreams(TopStreamsQuery topStreamsQuery, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (topStreamsQuery == null)
            {
                throw new ArgumentNullException(nameof(topStreamsQuery));
            }

            var request = $"{RequestConstants.TopStreams}?start={topStreamsQuery.Skip}&limit={topStreamsQuery.Take}";

            if (!IsNullOrWhiteSpace(topStreamsQuery.GameName))
            {
                request += $"&game={topStreamsQuery.GameName}";
            }

            var streamRoot = await HttpClientExtensions.ExecuteRequest <StreamsRoot>(request, cancellationToken);

            return(streamRoot?.Livestreams);
        }
        public async Task <List <Following> > GetUserFollows(string username, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (IsNullOrWhiteSpace(username))
            {
                throw new ArgumentNullException(nameof(username));
            }

            var request     = $"{RequestConstants.UserFollows.Replace("{0}", username)}";
            var userFollows = await HttpClientExtensions.ExecuteRequest <UserFollowsRoot>(request, cancellationToken);

            // if necessary, page until we get all followed streams
            while (userFollows.MaxResults > 0 && userFollows.Following.Count < userFollows.MaxResults)
            {
                var pagedRequest = $"{request}&offset={userFollows.Following.Count}";
                var pagedFollows = await HttpClientExtensions.ExecuteRequest <UserFollowsRoot>(pagedRequest, cancellationToken);

                userFollows.Following.AddRange(pagedFollows.Following);
            }

            return(userFollows.Following);
        }
        public async Task <List <Video> > GetChannelVideos(ChannelVideosQuery channelVideosQuery, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (channelVideosQuery == null)
            {
                throw new ArgumentNullException(nameof(channelVideosQuery));
            }
            if (IsNullOrWhiteSpace(channelVideosQuery.ChannelName))
            {
                throw new ArgumentNullException(nameof(channelVideosQuery.ChannelName));
            }

            var request = RequestConstants.ChannelVideos.Replace("{0}", channelVideosQuery.ChannelName);

            // hitbox doesn't actually have any offset/start value specified in their documentation
            // so maybe they dont have any paging available through the api: http://developers.hitbox.tv/#list-videos
            request += $"?offset={channelVideosQuery.Skip}&limit={channelVideosQuery.Take}";

            var channelVideosRoot = await HttpClientExtensions.ExecuteRequest <ChannelVideosRoot>(request, cancellationToken);

            return(channelVideosRoot?.Videos);
        }
Exemplo n.º 12
0
        public async Task <List <Channel> > GetTopStreams(BeamProPagedQuery pagedQuery, CancellationToken cancellationToken = default(CancellationToken))
        {
            var request = RequestConstants.Channels + $"?order=viewersCurrent:DESC&page={pagedQuery.Skip}&limit={pagedQuery.Take}";

            return(await HttpClientExtensions.ExecuteRequest <List <Channel> >(request, cancellationToken));
        }
Exemplo n.º 13
0
        /// <param name="channelId">Must be the "id" of the channel and not the channel name/token</param>
        /// <param name="pagedQuery"></param>
        /// <param name="cancellationToken"></param>
        public async Task <List <Recording> > GetChannelVideos(int channelId, BeamProPagedQuery pagedQuery, CancellationToken cancellationToken = default(CancellationToken))
        {
            var request = $"{RequestConstants.Videos.Replace("{0}", channelId.ToString())}?page={pagedQuery.Skip}&limit={pagedQuery.Take}";

            return(await HttpClientExtensions.ExecuteRequest <List <Recording> >(request, cancellationToken));
        }