private void Preview_Artist(object sender, EventArgs e, SeveralTracks tracks, PrivateProfile user, BitmapImage bimage, Grid grid) { int track = 0; Add_Hover(grid); string previewURL = null; System.Threading.Tasks.Task.Delay(25); // Get the preview url from the first song in the playlist while (previewURL == null) { previewURL = tracks.Tracks[track].PreviewUrl; track++; if (track > tracks.Tracks.Count) { return; } } if (previewURL != null) { previewer.Open(new Uri(previewURL)); previewer.Play(); userCover.Source = bimage; userCover.SetValue(HeightProperty, DependencyProperty.UnsetValue); userCover.SetValue(WidthProperty, DependencyProperty.UnsetValue); } }
public string getSongs(string artistID) { string url = "http://myconcert1.azurewebsites.net/api/Spotify/getArtistInfo/" + artistID; string resp = Models.UtilityMethods.getMethod(url); if (resp == "{\"followers\":\"\",\"popularity\":\"\",\"image\":\"\",\"spotifyID\":\"\"}") { return("{\"name\":\"\",\"songs\":\"\",\"url\":\"\"}"); } else { SeveralTracks tracks = spotify.GetArtistsTopTracks(artistID, "CR"); var Songs = new Dictionary <string, object>(); ArrayList individualData = new ArrayList(); for (int t = 0; t < 5; t++) { var diccB = new Dictionary <string, object>(); diccB.Add("name", tracks.Tracks[t].Name); diccB.Add("url", tracks.Tracks[t].PreviewUrl); individualData.Add(diccB); } Songs.Add("songs", individualData); return(Models.UtilityMethods.diccTOstrinJson(Songs)); } }
/// <summary> /// Returns a string that contains the URL of a 30-second preview mp3 for the given artist /// </summary> /// <param name="artistName"> Artist for whom to get the preview </param> /// <returns> /// String that contains the URL of a 30-second preview mp3 for the given artist /// </returns> public async Task <string> GetPreviewUrl(string artistName) { try { // Authorize Spotify API credentials Token token = await auth.DoAuthAsync(); SpotifyWebAPI api = new SpotifyWebAPI() { TokenType = token.TokenType, AccessToken = token.AccessToken }; // Get the track from Spotify API artistName = FormatArtistName(artistName); SearchItem item = api.SearchItems(artistName, SearchType.Artist); SeveralTracks tracks = api.GetArtistsTopTracks(item.Artists.Items[0].Id, "US"); FullTrack track = api.GetTrack(tracks.Tracks[0].Id); return(track.PreviewUrl); } catch { return("(Spotify preview not available)"); } }
public ActionResult Recommendations(string trackId, string artistId) { CustomToken token = ViewBag.Token; if (token.IsTokenEmpty()) { return(null); } var recommendations = _paradifyService.GetRecommendations(token, trackId, artistId); if (recommendations != null && recommendations.Tracks != null && recommendations.Tracks.Count > 0) { SeveralTracks tracks = _paradifyService.GetTracks(recommendations.Tracks.Select(t => t.Id).ToList(), token); if (tracks != null && tracks.Tracks != null && tracks.Tracks.Count > 0) { return(PartialView("~/Views/Shared/_RecommendedSongListShort.cshtml", tracks.Tracks)); } } return(PartialView("~/Views/Shared/_RecommendedSongListShort.cshtml", null)); }
private void Populate_Artists() { PrivateProfile user = _spotify.GetPrivateProfile(); Paging <FullArtist> artists = _spotify.GetUsersTopArtists(limit: 28); BitmapImage userArt = new BitmapImage(); userArt.BeginInit(); try { userArt.UriSource = new Uri(user.Images[0].Url, UriKind.Absolute); } catch { userArt.UriSource = new Uri("https://source.unsplash.com/random/600x600", UriKind.Absolute); } userArt.EndInit(); foreach (FullArtist artist in artists.Items) { Grid grid = new Grid(); // Get the image URL BitmapImage bimage = new BitmapImage(); bimage.BeginInit(); bimage.UriSource = new Uri(artist.Images[1].Url, UriKind.Absolute); bimage.EndInit(); // Bind the image to a brush ImageBrush imageBrush = new ImageBrush(); imageBrush.ImageSource = bimage; imageBrush.Stretch = System.Windows.Media.Stretch.UniformToFill; // Create the image container Ellipse ellipse = new Ellipse(); ellipse.Height = 100; ellipse.Width = 100; ellipse.Fill = imageBrush; ellipse.Margin = new Thickness(0, 10, 0, 0); ellipse.VerticalAlignment = System.Windows.VerticalAlignment.Top; // Create the song text TextBlock tBlock = new TextBlock(); tBlock.Text = artist.Name; tBlock.FontSize = 16; tBlock.Margin = new Thickness(0, 0, 0, 35); tBlock.VerticalAlignment = System.Windows.VerticalAlignment.Bottom; tBlock.HorizontalAlignment = System.Windows.HorizontalAlignment.Center; tBlock.Foreground = (SolidColorBrush) new BrushConverter().ConvertFromString("#FFC8C8C8"); // Create the event handlers SeveralTracks tracks = _spotify.GetArtistsTopTracks(artist.Id, user.Country); grid.MouseEnter += new MouseEventHandler((s, e) => Preview_Song(s, e, tracks.Tracks[0].Id, bimage, grid)); grid.MouseLeave += new MouseEventHandler((s, e) => Stop_Preview(s, e, userArt, grid)); grid.MouseDown += ((s, e) => Open_Artist(s, e, tracks)); grid.Cursor = Cursors.Hand; grid.Children.Add(ellipse); grid.Children.Add(tBlock); uArtists.Children.Add(grid); } }
private void Play_Artist(object sender, MouseEventArgs e, SeveralTracks tracks) { List <string> songs = new List <string>(); tracks.Tracks.ForEach((track) => songs.Add(track.Uri)); _ = _spotify.ResumePlayback(uris: songs, offset: ""); }
//creates the playlist from the selected artist private Playlist getPlaylistFromArtist(SeveralArtists relatedArtists, int size, int range) { List <string> genres = new List <string>(); int relatedArtistsCount = relatedArtists.Artists.Count; int artists = (int)((range / 5.0) * relatedArtistsCount); var rand = new Random(); Playlist returnedPlaylist = new Playlist(); FullTrack track = new FullTrack(); Dictionary <string, string> trackLengths = new Dictionary <string, string>(); List <string> playlistURIs = new List <string>(); SeveralTracks tracks = new SeveralTracks { Tracks = new List <FullTrack>() }; for (int i = 0; i < artists; i++) { tracks.Tracks.AddRange(_spotify.GetArtistsTopTracks(relatedArtists.Artists[i].Id, "US").Tracks); } //shuffles the list of tracks int n = tracks.Tracks.Count; while (n > 1) { n--; int k = rand.Next(n + 1); FullTrack temp = tracks.Tracks[k]; tracks.Tracks[k] = tracks.Tracks[n]; tracks.Tracks[n] = temp; } int count = 0; int iterations = 0; if (tracks.Tracks.Count != 0) { do { track = tracks.Tracks[iterations]; if (track != null && !returnedPlaylist.hasTrack(track.Id)) { trackLengths.Add(track.Id, getTrackLengthString(track.DurationMs)); returnedPlaylist.TrackList.Add(track); playlistURIs.Add(track.Uri); count++; } iterations++; } while (count < size && iterations < tracks.Tracks.Count); } TempData["TrackLengths"] = trackLengths; TempData["PlaylistURIs"] = playlistURIs; return(returnedPlaylist); }
public IEnumerator LoadUsersFollowedArtists() { yield return(new WaitForSeconds(2)); FollowedArtists followedArtists = spotifyManagerScript.GetUsersFollowedArtists(); if (followedArtists == null || followedArtists.Artists.Items.Count == 0) { Debug.LogError("followedArtists is null/empty"); } else { for (int i = 0; i < meshRenderers.Length; i++) { string followedArtistsImageURL = null; if (followedArtists.Artists.Items[i].Images.Count > 0) { followedArtistsImageURL = followedArtists.Artists.Items[i].Images[0].Url; } GameObject meshRendererGameObject = meshRenderers[i].transform.gameObject; PlaylistScript playlistScript = meshRendererGameObject.GetComponent <PlaylistScript>(); WWW imageURLWWW = null; if (followedArtistsImageURL != null) { imageURLWWW = new WWW(followedArtistsImageURL); yield return(imageURLWWW); meshRenderers[i].material.mainTexture = imageURLWWW.texture; } playlistScript.setPlaylistName(followedArtists.Artists.Items[i].Name); playlistScript.setPlaylistURI(followedArtists.Artists.Items[i].Uri); playlistScript.fullArtist = followedArtists.Artists.Items[i]; SeveralTracks artistTopTracks = spotifyManagerScript.GetArtistsTopTracks(followedArtists.Artists.Items[i].Id); playlistScript.audioAnalysisCustom = new AudioAnalysisCustom(spotifyManagerScript.GetAudioAnalysis(artistTopTracks.Tracks[0].Id)); if (imageURLWWW != null) { playlistScript.sprite = ConvertWWWToSprite(imageURLWWW); saveLoad.SaveTextureToFilePNG(Converter.ConvertWWWToTexture(imageURLWWW), "userFollowedArtist" + i + ".png"); } playlistScript.artistId = followedArtists.Artists.Items[i].Id; saveLoad.savedUserFollowedArtists.Add(new PlaylistScriptData(playlistScript)); } } }
public SeveralTracks GetArtistsTopTracks(string artistID) { if (privateProfile == null || privateProfile.Country == null || privateProfile.Country == "") { Debug.LogError("Invalid Private Profile, Defaulting to Ireland"); SeveralTracks artistTopTracks = _spotify.GetArtistsTopTracks(artistID, "IE"); return(artistTopTracks); } else { SeveralTracks artistTopTracks = _spotify.GetArtistsTopTracks(artistID, privateProfile.Country); return(artistTopTracks); } }
private void playArtist() { //just plays the artists top song if (artistId != "") { script = spotifyManager.GetComponent <Spotify>(); SeveralTracks artistTopTracks = script.GetArtistsTopTracks(artistId); if (artistTopTracks != null) { script.PlaySongUri(artistTopTracks.Tracks[0].Uri); } } else { Debug.LogError("artistId is empty"); } }
public string getChef(string artistID) { var chefAverage = new Dictionary <string, object>(); SeveralTracks tracks = spotify.GetArtistsTopTracks(artistID, "CR"); var average = 0.0; for (int i = 0; i < 3; i++) { var individualValue = 0.0; AudioFeatures audio = spotify.GetAudioFeatures(tracks.Tracks[1].Id); individualValue = (audio.Speechiness * 20) + (audio.Instrumentalness * 20) + (audio.Valence * 20) + (audio.Energy * 20) + (audio.Danceability * 20); average += individualValue; } chefAverage.Add("average", average / 3); return(Models.UtilityMethods.diccTOstrinJson(chefAverage)); }
public async Task <IEnumerable <SpotifyTrack> > GetArtistTopTracksAsync(string id, string country = "US") { SeveralTracks artistsTopTracksAsync = await this.RunConfig.Api.GetArtistsTopTracksAsync(id, country); IEnumerable <SpotifyTrackInfo> infos = artistsTopTracksAsync.Tracks.Select(track => new SpotifyTrackInfo(track)); if (this.RunConfig.Config.LazyLoad) { List <SpotifyTrack> tracks = new List <SpotifyTrack>(); foreach (SpotifyTrackInfo info in infos) { tracks.Add(await this.RunConfig.TrackConverter.CreateSpotifyTrackAsync(info, true)); } return(tracks); } return(await this.RunConfig.TrackConverter.CreateSpotifyTracksAsync(infos)); }
public IEnumerator Test_Spotify_GetArtistsTopTracks() { Spotify spotify = new Spotify(); spotify.privateProfile = new PrivateProfile(); spotify.privateProfile.Country = "IE"; spotify.TestSetup(); //Vince Staples string artistId = "68kEuyFKyqrdQQLLsmiatm"; SeveralTracks artistTopTracks = spotify.GetArtistsTopTracks(artistId); yield return(null); Debug.Log(artistTopTracks.Tracks[0].Name); Assert.IsFalse(artistTopTracks.HasError()); }
private async Task <string[]> getSeveralTracksNamesAsync(string[] uris) { string[] id = new string[uris.Length]; for (int i = 0; i < id.Length; i++) { id[i] = uris[i].Substring(14); } string[] tracksNames = new string[uris.Length]; for (int i = 0; i < uris.Length; i += 50) { int amount = (i + 50 > uris.Length) ? uris.Length - i : 50; SeveralTracks s = await api.GetSeveralTracksAsync(id.ToList().GetRange(i, amount)); //Gettet nur 50x for (int j = 0; j < s.Tracks.Count; j++) { tracksNames[i + j] = s.Tracks[j].Name; } } return(tracksNames); }
public async void LoadNewArtistDetails(string artistName) { SearchItem artistSearchResults = await _api.SearchItemsAsync(artistName, SearchType.Artist, 1, 0); var artist = artistSearchResults.Artists.Items.FirstOrDefault(); if (artist != null) { await LoadArtistImageFromApi(artist.Images[0].Url); SeveralTracks artistsTopTracks = await _api.GetArtistsTopTracksAsync(artist.Id, "us"); ArtistTopTracks = new ObservableCollection <FullTrack>(artistsTopTracks.Tracks); RelatedArtists = new ObservableCollection <FullArtistWithImage>(); await LoadRelatedArtists(artist); await LoadSongLyrics(MusicViewModel.GetInstance().CurrentlyPlayedSong.Title, artist.Name); await LoadArtistBio(artist.Name); } }
public IEnumerator loadTopArtists() { yield return(new WaitForSeconds(2)); usersTopArtists = spotifyManagerScript.GetUsersTopArtists(); if (usersTopArtists == null) { Debug.LogError("usersTopArtists is null"); } else { for (int i = 0; i < meshRenderers.Length; i++) { string featuredPlaylistImageURL = usersTopArtists.Items[i].Images[0].Url; GameObject meshRendererGameObject = meshRenderers[i].transform.gameObject; PlaylistScript playlistScript = meshRendererGameObject.GetComponent <PlaylistScript>(); WWW imageURLWWW = new WWW(featuredPlaylistImageURL); yield return(imageURLWWW); meshRenderers[i].material.mainTexture = imageURLWWW.texture; playlistScript.setPlaylistName(usersTopArtists.Items[i].Name); playlistScript.setPlaylistURI(usersTopArtists.Items[i].Uri); playlistScript.fullArtist = usersTopArtists.Items[i]; playlistScript.artistId = usersTopArtists.Items[i].Id; playlistScript.sprite = ConvertWWWToSprite(imageURLWWW); SeveralTracks artistTopTracks = spotifyManagerScript.GetArtistsTopTracks(usersTopArtists.Items[i].Id); playlistScript.audioAnalysisCustom = new AudioAnalysisCustom(spotifyManagerScript.GetAudioAnalysis(artistTopTracks.Tracks[0].Id)); saveLoad.SaveTextureToFilePNG(ConvertWWWToTexture(imageURLWWW), "topArtist" + i + ".png"); saveLoad.savedTopArtists.Add(new PlaylistScriptData(playlistScript)); } } }
//creates a playlist from the selected track private Playlist getPlaylistFromTrack(List <SeveralArtists> relatedArtistsList, int size, int range, string searchTrackId) { int relatedArtistsCount = 0; List <string> genres = new List <string>(); SeveralArtists reOrderedArtists = new SeveralArtists(); reOrderedArtists.Artists = new List <FullArtist>(); foreach (var artistList in relatedArtistsList) { relatedArtistsCount += artistList.Artists.Count; } int artistsAmount = (int)((range / 5.0) * relatedArtistsCount); //in the case that the song has multiple artists, //i don't want the list of related artists to be: related artists from the 1st, then 2nd then 3rd artist etc... //i want them to be spread out evenly to give a better playlist based on the songs artists for (int i = 0; i < relatedArtistsCount; i++) { for (int j = 0; j < relatedArtistsList.Count; j++) { if (i < relatedArtistsList[j].Artists.Count) { reOrderedArtists.Artists.Add(relatedArtistsList[j].Artists[i]); } } } var rand = new Random(); Playlist returnedPlaylist = new Playlist(); FullTrack track = new FullTrack(); SeveralTracks tracks = new SeveralTracks { Tracks = new List <FullTrack>() }; for (int i = 0; i < artistsAmount; i++) { tracks.Tracks.AddRange(_spotify.GetArtistsTopTracks(reOrderedArtists.Artists[i].Id, "US").Tracks); } //shuffles the list of tracks int n = tracks.Tracks.Count; while (n > 1) { n--; int k = rand.Next(n + 1); FullTrack temp = tracks.Tracks[k]; tracks.Tracks[k] = tracks.Tracks[n]; tracks.Tracks[n] = temp; } Dictionary <string, string> trackLengths = new Dictionary <string, string>(); int count = 0; int iterations = 0; if (tracks.Tracks.Count != 0) { do { track = tracks.Tracks[iterations]; if (track != null && !returnedPlaylist.hasTrack(track.Id)) { trackLengths.Add(track.Id, getTrackLengthString(track.DurationMs)); returnedPlaylist.TrackList.Add(track); playlistURIs.Add(track.Uri); count++; } iterations++; } while (count < size && iterations < tracks.Tracks.Count); } TempData["PlaylistURIs"] = playlistURIs; TempData["TrackLengths"] = trackLengths; return(returnedPlaylist); }
/** * @brief Solicita dato de una cancion en especifico. Retorna el nombre * @param partist El nombre del artista. * @param pindex indice para acceder a alguna cancion de la lista. * @return Nombre de la cancion. */ public string searchNameTrack(string pidartist, int pindex) { SeveralTracks tracks = _spotify.GetArtistsTopTracks(pidartist, "CR"); return(tracks.Tracks[pindex].Name); }