public IActionResult Index() { var api = new SpotifyWebApi.SpotifyWebApi(_spotifyAuthService.GetToken()); var fullPlaylistTracks = api.Playlist.GetPlaylistTracks(SpotifyUri.Make("1233033915", "3bdydssu6hXzOP4kLrI8cL")).Result; var playlistTracks = new List <PlaylistTrack>(); foreach (var track in fullPlaylistTracks) { playlistTracks.Add(new PlaylistTrack { Name = track.Track.Name, Artist = track.Track.Artists.FirstOrDefault().Name, AddedBy = track.AddedBy.DisplayName }); } List <TopArtist> top5Artists = playlistTracks .GroupBy(q => q.Artist) .OrderByDescending(gp => gp.Count()) .Take(5) .Select(g => new TopArtist { Artist = g.Key, Count = g.Count() }).ToList(); return(View()); }
public async Task <IActionResult> SavePlayedTracksAsync() { var playlistTracks = new List <PlaylistTrack>(); if (_spotifyAuthService.GetToken() != null) { var api = new SpotifyWebApi.SpotifyWebApi(_spotifyAuthService.GetToken()); var fullPlaylistTracks = api.Playlist.GetPlaylistTracks(SpotifyUri.Make("1233033915", "3bdydssu6hXzOP4kLrI8cL")).Result; foreach (var track in fullPlaylistTracks) { playlistTracks.Add(new PlaylistTrack { Name = track.Track.Name, Artist = track.Track.Artists.FirstOrDefault().Name, AddedBy = _usernames.GetValueOrDefault(track.AddedBy.Id) }); } } List <PlayedTrackViewModel> playedTrackViewModels = new List <PlayedTrackViewModel>(); var playedTrackEntities = _storageService.GetPlayedTracks().Result; for (var i = 0; i < playedTrackEntities.Count(); i++) { playedTrackViewModels.Add(TrackEntityToPlayedTrackViewModel.Map(playedTrackEntities[i], i, playlistTracks)); } await _storageService.AddPlayedTracksAsync(playedTrackViewModels); return(RedirectToAction("index")); }
public void UriExceptionTest() { Assert.Throws <ArgumentException>(() => SpotifyUri.Make("")); Assert.Throws <ArgumentException>(() => SpotifyUri.Make("", UriType.Album)); Assert.Throws <InvalidUriException>(() => SpotifyUri.Make("a:a:a:a:a")); Assert.Throws <InvalidUriException>(() => SpotifyUri.Make("spotify:::")); }
public void UriTypeTest(string u, UriType type) { var uri = SpotifyUri.Make(u); Assert.Equal(u, uri.FullUri); Assert.Equal(type, uri.Type); }
/// <summary>Updates the currently playing image.</summary> /// <returns>an awaitable</returns> private async Task UpdateCurrentlyPlayingImage() { var albumUriString = this.currentlyPlayingContext.Item?.Album.Uri; if (albumUriString == this.currentlyPlayingAlbumUri) { return; } this.currentlyPlayingAlbumUri = albumUriString; if (albumUriString != null) { var albumUri = SpotifyUri.Make(albumUriString); var album = await this.api.Album.GetAlbum(albumUri); var bitmapUri = new Uri(album.Images.First().Url); var image = new BitmapImage(bitmapUri); this.eventAggregator.GetEvent <CurrentlyPlayingImageChanged>().Publish(image); } else { this.eventAggregator.GetEvent <CurrentlyPlayingImageChanged>().Publish(null); } }
// [InlineData("spotify:user:1141820105:playlist:4y6G7PQjyw48ha4SdbLF0A", 10000)] public async Task GetPlaylistTracksTest(string uri, int expectedTrackCount) { var st = Stopwatch.StartNew(); var tracks = await this.Api.Playlist.GetPlaylistTracks(SpotifyUri.Make(uri)); st.Stop(); this.Output.WriteLine($"Getting {expectedTrackCount} tracks took {st.Elapsed:c}"); Assert.Equal(expectedTrackCount, tracks.Count); }
public void UriTest() { var u1 = SpotifyUri.Make("0ZGZTut99seZYeJTLy7QZG", UriType.Track); var u2 = SpotifyUri.Make("1141820105", "2vIxq3ZWHDDgrVfAzmIbDf"); Assert.Equal(UriType.Track, u1.Type); Assert.Equal("spotify:track:0ZGZTut99seZYeJTLy7QZG", u1.FullUri); Assert.Equal(UriType.Playlist, u2.Type); Assert.Equal("spotify:user:1141820105:playlist:2vIxq3ZWHDDgrVfAzmIbDf", u2.FullUri); }
public void UriExceptionTest() { Assert.Throws <ArgumentException>(() => SpotifyUri.Make("")); Assert.Throws <ArgumentException>(() => SpotifyUri.Make("", UriType.Album)); Assert.Throws <ArgumentException>(() => SpotifyUri.Make("", "")); Assert.Throws <ArgumentException>(() => SpotifyUri.Make("Test", "")); Assert.Throws <ArgumentException>(() => SpotifyUri.Make("", "Test")); Assert.Throws <NotSupportedException>(() => SpotifyUri.Make("Test", UriType.Playlist)); Assert.Throws <InvalidUriException>(() => SpotifyUri.Make("a:a:a:a:a")); Assert.Throws <InvalidUriException>(() => SpotifyUri.Make("spotify:::")); }
public void StartPlaybackTestPositionOffset() { this.Api.Player.StartPlayback( null, SpotifyUri.Make("0sNOF9WDwhWunNAHPD3Baj", UriType.Album), null, new PositionOffset() { Position = 1 }).Wait(); }
public void StartPlaybackTestUriOffset() { this.Api.Player.StartPlayback( null, SpotifyUri.Make("0sNOF9WDwhWunNAHPD3Baj", UriType.Album), null, new UriOffset { Uri = SpotifyUri.Make("2joHDtKFVDDyWDHnOxZMAX", UriType.Track).FullUri }).Wait(); }
public void GetAlbumTest() { var album = this.Api.Album.GetAlbum(SpotifyUri.Make("0sNOF9WDwhWunNAHPD3Baj", UriType.Album)).NonAsync(); Assert.AreEqual("0sNOF9WDwhWunNAHPD3Baj", album.Id); Assert.AreEqual("Epic/Legacy", album.Label); Assert.AreEqual("She's So Unusual", album.Name); Assert.AreEqual(13, album.Tracks.Total); Assert.AreEqual("Cyndi Lauper", album.Artists.First().Name); Assert.AreEqual("2joHDtKFVDDyWDHnOxZMAX", album.Tracks.Items[1].Id); Assert.AreEqual("6ClztHzretmPHCeiNqR5wD", album.Tracks.Items[2].Id); Assert.AreEqual("2tVHvZK4YYzTloSCBPm2tg", album.Tracks.Items[3].Id); }
public void StartPlaybackTestWithUris() { this.Api.Player.StartPlayback( null, null, new List <SpotifyUri> { SpotifyUri.Make("2joHDtKFVDDyWDHnOxZMAX", UriType.Track), SpotifyUri.Make("6ClztHzretmPHCeiNqR5wD", UriType.Track), SpotifyUri.Make("2tVHvZK4YYzTloSCBPm2tg", UriType.Track) }, new UriOffset { Uri = SpotifyUri.Make("2joHDtKFVDDyWDHnOxZMAX", UriType.Track).FullUri }).Wait(); }
private PlaylistTrack getSongFromApi() { var param = new AuthParameters { Scopes = Scope.All, ClientId = SettingsLoader.SettingsContainer.Spotify_Client_Id, ClientSecret = SettingsLoader.SettingsContainer.Spotify_Client_Secret, RedirectUri = "http://google.com", ShowDialog = false, // Set to true to login each time. }; var token = ClientCredentials.GetToken(param); ISpotifyWebApi api = new SpotifyWebApi.SpotifyWebApi(token); FullPlaylist playlist = api.Playlist.GetPlaylist(SpotifyUri.Make("spotify:user:1189618539:playlist:03gha5BWxoJ17xtn3FOvyl")).Result; return(playlist.Tracks.Items.OrderBy(x => Guid.NewGuid()).FirstOrDefault()); }
public IActionResult Index() { var playlistTracks = new List <PlaylistTrack>(); if (_spotifyAuthService.GetToken() != null) { var api = new SpotifyWebApi.SpotifyWebApi(_spotifyAuthService.GetToken()); var fullPlaylistTracks = api.Playlist.GetPlaylistTracks(SpotifyUri.Make("1233033915", "2CuhODa4xTTlemWopeXG71")).Result; foreach (var track in fullPlaylistTracks) { var usernameModel = _usernames.GetValueOrDefault(track.AddedBy.Id); playlistTracks.Add(new PlaylistTrack { Name = track.Track.Name, Artist = track.Track.Artists.FirstOrDefault().Name, AddedBy = usernameModel?.Name, AddedByImage = usernameModel?.ImageName }); } } List <PlayedTrackViewModel> playedTrackViewModels = new List <PlayedTrackViewModel>(); var playedTrackEntities = _storageService.GetPlayedTracks().Result; if (playedTrackEntities != null) { for (var i = 0; i < playedTrackEntities.Count(); i++) { playedTrackViewModels.Add(TrackEntityToPlayedTrackViewModel.Map(playedTrackEntities[i], i, playlistTracks)); } } ViewBag.PlayedTracks = playedTrackViewModels; return(View()); }
public void MakeTest() { SpotifyUri.Make("spotify:playlist:3ewZM7pLkkmbqULVsRZwnM"); }
public async Task GetAlbumTracksTest(string uri, int expectedTrackCount) { var tracks = await this.Api.Album.GetAlbumTracks(SpotifyUri.Make(uri)); Assert.Equal(expectedTrackCount, tracks.Count); }
/// <summary>Activates the playlist.</summary> public void ActivatePlaylist() { this.playListViewModel.ActivatePlaylist(SpotifyUri.Make(this.Uri)); }
/// <summary> /// Executes the play command. /// </summary> private void PlayCommandExecute() { this.playBackService.SetPlaylist(SpotifyUri.Make(this.Uri)); }
/// <summary>Executes the play command.</summary> private void PlayCommandExecute() { this.playbackService.SetSong(SpotifyUri.Make(this.PlaylistUri), SpotifyUri.Make(this.Uri)); }
public void GetPlaylistTest() { var test = this.Api.Playlist.GetPlaylist(SpotifyUri.Make("spotify:playlist:3ewZM7pLkkmbqULVsRZwnM")).Result; }