/// <summary> /// Attach Get Playlist Command /// </summary> /// <param name="client">Spotify Sdk Client</param> /// <param name="response">Playlist Response</param> /// <param name="overrideIsAttach">Override Is Attach?</param> public static void AttachGetPlaylistCommands( this ISpotifySdkClient client, PlaylistResponse response, bool?overrideIsAttach = null) { var isAttach = GetConfig(client.Config.IsAttachGetPlaylistCommands, overrideIsAttach); if (isAttach && response != null) { // Playlist Command if (client.CommandActions.Playlist != null) { response.Command = new GenericCommand <PlaylistResponse>( client.CommandActions.Playlist); } // Change a Playlist's Details Command if (client.CommandActions.SetPlaylist != null) { response.SetPlaylistCommand = new GenericCommand <PlaylistResponse>( client.CommandActions.SetPlaylist); } // Upload a Custom Playlist Cover Image Command if (client.CommandActions.SetPlaylistImage != null) { response.SetPlaylistImageCommand = new GenericCommand <PlaylistResponse>( client.CommandActions.SetPlaylistImage); } // Add User Playback Command response.AddUserPlaybackCommand = new GenericCommand <IPlaybackResponse>( client.AddUserPlaybackHandler); // User Commands client.AttachGetUserCommands(response.Owner, isAttach); } }
public void GetFourtyRunningSongs(string query) { var id = GetSongId(query); var songIds = new TermList(); songIds.Add(id); StaticArgument staticArgument = new StaticArgument { Type = "song-radio", SongID = songIds, Results = 40, MinTempo = 88, MaxTempo = 92, Variety = 1 }; using (var session = new EchoNestSession(ApiKey)) { PlaylistResponse searchResponse = session.Query <Static>().Execute(staticArgument); Assert.IsNotNull(searchResponse); Assert.IsNotNull(searchResponse.Songs); Assert.IsTrue(searchResponse.Songs.Any()); Assert.AreEqual(40, searchResponse.Songs.Count); } }
public void GetBasicPlaylist_WhereArtistName_HasSongsByArtist(string artistName) { BasicArgument basicArgument = new BasicArgument { Results = 10, Dmca = true }; TermList artistTerms = new TermList { artistName }; basicArgument.Artist.AddRange(artistTerms); using (var session = new EchoNestSession(ApiKey)) { PlaylistResponse searchResponse = session.Query <Basic>().Execute(basicArgument); Assert.IsNotNull(searchResponse); System.Diagnostics.Debug.WriteLine("Songs for : {0}", artistName); foreach (SongBucketItem song in searchResponse.Songs) { System.Diagnostics.Debug.WriteLine("\t{0} ({1})", song.Title, song.ArtistName); } } }
public async Task <ActionResult <PlaylistResponse> > Put(int id, [FromBody] PlaylistResponse input, CancellationToken ct = default) { try { if (input == null) { return(BadRequest()); } if (await _chinookSupervisor.GetPlaylistByIdAsync(id, ct) == null) { return(NotFound()); } var errors = JsonConvert.SerializeObject(ModelState.Values .SelectMany(state => state.Errors) .Select(error => error.ErrorMessage)); Debug.WriteLine(errors); if (await _chinookSupervisor.UpdatePlaylistAsync(input, ct)) { return(Ok(input)); } return(StatusCode(500)); } catch (Exception ex) { return(StatusCode(500, ex)); } }
public string GetPagedUserPlaylists([FromBody] PagedPlaylistRequest request) { PlaylistResponse playlistResponse = new PlaylistResponse(); List <Playlist> playlists = new List <Playlist>(); WebClient web = new WebClient(); web.Headers.Set("Authorization", $"Bearer {request.accessToken}"); JObject response = JObject.Parse(web.DownloadString(request.getUrl)); JArray items = response["items"].ToObject <JArray>(); foreach (JObject item in items) { Playlist playlist = new Playlist { name = item["name"].ToString(), href = item["href"].ToString(), uri = item["uri"].ToString(), }; playlists.Add(playlist); } playlistResponse.playlists = playlists; playlistResponse.previousUrl = response["previous"].ToString(); playlistResponse.nextUrl = response["next"].ToString(); playlistResponse.total = response["total"].ToString(); playlistResponse.limit = response["limit"].ToString(); string result = JsonConvert.SerializeObject(playlistResponse); return(result); }
public void GetBasicPlaylist_WhereArtistName_HasSongsByArtist(string artistName) { //arrange BasicArgument basicArgument = new BasicArgument { Results = 10, Dmca = true }; TermList artistTerms = new TermList { artistName }; basicArgument.Artist.AddRange(artistTerms); //act using (EchoNestSession session = new EchoNestSession(ConfigurationManager.AppSettings.Get("echoNestApiKey"))) { //act PlaylistResponse searchResponse = session.Query <Basic>().Execute(basicArgument); //assert Assert.IsNotNull(searchResponse); // output Console.WriteLine("Songs for : {0}", artistName); foreach (SongBucketItem song in searchResponse.Songs) { Console.WriteLine("\t{0} ({1})", song.Title, song.ArtistName); } Console.WriteLine(); } }
/// <summary>Constructor</summary> /// <param name="client">Spotify Sdk Client</param> /// <param name="response">Playlist Response</param> public SetPlaylistDialogViewModel(ISpotifySdkClient client, PlaylistResponse response) : base(client, new SetPlaylistViewModel(response)) { // Commands PrimaryCommand = new GenericCommand <SetPlaylistViewModel>(SetPlaylist); }
/// <summary> /// Set Playlist Extended Properties /// </summary> /// <param name="client">Spotify Sdk Client</param> /// <param name="response">Playlist Response</param> public static void SetPlaylistExtended(this ISpotifySdkClient client, PlaylistResponse response) { if (response != null) { client.CurrentPlaylist = response; response.IsOwnPlaylist = client.IsPlaylistOwnedByCurrentUser(response); response.IsEditable = response.IsOwnPlaylist || response.Collaborative; } }
public String UpdateTestSetFromUserDemand() { PlaylistResponse result = this.Execute(); if (result.Status.Code == ResponseCode.Success) { InsertSongs(result, null); } return(result.Status.Message); }
public void UpdateTestSetByGenre(String genre) { PlaylistResponse result = this.Execute(genre, 15); if (result.Status.Code != ResponseCode.Success) { return; } InsertSongs(result, genre); }
/// <summary> /// Attach Get Playlist Toggles /// </summary> /// <param name="client">Spotify Sdk Client</param> /// <param name="response">Playlist Response</param> public static async Task AttachGetPlaylistToggles( this ISpotifySdkClient client, PlaylistResponse response) { if (client.Config.IsAttachGetPlaylistToggles && response != null) { // Toggle Follow response.ToggleFollow = await client.GetToggleAsync( ToggleType.Follow, response.Id, (byte)FollowType.Playlist); } }
public async Task <IActionResult> GetPlaylist() { SongList list = await _playlistDispatcher.GetPlaylistByChannelId( 132, // P1 DateTime.Parse("2020-09-10"), DateTime.Parse("2020-09-13"), 100); PlaylistResponse model = CreateModel(list); return(Ok(model)); }
public async Task <PlaylistResponse> AddPlaylistAsync(PlaylistResponse newPlaylistViewModel, CancellationToken ct = default) { var playlist = new Playlist { Name = newPlaylistViewModel.Name }; playlist = await _playlistRepository.AddAsync(playlist, ct); newPlaylistViewModel.PlaylistId = playlist.PlaylistId; return(newPlaylistViewModel); }
/// <summary> /// Enumerates videos included in the specified playlist. /// </summary> public async IAsyncEnumerable <Video> GetVideosAsync(PlaylistId id) { var encounteredVideoIds = new HashSet <string>(); var index = 0; while (true) { var response = await PlaylistResponse.GetAsync(_httpClient, id, index); var countDelta = 0; foreach (var video in response.GetVideos()) { var videoId = video.GetId(); // Skip already encountered videos if (!encounteredVideoIds.Add(videoId)) { continue; } yield return(new Video( videoId, video.GetTitle(), video.GetAuthor(), video.GetChannelId(), video.GetUploadDate(), video.GetDescription(), video.GetDuration(), new ThumbnailSet(videoId), video.GetKeywords(), new Engagement( video.GetViewCount(), video.GetLikeCount(), video.GetDislikeCount() ) )); countDelta++; } // Videos loop around, so break when we stop seeing new videos if (countDelta <= 0) { break; } index += countDelta; } }
public async Task <bool> UpdatePlaylistAsync(PlaylistResponse playlistViewModel, CancellationToken ct = default) { var playlist = await _playlistRepository.GetByIdAsync(playlistViewModel.PlaylistId, ct); if (playlist == null) { return(false); } playlist.PlaylistId = playlistViewModel.PlaylistId; playlist.Name = playlistViewModel.Name; return(await _playlistRepository.UpdateAsync(playlist, ct)); }
/// <summary> /// Gets the metadata associated with the specified playlist. /// </summary> public async Task <Playlist> GetAsync(PlaylistId id) { var response = await PlaylistResponse.GetAsync(_httpClient, id); return(new Playlist( id, response.GetTitle(), response.TryGetAuthor(), response.TryGetDescription() ?? "", new Engagement( response.TryGetViewCount() ?? 0, response.TryGetLikeCount() ?? 0, response.TryGetDislikeCount() ?? 0 ))); }
public void GetStaticPlaylist_WhereMoodAndStyle_HasVarietyOfArtists(string title, string styles, string moods) { //arrange TermList styleTerms = new TermList(); foreach (string s in styles.Split(',')) { styleTerms.Add(s); } TermList moodTerms = new TermList(); foreach (string s in moods.Split(',')) { moodTerms.Add(s); } StaticArgument staticArgument = new StaticArgument { Results = 25, Adventurousness = 0.4, Type = "artist-description", Variety = 0.4 /* variety of artists */ }; staticArgument.Styles.AddRange(styleTerms); staticArgument.Moods.AddRange(moodTerms); //act using (EchoNestSession session = new EchoNestSession(ConfigurationManager.AppSettings.Get("echoNestApiKey"))) { //act PlaylistResponse searchResponse = session.Query <Static>().Execute(staticArgument); //assert Assert.IsNotNull(searchResponse); Assert.IsNotNull(searchResponse.Songs); Assert.IsTrue(searchResponse.Songs.Any()); // output Console.WriteLine("Songs for : {0}", title); foreach (SongBucketItem song in searchResponse.Songs) { Console.WriteLine("\t{0} ({1})", song.Title, song.ArtistName); } Console.WriteLine(); } }
/// <summary> /// Enumerates videos returned by the specified search query. /// </summary> /// <param name="searchQuery">The term to look for.</param> /// <param name="firstPage">Sets how many page should be skipped from the beginning of the search.</param> /// <param name="takePage">Limits how many page should be requested to complete the search.</param> public async IAsyncEnumerable <Video> GetVideosAsync(string searchQuery, int firstPage, int takePage) { var encounteredVideoIds = new HashSet <string>(); for (var page = firstPage; page < firstPage + takePage; page++) { var response = await PlaylistResponse.GetSearchResultsAsync(_httpClient, searchQuery, page); var countDelta = 0; foreach (var video in response.GetVideos()) { var videoId = video.GetId(); // Skip already encountered videos if (!encounteredVideoIds.Add(videoId)) { continue; } yield return(new Video( videoId, video.GetTitle(), video.GetAuthor(), video.GetChannelId(), video.GetUploadDate(), video.GetDescription(), video.GetDuration(), new ThumbnailSet(videoId), video.GetKeywords(), new Engagement( video.GetViewCount(), video.GetLikeCount(), video.GetDislikeCount() ) )); countDelta++; } // Videos loop around, so break when we stop seeing new videos if (countDelta <= 0) { break; } } }
public async Task <ActionResult <PlaylistResponse> > Post([FromBody] PlaylistResponse input, CancellationToken ct = default) { try { if (input == null) { return(BadRequest()); } return(StatusCode(201, await _chinookSupervisor.AddPlaylistAsync(input, ct))); } catch (Exception ex) { return(StatusCode(500, ex)); } }
/// <summary> /// Gets the metadata associated with the specified playlist. /// </summary> public async Task <Playlist> GetAsync(string id) { var response = await PlaylistResponse.GetAsync(_httpClient, id); var thumbnails = response .GetVideos() .FirstOrDefault()? .GetId() .Pipe(i => new ThumbnailSet(i)); return(new Playlist( id, response.GetTitle(), response.TryGetAuthor(), response.TryGetDescription() ?? "", thumbnails)); }
/// <summary> /// Enumerates videos included in the specified playlist. /// </summary> public async IAsyncEnumerable <PlaylistVideo> GetVideosAsync(PlaylistId id) { var encounteredVideoIds = new HashSet <string>(); var continuationToken = ""; while (true) { var response = await PlaylistResponse.GetAsync(_httpClient, id, continuationToken); foreach (var video in response.GetPlaylistVideos()) { var videoId = video.GetId(); // Skip already encountered videos if (!encounteredVideoIds.Add(videoId)) { continue; } // Skip deleted videos if (string.IsNullOrEmpty(video.GetChannelId())) { continue; } yield return(new PlaylistVideo( videoId, video.GetTitle(), video.GetAuthor(), video.GetChannelId(), video.GetDescription(), video.GetDuration(), video.GetViewCount(), new ThumbnailSet(videoId) )); } continuationToken = response.TryGetContinuationToken(); if (string.IsNullOrEmpty(continuationToken)) { break; } } }
public void GetStaticPlaylist_WhereMoodAndStyle_HasVarietyOfArtists(string title, string styles, string moods) { TermList styleTerms = new TermList(); foreach (string s in styles.Split(',')) { styleTerms.Add(s); } TermList moodTerms = new TermList(); foreach (string s in moods.Split(',')) { moodTerms.Add(s); } StaticArgument staticArgument = new StaticArgument { Results = 25, Adventurousness = 0.4, Type = "artist-description", Variety = 0.4 /* variety of artists */ }; staticArgument.Styles.AddRange(styleTerms); staticArgument.Moods.AddRange(moodTerms); using (var session = new EchoNestSession(ApiKey)) { PlaylistResponse searchResponse = session.Query <Static>().Execute(staticArgument); Assert.IsNotNull(searchResponse); Assert.IsNotNull(searchResponse.Songs); Assert.IsTrue(searchResponse.Songs.Any()); System.Diagnostics.Debug.WriteLine("Songs for : {0}", title); foreach (SongBucketItem song in searchResponse.Songs) { System.Diagnostics.Debug.WriteLine("\t{0} ({1})", song.Title, song.ArtistName); } } }
public async Task FetchThumbnailsAndPlaylistCounts() { int numLists = 0; if (ServiceAccessor.ConnectedToInternet()) { // Get the playlists for the game PlaylistResponse playResponse = await ServiceAccessor.GetCategoryPlaylists(GameModel.categories.ToList()); foreach (Category cat in GameModel.categories) { cat.playlists = playResponse.playlists[cat.categoryId]; } // Count the playlists and get a thumbnail foreach (KeyValuePair <string, BindableCollection <Playlist> > entry in playResponse.playlists) { numLists += entry.Value.Count; if (Thumbnail == "ms-appx:///Assets/hudl-mark-gray.png") { foreach (Playlist playlist in entry.Value) { if (playlist.thumbnailLocation != null) { Thumbnail = playlist.thumbnailLocation; Stretch = "UniformToFill"; } } } } } else { foreach (Category cat in GameModel.categories) { numLists += cat.playlists.Count; } } //Populate the NumPlaylists field with the counter NumPlaylists = numLists.ToString(); }
/// <summary> /// Enumerates videos returned by the specified search query. /// </summary> /// <param name="searchQuery">The term to look for.</param> /// <param name="startPage">Sets how many page should be skipped from the beginning of the search.</param> /// <param name="pageCount">Limits how many page should be requested to complete the search.</param> public async IAsyncEnumerable <PlaylistVideo> GetVideosAsync(string searchQuery, int startPage, int pageCount) { var encounteredVideoIds = new HashSet <string>(); var continuationToken = ""; for (var page = 0; page < startPage + pageCount; page++) { var response = await PlaylistResponse.GetSearchResultsAsync(_httpClient, searchQuery, continuationToken); if (page >= startPage) { foreach (var video in response.GetVideos()) { var videoId = video.GetId(); // Skip already encountered videos if (!encounteredVideoIds.Add(videoId)) { continue; } yield return(new PlaylistVideo( videoId, video.GetTitle(), video.GetAuthor(), video.GetChannelId(), video.GetDescription(), video.GetDuration(), video.GetViewCount(), new ThumbnailSet(videoId) )); } } continuationToken = response.TryGetContinuationToken(); if (string.IsNullOrEmpty(continuationToken)) { break; } } }
/// <summary> /// Gets the metadata associated with the specified playlist. /// </summary> public async Task <Playlist> GetAsync(PlaylistId id) { var response = await PlaylistResponse.GetAsync(_httpClient, id); var thumbnails = response .GetVideos() .FirstOrDefault()? .GetId() .Pipe(i => new ThumbnailSet(i)); return(new Playlist( id, response.GetTitle(), response.TryGetAuthor(), response.TryGetDescription() ?? "", thumbnails, new Engagement( response.TryGetViewCount() ?? 0, response.TryGetLikeCount() ?? 0, response.TryGetDislikeCount() ?? 0 ))); }
private void InsertSongs(PlaylistResponse result, string genre) { for (int i = 0; i < result.Songs.Count; i++) { var track = result.Songs[i]; Song song = database.Song.FindByName(track.Title); this.UpdateSong(song, track.ArtistName, genre); TheEchoNest echosong = database.TheEchoNest.FindBySongName(song.Name); if (echosong == null) { continue; } this.UpdateAudioProperties(echosong, track); echosong.Song = song; SaveIntoDatabase(); } }
private async Task <Video> GetVideoFromMixPlaylistAsync(VideoId id) { var playlistInfo = await PlaylistResponse.GetAsync(_httpClient, "RD" + id.Value); var video = playlistInfo.GetVideos().First(x => x.GetId() == id.Value); return(new Video( id, video.GetTitle(), video.GetAuthor(), video.GetChannelId(), video.GetUploadDate(), video.GetDescription(), video.GetDuration(), new ThumbnailSet(id), video.GetKeywords(), new Engagement( video.GetViewCount(), video.GetLikeCount(), video.GetDislikeCount() ) )); }
private PlaylistData CreateEchonestPlaylist(string apiKey) { var seedArtists = new TermList(); seedArtists.Add(Query); StaticArgument staticArgument = new StaticArgument { Results = 40, Artist = seedArtists, Type = "artist-radio" }; using (var session = new EchoNestSession(apiKey)) { PlaylistResponse searchResponse = session.Query <Static>().Execute(staticArgument); var playlistData = new PlaylistData(); playlistData.Items = new List <PlaylistDataItem>(); playlistData.Description = Query; playlistData.Title = string.Format("{0} playlist", Query); playlistData.SearchKeys = new List <string>(); foreach (var song in searchResponse.Songs) { var item = new PlaylistDataItem(); item.Artist = song.ArtistName; item.Title = song.Title; playlistData.Items.Add(item); var searchKey = string.Format("{0} {1}", item.Artist, item.Title); playlistData.SearchKeys.Add(searchKey); } return(playlistData); } }
/// <summary> /// Enumerates videos included in the specified playlist. /// </summary> public async IAsyncEnumerable <Video> GetVideosAsync(string id) { var encounteredstrings = new HashSet <string>(); var index = 0; while (true) { var response = await PlaylistResponse.GetAsync(_httpClient, id, index); var countDelta = 0; foreach (var video in response.GetVideos()) { var videoId = video.GetId(); // Skip already encountered videos if (!encounteredstrings.Add(videoId)) { continue; } //TODO yield return(null); countDelta++; } // Videos loop around, so break when we stop seeing new videos if (countDelta <= 0) { break; } index += countDelta; } }
public void GetPlaylistByArtistOrSong(string query) { var seedArtists = new TermList(); seedArtists.Add(query); StaticArgument staticArgument = new StaticArgument { Results = 40, Artist = seedArtists, Type = "artist-radio" }; using (var session = new EchoNestSession(ApiKey)) { PlaylistResponse searchResponse = session.Query <Static>().Execute(staticArgument); Assert.IsNotNull(searchResponse); Assert.IsNotNull(searchResponse.Songs); Assert.IsTrue(searchResponse.Songs.Any()); Assert.AreEqual(40, searchResponse.Songs.Count); } }