public static async Task <Song> AddSongToQuiz(SpotifyTokens token, string href) { Track newTrack; string albumDate; newTrack = await SpotifyManager.GetOneSong(token, href); albumDate = await SpotifyManager.GetOneAlbum(token, newTrack.Album.Href); StringBuilder builder = new StringBuilder(); foreach (var artist in newTrack.Artists) { builder.Append(artist.Name); if (artist != newTrack.Artists[newTrack.Artists.Count - 1]) { builder.Append(", "); } } var newSong = new Song { Artist = builder.ToString(), Title = newTrack.Name, RealeaseDate = albumDate, AlbumTitle = newTrack.Album.Name, SpotifyReferenceID = newTrack.Href, PreviewUrl = newTrack.PreviewUrl }; return(newSong); }
/// <summary> /// Initializes a new instance of the <see cref="CommandPreviousTrack"/> class. /// Adds our command handlers for menu (commands must exist in the command table file) /// </summary> /// <param name="package">Owner package, not null.</param> private CommandPreviousTrack(Package package) { if (package == null) { throw new ArgumentNullException("package"); } this.package = package; SpotifyRemote spotifyRemotePackage = package as SpotifyRemote; m_spotifyManager = spotifyRemotePackage.GetSpotifyManager(); OleMenuCommandService commandService = this.ServiceProvider.GetService(typeof(IMenuCommandService)) as OleMenuCommandService; OleMenuCommand menuItem = null; if (commandService != null) { var menuCommandID = new CommandID(CommandSet, CommandId); menuItem = new OleMenuCommand(this.MenuItemCallback, menuCommandID); commandService.AddCommand(menuItem); } SettingsManager setManager = SettingsManager.GetSettingsManager(); setManager.SetTbButtonPrevious(ref menuItem); }
/// <summary> /// Initializes a new instance of the <see cref="CommandPlayPause"/> class. /// Adds our command handlers for menu (commands must exist in the command table file) /// </summary> /// <param name="package">Owner package, not null.</param> private CommandPlayPause(Package package) { // TODO: fix not playing bug in vs 2019. if (package == null) { throw new ArgumentNullException("package"); } this.package = package; var spotifyRemotePackage = package as SpotifyRemote; m_spotifyManager = spotifyRemotePackage.GetSpotifyManager(); var commandService = ServiceProvider.GetService(typeof(IMenuCommandService)) as OleMenuCommandService; OleMenuCommand menuItem = null; if (commandService != null) { var menuCommandID = new CommandID(CommandSet, CommandId); menuItem = new OleMenuCommand(MenuItemCallback, menuCommandID); commandService.AddCommand(menuItem); } var setManager = SettingsManager.GetSettingsManager(); setManager.SetTbButtonPlayPause(ref menuItem); }
public static void GetSpotifyTracks(HttpClient client, string message, string searchKeywords) { searchKeywords = string.IsNullOrWhiteSpace(searchKeywords) ? message : searchKeywords; var spotifyManager = new SpotifyManager(); var spotify = spotifyManager.RunAsync(searchKeywords); //client.PostAsJsonAsync(_slackMessageWebHook, spotifySlackMessage); }
public Startup(IHostingEnvironment env) { var builder = new ConfigurationBuilder() .SetBasePath(env.ContentRootPath); builder.AddEnvironmentVariables(); Configuration = builder.Build(); MongoManager.SetupMongoClient(Configuration["MongoConnection"]); SpotifyManager.SetVariables(Configuration["SpotifyClientId"], Configuration["SpotifyClientSecret"]); }
/// <summary> /// Begins the listening for messages, and signals from the signal app /// </summary> public void StartListening() { SubscribeGeneralMessage(Gestures.UP); SubscribeGeneralMessage(Gestures.DOWN); SubscribeGeneralMessage(Gestures.LEFT); SubscribeGeneralMessage(Gestures.RIGHT); IMusicManager musicManager = new SpotifyManager(); actionHandler.RegisterMusicManager(musicManager); MessagingCenter.Subscribe <SettingsViewModel>(this, Gestures.SPOTIFY, async message => { if (!actionHandler.HasAuthenticatedMusicManager) { MessagingCenter.Subscribe <SpotifyLoginMessage>(this, "LoginSuccess", message => { if (!actionHandler.HasAuthenticatedMusicManager) { actionHandler.UpdateMusicManagerAuthentication(true); MessagingCenter.Send(new SpotifyLoginMessage("RegistrationSuccess", message.HasPremium), "RegistrationSuccess"); } }); await musicManager.Init(); } }); MessagingCenter.Subscribe <DNDPermissionMessage>(this, "DNDAdded", message => { if (!notificationManager.IsNotificationPolicyAccessGranted) { Intent intent = new Intent(Android.Provider.Settings.ActionNotificationPolicyAccessSettings); StartActivity(intent); } else { MessagingCenter.Send(new DNDPermissionMessage(), "DNDGranted"); } }); MessagingCenter.Subscribe <string>(this, "GPSRoute", async message => { GPSManager gpsManager = new GPSManager(); GPSHandler handler = new GPSHandler(); GPSSetting setting = await handler.GetSetting(); Rootobject root = await gpsManager.GetDirectionsAsync(setting.Destination, setting.Mode); if (root.status.Equals("NOT_FOUND")) { MessagingCenter.Send <string>("", "Unsuccessful"); return; } MessagingCenter.Send <string, Rootobject>("", "GetRoute", root); }); }
public static async Task <List <PlaylistVM> > GetPlaylists(SpotifyTokens token) { ListOfPlaylists allReturnedPlaylists; allReturnedPlaylists = await SpotifyManager.GetAllUserPlaylists(token); var playlists = new List <PlaylistVM>(); foreach (var item in allReturnedPlaylists.Items) { playlists.Add(new PlaylistVM(item.Name, item.Tracks.Href)); } return(playlists); }
public static async Task <bool> ExportPlaylistAsync(SpotifyTokens token, string quizId) { bool createResult = false; var quizToExport = JsonConvert.DeserializeObject <Quiz>(await MongoManager.GetOneQuizAsync(quizId, "Quizzes")); var playlistName = quizToExport.Name; // Check if it already exists, in that case warn user? Replace all songs? // The way this works now is that a new playlist is created with the same name if it already exists. //var listOfPlaylists = await SpotifyManager.GetAllUserPlaylists(token); //bool playlistExists = false; //foreach (var item in listOfPlaylists.Items) //{ // if (item.Name == playlistName) // { // playlistExists = true; // break; // } //} if (true /*!playlistExists*/) { // Create a new spotifyPlaylist with the chosen name if it does not exist. // In SpotifyManager. var newPlaylistId = await SpotifyManager.CreateNewPlaylistAsync(token, playlistName); // Add tracks to the newly created playlist. // In SpotifyManager. StringBuilder tracks = new StringBuilder(); foreach (var song in quizToExport.Songs) { tracks.Append("spotify:track:" + song.SpotifyReferenceID); if (song != quizToExport.Songs[quizToExport.Songs.Count - 1]) { tracks.Append(","); } } var tracksAddResult = SpotifyManager.AddTracksToPlaylist(token, newPlaylistId, tracks.ToString()); if (tracksAddResult == "Created") { createResult = true; await MongoManager.UpdateSpotifyPlaylistRefAsync(quizId, newPlaylistId); } } return(createResult); }
public static async Task <Quiz> GenerateQuiz(SpotifyTokens token, PlaylistVM viewModel) { ListOfSongs allReturnedSongs; allReturnedSongs = await SpotifyManager.GetAllSongsFromPlaylist(token, viewModel.SpotifyRef); var quiz = new Quiz(); quiz._id = Guid.NewGuid().ToString(); quiz.Name = viewModel.Name; quiz.PlaylistRef = viewModel.SpotifyRef; quiz.Owner = token.Username; int counter = 0; foreach (var item in allReturnedSongs.Items) { StringBuilder builder = new StringBuilder(); foreach (var artist in item.Track.Artists) { builder.Append(artist.Name); if (artist != item.Track.Artists[item.Track.Artists.Count - 1]) { builder.Append(", "); } } quiz.Songs.Add(new Song { Title = item.Track.Name, Artist = builder.ToString(), AlbumTitle = item.Track.Album.Name, RealeaseDate = allReturnedSongs.AlbumInfo.AlbumInfo[counter].ReleaseDate, SpotifyReferenceID = item.Track.Href, PreviewUrl = item.Track.PreviewUrl }); counter++; } return(quiz); }
/// <summary> /// Initializes a new instance of the <see cref="CommandOpenSpotify"/> class. /// Adds our command handlers for menu (commands must exist in the command table file) /// </summary> /// <param name="package">Owner package, not null.</param> private CommandOpenSpotify(Package package) { if (package == null) { throw new ArgumentNullException("package"); } var spotifyRemotePackage = package as SpotifyRemote; m_spotifyManager = spotifyRemotePackage.GetSpotifyManager(); this.package = package; var commandService = ServiceProvider.GetService(typeof(IMenuCommandService)) as OleMenuCommandService; OleMenuCommand menuItem = null; if (commandService != null) { var menuCommandID = new CommandID(CommandSet, CommandId); menuItem = new OleMenuCommand(MenuItemCallback, menuCommandID); commandService.AddCommand(menuItem); } // Initialize TrackChangeAnimator. m_trackChangeAnimator = new TrackChangeAnimator(); m_trackChangeAnimator.Initialize(menuItem, m_currentTextlabel); m_spotifyManager.SpotifyClientTrackChange += SpotifyClientTrackChange; var setManager = SettingsManager.GetSettingsManager(); setManager.SetTbButtonOpen(ref menuItem); setManager.SetTrackChangeAnimation(ref m_trackChangeAnimator); }
public static void Main(string[] args) { /* ALGORITMO DEL CHEF */ /* Console.WriteLine("Algoritmo del Chef"); * List<string> _winner = new List<string>(); * List<string> _other = new List<string>(); * * _winner.Add("The Doors"); * _winner.Add("Pink Floyd"); * _winner.Add("Metallica"); * * _other.Add("Janis Joplin"); * _other.Add("Jefferson Airplane"); * _other.Add("Led Zeppelin"); * Chef _chef = new Chef(); * * try * { * string res = _chef.chefAlgorythm(_winner, _other); * } * catch (Exception e) * { * Console.WriteLine("Error: No hay suficiente informacion de las bandas en Spotify..."); * Console.WriteLine("Algoritmo del Chef alternativo"); * _chef.alternativeChefAlgorythm(_winner, _other); * } */ /* ALGORITMO DE ENCRIPTACION */ /* Console.WriteLine("Encriptacion"); * SHA256Encriptation _sha = new SHA256Encriptation(); * string encrypted_str = _sha.sha256Encrypt("hola"); * Console.WriteLine("Hola encriptado: " + encrypted_str); */ /* ESTRATEGIA 100 DOLARES */ /* Console.WriteLine("Estrategia de los 100 dólares"); * DolarStrategy _dolar = new DolarStrategy(); * List<int> dolar_votes = new List<int>(); * dolar_votes.Add(25); * dolar_votes.Add(25); * dolar_votes.Add(15); * dolar_votes.Add(5); * dolar_votes.Add(30); * * bool isHundred = _dolar.checkDolars(dolar_votes); * if (isHundred) * { * Console.WriteLine("Su votación está correcta..."); * } */ SpotifyManager sp = new SpotifyManager(); string id = sp.searchArtistID("The Doors"); string name = sp.searchNameTrack(id, 3); string track = sp.searchURLTrack(id, 3); string album = sp.searchAlbumTrack(id, 3); Console.WriteLine(name); Console.WriteLine(track); Console.WriteLine(album); Console.ReadLine(); }
public void TestInitialize() { ISpotifyClient testClient = new SpotifyClientMock(); spotifyManager = new SpotifyManager(testClient); }