예제 #1
0
        public async Task <List <SpotifySearchResult> > GetSearchResults(SpotifyContent spotifySong, string mode, int maxResults)
        {
            await CreateYouTubeService();

            var searchListRequest = youtubeService.Search.List("snippet");
            var searchTerm        = spotifySong.item.name + " " + spotifySong.item.artists.First().name;

            if (!string.IsNullOrEmpty(mode))
            {
                searchTerm += " " + mode;
            }
            searchListRequest.Q          = searchTerm;
            searchListRequest.MaxResults = maxResults;

            var searchListResponse = await searchListRequest.ExecuteAsync();

            var songs = searchListResponse.Items.Where(s => s.Id.Kind.Equals("youtube#video"));
            var spotifySearchResults = new List <SpotifySearchResult>();

            foreach (var song in songs)
            {
                spotifySearchResults.Add(new SpotifySearchResult
                {
                    Name         = song.Snippet.Title,
                    ThumbnailUrl = song.Snippet.Thumbnails.Default__.Url,
                    VideoId      = song.Id.VideoId
                });
            }

            return(spotifySearchResults);
        }
예제 #2
0
        public async Task <string> FetchUrl(SpotifyContent spotifySong, string mode)
        {
            await CreateYouTubeService();

            var searchListRequest = youtubeService.Search.List("snippet");
            var searchTerm        = spotifySong.item.name + " " + spotifySong.item.artists.First().name;

            if (!string.IsNullOrEmpty(mode))
            {
                searchTerm += " " + mode;
            }
            searchListRequest.Q          = searchTerm;
            searchListRequest.MaxResults = 1;

            var searchListResponse = await searchListRequest.ExecuteAsync();

            var song   = searchListResponse.Items.FirstOrDefault(s => s.Id.Kind.Equals("youtube#video"));
            var songId = song?.Id?.VideoId;

            if (song == null)
            {
                //TODO: pick random videos if not found.
                return("15_Y3_eRfOU&t");
            }

            return(songId);
        }