/// <summary> /// Grabs all the albums from the artist the user just selected. /// </summary> /// <param name="artist">The individual artist.</param> public void SearchArtistsAlbums(FullArtist artist) { searchLoadingSpinner.IsVisible = true; searchLoadingSpinner.IsRunning = true; artistsScrollLayout.IsVisible = false; songsView.IsVisible = false; albumsTopLeftLayout.Children.Clear(); albumsTopRightLayout.Children.Clear(); songsView.Root.Clear(); albumIndex = 1; Task.Factory.StartNew(() => artistsAlbums = _spotify.GetArtistsAlbums(artist.Id)) .ContinueWith(antecendent => { foreach (var album in artistsAlbums.Items) { albumIndex++; var imagesCount = album.Images.Count; UpdateAlbumList(album, album.Images[imagesCount / 2].Url, album.Name); } searchLoadingSpinner.IsVisible = false; searchLoadingSpinner.IsRunning = false; albumsScrollLayout.IsVisible = true; }, TaskScheduler.FromCurrentSynchronizationContext() ); }
public string getArtistInfo(string artistID) { FullArtist artist = spotify.GetArtist(artistID); if ((artist.StatusCode().ToString()) == "OK") { var info = new Dictionary <string, object>(); info.Add("followers", artist.Followers.Total); info.Add("popularity", artist.Popularity); info.Add("image", artist.Images[0].Url); info.Add("spotifyID", artistID); return(Models.UtilityMethods.diccTOstrinJson(info)); } else { return("{\"followers\":\"\",\"popularity\":\"\",\"image\":\"\",\"spotifyID\":\"\"}"); } /*} * catch (Exception e) * { * return "{\"followers\":\"\",\"popularity\":\"\",\"image\":\"\",\"spotifyID\":\"\"}"; * }*/ }
public IMusic ParseUri(string uri) { //https://open.spotify.com/track/2fTdRdN73RgIgcUZN33dvt //https://open.spotify.com/album/2N367tN1eIXrHNVe86aVy4?si=A-1kS4F4Tfy2I_PYEDVhMA //https://open.spotify.com/artist/5cj0lLjcoR7YOSnhnX0Po5 uri = NormalizeSpotifyUri(uri); string[] uriParts = uri.Split("/"); if (uriParts.Contains("track")) { FullTrack sTrack = ConverterBot.Clients.SpotifyClient.Tracks.Get(uriParts.Last( )).Result; return(new Track(sTrack.Name, sTrack.Artists.First( ).Name, sTrack.Album.Name, 0, sTrack.Id)); } if (uriParts.Contains("album")) { string id; if (uriParts.Last( ).Contains("?")) { id = uriParts.Last( ).Split("?").First( ); } else { id = uriParts.Last( ); } FullAlbum sAlbum = ConverterBot.Clients.SpotifyClient.Albums.Get(id).Result; return(new Album(sAlbum.Name, sAlbum.Artists.First( ).Name, sAlbum.ReleaseDate, sAlbum.Id)); } if (uriParts.Contains("artist")) { FullArtist sArtist = ConverterBot.Clients.SpotifyClient.Artists.Get(uriParts.Last( )).Result; List <SimpleAlbum>?sArtistAlbums = ConverterBot.Clients.SpotifyClient.Artists.GetAlbums(uriParts.Last( )).Result.Items; SimpleAlbum sSampleAlbum = sArtistAlbums?.First( ); Album sampleAlbum = new Album(sSampleAlbum?.Name, sArtist.Name, sSampleAlbum?.ReleaseDate, sSampleAlbum?.Id); return(new Artist(sArtist.Name, sampleAlbum, null, sArtist.Id)); } return(null); }
public async Task GetArtists( ) { foundArtists = new List <FullArtist>(); albumsByArtist = new Dictionary <FullArtist, List <SimpleAlbum> >(); for (int i = 0; i < artistNames.Count; i++) { FullArtist artistFromName = await currentForm.spotifyConnection.GetArtistFromName(artistNames[i]); if (artistFromName != null) { albumsByArtist.Add(artistFromName, new List <SimpleAlbum>()); foundArtists.Add(artistFromName); currentForm.DisplayString(string.Format("Found artist {0} from name {1}", artistFromName.Name, artistNames[i])); } else { currentForm.DisplayString(string.Format("Could not find artist {0} on spotify", artistNames[i])); } } currentForm.DisplayString("Done finding artists on spotify"); for (int i = 0; i < artistNames.Count; i++) { currentForm.DisplayString(string.Format("Finding text from artist {0}", foundArtists[i].Name)); await GetAlbumsFromArtist(i); } }
private async void ScrapeButton_Click(object sender, RoutedEventArgs e) { ScrapeButton.IsEnabled = false; try { Paging <PlaylistTrack> tracks = GetPlaylistTracks(); bool skip = true; foreach (PlaylistTrack plt in tracks.Items) { SimpleArtist artist = plt.Track.Artists.FirstOrDefault(); //// skip the ones that we've processed :\ //if(artist.Id == "0z6zRFzl5njXWLVAisXQBz") //{ // skip = false; // continue; //} //if (skip) { continue; } FullArtist fullArtist = _spotify.GetArtist(artist.Id); await ScrapeArtistInfo(fullArtist); } } catch (System.Exception ex) { ArtistProgressList.Items.Add("** Error: " + ex.Message); } }
/// <summary> /// Converts FullArtist to ArtistDetails /// </summary> /// <param name="results"></param> /// <returns></returns> private static ArtistDetails ConvertToArtistDetails(FullArtist result) { try { // Return null if null is passed if (result == null) { return(null); } // Convert and return the results return(new ArtistDetails { Id = result.Id, Name = result.Name, Genres = result.Genres, ImageUrl = result.Images?.Select(x => x.Url).FirstOrDefault() }); } catch (Exception Ex) { // Throw a new exception to bubble up throw new Exception("Exception Occurred: " + Ex.Message); } }
/** * @brief Solicita dato de un artista en especifico. Retorna la popularidad del artista de interes. * @param partist El nombre del artista. * @return La popularidad del artista, segun spotify. */ public int searchArtistPopularity(string partist) { int popularity = 0; FullArtist info_artist = null; SearchItem item = _spotify.SearchItems(partist, SearchType.Artist); try { //Busca el dato for (int i = 0; i < item.Artists.Items.Count; i++) { if (partist == item.Artists.Items[i].Name) { info_artist = item.Artists.Items[i]; } } popularity = info_artist.Popularity; } catch (Exception) { popularity = 0; } return(popularity); }
private Performer ConvertArtistToPerfomer(FullArtist artist) { return(new Performer { SpotifyId = artist.Id, SpotifyArtistObj = artist, }); }
public async Task <SubscribedArtist> RetrieveSubscribedArtist(string id) { IEnumerable <SimpleAlbum> albums = await dataLayer.ExecuteQuery(new AlbumsForArtistQuery(id)).ToListAsync(); FullArtist artist = await dataLayer.ExecuteQuery(new ArtistByIdQuery(id)); return(new SubscribedArtist(id, artist.Name, albums.Select(album => album.Id))); }
public string getImage(string artistID) { FullArtist artist = spotify.GetArtist(artistID); var image = new Dictionary <string, object>(); image.Add("URL", artist.Images[0].Url); return(Models.UtilityMethods.diccTOstrinJson(image)); }
/// <summary> /// Similar to updating albums, the spotify API is called, limiting only 20 results, and creating new Frame views within a stack layout. /// </summary> /// <param name="artist">The artist.</param> /// <param name="artistImageSource">The artist's image url.</param> /// <param name="artistName"> The name of the artist.</param> public void UpdateArtistList(FullArtist artist, ImageSource artistImageSource, string artistName, int artistPopularity) { var artistPopularityString = artistPopularity.ToString(); artistFrame = new Frame { Padding = 0, Margin = 0, GestureRecognizers = { new TapGestureRecognizer { Command = new Command(() =>{ SearchArtistsAlbums(artist); }) }, }, Content = new StackLayout { Children = { new Xamarin.Forms.Image { HeightRequest = 200, Aspect = Aspect.Fill, Source = artistImageSource, }, new Label { Text = artistName, LineBreakMode = LineBreakMode.TailTruncation, TextColor = Color.FromHex("212121"), FontSize = 12, Margin = new Thickness(7, 0, 0, 0), }, new Label { Text = "Popularity: " + artistPopularityString, LineBreakMode = LineBreakMode.TailTruncation, TextColor = Color.FromHex("757575"), FontSize = 10, Margin = new Thickness(7, -3, 0, 7), } } } }; // Places the Frame to the left. (if the index is an even number) if (artistIndex % 2 == 0) { artistsTopLeftLayout.Children.Add(artistFrame); } // Places the Frame to the right. (if the index is an odd number) else { artistsTopRightLayout.Children.Add(artistFrame); } }
private IEnumerator DisplayArtist() { FullArtist artist = spotifyScript.GetFullArtist(artistID); string artistImageURL = artist.Images[0].Url; WWW imageURLWWW = new WWW(artistImageURL); yield return(imageURLWWW); meshRenderer.material.mainTexture = imageURLWWW.texture; }
public async Task <Image> LoadRelatedArtistsImages(FullArtist artist) { using (WebClient webClient = new WebClient()) { var data = await webClient.DownloadDataTaskAsync(artist.Images.LastOrDefault().Url); var mem = new MemoryStream(data); return(Image.FromStream(mem)); } }
private ImportListItemInfo ParseFullArtist(FullArtist artist) { if (artist?.Name.IsNotNullOrWhiteSpace() ?? false) { return(new ImportListItemInfo { Artist = artist.Name, }); } return(null); }
private string GenerateMarkdown(FullArtist artist) { var searchQuery = GetSearchString(artist.Name); var sb = new StringBuilder(); sb.AppendLine($"{artist.Name}"); sb.AppendLine($"{GenerateMarkdownForAllSearchEngines(searchQuery)}"); sb.AppendLine($"artist popularity: {artist.Popularity} | genres: {string.Join(", ", artist.Genres)}"); return(sb.ToString()); }
private WebArtist CreateArtist(FullArtist artist) { var webArtist = CreateArtist(artist as SimpleArtist); webArtist.IsPartial = false; var image = artist.Images?.FirstOrDefault(); if (image != null) { webArtist.Artwork = new Uri(image.Url); } return(webArtist); }
/** * @brief Solicita dato de un artista en especifico. Retorna los generos del artista de interes. * @param partist El nombre del artista. * @return Lista de generos del artista, segun spotify. */ public List <string> searchArtistGenres(string partist) { FullArtist info_artist = null; SearchItem item = _spotify.SearchItems(partist, SearchType.Artist); //Busca el dato for (int i = 0; i < item.Artists.Items.Count; i++) { if (partist == item.Artists.Items[i].Name) { info_artist = item.Artists.Items[i]; } } return(info_artist.Genres); }
protected override async void OnSpotifyConnectionChanged(SpotifyClient client) { base.OnSpotifyConnectionChanged(client); if (client != null) { _artistInfo = await client.Artists.Get(ArtistId); } else { _artistInfo = null; } UpdateUI(); }
public async Task <List <SimpleAlbum> > GetAlbumsFromArtist(FullArtist artist) { Paging <SimpleAlbum> tempAlbumCollection = null; List <SimpleAlbum> totalAlbumsCollection = new List <SimpleAlbum>(); int startIndex = 0; do { tempAlbumCollection = await _spotify.GetArtistsAlbumsAsync(artist.Id, AlbumType.Album, 50, startIndex, "CA"); totalAlbumsCollection.AddRange(RemoveDuplicates(tempAlbumCollection.Items, totalAlbumsCollection)); startIndex += 50; }while (tempAlbumCollection.Items.Count == 50); return(totalAlbumsCollection); }
private void addArtistToCollection(List <string> genres, FullArtist artist, Dictionary <string, List <FullArtist> > artistsByGenre) { foreach (var genre in genres) { if (artistsByGenre.Keys.Contains(genre)) { artistsByGenre[genre].Add(artist); } else { artistsByGenre.Add(genre, new List <FullArtist> { artist }); } } }
public async Task LoadRelatedArtists(FullArtist artist) { var relatedArtists = await _api.GetRelatedArtistsAsync(artist.Id); foreach (var relatedArtist in relatedArtists.Artists.Take(5)) { if (relatedArtist != null) { Image smallImg = await LoadRelatedArtistsImages(relatedArtist); var ra = new FullArtistWithImage { FullArtist = relatedArtist, SmallImage = smallImg }; RelatedArtists.Add(ra); } } }
public IEnumerator Test_Spotify_GetFullArtist() { Spotify spotify = new Spotify(); spotify.TestSetup(); //Vince Staples string artistId = "68kEuyFKyqrdQQLLsmiatm"; FullArtist artist = spotify.GetFullArtist(artistId); yield return(null); Debug.Log(artist.Name); Assert.IsFalse(artist.HasError()); }
public ActionResult Index() { SpotifyWebAPI api = new SpotifyWebAPI(); List <String> artists = new List <string>(); ClientCredentialsAuth client = new ClientCredentialsAuth(); client.ClientId = "559a2c8e37d946d782cc29bb373a63f0"; client.ClientSecret = "23915a1a8a5e406ea1df5bc8baec36e4"; Token token = client.DoAuth(); api.AccessToken = token.AccessToken; api.UseAuth = true; api.UseAutoRetry = true; api.TokenType = "Bearer"; FullArtist homie = api.GetArtist("1KpCi9BOfviCVhmpI4G2sY"); return(View()); }
public async Task <ArtistDetails> GetArtist(Spotify sp, SpotterAzure_dbContext dbContext) { if (DateTime.Now.AddDays(-7) > this.TrueAt.Value || this.Details == null) { try { FullArtist features = await sp.spotify.Artists.Get(this.ArtistId); this.Details = JObject.FromObject(features).ToString(); dbContext.Update(this); } catch { return(null); } } return(JObject.Parse(this.Details).ToObject <ArtistDetails>()); }
public async void GetAndAddTopTracks(FullArtist artist, int trackCount, ProgressBarWrapperTask trackSearchTask) { int nextDelay = m_ViewModel.RequestStaggerer.GetNextDelay(); bool printLog = nextDelay % (RequestStaggerer.STAGGER_TIME * 10) == 0; await Task.Delay(nextDelay); if (printLog) { int remainingArtists = (m_ViewModel.RequestStaggerer.CurrentWait - nextDelay) / RequestStaggerer.STAGGER_TIME; m_ViewModel.VisualLogger.AddLine($"Top songs of artists remaining: {remainingArtists}"); } ArtistsTopTracksResponse response = await m_ViewModel.CurrentUser.Artists.GetTopTracks(artist.Id, new ArtistsTopTracksRequest("DE")); trackSearchTask.CompleteSection(trackCount); for (int i = 0; i < trackCount && i < response.Tracks.Count; i++) { m_ViewModel.Playlist.AddTrack(response.Tracks[i]); } }
protected override async void OnSpotifyConnectionChanged(SpotifyClient client) { base.OnSpotifyConnectionChanged(client); // On connect, if artist id set, then retrieve from API if (client != null && !string.IsNullOrEmpty(ArtistId)) { _artist = await client.Artists.Get(ArtistId); _dispatcher.Add(() => { UpdateUI(); }); } else if (_artist == null) { // Set to inactive if no artist set SetUIActive(false); } }
private static async Task <List <ArtistGenre> > CreateArtistGenres( FullArtist fullArtist, IRepositoryManager repositoryManager) { List <ArtistGenre> artistGenres = new List <ArtistGenre>(); HashSet <string> strippedGenres = fullArtist.Genres.Select(g => g.Replace(" ", "")).ToHashSet(); var existingGenres = await repositoryManager.GenreRepository.GetManyByCodeAsync(strippedGenres); var existingGenreCodes = existingGenres.Select(g => g.Code).ToHashSet(); foreach (var genre in fullArtist.Genres) { var strippedGenre = genre.Replace(" ", ""); var existingGenre = existingGenreCodes.Contains(strippedGenre) ? existingGenres.Where(g => g.Code == strippedGenre).FirstOrDefault() : null; if (existingGenre != null) { artistGenres.Add(new ArtistGenre { GenreId = existingGenre.Id }); } else { var newGenre = GenreFormattingHelper.CreateNewGenre(genre, strippedGenre); artistGenres.Add(new ArtistGenre { Genre = newGenre }); } } return(artistGenres); }
/** * Solicita dato de un artista * en especifico. Retorna la cantidad de * seguidores de un artista **/ /** * @brief Solicita dato de un artista en especifico. Retorna la cantidad de seguidores del artista de interes. * @param partist El nombre del artista. * @return Los seguidores del artista, segun spotify. */ public int searchArtistFollowers(string partist) { int followers = 0; FullArtist info_artist = null; SearchItem item = _spotify.SearchItems(partist, SearchType.Artist); try { //Busca el dato for (int i = 0; i < item.Artists.Items.Count; i++) { if (partist == item.Artists.Items[i].Name) { info_artist = item.Artists.Items[i]; } } followers = info_artist.Followers.Total; } catch (Exception) { followers = 0; } return(followers); }
/** * @brief Solicita dato de un artista en especifico. Retorna una de las imagenes de un artista proporcionada por spotify. * @param partist El nombre del artista. * @return Lista de imagenes del artista, proveida por spotify. * Ernesto: Modificacion de retorno */ public string searchArtistImages(string partist) { string url = null; FullArtist info_artist = null; SearchItem item = _spotify.SearchItems(partist, SearchType.Artist); try { //Busca el dato for (int i = 0; i < item.Artists.Items.Count; i++) { if (partist == item.Artists.Items[i].Name) { info_artist = item.Artists.Items[i]; } } url = info_artist.Images.ToArray()[0].Url; } catch (Exception) { url = "No_image"; } return(url); }
/*****************************************************************/ /** * @brief Solicita dato de un artista en especifico. Retorna el ID del artista de interes. * @param partist El nombre del artista. * @return El identificador del artista, segun spotify. */ public string searchArtistID(string partist) { string respuesta = ""; FullArtist info_artist = null; SearchItem item = _spotify.SearchItems(partist, SearchType.Artist); try { //Busca el dato for (int i = 0; i < item.Artists.Items.Count; i++) { if (partist == item.Artists.Items[i].Name) { info_artist = item.Artists.Items[i]; } } respuesta = info_artist.Id; } catch (Exception) { respuesta = ""; } return(respuesta); }