private void createSpotifyPlaylists() { String fileName = fileNameTB.Text; if (fileName != null && fileName.Length > 0) { messageLbl.Text = ""; XDocument doc = XDocument.Load(fileName);; List <XElement> tracksXml = doc.Root.Element("dict").Element("dict").Elements("dict").ToList();; List <FullTrack> spotifyTracks = new List <FullTrack>(); for (int i = 0; i < tracksXml.Count; i++) { XElement track = tracksXml[i]; String name = getNode(track, "Name").Value; String artist = getNode(track, "Artist").Value; String album = getNode(track, "Album").Value; ProgressLbl.Text = String.Format("Searching for ({0}/{1} -> Name: {2} Artist: {3} Album: {4} ", i + 1, tracksXml.Count, name, artist, album); FullTrack spotifyTrack = searchSpotify(name, artist, album); if (spotifyTrack != null) { spotifyTracks.Add(spotifyTrack); } else { AddTrackToErrorLog(name, artist, album); } } PrivateProfile profile = SpotifyAPI.GetPrivateProfile(); if (!profile.HasError()) { String playlistName = Path.GetFileNameWithoutExtension(openFileDialog1.FileName); FullPlaylist playlist = SpotifyAPI.CreatePlaylist(profile.Id, playlistName); if (!playlist.HasError()) { messageLbl.Text += "\n\nPlaylist-URI: " + playlist.Uri; foreach (FullTrack spotifyTrack in spotifyTracks) { SpotifyAPI.AddPlaylistTrack(playlist.Id, spotifyTrack.Uri); } } else { messageLbl.Text += "\n\nERROR: " + playlist.Error.Message; } } else { messageLbl.Text += "\n\nERROR: " + profile.Error.Message; } } else { messageLbl.Text += "Please Choose a file"; } }
public void AllLibraryToPlaylist(SpotifyWebAPI spotify) { //saves all track ids to list var tracksUri = HelperFunctions.GetSavedTracksUris(spotify); Console.WriteLine($"Number of tracks: {tracksUri.Count}"); // gets user id PrivateProfile user = spotify.GetPrivateProfile(); if (user.HasError()) { Console.WriteLine("\n\nProfileID not read properly. Cannot create playlist.\n\n"); } var userId = user.Id; //creates new empty playlist FullPlaylist playlist = spotify.CreatePlaylist(userId, "Library to Playlist"); //error notification Console.WriteLine(playlist.HasError() ? "/n/nError while creating playlist.\n\n" : "Playlist created and named \"Library to Playlist\""); //inserts playlist tracks to playlist HelperFunctions.InsertTracks(spotify, tracksUri, playlist.Id); Console.WriteLine("\nWarning: there may be less songs added to playlist than are present in library, because they might be not available"); Console.WriteLine("\nTask ended. Press any key to exit. . ."); }
public FullPlaylist CreateAPlaylist(CreatePlaylistModel model) { Token token = GetToken(); PrivateProfile profile = GetMe(token); if (profile.Id == null && token.RefreshToken != null) { string oldRefreshToken = token.RefreshToken; token = RefreshToken(token.RefreshToken, Constants.ClientSecret); token.RefreshToken = oldRefreshToken; _tokenService.SetToken(token); profile = GetMe(token); } SpotifyAPI.Web.SpotifyWebAPI api = new SpotifyWebAPI() { AccessToken = token.AccessToken, TokenType = token.TokenType }; FullPlaylist fullPlaylist = api.CreatePlaylist(profile.Id, model.Name); if (fullPlaylist.HasError()) { throw new Exception("Playlist can not be created"); } return(fullPlaylist); }
public FullPlaylist GetPlaylist(string userId, string playlistId) { FullPlaylist fullPlaylist = _spotify.GetPlaylist(userId, playlistId); if (fullPlaylist.HasError()) { Debug.LogError(fullPlaylist.Error.Message); Debug.LogError(fullPlaylist.Error.Status); } return(fullPlaylist); }
public FullPlaylist CreatePlaylist(string name, bool mode) { var profile_id = _spotify.GetPrivateProfile().Id; FullPlaylist playlist = _spotify.CreatePlaylist(profile_id, name, mode); while (playlist.HasError()) { Thread.Sleep(apiSleepTime); Console.WriteLine("Error Status: " + playlist.Error.Status); Console.WriteLine("Error Msg: CreatePlayList" + playlist.Error.Message); } return(playlist); }
private void CreatePlaylist(List <string> tracks) { FullPlaylist newReleases = spotify.CreatePlaylist(profile.Id, DateTime.Now.ToString("MM/dd") + " Releases"); SearchItem song = new SearchItem(); ErrorResponse response = new ErrorResponse(); if (newReleases.HasError()) //This might need more graceful integration { Console.WriteLine(newReleases.Error.Message); } foreach (string target in tracks) { if (target.Contains("EP") || target.Contains("Album") || target.Contains("Remixes")) { song = spotify.SearchItems(target, SearchType.Album); if (song.Albums.Total > 0) { FullAlbum album = spotify.GetAlbum(song.Albums.Items[0].Id); for (int i = 0; i < album.Tracks.Total; i++) { response = spotify.AddPlaylistTrack(profile.Id, newReleases.Id, album.Tracks.Items[i].Uri); playlistsListBox.Items.Add(album.Tracks.Items[i].Name); } } } else { song = spotify.SearchItems(target, SearchType.Track); if (song.Tracks.Items.Count > 0) { response = spotify.AddPlaylistTrack(profile.Id, newReleases.Id, song.Tracks.Items[0].Uri); playlistsListBox.Items.Add(song.Tracks.Items[0].Name); } if (response.HasError()) //This might need more graceful integration { Console.WriteLine(response.Error.Message); } } } MessageBox.Show("Playlist Created!"); if (response.HasError()) //This might need more graceful integration { Console.WriteLine(response.Error.Message); } }
public IEnumerator Test_Spotify_GetPlaylist() { Spotify spotify = new Spotify(); spotify.TestSetup(); //Piano in the background string playlistId = "37i9dQZF1DX7K31D69s4M1"; string userId = "spotify"; FullPlaylist fullPlaylist = spotify.GetPlaylist(userId, playlistId); // yield return(null); Debug.Log(fullPlaylist.Name); Assert.IsFalse(fullPlaylist.HasError()); }
private static async Task <string> CreatePlaylist(SpotifyWebAPI api, string playlistName) { PrivateProfile profile = await api.GetPrivateProfileAsync(); string name = string.IsNullOrEmpty(profile.DisplayName) ? profile.Id : profile.DisplayName; profileId = profile.Id; Console.WriteLine($"Hello there, {name}!"); Console.WriteLine("Will create a new playlist with name: " + playlistName); FullPlaylist playlist = api.CreatePlaylist(profileId, playlistName, false); if (!playlist.HasError()) { //Store the ID for future use playlistId = playlist.Id; } Console.WriteLine("Playlist-URI: " + playlist.Uri); Console.WriteLine("Playlist-ID: " + playlist.Id); return(playlist.Id); }
public async Task <Dictionary <string, string> > GetTop50UsaPlaylistDictAsync(SpotifyWebAPI spotify) { Dictionary <string, string> dict = new Dictionary <string, string>(); FullPlaylist top50UsaPlaylist = await spotify.GetPlaylistAsync("37i9dQZEVXbLRQDuF5jeBp"); if (top50UsaPlaylist.HasError()) { Console.WriteLine("Error Status: " + top50UsaPlaylist.Error.Status); Console.WriteLine("Error Msg: " + top50UsaPlaylist.Error.Message); return(null); } foreach (PlaylistTrack track in top50UsaPlaylist.Tracks.Items) { if (!dict.ContainsKey(track.Track.Id)) { dict.Add(track.Track.Id, track.Track.Name); } } return(dict); }
private async void execMethod(string cmd, string obj) { if (cmd == "open" && !SpotifyLocalAPI.IsSpotifyRunning()) // Start Spotify { Console.WriteLine("Abrir Spotify"); SpotifyLocalAPI.RunSpotify(); SpotifyLocalAPI.RunSpotifyWebHelper(); Connect(); AuthConnect(); t.Speak("O que queres ouvir?"); } if (SpotifyLocalAPI.IsSpotifyRunning()) { if (cmd == "pause") // Pausar { Console.WriteLine("Pausa"); await _spotify.Pause(); t.Speak("Estarei aqui à tua espera."); } if (cmd == "play") // Retomar { Console.WriteLine("Retomar"); await _spotify.Play(); } if (cmd == "mute") // Silenciar { Console.WriteLine("Silenciar"); _spotify.Mute(); t.Speak("Já podes atender."); } if (cmd == "unmute") // Volume { Console.WriteLine("Volume"); _spotify.UnMute(); } if (cmd == "volumeUp") // Aumentar volume { Console.WriteLine("Aumentar volume"); _spotify.SetSpotifyVolume(PostureVerify.getVol() + 25); } if (cmd == "volumeDown") // Diminuir volume { Console.WriteLine("Dimiuir volume"); _spotify.SetSpotifyVolume(PostureVerify.getVol() - 25); } if (cmd == "close") // Fechar Spotify { Console.WriteLine("Fechar"); SpotifyLocalAPI.StopSpotify(); t.Speak("Obrigado pela tua preferência. Até à próxima!"); } if (cmd == "createList") // Criar lista de reprodução { String name = obj; Console.WriteLine("Criar lista de reprodução"); FullPlaylist playlist = _spotifyWeb.CreatePlaylist(id, name); if (!playlist.HasError()) { Console.WriteLine("Playlist-URI:" + playlist.Uri); } t.Speak("Lista de reprodução " + name + " criada com sucesso"); } if (cmd == "addList") // Adicionar à lista de reprodução { String name = obj; Console.WriteLine("Adicionar à lista de reprodução"); String uri = _spotify.GetStatus().Track.TrackResource.Uri; List <SimplePlaylist> playlist = _spotifyWeb.GetUserPlaylists(id).Items; int index = playlist.FindIndex(x => x.Name == name); _spotifyWeb.AddPlaylistTrack(id, _spotifyWeb.GetUserPlaylists(id).Items[index].Id, uri); t.Speak("Música adicionada com sucesso!"); } if (cmd == "removeList") // Remover música da lista de reprodução { Console.WriteLine("Remover música da lista de reprodução"); String uri = _spotify.GetStatus().Track.TrackResource.Uri; String playlist = _spotifyWeb.GetUserPlaylists(id).Items[0].Id; _spotifyWeb.RemovePlaylistTrack(id, playlist, new DeleteTrackUri(uri)); t.Speak("Música removida!"); } if (cmd == "identify") // Reconhecer música actual { Console.WriteLine("Não me lembro do nome desta música"); String name = _spotify.GetStatus().Track.TrackResource.Name; t.Speak("A música que estás a ouvir é" + name); } if (cmd == "playMusic") // Ouvir música { SearchType search_type = SearchType.Track; SearchItem item; String musica; musica = obj; Console.WriteLine("Ouvir " + musica + "!"); item = _spotifyWeb.SearchItems(musica, search_type, 1, 0, "pt"); await _spotify.PlayURL(item.Tracks.Items[0].Uri, ""); } if (cmd == "playAlbum") // Ouvir álbum { SearchType search_type = SearchType.Album; SearchItem item; String album; album = obj; Console.WriteLine("Ouvir " + album + "!"); item = _spotifyWeb.SearchItems(album, search_type, 1, 0, "pt"); await _spotify.PlayURL(item.Albums.Items[0].Uri, ""); } if (cmd == "playArtist") // Ouvir artista { SearchType search_type = SearchType.Track; SearchItem item; String artist; artist = obj; Console.WriteLine("Ouvir " + artist + "!"); item = _spotifyWeb.SearchItems(artist, search_type, 1, 0, "pt"); await _spotify.PlayURL(item.Artists.Items[0].Uri, ""); } } else { t.Speak("Spotify não está aberto."); } }
public override async Task OperateCommand(CommandContext ctx, params string[] args) { await base.OperateCommand(ctx, args); string subCommand = args[0]; guildData data = Utils.returnGuildData(ctx.Guild.Id); switch (subCommand.ToLower()) { case "play": //Play the tunes! await VoiceJoin(ctx); //We need to download the spotify song or whatever if (args[1] != null) { //Start to play the song if (args[1].Contains("youtube") || args[1].Contains("youtu.be")) { } else if (args[1].Contains("spotify")) { //Initialise the spotify bot if has not done yet! if (api == null) { CredentialsAuth auth = new CredentialsAuth("7c09a36e2ef84c2abc068c8979103d17", "d21bc05a3f604089b176e3b3e5975e0b"); Token token = await auth.GetToken(); api = new SpotifyWebAPI { AccessToken = token.AccessToken, TokenType = token.TokenType }; } string uriCode = null; Uri uri = new UriBuilder(args[1]).Uri; if (args[1] != null) { //Get the spotify track from url or the uri code uriCode = uri.Segments[2]; } if (uriCode != null) { if (uri.Segments[1] == "track") { FullTrack track = await api.GetTrackAsync(uriCode); if (track.Artists != null) { List <string> artists = new List <string>(); foreach (SimpleArtist artist in track.Artists) { artists.Add(artist.Name); } string connectArtist = string.Join(",", artists.ToArray()); await ctx.RespondAsync("Playing: " + track.Name + " By: " + connectArtist); } if (track.HasError()) { await ctx.RespondAsync("The track when playing had an issue!"); } } else if (uri.Segments[1] == "playlist") { //Playlist FullPlaylist list = await api.GetPlaylistAsync(uriCode); await ctx.RespondAsync("Playing: " + list.Name); if (list.HasError()) { await ctx.RespondAsync("The playlist had and issue"); } } } else { await ctx.RespondAsync("Invalid url or uri code"); } } } else { await ctx.RespondAsync("No song link was defined!"); } break; case "stop": //Stop the tunes! break; case "leave": case "fuckoff": //Leave the channel forcefully! await VoiceLeave(ctx); break; case "autoleave": //Set if the bot should automatically leave the voice channel when no one is in the voice channel if (data.autoSongLeave == false) { data.autoSongLeave = true; await ctx.RespondAsync("This bot will leave the party when everyone else has finished!"); } else if (data.autoSongLeave == true) { data.autoSongLeave = false; await ctx.RespondAsync("This bot will keep on partying!"); } break; case "loop": //loop the song that is currently playing if (data.loopSong == false) { data.loopSong = true; await ctx.RespondAsync("Looping Song !"); } else if (data.loopSong == true) { data.loopSong = false; await ctx.RespondAsync("Not Looping Song!"); } break; default: case "help": //Show the help on it. Dictionary <string, string> argumentsHelp = new System.Collections.Generic.Dictionary <string, string>(); argumentsHelp.Add(";;song play", "specify a song right after play with a space then this bot will play or specify a link (overrides queue)"); argumentsHelp.Add(";;song stop", "stop whatever is playing"); argumentsHelp.Add(";;song leave", "forces the bot to leave the current voice channel"); argumentsHelp.Add(";;song autoleave", "turns on auto leave the bot will leave the channel when no one is present"); argumentsHelp.Add(";;song loop", "loops the current song and disables queue"); DiscordEmbed embedHelp = JosephineEmbedBuilder.CreateEmbedMessage(ctx, "Sub-Commands", "for ';;announce set'", null, JosephineBot.defaultColor, argumentsHelp, false); await ctx.RespondAsync("Go to http://discord.rickasheye.xyz/ for all sub-commands", false, embedHelp); break; } }
public bool isPlaylist(string id) { FullPlaylist playlist = _spotify.GetPlaylist(id, "", "");; return(!playlist.HasError()); }
private void CreatePlaylist(List <string> tracks) { FullPlaylist newReleases = spotify.CreatePlaylist(profile.Id, DateTime.Now.ToString("MM/dd") + " Releases"); SearchItem song = new SearchItem(); ErrorResponse response = new ErrorResponse(); if (newReleases.HasError()) //This might need more graceful integration { Console.WriteLine(newReleases.Error.Message); } // Passes cursor update to main thread mainThread.Post((object state) => { Mouse.OverrideCursor = Cursors.Wait; Status.Text = "Status: Searching"; }, null); foreach (string target in tracks) { if (target.Contains("EP") || target.Contains("Album") || target.Contains("Remixes")) { song = spotify.SearchItems(target, SearchType.Album); if (song.Albums.Total > 0) { FullAlbum album = spotify.GetAlbum(song.Albums.Items[0].Id); for (int i = 0; i < album.Tracks.Total; i++) { response = spotify.AddPlaylistTrack(profile.Id, newReleases.Id, album.Tracks.Items[i].Uri); // Passes listbox ui update to main thread mainThread.Send((object state) => { songs.Add(new Song() { SongTitle = album.Tracks.Items[i].Name }); }, null); } } } else { song = spotify.SearchItems(target, SearchType.Track); if (song.Tracks.Items.Count > 0) { response = spotify.AddPlaylistTrack(profile.Id, newReleases.Id, song.Tracks.Items[0].Uri); // Passes listbox ui update to main thread mainThread.Send((object state) => { songs.Add(new Song() { SongTitle = song.Tracks.Items[0].Name }); }, null); } if (response.HasError()) //This might need more graceful integration { Console.WriteLine(response.Error.Message); } } // pass percent complete updates to main thread mainThread.Send((object state) => { percentDone += counter; progressBar.Value = percentDone; Amount.Text = percentDone.ToString("0.") + "%"; }, null); } // Passes cursor update to main thread mainThread.Post((object state) => { Mouse.OverrideCursor = Cursors.Arrow; Status.Text = "Status: Complete"; }, null); MessageBox.Show("Playlist Created!"); if (response.HasError()) //This might need more graceful integration { Console.WriteLine(response.Error.Message); } }