public SpotifyChecker() { spotifyApi = new SpotifyAPI(SpotifyAPI.GetOAuth(), "recordify.spotilocal.com"); cfid = spotifyApi.CFID; currentStatus = spotifyApi.Status; scanningThreadStart = new ThreadStart(getData); }
public AlbumQuery SearchForAlbum(string album) { SpotifyAPI api = new SpotifyAPI(); AlbumQuery returnedAlbum = api.GetAlbum(album); return(returnedAlbum); }
public SettingsWindow() { InitializeComponent(); try { _spotifyApi = new SpotifyAPI(SpotifyAPI.GetOAuth(), "127.0.0.1"); } catch (Exception ex) { MessageBox.Show("Feil oppstod ved initialisering av SpotifyAPI:" + Environment.NewLine + ex.Message, "En feil oppstod", MessageBoxButton.OK, MessageBoxImage.Error); Close(); return; } _timer = new DispatcherTimer(TimeSpan.FromSeconds(5), DispatcherPriority.Background, OnTimerTick, Application.Current.Dispatcher); _timer.Stop(); _statusModel = new StatusModel(); _statusModel.TaskbarIcon = TaskbarIcon; DataContext = _statusModel; TxtAuth.Text = Settings.Default.Auth; TxtUrl.Text = Settings.Default.ScrobbleUrl; ChkDebug.IsChecked = Settings.Default.Debug; ChkUrlEncoded.IsChecked = Settings.Default.UrlEncoded; }
public AlbumDetails GetAlbumDetails(string id) { SpotifyAPI api = new SpotifyAPI(); AlbumDetails returnedAlbum = api.GetAlbumDetails(id); return(returnedAlbum); }
static void Main(string[] args) { Console.WriteLine("SpotifyLocalAPI demonstration"); Console.WriteLine("By JariZ.nl 2012"); Console.WriteLine("Warning: This demo requires you to have Spotify open and running!"); Console.WriteLine(); Console.WriteLine("Authenticating..."); try { SpotifyAPI API = new SpotifyAPI(SpotifyAPI.GetOAuth(), "jariz-example.spotilocal.com"); Responses.CFID cfid = API.CFID; //It's required to get the contents of API.CFID before doing anything, even if you're not intending to do anything with the CFID if (cfid.error != null) { Console.WriteLine(string.Format("Spotify returned a error {0} (0x{1})", cfid.error.message, cfid.error.type)); Thread.Sleep(-1); } Responses.Status Current_Status = API.Status; if (cfid.error != null) { Console.WriteLine(string.Format("Spotify returned a error {0} (0x{1})", cfid.error.message, cfid.error.type)); Thread.Sleep(-1); } if (Current_Status.track != null) { Console.WriteLine(string.Format("You're listening to {0} - {1} from the album '{2}'", Current_Status.track.track_resource.name, Current_Status.track.artist_resource.name, Current_Status.track.album_resource.name)); } else { Console.WriteLine("You're not listening to any songs"); } Thread.Sleep(1000); //Pause playback Current_Status = API.Pause; Thread.Sleep(1000); //Resume playback Current_Status = API.Resume; Thread.Sleep(1000); //Play 'Evil Boy' API.URI = "spotify:track:3wcekXbEsDFv9OfyJe1q5d"; Current_Status = API.Play; Thread.Sleep(1000); //Get current album art and open it in browser string art = API.getArt(Current_Status.track.album_resource.uri); //get current art url Process.Start(art); //open url in browser Console.WriteLine(); Console.WriteLine("Tests complete."); } catch (Exception z) { Console.WriteLine("Unexpected error:\r\n" + z.ToString()); } Thread.Sleep(-1); }
/// <summary> /// Initializes a new instance of the <see cref="MainWindow" /> class. /// </summary> public MainWindow() { _mediaPlayer = new MediaPlayerConsumer(); InitializeComponent(); _spotify = new SpotifyAPI(); SetUserInfo(); CurrentPage.Content = new HomePage(); }
// http://localhost:5000/playlist/coordinates/10.5/10.5 public ContentResult GetLocationByCoordinates(double latitude, double longitude) { PlayListRecomedation playlist = new PlayListRecomedation(latitude, longitude); Category musicType = playlist.getRecomedation(); SpotifyAPI spotifyAPI = new SpotifyAPI(_configuration); string json = spotifyAPI.getListOfTracks(musicType); Console.WriteLine(json); return(Content(json, "application/json")); }
// http://localhost:5000/playlist/city/fortaleza public ContentResult GetLocationByName(string nameId) { PlayListRecomedation playlist = new PlayListRecomedation(nameId); Category musicType = playlist.getRecomedation(); SpotifyAPI spotifyAPI = new SpotifyAPI(_configuration); string json = spotifyAPI.getListOfTracks(musicType); Console.WriteLine(json); return(Content(json, "application/json")); }
private void InitSpot() { try { api = new SpotifyAPI(SpotifyAPI.GetOAuth()); cfid = api.CFID; initExcpt = null; } catch (Exception e) { initExcpt = e; } }
public static bool Play(string spotifyUrl = "") { if (!string.IsNullOrEmpty(spotifyUrl)) { Task.Run(() => SpotifyAPI.PlayURL(spotifyUrl)); } else { Task.Run(() => SpotifyAPI.Play()); } return(true); }
// Attempt to acquire the Spotify resources private void setupSpotify() { m_spotifyApiInstance = new SpotifyAPI(SpotifyAPI.GetOAuth(), "jariz-example.spotilocal.com"); m_cfid = m_spotifyApiInstance.CFID; if (m_cfid.error != null) { Console.WriteLine(string.Format("Spotify returned a error {0} (0x{1})", m_cfid.error.message, m_cfid.error.type)); // Thread.Sleep(-1); } else { // it was ok } }
static void Main(string[] args) { string clientID = "305dbadf23cd4d9688868eb01857b54b"; string redirectID = "http%3A%2F%2Flocalhost%3A62177"; string state = "123"; Scope scope = Scope.UserLibraryRead; SpotifyAPI api = new SpotifyAPI(clientID, redirectID, state, scope, true); string[] test = new string[2] { "1FpEcjbwwsSKIeCBzNKZdc", "2YDNDwQvsU0njt7Kq0xNRY" }; Console.WriteLine(api.GetSeveralAlbums(test)); Console.ReadLine(); }
/// <summary> /// Initialises the Spotify API. /// </summary> public Spotify() { string clientID = ApiKeys.GetSpotifyClientIdFromAppData(); string redirectID = "http%3A%2F%2Flocalhost%3A62177"; string state = "123"; List <Scope> scope = new List <Scope>() { Scope.UserReadPrivate, Scope.UserReadBirthdate, Scope.UserModifyPlaybackState, Scope.UserModifyPlaybackState, Scope.UserFollowRead, Scope.UserFollowModify, Scope.UserReadRecentlyPlayed, Scope.UserReadPlaybackState }; Api = new SpotifyAPI(clientID, redirectID, state, scope, true); }
public void Dispose() { lcd.Dispose(); cfid = null; api = null; spotTimer.Enabled = false; spotTimer.Dispose(); spotTimer = null; lcdTimer.Enabled = false; lcdTimer.Dispose(); lcdTimer = null; refreshTimer.Enabled = false; refreshTimer.Dispose(); refreshTimer = null; initExcpt = null; }
public static bool Init() { bool ret = false; try { _API = new SpotifyAPI(SpotifyAPI.GetOAuth(), "127.0.0.1"); //It's required to get the contents of API.CFID before doing anything, even if you're not intending to do anything with the CFID _cfid = _API.CFID; if (_cfid.error != null) { throw new Exception(string.Format("Spotify returned a error {0} (0x{1})", _cfid.error.message, _cfid.error.type)); } _Current_Status = _API.Status; if (_cfid.error != null) { throw new Exception(string.Format("Spotify returned a error {0} (0x{1})", _cfid.error.message, _cfid.error.type)); } _tmr = new Timer() { Interval = 5000, Enabled = true }; _tmr.Elapsed += _tmr_Elapsed; _tmr.Start(); ret = true; } catch (Exception ex) { Debug.WriteLine(ex.Message); ret = false; } return(ret); }
public static IMusicServiceStatus GetStatus() { var result = new MusicServiceStatus(); var status = SpotifyAPI.GetStatus(); if (status != null) { result.IsPlaying = status.Playing; result.Artist = status.Track?.ArtistResource?.Name; result.Track = status.Track?.TrackResource?.Name; result.Length = status.Track != null ? status.Track.Length : 0; result.Current = status.PlayingPosition; result.TrackSource = TrackSource.Spotify; if (status.Track != null && status.Track.AlbumResource != null) { result.AlbumArtWork = status.Track.GetAlbumArtUrl(AlbumArtSize.Size160); } } return(result); }
/// <summary> /// Gets the top tracks of an artist /// </summary> /// <param name="artistId"></param> private async void _GetTracks(string artistId) { try { IsLoading = true; var topTracks = await SpotifyAPI.GetTopTracks(artistId); if (topTracks != null && topTracks.Count > 0) { foreach (Track track in topTracks) { Tracks.Add(track); } } IsLoading = false; } catch (Exception e) { Console.WriteLine("Error Populate Tracks"); Console.WriteLine(e.Message); } }
/// <summary> /// Populates the list of artists refer to query /// </summary> /// <param name="query">string variable to artist searching</param> /// <returns></returns> public async Task _SearchArtists(string query) { try { IsLoading = true; var artistList = await SpotifyAPI.GetArtists(query.ToLower()); if (artistList != null && artistList.Count > 0) { Artists.Clear(); foreach (Artist artist in artistList) { Artists.Add(artist); } } IsLoading = false; } catch (Exception e) { Console.WriteLine("Error Populate Artists"); Console.WriteLine(e.Message); } }
public static void Pause() => Task.Run(() => SpotifyAPI.Pause());
public static void Dispose() { _API = null; _cfid = null; _tmr.Stop(); }
static void Main(string[] args) { string clientID = "305dbadf23cd4d9688868eb01857b54b"; string redirectID = "http%3A%2F%2Flocalhost%3A62177"; string state = "123"; List <Scope> scope = new List <Scope>() { Scope.UserReadPrivate, Scope.UserReadBirthdate, Scope.UserModifyPlaybackState, Scope.UserModifyPlaybackState, Scope.UserFollowRead, Scope.UserFollowModify, Scope.UserReadRecentlyPlayed, Scope.UserReadPlaybackState }; SpotifyAPI api = new SpotifyAPI(clientID, redirectID, state, scope, true); api.Authenticated += Api_Authenticated; Task.Run(() => { api.Authenticate(true); }); while (authenticated == false) { } /* * string[] albumIds = new string[2] {"1FpEcjbwwsSKIeCBzNKZdc", "2YDNDwQvsU0njt7Kq0xNRY"}; * * Console.WriteLine(api.GetSeveralAlbums(albumIds, Markets.AD));*/ /*List<AlbumType> albumTypes = new List<AlbumType>() * { * AlbumType.Single, AlbumType.Album, AlbumType.ApppearsOn, AlbumType.Compilation * }; * * Console.WriteLine(api.GetArtistsAlbums("2zFkwocH9Ah8KpUzydbcrO", albumTypes, 20, 0));*/ //Console.WriteLine(api.GetAlbumTracks("3tqWiJf0QKpxX2IItsAl24", Market.AD, 20, 0)); //Console.WriteLine(api.GetArtist("4F7Q5NV6h5TSwCainz8S5A")); /*List<string> artistIds = new List<string>() * { * "34W7ZCX0LZeJd8q6boKGOk", "4PDpGtF16XpqvXxsrFwQnN", "3HJzLaMbS0jMabxS3wttGk" * }; * * Console.WriteLine(api.GetSeveralArtists(artistIds));*/ //Console.WriteLine(api.GetArtistsTopTracks("6Zq5ky484xYTgxE6dQ8yHh", Market.AD)); //Console.WriteLine(api.GetArtistsRelatedArtists("34W7ZCX0LZeJd8q6boKGOk")); //Console.WriteLine(api.GetTrack("0hz62SbhrP77G1cajlwaEH", Market.ES)); /* List<string> trackids = new List<string>() * { * "250RLekaiL1q9qZer975Eg", "0pf9ik9MHYZnxEgDw3NYp0", "250RLekaiL1q9qZer975Eg", "0pf9ik9MHYZnxEgDw3NYp0" * };*/ /*Console.WriteLine(api.GetSeveralTracks(trackids, Market.ES));*/ //Console.WriteLine(api.GetAudioFeaturesForTrack("184r9uzj1Coildl16EK5Qz")); //Console.WriteLine(api.GetAudioFeaturesForSeveralTracks(trackids)); //Console.WriteLine(api.GetAudioAnalysisForTrack("4r1zlgDyILnZq9fEaSwFGd")); /*List<SearchType> searchTypes = new List<SearchType>() * { * SearchType.playlist, SearchType.album * }; * * Console.WriteLine(api.Search("roadhouse%20OR%20blues", searchTypes, Market.AD, 20, 0));*/ //Console.WriteLine(api.GetUsersPlaylists("name", 20, 0)); //Console.WriteLine(api.GetCurrentUsersPlaylists(10, 0)); //Console.WriteLine(api.GetPlaylist("5WzFmpYAKQ8frPXw5yIJtz", Market.AD)); //Console.WriteLine(api.GetPlaylistsTracks("5kIg55zaJKaFKgqrwOKffb", 20, 0)); //Console.WriteLine(api.CreatePlaylist("leonkouz", "test", false, "Name", false)); //Console.WriteLine(api.AddTrackToPlaylist("leonkouz", "1npLUC4yTNWePi0qGwbWN8", trackids)); //Console.WriteLine(api.RemoveTrackFromPlaylist("leonkouz", "1npLUC4yTNWePi0qGwbWN8", "0pf9ik9MHYZnxEgDw3NYp0")); /*Dictionary<string, int> trackIds = new Dictionary<string, int>() * { * {"0pf9ik9MHYZnxEgDw3NYp0", 1 }, * };*/ //Console.WriteLine(api.RemoveTracksFromPlaylist("leonkouz", "1npLUC4yTNWePi0qGwbWN8", trackIds, "y43RmddChW8L88cIjgqDdbTIdYl9bsb8i6u9JzO91F8wM3lUMCFsF2LIqLoQui4A")); //Console.WriteLine(api.ReorderPlaylistTracks("leonkouz", "1npLUC4yTNWePi0qGwbWN8", 0, 2, 3)); //Console.WriteLine(api.ChangePlaylistDetails("leonkouz", "1npLUC4yTNWePi0qGwbWN8", "new name", null, null, null)); //Console.WriteLine(api.GetUserProfile("leonkouz")); //Console.WriteLine(api.GetCurrentUserProfile()); //Console.WriteLine(api.GetCurrentUsersSavedTracks(Market.ES, 0, 0)); //Console.WriteLine(api.CheckCurrentUsersSavedTracks(trackids)); //Console.WriteLine(api.SaveTracksForCurrentUser(trackids)); //Console.WriteLine(api.RemoveTracksForCurrentUser(trackids)); //Console.WriteLine(api.GetCurrentUsersSavedAlbums(Market.AD)); //Console.WriteLine(api.CheckUsersSavedAlbums("02S1126Q5E4gUEtpTI6W38")); /*List<string> albumIds = new List<string>() * { * "4lVR2fg3DAUQpGVJ6DciHW", "7J0uECwRkAFLiZljgYFq1w" * };*/ //Console.WriteLine(api.SaveAlbumsForCurrentUser(albumIds)); //Console.WriteLine(api.RemoveAlbumsForCurrentUser(albumIds)); //Console.WriteLine(api.GetCurrentUsersTopTracks(20, 0, TimeRange.LongTerm)); //Console.WriteLine(api.GetCurrentUsersTopArtists(20, 0, TimeRange.LongTerm)); //Console.WriteLine(api.GetListOfNewReleases(20, 0)); //Console.WriteLine(api.GetFeaturedPlaylists("2018-02-01T09:01:02", 20, 0)); //Console.WriteLine(api.GetBrowseCategories(Market.BR, 20, 0)); //Console.WriteLine(api.GetCategoryPlaylist("dinner",Market.EC ,20, 0)); //Console.WriteLine(api.GetCurrentUsersFollowedArtists()); /* * List<string> userIds = new List<string>() * { * "tezzbian", "biggboris" * }; * * List<string> artistIds = new List<string>() * { * "41MozSoPIsD1dJM0CLPjZF", "6gzXCdfYfFe5XKhPKkYqxV" * };*/ //Console.WriteLine(api.CheckIfCurrentUserIsFollowingArtist("41MozSoPIsD1dJM0CLPjZF")); //Console.WriteLine(api.CheckIfCurrentUserIsFollowingArtists(artistIds)); //Console.WriteLine(api.CheckIfCurrentUserIsFollowingUser("tezzbian")); //Console.WriteLine(api.CheckIfCurrentUserIsFollowingUsers(userIds)); //Console.WriteLine(api.FollowUser("biggboris")); //Console.WriteLine(api.FollowUsers(userIds)); //Console.WriteLine(api.FollowArtist("3Nrfpe0tUJi4K4DXYWgMUX")); //Console.WriteLine(api.FollowArtists(artistIds)); //Console.WriteLine(api.UnfollowUser("tezzbian")); //Console.WriteLine(api.UnfollowUsers(userIds)); //Console.WriteLine(api.UnfollowArtist("31ID15xoalmnSgwPhHJZrR")); //Console.WriteLine(api.UnfollowArtists(artistIds)); //Console.WriteLine(api.CheckIfUsersFollowPlaylist("leonkouz", "5dbkqx1RxAiTf64YCfxocS", artistOrUserId)); //Console.WriteLine(api.FollowPlaylist("spotify", "37i9dQZF1DWVbckf5vh03w", false)); //Console.WriteLine(api.UnfollowPlaylist("spotify", "37i9dQZF1DWVbckf5vh03w")); //Console.WriteLine(api.GetCurrentUsersRecentlyPlayedTracks(20, Time.Before, "1518343202525")); //Console.WriteLine(api.GetCurrentPlaybackInformation(Market.AR)); //Console.WriteLine(api.TransferUsersPlayback("bad41f473b836de526e5c1cbac1b9f63ebe283d5", true)); //Console.WriteLine(api.GetUsersAvailableDevices()); //Console.WriteLine(api.GetUsersCurrentPlayingTrack(Market.AT)); //Console.WriteLine(api.Resume("bad41f473b836de526e5c1cbac1b9f63ebe283d5")); //Console.WriteLine(api.PlayTracks(trackids, 1)); //Console.WriteLine(api.PlayAlbum("5f8pMn2A5d5lKMDapYbCmp", 5)); //Console.WriteLine(api.PlayPlaylist("5LXyV8imf7zQ5eCXI5CQ8s", "tezzbian", 5)); //Console.WriteLine(api.PlayArtist("7ohlPA8dRBtCf92zaZCaaB")); //Console.WriteLine(api.Pause("13c53822b6a6f324e088becda0f6f052737d7d5c")); //Console.WriteLine(api.NextTrack("13c53822b6a6f324e088becda0f6f052737d7d5c")); //Console.WriteLine(api.PreviousTrack("13c53822b6a6f324e088becda0f6f052737d7d5c")); //Console.WriteLine(api.Seek(2500000, "13c53822b6a6f324e088becda0f6f052737d7d5c")); //Console.WriteLine(api.SetRepeatMode(RepeatState.track)); //Console.WriteLine(api.SetVolume(10, "13c53822b6a6f324e088becda0f6f052737d7d5c")); //Console.WriteLine(api.SetShuffleStatus(false, "13c53822b6a6f324e088becda0f6f052737d7d5c")); Console.ReadLine(); }
public Boolean IsFiltered(SpotifyAPI.Local.Models.Track iTrack, out FilterBase oFilter) { oFilter = null; if (TrackFilters.ContainsKey(iTrack.TrackResource.Uri)) { //we matched a specific track in the filters oFilter = TrackFilters[iTrack.TrackResource.Uri]; return (true); } else { //it's not a track filter so let's see if it's an artist uri filter if(ArtistFilters.ContainsKey(iTrack.ArtistResource.Uri)) { //we matched a specific artist in the filters oFilter = ArtistFilters[iTrack.ArtistResource.Uri]; return (true); } else { //it's not a specific artist filter so let's look for a name match foreach (ArtistFilter curArtistFilter in ArtistFilters.Values) { if(curArtistFilter.Field == ArtistFilter.FilterField.name) { if (iTrack.ArtistResource.Name.IndexOf(curArtistFilter.Value, StringComparison.InvariantCultureIgnoreCase) > -1) { //we matched the track by artist name in the filters oFilter = curArtistFilter; return (true); } } } } } //this track isn't filtered return (false); }
public static float GetVolume() => SpotifyAPI.GetSpotifyVolume();
public static void SetVolume(float volume) => SpotifyAPI.SetSpotifyVolume(volume);
public static void Previous() => SpotifyAPI.Previous();
public Server() { // Default message. Console.WriteLine( "This is the CampFire listener, if you keep this running in the background with Spotify open it will play tracks when they are recieved by the webpage.\r\n"); _api = new SpotifyAPI(SpotifyAPI.GetOAuth(), "SpotifyServer.spotilocal.com"); _currentStatus = _api.Status; _cfid = _api.CFID; FleckLog.Level = LogLevel.Debug; var allSockets = new List <IWebSocketConnection>(); var server = new WebSocketServer("ws://localhost:8181/CampFire"); server.Start(socket => { socket.OnOpen = () => { Console.WriteLine("Open connection."); // Add the new connection to our list so we can send messages back. allSockets.Add(socket); }; socket.OnClose = () => { Console.WriteLine("Closed connection, the CampFire webpage has been closed."); // Make sure we remove them from out list when we are not connected to em. allSockets.Remove(socket); }; socket.OnMessage = message => { // When a message is recieved it comes in the from NAME^spotify:track:oiasdoijasd so we split the string with ^ to get the name and uri. string[] details = message.Split('^'); // Don't ask why we have to do this, if we don't it borks. heh. string username = Convert.ToString(details[0]); string uri = Convert.ToString(details[1]); // Set our spotify to look at the new uri and then play it _api.URI = uri; _currentStatus = _api.Play; string trackName = _currentStatus.track.track_resource.name; string artistName = _currentStatus.track.artist_resource.name; // Message all users that X user has played X, we have to do this because there is no other way of telling the other people connecting WHO played what song allSockets.ToList().ForEach(s => s.Send(username + " played " + trackName + " - " + artistName)); Console.WriteLine("Playing: " + _currentStatus.track.track_resource.name + " - " + _currentStatus.track.artist_resource.name); }; }); var inpt = Console.ReadLine(); if (inpt != "exit") { Console.ReadLine(); } }