Пример #1
0
        /// <summary>
        /// Gets the users 'Dashboard' aka 'Stream'
        /// </summary>
        /// <param name="type">The filtered type</param>
        /// <param name="tracksOnly"></param>
        /// <param name="startIndex">The index to begin from</param>
        /// <param name="length">The length of how many items to retrive</param>
        /// <returns></returns>
        public static List <int> GetNextDashboard(DashboardType type = DashboardType.All, bool tracksOnly = true)
        {
            // Buffer for returned activity
            List <int> list = new List <int>();

            // Check if there is more to get
            if (_dashboardHref == "stop")
            {
                return(list);
            }

            // Set url variable
            string url = "";

            if (_dashboardHref != null)
            {
                url = _dashboardHref;
            }
            else
            {
                // Switch for what dashboard to get
                switch (type)
                {
                default:
                case DashboardType.All:
                    url = "me/activities";
                    break;

                case DashboardType.Affiliated:
                    url = "me/activities/tracks/affiliated";
                    break;

                case DashboardType.Exclusive:
                    url = "me/activities/tracks/exclusive";
                    break;

                case DashboardType.Own:
                    url = "me/activities/all/own";
                    break;
                }
                url += SoundCloudCore.Pagination;
            }

            // Get Response
            var res = SoundCloudCore.SendRequest <Dictionary <string, dynamic> >(url);

            _dashboardHref = res.ContainsKey("next_href") ? res["next_href"] : "stop";

            foreach (var dict in res["collection"])
            {
                if (tracksOnly && dict["type"].Value.Contains("track"))
                {
                    list.Add(JsonConvert.DeserializeObject <Track>(dict["origin"].ToString()).ID);
                    System.IO.File.AppendAllText("log.log", dict["origin"].ToString());
                }
            }
            return(list);
        }
Пример #2
0
        /// <summary>
        /// Searches for Users using a filter
        /// </summary>
        /// <param name="q">Query string</param>
        /// <param name="startIndex">StartIndex of response</param>
        /// <param name="length">Length of how many tracks to get</param>
        public static List <User> Search(string q, int startIndex = 0, int length = 10)
        {
            // Validate Param
            startIndex = startIndex > 8000 ? 8000 : startIndex;
            length     = length > 200 ? 200 : length;

            // Get Response
            return(SoundCloudCore.SendRequest <List <User> >(string.Format("users?q={0}&offset={1}&limit={2}", q, startIndex, length)));
        }
Пример #3
0
 public static bool Like(int id, bool dislike = true)
 {
     try {
         SoundCloudCore.SendRequest <object>("me/favorites/" + id + "?", dislike ? HttpRequestMethod.DELETE : HttpRequestMethod.PUT);
         return(true);
     }
     catch {
         return(false);
     }
 }
Пример #4
0
        /// <summary>
        /// Gets a list of Playlists
        /// </summary>
        /// <param name="startIndex">Start index of search</param>
        /// <param name="length">Length of how many Playlists to get</param>
        public List <Playlist> GetPlaylists(int startIndex = 0, int length = 10)
        {
            // Validate Param
            startIndex = startIndex > 8000 ? 8000 : startIndex;
            length     = length > 200 ? 200 : length;

            if (startIndex + length > PlaylistsCount)
            {
                startIndex = 0;
                length     = PlaylistsCount - 1;
            }
            // Get Response
            return(SoundCloudCore.SendRequest <List <Playlist> >(string.Format("users/{0}/playlists?offset={1}&limit={2}", ID, startIndex, length)));
        }
Пример #5
0
        /// <summary>
        /// Gets a list of Playlists
        /// </summary>
        /// <param name="startIndex">Start index of search</param>
        /// <param name="length">Length of how many Playlists to get</param>
        public static List <Playlist> GetPlaylists(int startIndex = 0, int limit = 10)
        {
            // Validate Param
            startIndex = startIndex > 8000 ? 8000 : startIndex;
            limit      = limit > 200 ? 200 : limit;

            if ((startIndex + limit) > PlaylistsCount)
            {
                startIndex = 0;
                limit      = PlaylistsCount - 1;
            }
            // Get Response
            return(SoundCloudCore.SendRequest <List <Playlist> >(string.Format("me/playlists?offset={0}&limit={1}", startIndex, limit)));
        }
Пример #6
0
        /// <summary>
        /// Gets a Track from it's unique ID
        /// </summary>
        /// <param name="id">ID of track</param>
        public static int GetTrack(int id, bool reload = false)
        {
            // Check if this track already exists
            if (!reload)
            {
                if (SoundCloudCore.Tracks.ContainsKey(id))
                {
                    return(id);
                }
            }
            // Get Track
            var track = SoundCloudCore.SendRequest <Track>("tracks/" + id + "?");

            // Add to collection
            SoundCloudCore.Tracks.Add(track.ID, track);
            return(track.ID);
        }
Пример #7
0
        /// <summary>
        /// Refreshes the connected users info
        /// </summary>
        public static void Refresh()
        {
            var res = SoundCloudCore.SendRequest <Dictionary <string, object> >("me?");

            // Format Strings
            Username    = (string)res["username"];
            Permalink   = (string)res["permalink"];
            AvatarUrl   = (string)res["avatar_url"] + "?" + SoundCloudCore.PostToken;
            Fullname    = (string)res["full_name"];
            Description = (string)res["description"];
            Website     = (string)res["website"];

            // Format Integers
            ID              = Convert.ToInt32(res["id"]);
            TracksCount     = Convert.ToInt32(res["track_count"]);
            PlaylistsCount  = Convert.ToInt32(res["playlist_count"]);
            FollowersCount  = Convert.ToInt32(res["followers_count"]);
            FollowingsCount = Convert.ToInt32(res["followings_count"]);
            LikesCount      = Convert.ToInt32(res["public_favorites_count"]);
        }
Пример #8
0
        /// <summary>
        /// Gets a list of liked Tracks
        /// </summary>
        /// <param name="startIndex">Start index of search</param>
        /// <param name="length">Length of how many Tracks to get</param>
        public List <int> GetLikedTracks(int startIndex = 0, int length = 10)
        {
            // Validate Param
            startIndex = startIndex > 8000 ? 8000 : startIndex;
            length     = length > 200 ? 200 : length;

            if ((startIndex + length) > LikesCount)
            {
                startIndex = 0;
                length     = LikesCount - 1;
            }
            // Get Response
            var res = SoundCloudCore.SendRequest <List <Track> >(string.Format("users/{0}/favorites?offset={1}&limit={2}", ID, startIndex, length));

            List <int> list = new List <int>();

            foreach (var track in res)
            {
                list.Add(track.ID);
            }
            return(list);
        }
Пример #9
0
        /// <summary>
        /// Gets a list of liked Tracks
        /// </summary>
        /// <param name="startIndex">Start index of search</param>
        /// <param name="length">Length of how many Tracks to get</param>
        public static List <int> GetLikedTracks(int startIndex = 0, int limit = 10)
        {
            // Validate Param
            startIndex = startIndex > 8000 ? 8000 : startIndex;
            limit      = limit > 200 ? 200 : limit;

            if ((startIndex + limit) > LikesCount)
            {
                startIndex = 0;
                limit      = LikesCount - 1;
            }
            // Get Response
            var res = SoundCloudCore.SendRequest <List <Track> >(string.Format("me/favorites?offset={0}&limit={1}", startIndex, limit));

            List <int> list = new List <int>();

            foreach (var track in res)
            {
                list.Add(track.ID);
            }
            return(list);
        }
Пример #10
0
        static List <int> GetNextLiked()
        {
            // Buffer for returned tracks
            List <int> list = new List <int>();

            // Check if there is more to get
            if (_likeHref == "stop")
            {
                return(list);
            }

            var url = _likeHref != null ? _likeHref : "me/favorites" + SoundCloudCore.Pagination;

            // Get Response
            var res = SoundCloudCore.SendRequest <Dictionary <string, dynamic> >(url);

            _likeHref = res.ContainsKey("next_href") ? res["next_href"] : "stop";

            foreach (var dict in res["collection"])
            {
                list.Add(Track.GetTrack(JsonConvert.DeserializeObject <Dictionary <string, object> >(dict.ToString())));
            }
            return(list);
        }
Пример #11
0
        /// <summary>
        /// Traverses down the pagination to get net set of Playlists
        /// </summary>
        /// <returns></returns>
        static List <Playlist> GetNextPlaylists()
        {
            // Buffer for returned playlists
            List <Playlist> list = new List <Playlist>();

            // Check if there is more to get
            if (_playlistHref == "stop")
            {
                return(list);
            }

            var url = _playlistHref != null ? _playlistHref : "me/playlists" + SoundCloudCore.Pagination;

            // Get Response
            var res = SoundCloudCore.SendRequest <Dictionary <string, dynamic> >(url);

            _playlistHref = res.ContainsKey("next_href") ? _playlistHref = res["next_href"] : _playlistHref = "stop";

            foreach (var dict in res["collection"])
            {
                list.Add(JsonConvert.DeserializeObject <Playlist>(dict.ToString()));
            }
            return(list);
        }
Пример #12
0
 /// <summary>
 /// Gets a User from it's unique ID
 /// </summary>
 /// <param name="id">ID of track</param>
 public static User GetUser(int id)
 {
     return(SoundCloudCore.SendRequest <User>(string.Format("users/{0}?", id)));
 }
Пример #13
0
 /// <summary>
 /// Searches for playlists that matches a filter
 /// </summary>
 /// <param name="q">Query string </param>
 /// <param name="startIndex">StartIndex of the request</param>
 /// <param name="length">Length of how many results to get</param>
 public static List <Playlist> Search(string q, int startIndex = 0, int length = 10)
 {
     // Get Response & Validate param
     return(SoundCloudCore.SendRequest <List <Playlist> >(string.Format("playlists?q={0}&offset={1}&limit={2}", q, startIndex > 8000 ? 8000 : startIndex, length > 200 ? 200 : length)));
 }
Пример #14
0
 /// <summary>
 /// Gets the album cover of the Track
 /// </summary>
 /// <param name="size">Size in pixels</param>
 /// <returns>The URL of the image</returns>
 public string GetCover(AlbumSize size = AlbumSize.x100)
 {
     return(SoundCloudCore.ResolveCoverUrl(ArtworkUrl, size));
 }
Пример #15
0
        /// <summary>
        /// Searches for Tracks using a filter
        /// </summary>
        /// <param name="q">Query string</param>
        /// <param name="startIndex">StartIndex of response</param>
        /// <param name="length">Length of how many tracks to get</param>
        /// <param name="tags">Track tags</param>
        /// <param name="filter">Filter between 'all', 'public', 'private'</param>
        /// <param name="durationFrom">Track duration from</param>
        /// <param name="durationTo">Track duration to</param>
        /// <param name="createdFrom">Time created from</param>
        /// <param name="createdTo">Time created to</param>
        /// <param name="ids">A list of track ID's to filter on</param>
        /// <param name="genres">A list of genres</param>
        /// <param name="types">A list of types</param>
        /// <param name="license">A license to filter on</param>
        /// <param name="bpmFrom">Beats Per Minute from</param>
        /// <param name="bpmTo">Beats Per Minute from</param>
        /// <returns></returns>
        public static List <int> Search(string q, int startIndex, int length, string[] tags, string filter, TimeSpan durationFrom,
                                        TimeSpan durationTo, DateTime createdFrom, DateTime createdTo, int[] ids = null, string[] genres = null,
                                        string[] types = null, string license = null, int?bpmFrom = null, int?bpmTo = null)
        {
            var query = "tracks?";

            #region Old Code

            /*
             * // Format Strings
             * if(q != null)
             *  query += "q=" + q + "&";
             * if(filter != null)
             *  query += "filter=" + filter + "&";
             * if(license != null)
             *  query += "license=" + license + "&";
             * // Format Integers
             * if(bpmFrom != null)
             *  query += "bpm[from]=" + bpmFrom + "&";
             * if(bpmTo != null)
             *  query += "bpm[to]=" + bpmTo + "&";
             * if(startIndex > 0)
             *  query += "offset=" + (startIndex > 8000 ? 8000 : startIndex) + "&";
             * if(length > 0)
             *  query += "limit=" + (length > 200 ? 200 : length) + "&";
             *
             * // Format Arrays
             * if(tags != null && tags.Length > 0)
             *  query += "tags=" + string.Join(",", tags) + "&";
             * if(ids != null && ids.Length > 0)
             *  query += "ids=" + string.Join(",", ids) + "&";
             * if(genres != null && genres.Length > 0)
             *  query += "genres=" + string.Join(",", genres) + "&";
             * if(types != null && types.Length > 0)
             *  query += "types=" + string.Join(",", types) + "&";
             *
             * // Format TimeSpans
             * if(durationFrom != TimeSpan.MinValue)
             *  query += "duration[from]=" + durationFrom.TotalMilliseconds + "&";
             * if(durationTo != TimeSpan.MaxValue)
             *  query += "duration[to]=" + durationTo.TotalMilliseconds + "&";
             *
             * // Format DateTime s
             * if(createdFrom != DateTime.MinValue)
             *  query += "created_at[from]=" + createdFrom.ToString("yyyy-MM-dd hh:mm:ss") + "&";
             * if(createdTo != DateTime.MaxValue)
             *  query += "created_at[to]=" + createdTo.ToString("yyyy-MM-dd hh:mm:ss") + "&";
             */
            #endregion

            // Format Strings
            query += q != null ? "q=" + q + "&" : "";
            query += filter != null ? "filter=" + filter + "&" : "";
            query += license != null ? "license=" + license + "&" : "";

            // Format Integers
            query += bpmFrom != null ? "bpm[from]=" + bpmFrom + "&" : "";
            query += bpmTo != null ? "bpm[to]=" + bpmTo + "&" : "";
            query += startIndex > 0 ? "offset=" + (startIndex > 8000 ? 8000 : startIndex) + "&" : "";
            query += length > 0 ? "limit=" + (length > 200 ? 200 : length) + "&" : "";

            // Format Arrays
            query += tags != null && tags.Length > 0 ? "tags=" + string.Join(",", tags) + "&" : "";
            query += ids != null && ids.Length > 0 ? "ids=" + string.Join(",", ids) + "&" : "";
            query += genres != null && genres.Length > 0 ? "genres=" + string.Join(",", genres) + "&" : "";
            query += types != null && types.Length > 0 ? "types=" + string.Join(",", types) + "&" : "";

            // Format TimeSpans
            query += durationFrom != TimeSpan.MinValue ? "duration[from]=" + durationFrom.TotalMilliseconds + "&" : "";
            query += durationTo != TimeSpan.MaxValue ? "duration[to]=" + durationTo.TotalMilliseconds + "&" : "";

            // Format DateTimes
            query += createdFrom != DateTime.MinValue ? "created_at[from]=" + createdFrom.ToString("yyyy-MM-dd hh:mm:ss") + "&" : "";
            query += createdTo != DateTime.MaxValue ? "created_at[to]=" + createdTo.ToString("yyyy-MM-dd hh:mm:ss") + "&" : "";

            // Get Response
            var res = SoundCloudCore.SendRequest <List <Track> >(query.Substring(0, query.Length - 1), HttpRequestMethod.GET);

            // Create a list of the tracks
            List <int> tracks = new List <int>();
            foreach (var track in res)
            {
                tracks.Add(track.ID);
            }

            return(tracks);
        }