示例#1
0
        public override object ReadJson(JsonReader reader, Type objectType,
                                        object existingValue, JsonSerializer serializer)
        {
            var token = JToken.ReadFrom(reader);

            if (token.Type == JTokenType.Null)
            {
                return(null);
            }

            if (token["track"] == null)
            {
                return(null);
            }

            if (token["track"].Value <bool>() == true)
            {
                var obj = new FullTrack();
                serializer.Populate(token.CreateReader(), obj);
                return(obj);
            }
            else
            {
                var obj = new FullEpisode();
                serializer.Populate(token.CreateReader(), obj);
                return(obj);
            }
        }
示例#2
0
 public SpotifyTrack(FullTrack track)
 {
     this.Title = track.Name;
     this.Artists = track.Artists.Select(x => x.Name).ToArray();
     this.SpotifyId = track.Id;
     this.Popularity = track.Popularity;
     this.Album = track.Album.Name;
     this.SpotifyUri = track.Uri;
 }
        public String AddSongToPlayList(String playlistName, String songName, String artist)
        {
            if (mProfile == null || mSpotify == null)
            {
                return("you need to connect to spotify before you can use this feature");
            }

            if (playlists == null)
            {
                playlists = mSpotify.GetUserPlaylists(mProfile.Id).Items;
            }

            Models.SimplePlaylist playlist = playlists.Find(x => x.Name == playlistName);

            if (playlist == null)
            {
                return($"could not find playlist {playlistName}");
            }

            Models.SearchItem search = mSpotify.SearchItems(songName, Enums.SearchType.Track);

            if (search.Tracks == null || search.Tracks.Items.Count == 0)
            {
                return($"could not find song {songName}");
            }

            Models.FullTrack songData = search.Tracks.Items.Find(x => String.Equals(x.Artists[0].Name, artist, StringComparison.OrdinalIgnoreCase));

            if (songData == null)
            {
                return($"could not find song {songName} by {artist}");
            }

            Models.ErrorResponse error = mSpotify.AddPlaylistTrack(mProfile.Id, playlist.Id, songData.Uri);

            if (error.Error != null)
            {
                return(error.Error.Message);
            }

            return($"{songName} by {artist} was sucessfully added to {playlistName}");
        }
 public Task<string> GetArtworkAsync(FullTrack track) => GetArtworkAsync(track.Album);