private async Task <T> PerformRequest <T>(Func <Task <T> > request, string errorMsg, bool retry) where T : BasicModel { T response = await request(); if (response == null || response.StatusCode() == HttpStatusCode.NoContent) { return(null); } LogReturnedValueIfError(errorMsg, response); var statusCode = response.StatusCode(); if (statusCode == (HttpStatusCode)431) { logger.Debug("HTTP 431 received: a new instance of SpotifyWebApi will be created."); this._spotifyWebApi = null; // Retry if (retry) { response = await this.PerformRequest(request, errorMsg, false).ConfigureAwait(false); } } return(response); }
static Worker() { LocalApi = new SpotifyAPI.Local.SpotifyLocalAPI(); WebApi = new SpotifyAPI.Web.SpotifyWebAPI(); WebApi.UseAuth = false; }
public WebAPI() { _spotify = new SpotifyAPI.Web.SpotifyWebAPI { UseAuth = false }; }
async Task UserLogin() { SpotifyAPI = await Spotify.UserLogin("7f08980f1dae4f3d98a40d44ef235b03"); UserProfile = await SpotifyAPI.GetPrivateProfileAsync(); txtUserProfile.Text = "Logged in as: " + UserProfile.DisplayName; lvArticles.SelectionChanged += SelectedArticleChanged; }
public LocalControl() { InitializeComponent(); _spotify = new SpotifyLocalAPI(); _spotifyWEB = new SpotifyAPI.Web.SpotifyWebAPI(); _spotify.OnPlayStateChange += _spotify_OnPlayStateChange; _spotify.OnTrackChange += _spotify_OnTrackChange; _spotify.OnTrackTimeChange += _spotify_OnTrackTimeChange; _spotify.OnVolumeChange += _spotify_OnVolumeChange; //_spotify.SynchronizingObject = this; artistLinkLabel.Click += (sender, args) => Process.Start(artistLinkLabel.Tag.ToString()); albumLinkLabel.Click += (sender, args) => Process.Start(albumLinkLabel.Tag.ToString()); titleLinkLabel.Click += (sender, args) => Process.Start(titleLinkLabel.Tag.ToString()); //SpotifyAPI.Example.WebControl.RunAuthorization(); Connect(); }
public HttpResponseMessage Get() { string artistId = "3zunDAtRDg7kflREzWAhxl"; //var result = DownloadData<FullArtist>(string.Format("https://api.spotify.com/v1/artists/" + artistId)); var api = new SpotifyAPI.Web.SpotifyWebAPI() { AccessToken = this.AccessToken.AccessToken, TokenType = this.AccessToken.TokenType, UseAuth = true }; var artists = new List <FullArtist>(); var tenArtists = api.GetFollowedArtists(10); artists.AddRange(tenArtists.Artists.Items); while (artists.Count < tenArtists.Artists.Total) { var lastArtistId = artists.Last().Id; tenArtists = api.GetFollowedArtists(10, lastArtistId); artists.AddRange(tenArtists.Artists.Items); } var artistsByGenre = new Dictionary <string, List <FullArtist> >(); foreach (var artist in artists) { var genresForArtist = artist.Genres.Count == 0 ? new List <string> { "Unknown genre" } : artist.Genres; addArtistToCollection(genresForArtist, artist, artistsByGenre); } return(this.Request.CreateResponse(HttpStatusCode.OK, artistsByGenre)); }
public HttpResponseMessage GetAlbumsByArtists(string[] artistIds) { var result = new List <SimpleAlbum>(); var api = new SpotifyAPI.Web.SpotifyWebAPI() { AccessToken = this.AccessToken.AccessToken, TokenType = this.AccessToken.TokenType, UseAuth = true }; foreach (var artistId in artistIds) { var albumPage = api.GetArtistsAlbums(artistId, SpotifyAPI.Web.Enums.AlbumType.All); result.AddRange(albumPage.Items); } return(this.Request.CreateResponse(HttpStatusCode.OK, result)); }
public SpotifyManager() { spotClient = null; spotWeb = null; spotClientConnected = false; }
void _auth_OnResponseReceivedEvent(Token token, string state) { _auth.StopHttpServer(); if (state != "XSS") { return; } if (token.Error != null) { return; } _spotify = new SpotifyAPI.Web.SpotifyWebAPI { UseAuth = true, AccessToken = token.AccessToken, TokenType = token.TokenType }; check = false; }
public SpotifyModel GetSpotifyModel() { _auth = new ImplicitGrantAuth { RedirectUri = "http://localhost:8000", ClientId = "26d287105e31491889f3cd293d85bfea", Scope = Scope.UserReadPrivate | Scope.UserReadEmail | Scope.PlaylistReadPrivate | Scope.UserLibrarayRead | Scope.UserReadPrivate | Scope.UserFollowRead | Scope.UserReadBirthdate, State = "XSS" }; _auth.OnResponseReceivedEvent += _auth_OnResponseReceivedEvent; _auth.StartHttpServer(8000); _auth.DoAuth(); SpotifyModel sm = new SpotifyModel(); _spotifyLocal = new SpotifyLocalAPI(); if (!SpotifyLocalAPI.IsSpotifyRunning()) { return sm; } if (!SpotifyLocalAPI.IsSpotifyWebHelperRunning()) { return sm; } bool successful = _spotifyLocal.Connect(); if (successful) { UpdateInfos(); _spotifyLocal.ListenForEvents = true; sm.IsPlaying = true; try { sm.SongTitle = _currentTrack.TrackResource.Name; sm.VotedItemsDictionary = GetDictionaryDetails(sm.SongTitle); sm.SongArtist = _currentTrack.ArtistResource.Name; Bitmap derp = new Bitmap(_currentTrack.GetAlbumArt(AlbumArtSize.Size320)); Byte[] imgFile; var stream = new MemoryStream(); derp.Save(stream, ImageFormat.Png); imgFile = stream.ToArray(); sm.SongAlbumArt = _currentTrack.GetAlbumArtUrl(AlbumArtSize.Size320); sm.IsPlaying = true; stream.Close(); sm.Tracks = GetPlaylists(); int index = 0; foreach (var track in sm.Tracks) { if (track.title.Equals(_currentTrack.TrackResource.Name)) { break; } index++; } if (index == 0) index++; sm.PreviousSongAlbumArt = sm.Tracks[index - 1].albumArt; sm.PreviousSongTitle = sm.Tracks[index - 1].title; sm.PreviousSongArtist = sm.Tracks[index - 1].artist; if (index + 1 >= sm.Tracks.Count) index = 0; else index++; sm.NextSongAlbumArt = sm.Tracks[index].albumArt; sm.NextSongTitle = sm.Tracks[index].title; sm.NextSongArtist = sm.Tracks[index].artist; _auth = null; _spotifyLocal = null; _spotify = null; } catch (Exception e) { } } if (Winner) { sm.Truncate(); Winner = false; } string ip = Request.UserHostAddress; sm.IsValidIP = sm.IsValidVote(ip); return sm; }