public async Task <IEnumerable <SongRequestModel> > Search(string identifier) { List <SongRequestModel> results = new List <SongRequestModel>(); try { if (identifier.StartsWith(SpotifyTrackPrefix) || identifier.StartsWith(SpotifyLinkPrefix)) { identifier = identifier.Replace(SpotifyTrackPrefix, ""); identifier = identifier.Replace(SpotifyLinkPrefix, ""); if (identifier.Contains('?')) { identifier = identifier.Substring(0, identifier.IndexOf('?')); } SpotifySongModel song = await ChannelSession.Services.Spotify.GetSong(identifier); if (song != null) { if (!song.Explicit || ChannelSession.Settings.SpotifyAllowExplicit) { results.Add(new SongRequestModel() { ID = song.ID, URI = song.Uri, Name = song.ToString(), AlbumImage = (!string.IsNullOrEmpty(song.Album?.ImageLink)) ? song.Album?.ImageLink : SpotifyDefaultAlbumArt, Type = SongRequestServiceTypeEnum.Spotify, Length = song.Duration }); } } } else { foreach (SpotifySongModel song in await ChannelSession.Services.Spotify.SearchSongs(identifier)) { if (!song.Explicit || ChannelSession.Settings.SpotifyAllowExplicit) { results.Add(new SongRequestModel() { ID = song.ID, URI = song.Uri, Name = song.ToString(), AlbumImage = (!string.IsNullOrEmpty(song.Album?.ImageLink)) ? song.Album?.ImageLink : SpotifyDefaultAlbumArt, Type = SongRequestServiceTypeEnum.Spotify, Length = song.Duration }); } } } } catch (Exception ex) { Logger.Log(ex); } return(results); }
public async Task <bool> AddSongToPlaylist(SpotifyPlaylistModel playlist, SpotifySongModel song) { try { if (playlist != null && song != null) { HttpResponseMessage response = await this.PostAsync(string.Format("playlists/{0}/tracks?uris=spotify:track:" + song.ID, playlist.ID), null); return(response.StatusCode == HttpStatusCode.Created); } } catch (Exception ex) { Logger.Log(ex); } return(false); }
public async Task <bool> PlaySong(SpotifySongModel song) { return(await this.PlaySong(song.Uri)); }
public async Task RemoveSongFromPlaylist(SpotifyPlaylistModel playlist, SpotifySongModel song) { await this.RemoveSongsFromPlaylist(playlist, new List <SpotifySongModel>() { song }); }