예제 #1
0
        public async Task <SearchResponse> GetResults()
        {
            SearchResponse      response = new SearchResponse();
            List <SearchResult> result   = await LoadItems();

            List <string> videosId    = new List <string>();
            List <string> channelsId  = new List <string>();
            List <string> playlistsId = new List <string>();

            result.ForEach(item =>
            {
                switch (item.Id.Kind)
                {
                case "youtube#video":
                    videosId.Add(item.Id.VideoId);
                    break;

                case "youtube#channel":
                    channelsId.Add(item.Id.ChannelId);
                    break;

                case "youtube#playlist":
                    playlistsId.Add(item.Id.PlaylistId);
                    break;
                }
            });

            VideoQuery videoQuery = new VideoQuery
            {
                Part       = "snippet,contentDetails",
                Id         = string.Join(",", videosId),
                MaxResults = this.Query.MaxResults
            };
            VideoListResponse videoResponse = await service.GetVideoInfo(videoQuery);

            response.Videos.AddRange(videoResponse.Items);

            ChannelQuery channelQuery = new ChannelQuery
            {
                Part       = "snippet,statistics",
                Id         = string.Join(",", channelsId),
                MaxResults = this.Query.MaxResults
            };
            ChannelListResponse channelResponse = await service.GetChannelInfo(channelQuery);

            response.Channels.AddRange(channelResponse.Items);

            PlaylistQuery playlistQuery = new PlaylistQuery
            {
                Part       = "snippet,status,contentDetails",
                Id         = string.Join(",", playlistsId),
                MaxResults = this.Query.MaxResults
            };
            PlaylistListResponse playlistResponse = await service.GetPlaylistInfo(playlistQuery);

            response.Playlists.AddRange(playlistResponse.Items);

            return(response);
        }
        public GetPlaylistListQuery(PlaylistQuery playlistQuery)
        {
            if (playlistQuery is null)
            {
                throw new System.ArgumentNullException(nameof(playlistQuery));
            }

            Name       = playlistQuery.Name;
            PageNumber = playlistQuery.PageNumber;
            PageSize   = playlistQuery.PageSize;
        }
예제 #3
0
        public async Task <Page <Playlist> > GetAsync(PlaylistQuery query,
                                                      CancellationToken cancel)
        {
            var allPlaylists = await GetAllPlaylistsFromFileAsync(cancel);

            return(new Page <Playlist>
            {
                TotalCount = allPlaylists.Count,
                Items = allPlaylists.Select(x => x.Value).Skip(query.Offset).Take(query.Limit).ToList()
            });
        }
예제 #4
0
        public GetPlaylistListQuery(PlaylistQuery playlistQueryParams)
        {
            if (playlistQueryParams is null)
            {
                throw new System.ArgumentNullException(nameof(playlistQueryParams));
            }

            Name       = playlistQueryParams.Name;
            Order      = playlistQueryParams.Order;
            PageNumber = playlistQueryParams.PageNumber;
            PageSize   = playlistQueryParams.PageSize;
        }
예제 #5
0
        public async Task <IActionResult> GetPlaylistsTrackById(
            [FromRoute] int trackId,
            [FromQuery] PlaylistQuery playlistQuery)
        {
            var track = await _mediator.Send(new GetPlaylistListQuery(trackId, playlistQuery));

            if (track == null)
            {
                return(NotFound());
            }

            return(Ok(track));
        }
예제 #6
0
        public async Task <IActionResult> GetPlaylists([FromQuery] PlaylistQuery playlistQuery)
        {
            var playlists = await _mediator.Send(new GetPlaylistListQuery(playlistQuery));

            return(this.OkWithPageHeader(playlists, nameof(GetPlaylists), playlistQuery, _urlHelper));
        }
예제 #7
0
 public GetPlaylistListQuery(int trackId, PlaylistQuery playlistQuery) : this(playlistQuery)
 {
     TrackId = trackId;
 }
예제 #8
0
 public Task <Page <Playlist> > GetAsync(PlaylistQuery query,
                                         CancellationToken cancel = default)
 {
     return(_playlistRepository.GetAsync(query, cancel));
 }