public List <SpotifyItem> GetSpotifyItems() { List <SpotifyItem> spotifyItems = new List <SpotifyItem>(); var spotifyItem1 = new SpotifyItem { Artist = "The Killers", Song = "Runaways" }; var spotifyItem2 = new SpotifyItem { Artist = "U2", Song = "With or without you" }; var spotifyItem3 = new SpotifyItem { Artist = "Coldplay", Song = "Yellow" }; spotifyItems.Add(spotifyItem1, spotifyItem2, spotifyItem3); return(spotifyItems); }
void ExtractTrack(string response) { SpotifyItem item = SpotifyItem.CreateFromJSON(response); /* If no track is being listened */ if (item == null) { trackName.text = "No track selected"; albumName.text = ""; artistName.text = ""; deviceName.text = ""; } else { SpotifyTrack track = item.item; /* Setting the current value of the progress bar */ slider.value = item.progress_ms; deviceName.text = "Listening on " + item.device.name; if (!item.is_playing && !isPaused) { animator.SetBool("paused", true); isPaused = true; } else if (item.is_playing && isPaused) { animator.SetBool("paused", false); isPaused = false; } /* Check to see if track has changed */ if (trackName.text != track.name) { trackName.text = track.name; artistName.text = "by " + track.artists[0].name; /* Setting the max value of the progress bar */ slider.maxValue = track.duration_ms; /* If album is a new one, download image and change image */ if (track.album.name != albumName.text) { albumName.text = track.album.name; animator.SetBool("loading", true); StartCoroutine(DownloadAlbumImage(track.album.images)); } } } }
private static async Task <YoutubeItems> GetYoutubeItems(SpotifyItem track) { var youtubeRequest = new HttpRequestMessage(HttpMethod.Get, $"https://www.googleapis.com/youtube/v3/search?q={track.Track.Artists[0].Name}-{track.Track.Name}&type=video&part=id&maxResults=1&key={YOUTUBE_APP_KEY}"); var youtubeRequestResponse = await _httpClient.SendAsync(youtubeRequest); youtubeRequestResponse.EnsureSuccessStatusCode(); var youtubeItems = await youtubeRequestResponse.Content.ReadAsAsync <YoutubeItems>(); return(youtubeItems); }
private async void getPlaylist() { //show progress indicator setProgressIndicator(true); SystemTray.ProgressIndicator.Text = "Getting your Tweet Mix"; try { //set an int as the id int id = 0; //build twitter url string url = twitter.getUrl(username, apiAttempt); //call twitter vaI base api class, we only want the response code at this point string apiResponse = await twitter.Call(url); //if the response did not come back null or contain an error code if (apiResponse != null || apiResponse.Contains("Error: ")) { //use json.net to turn json into an opject TwitterItems apiData = JsonConvert.DeserializeObject <TwitterItems>(apiResponse); //loop through and set everything to the list foreach (Status data in apiData.statuses) { PlayListItems items = new PlayListItems(); //add id to list items.ID = id.ToString(); //add twitter details to list items.Message = data.text; items.ProfileImage = data.user.profile_image_url; items.Username = data.user.name; //go spilt the message via the Song class Song song = spiltMessage(data.text); //add those values to the list items.ArtistName = song.Artist; items.SongName = song.Track; //now we need the artowrk so go get it from spotify as its more reliable SpotifyApi spotify = new SpotifyApi(); //build a url of the songname to go ask spotify for its details string spotifySearchUrl = spotify.BuildSearchUrl(song.Track); string response = await spotify.Call(spotifySearchUrl); //add in method so that calls can be used again if (response != null) { List <SpotifyItem> tracks = new List <SpotifyItem>(); SpotifyItem spotifyApiData = JsonConvert.DeserializeObject <SpotifyItem>(response); //call the spotify embed api to go get artwork string spotifyArtowrkUrl = spotify.buildEmbedUrl(spotifyApiData.tracks[0].href); string artworkResponse = await spotify.Call(spotifyArtowrkUrl); SpotifyImageItems imageData = JsonConvert.DeserializeObject <SpotifyImageItems>(artworkResponse); items.AlbumArtworkUrl = imageData.thumbnail_url; } Items.Add(items); id++; } } else if (apiResponse.Contains("Error: ")) { //lets go see what error it is int errorCode = twitter.getCorrectError(apiResponse); if (errorCode == 429 && apiAttempt < 3) { setProgressIndicator(false); //call again; callAgain(); } else { string errorMessage = twitter.ErrorMesssage(errorCode); showError(errorMessage); callAgain(); setProgressIndicator(false); } } setProgressIndicator(false); } catch (UnauthorizedAccessException) { MessageBox.Show("Wifi is disabled in phone settings"); } catch (Exception e) { MessageBox.Show(e.Message); setProgressIndicator(false); callAgain(); } setDataContext(); }