예제 #1
0
        public string CreatePlaylist(TokenResponse token, PlaylistResult playlist)
        {
            _client.DefaultRequestHeaders.Add("Authorization", $"Bearer {token.AccessToken}");

            var user = GetUser();

            _requestLogger.LogSpotify(user, playlist, token);

            var createdPlaylist = CreateNew(user, playlist.ArtistName);

            var tracklist = new Tracklist {
                Uris = new List <String>()
            };

            foreach (var song in playlist.Songs)
            {
                try
                {
                    tracklist.Uris.Add(GetTrack(playlist.ArtistName, song.Name).Uri);
                }
                catch (Exception)
                {
                    try
                    {
                        foreach (var songName in song.Name.Split("/"))
                        {
                            tracklist.Uris.Add(GetTrack(playlist.ArtistName, songName.Trim()).Uri);
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
            }

            SetTracks(user, createdPlaylist, tracklist);

            return(createdPlaylist.ExternalUrls.Spotify);
        }