Пример #1
0
        public async Task GetBackgroundForSoundCloudAsyncTask(string link)
        {
            string result = await StaticMethod.GetJsonStringTask(link);

            HtmlDocument doc = new HtmlDocument();

            doc.LoadHtml(result);

            photosCollection = new ObservableCollection <Photos>();
            // var nodeCollection=doc.DocumentNode.Descendants
        }
        /// <summary>
        /// //////
        /// </summary>
        /// <param name="link"></param>
        /// <returns></returns>
        public async Task GetSearchCollectionAsyncTask(string link)
        {
            var result = await StaticMethod.GetJsonStringTask(link);

            if (result != null)
            {
                var getItem = JsonConvert.DeserializeObject <SearchSoundCloud.RootObject>(result);
                SearchTrackCollection = new ObservableCollection <SearchSoundCloud.Collection>();
                foreach (var item in getItem.collection)
                {
                    SearchTrackCollection.Add(item);
                }
            }
        }
        /// <summary>
        /// ///////
        /// </summary>
        /// <param name="link"></param>
        /// <returns></returns>
        public async Task GetPlaylistAsyncTask(string link)
        {
            var result = await StaticMethod.GetJsonStringTask(link);

            PlaylistCollection = new ObservableCollection <PlaylistSoundCloud.Track>();
            if (result != null)
            {
                var getItem = JsonConvert.DeserializeObject <PlaylistSoundCloud.RootObject>(result);
                foreach (var item in getItem.tracks)
                {
                    PlaylistCollection.Add(item);
                }
            }
        }
        /// <summary>
        /// ////
        /// </summary>
        /// <param name="link"></param>
        /// <returns></returns>
        public async Task GetTrackCollectionUserAsyncTask(string link)
        {
            var result = await StaticMethod.GetJsonStringTask(link);

            if (result != null)
            {
                var getItem = JsonConvert.DeserializeObject <UserSoundCloud.RootObject>(result);

                foreach (var item in getItem.collection)
                {
                    UserTrack.Add(item);
                }
                //Next_href.Add(getItem.next_href);
            }
        }
        /// <summary>
        /// //////
        /// </summary>
        /// <param name="link"></param>
        /// <returns></returns>
        public async void GetUserInforAsyncTask(string link, string linkuser, ImageBrush img, TextBlock username, TextBlock follower, TextBlock following, TextBlock tracks)
        {
            try
            {
                var result = await StaticMethod.GetJsonStringTask(linkuser);

                var getItem = JsonConvert.DeserializeObject <RootObject>(result);
                img.ImageSource = new BitmapImage(new Uri(getItem.avatar_url));
                username.Text   = getItem.username;
                follower.Text   = getItem.followers_count.ToString();
                following.Text  = getItem.followings_count.ToString();
                tracks.Text     = getItem.track_count.ToString();
            }
            catch (Exception)
            {
                return;
            }
        }
/// <summary>
/// ///////
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
        public async Task <string> Getlinkdownload(int id, string _api_key)
        {
            string link   = "";
            var    result = await StaticMethod.GetJsonStringTask("https://api.soundcloud.com/i1/tracks/" + id + "/streams?client_id=" + _api_key);

            if (result != null)
            {
                var Getlink = JsonConvert.DeserializeObject <DownloadSoundCloud>(result);
                if (Getlink.http_mp3_128_url != null)
                {
                    link = Getlink.http_mp3_128_url;
                }

                else
                {
                    link = Getlink.hls_mp3_128_url;
                }
            }
            return(link);
        }
        /*
         * public void GetOffset(string next_url, int _t)
         * {
         *  Uri uri = new Uri(next_url);
         *  WwwFormUrlDecoder _decover = new WwwFormUrlDecoder(uri.Query);
         *  int offset;
         *  offset=(Convert.ToInt32(_decover.GetFirstValueByName("offset")));
         *  _t= offset;
         * }
         */
        /// <summary>
        /// //////
        /// </summary>
        /// <param name="link"></param>
        /// <returns></returns>
        public async Task GetTrackAsyncTask(string link)
        {
            var result = await StaticMethod.GetJsonStringTask(link);

            TrackCollection = new ObservableCollection <TracksSoundCloud.Track>();
            if (result != null)
            {
                var getItem = JsonConvert.DeserializeObject <TracksSoundCloud.RootObject>(result);
                //GetOffset(getItem.next_href,t);

                if (getItem != null)
                {
                    foreach (var item in getItem.tracks)
                    {
                        TrackCollection.Add(item);
                    }
                }
                else
                {
                    return;
                }
            }
        }