public async Task <ExecutedQuery> ExecuteQueryAsync(Query query) { // Video if (query.Type == QueryType.Video) { var video = await _youtubeClient.GetVideoAsync(query.Value); var title = video.Title; return(new ExecutedQuery(query, title, new[] { video })); } // Playlist if (query.Type == QueryType.Playlist) { var playlist = await _youtubeClient.GetPlaylistAsync(query.Value); var title = playlist.Title; return(new ExecutedQuery(query, title, playlist.Videos)); } // Channel if (query.Type == QueryType.Channel) { var channel = await _youtubeClient.GetChannelAsync(query.Value); var videos = await _youtubeClient.GetChannelUploadsAsync(query.Value); var title = $"Channel uploads: {channel.Title}"; return(new ExecutedQuery(query, title, videos)); } // User if (query.Type == QueryType.User) { var channelId = await _youtubeClient.GetChannelIdAsync(query.Value); var videos = await _youtubeClient.GetChannelUploadsAsync(channelId); var title = $"User uploads: {query.Value}"; return(new ExecutedQuery(query, title, videos)); } // Search if (query.Type == QueryType.Search) { var videos = await _youtubeClient.SearchVideosAsync(query.Value, 5); var title = $"Search: {query.Value}"; return(new ExecutedQuery(query, title, videos)); } throw new ArgumentException($"Could not parse query [{query}].", nameof(query)); }
public async Task <ExecutedQuery> ExecuteQueryAsync(Query query) { // Video if (query.Type == QueryType.Video) { var video = await _youtubeClient.GetVideoAsync(query.Value); var title = video.Title; return(new ExecutedQuery(query, title, new[] { video })); } // Playlist if (query.Type == QueryType.Playlist) { var playlist = await _youtubeClient.GetPlaylistAsync(query.Value); var title = playlist.Title; return(new ExecutedQuery(query, title, playlist.Videos)); } // Channel if (query.Type == QueryType.Channel) { var channel = await _youtubeClient.GetChannelAsync(query.Value); var videos = await _youtubeClient.GetChannelUploadsAsync(query.Value); var title = $"Channel uploads: {channel.Title}"; return(new ExecutedQuery(query, title, videos)); } // User if (query.Type == QueryType.User) { var channelId = await _youtubeClient.GetChannelIdAsync(query.Value); var videos = await _youtubeClient.GetChannelUploadsAsync(channelId); var title = $"User uploads: {query.Value}"; return(new ExecutedQuery(query, title, videos)); } // Search if (query.Type == QueryType.Search) { if (query.Value.Split(';').Length > 1) { var splitted = query.Value.Split(';'); List <YoutubeExplode.Models.Video> video = new List <YoutubeExplode.Models.Video>(); for (int i = 0; i < splitted.Length; i++) { IReadOnlyList <YoutubeExplode.Models.Video> videos = await _youtubeClient.SearchVideosAsync(splitted[i], 1); video.Add(videos[0]); } var title = $"Search: BulkList"; return(new ExecutedQuery(query, title, video.AsReadOnly())); } else { var videos = await _youtubeClient.SearchVideosAsync(query.Value, 1); var title = $"Search: {query.Value}"; return(new ExecutedQuery(query, title, videos)); } } throw new ArgumentException($"Could not parse query [{query}].", nameof(query)); }