public Track Map(S.ITrack track, SpotifyMusicProvider musicProvider, string user, bool mapAlbum = false, bool mapArtists = false) { string trackLink = track.GetLinkString(); var trackResult = new Track { Link = trackLink, Name = track.Name, IsAvailable = track.IsAvailable, Duration = track.Duration, DurationMilliseconds = (long)track.Duration.TotalMilliseconds, MusicProvider = musicProvider.Descriptor, ExternalLink = new Uri(musicProvider.ExternalLinkBaseUrl, "/track/" + trackLink) }; if (mapAlbum && track.Album != null) { trackResult.Album = albumMapper.Map(track.Album, musicProvider); } if (mapArtists && track.Artists != null) { trackResult.Artists = track.Artists.Select(t => artistMapper.Map(t, musicProvider)).ToArray(); } //We want to set whether the track is already queued if (alreadyQueuedHelper != null) { trackResult = alreadyQueuedHelper.ResetAlreadyQueued((trackResult), user); } return(trackResult); }
public SearchResults SearchAll(string searchTerm, string user) { Login(); using (var search = session.Search(searchTerm, 0, 30, 0, 15, 0, 15, 0, 0, sp_search_type.STANDARD)) { search.WaitForCompletion(); if (!search.IsComplete) { logger.Error("Search for {0} timed out", searchTerm); return(null); } var results = new SearchResults(); //set up artists var pagedArtists = new ArtistPagedList { Total = search.TotalArtists, Artists = search.Artists.Select(a => new ArtistMapper().Map(a, this)).ToArray() }; //set up albums var pagedAlbums = new AlbumPagedList { Total = search.TotalAlbums, Albums = search.Albums.Where(a => a.IsAvailable) .Select(a => albumMapper.Map(a, this, true)) .ToArray() }; ////set up tracks var pagedTracks = new TrackPagedList { Total = search.TotalTracks, Tracks = search.Tracks .Select(t => trackMapper.Map(t, this, user, true, true)) .Where(t => t.IsAvailable) .ToArray() }; results.PagedArtists = pagedArtists; results.PagedAlbums = pagedAlbums; results.PagedTracks = pagedTracks; return(results); } }