Esempio n. 1
0
        internal static object LoadData(String url, Type contractType, bool mock = false)
        {
            object ret;

            if (!mock)
            {
                const String resolveUrl = "http://api.soundcloud.com/resolve?url={0}&client_id={1}";
                var          request    = (HttpWebRequest)WebRequest.Create(String.Format(resolveUrl, url, ClientId));
                request.Method = WebRequestMethods.Http.Get;
                request.Accept = "application/json";
                var response = request.GetResponse().GetResponseStream();
                if (response == null)
                {
                    throw new HandledException(
                              "Soundcloud API failed to respond! This could due to an issue with your connection.");
                }

                ret = new DataContractJsonSerializer(contractType).ReadObject(response);
            }
            else
            {
                ret = new SCTrackData();
            }

            return(ret);
        }
Esempio n. 2
0
        internal static object LoadData(String url, Type contractType, bool mock = false)
        {
            object ret;
            if (!mock)
            {
                const String resolveUrl = "http://api.soundcloud.com/resolve?url={0}&client_id={1}";
                var request = (HttpWebRequest)WebRequest.Create(String.Format(resolveUrl, url, ClientId));
                request.Method = WebRequestMethods.Http.Get;
                request.Accept = "application/json";
                var response = request.GetResponse().GetResponseStream();
                if (response == null)
                    throw new HandledException(
                        "Soundcloud API failed to respond! This could due to an issue with your connection.");

                ret = new DataContractJsonSerializer(contractType).ReadObject(response);
            }
            else
                ret = new SCTrackData();

            return ret;
        }
Esempio n. 3
0
        /// <summary>
        /// Gather and prepare all the necessary information for downloading the actual remote resource
        /// </summary>
        /// <param name="url">The URL to the individual song</param>
        /// <param name="view">The proxy to report information back to</param>
        /// <param name="trackData">The track's metadata retrieved from SoundCloud</param>
        /// <returns>A Sound representation of the remote resource</returns>
        public SCTrackStream(String url, InfoReportProxy view, SCTrackData trackData) : base(url, view)
        {
            _trackData = trackData;
            _origUrl = url;
            View = view;

            // _trackData is null if there was an error parsing the response
            if (_trackData == null)
                throw new HandledException("Downloaded track information was corrupted!", true);

            var tokens = WebUtility.HtmlDecode(_trackData.Title).Split('-');
            _author = _trackData.User.Username;
            _title = _trackData.Title;
            Genre = _trackData.Genre ?? "";

            // Split the song name if it contains the Author
            if (tokens.Length > 1)
            {
                BugSenseHandler.Instance.LeaveBreadCrumb("Song name split");
                _author = tokens[0].Trim();
                _title = tokens[1].Trim();
            }

            var rand = GenerateRandomString(8) + ".mp3";

            var directory = Settings.DownloadFolder + GetCleanFileName(Settings.AuthorFolder ? _author : "");

            if (!Directory.Exists(directory))
                Directory.CreateDirectory(directory);

            // Use the download url if it exists, probably better quality
            var absoluteUrl = directory + "\\" + GetCleanFileName(_title) + ".mp3";
            var artworkUrl = _trackData.ArtworkUrl ?? _trackData.User.AvatarUrl;

            Extras = new List<DownloadItem> { new DownloadItem(new Uri(artworkUrl), Path.GetTempPath() + rand + ".jpg") };

            MainResource = new DownloadItem(new Uri(GetDownloadUrl()), absoluteUrl);
        }
Esempio n. 4
0
 public static SCPlaylistData LoadData(String url, bool mock = false)
 {
     return(SCTrackData.LoadData(url, typeof(SCPlaylistData), mock) as SCPlaylistData);
 }