Ejemplo n.º 1
0
        /// <summary>
        /// Remove one or more tracks from the current user’s “Your Music” library.
        /// </summary>
        /// <param name="tracks"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        public async Task <bool> AreSaved(List <string> trackIds, AuthenticationToken token)
        {
            string tracksUri = CreateCommaSeperatedList(trackIds);
            var    json      = await HttpHelper.Get("https://api.spotify.com/v1/me/tracks/contains?ids=" + tracksUri, token);

            var obj = JsonConvert.DeserializeObject(json, new JsonSerializerSettings
            {
                TypeNameHandling       = TypeNameHandling.All,
                TypeNameAssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple
            });

            return(Convert.ToBoolean(obj.ToString().Replace("{", string.Empty).Replace("[", string.Empty).Replace("}", string.Empty).Replace("]", string.Empty).Trim()));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Search for a track
        /// </summary>
        /// <param name="trackName"></param>
        /// <param name="albumName"></param>
        /// <param name="artistName"></param>
        /// <param name="year"></param>
        /// <param name="genre"></param>
        /// <param name="upc"></param>
        /// <param name="isrc"></param>
        /// <param name="limit"></param>
        /// <param name="offset"></param>
        /// <returns></returns>
        public static async Task <Page <Track> > Search(string trackName,
                                                        string albumName  = "",
                                                        string artistName = "",
                                                        string year       = "",
                                                        string genre      = "",
                                                        string upc        = "",
                                                        string isrc       = "",
                                                        int limit         = 20,
                                                        int offset        = 0)
        {
            string queryString = "https://api.spotify.com/v1/search?q=track:" + trackName.Replace(" ", "%20");

            if (albumName != "")
            {
                queryString += "%20:album:" + albumName.Replace(" ", "%20");
            }
            if (artistName != "")
            {
                queryString += "%20:artist:" + artistName.Replace(" ", "%20");
            }
            if (year != "")
            {
                queryString += "%20:year:" + year.Replace(" ", "%20");
            }
            if (genre != "")
            {
                queryString += "%20:genre:" + genre.Replace(" ", "%20");
            }
            if (upc != "")
            {
                queryString += "%20:upc:" + upc.Replace(" ", "%20");
            }
            if (isrc != "")
            {
                queryString += "%20:isrc:" + isrc.Replace(" ", "%20");
            }

            queryString += "&limit=" + limit;
            queryString += "&offset=" + offset;
            queryString += "&type=track";

            var json = await HttpHelper.Get(queryString);

            var obj = JsonConvert.DeserializeObject <tracksearchresult>(json, new JsonSerializerSettings
            {
                TypeNameHandling       = TypeNameHandling.All,
                TypeNameAssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple
            });

            return(obj.tracks.ToPOCO <Track>());
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Get several tracks
        /// </summary>
        /// <param name="trackIds"></param>
        /// <returns></returns>
        public static async Task <List <Track> > GetTracks(List <string> trackIds)
        {
            var json = await HttpHelper.Get("https://api.spotify.com/v1/tracks?ids=" + CreateCommaSeperatedList(trackIds));

            var obj = JsonConvert.DeserializeObject <trackarray>(json, new JsonSerializerSettings
            {
                TypeNameHandling       = TypeNameHandling.All,
                TypeNameAssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple
            });

            List <Track> tracks = new List <Track>();

            foreach (var item in obj.tracks)
            {
                tracks.Add(item.ToPOCO());
            }

            return(tracks);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Get an artist's top tracks
        /// </summary>
        /// <param name="trackIds"></param>
        /// <returns></returns>
        public static async Task <List <Track> > GetArtistTopTracks(string artistId, string countryCode = "US")
        {
            var json = await HttpHelper.Get("https://api.spotify.com/v1/artists/" + artistId + "/top-tracks?country=" + countryCode);

            var obj = JsonConvert.DeserializeObject <trackarray>(json, new JsonSerializerSettings
            {
                TypeNameHandling       = TypeNameHandling.All,
                TypeNameAssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple
            });

            List <Track> tracks = new List <Track>();

            foreach (var item in obj.tracks)
            {
                tracks.Add(item.ToPOCO());
            }

            return(tracks);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Get an artist's related artists
        /// </summary>
        /// <param name="artistId"></param>
        /// <returns></returns>
        public static async Task <List <Artist> > GetRelatedArtists(string artistId)
        {
            var json = await HttpHelper.Get("https://api.spotify.com/v1/artists/" + artistId + "/related-artists");

            var obj = JsonConvert.DeserializeObject <artistarray>(json, new JsonSerializerSettings
            {
                TypeNameHandling       = TypeNameHandling.All,
                TypeNameAssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple
            });

            List <Artist> artists = new List <Artist>();

            foreach (var item in obj.artists)
            {
                artists.Add(item.ToPOCO());
            }

            return(artists);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Get a list of new album releases featured in Spotify (shown, for example, on a Spotify player’s “Browse” tab).
        /// </summary>
        /// <param name="token"></param>
        /// <param name="country"></param>
        /// <param name="limit"></param>
        /// <param name="offset"></param>
        /// <returns></returns>
        public async static Task <Page <Album> > GetNewReleases(AuthenticationToken token, string country = "", int limit = 20, int offset = 0)
        {
            var queryString = "https://api.spotify.com/v1/browse/new-releases?";

            queryString += "limit=" + limit;
            queryString += "&offset=" + offset;

            if (country != string.Empty)
            {
                queryString += "&country=" + country;
            }

            var json = await HttpHelper.Get(queryString, token);

            var obj = JsonConvert.DeserializeObject <albumsearchresult>(json, new JsonSerializerSettings
            {
                TypeNameHandling       = TypeNameHandling.All,
                TypeNameAssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple
            });

            return(obj.albums.ToPOCO <Album>());
        }
Ejemplo n.º 7
0
        /// <summary>
        /// If this object has a Next page get it
        /// else
        /// throw new Exception("Next page does not exist.");
        /// </summary>
        /// <returns></returns>
        public async Task <Page <T> > GetNextPage()
        {
            if (!HasNextPage)
            {
                throw new Exception("Next page does not exist.");
            }

            var json = await HttpHelper.Get(Next);

            if (typeof(T) == typeof(Album))
            {
                var obj = JsonConvert.DeserializeObject <page <album> >(json, new JsonSerializerSettings
                {
                    TypeNameHandling       = TypeNameHandling.All,
                    TypeNameAssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple
                });

                return(obj.ToPOCO <T>());
            }

            if (typeof(T) == typeof(Artist))
            {
                var obj = JsonConvert.DeserializeObject <page <artist> >(json, new JsonSerializerSettings
                {
                    TypeNameHandling       = TypeNameHandling.All,
                    TypeNameAssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple
                });

                return(obj.ToPOCO <T>());
            }

            if (typeof(T) == typeof(Track))
            {
                var obj = JsonConvert.DeserializeObject <page <track> >(json, new JsonSerializerSettings
                {
                    TypeNameHandling       = TypeNameHandling.All,
                    TypeNameAssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple
                });

                return(obj.ToPOCO <T>());
            }

            if (typeof(T) == typeof(Playlist))
            {
                var obj = JsonConvert.DeserializeObject <page <playlist> >(json, new JsonSerializerSettings
                {
                    TypeNameHandling       = TypeNameHandling.All,
                    TypeNameAssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple
                });

                return(obj.ToPOCO <T>());
            }

            if (typeof(T) == typeof(PlaylistTrack))
            {
                var obj = JsonConvert.DeserializeObject <page <playlisttrack> >(json, new JsonSerializerSettings
                {
                    TypeNameHandling       = TypeNameHandling.All,
                    TypeNameAssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple
                });

                return(obj.ToPOCO <T>());
            }

            return(null);
        }