SDownload.Framework.Streams.SCTrackStream.GetDownloadUrl C# (CSharp) Method

GetDownloadUrl() private method

Gets the download url for the main resource
private GetDownloadUrl ( ) : String
return String
        private String GetDownloadUrl()
        {
            var songDownload = (_trackData.DownloadUrl != null && Settings.UseDownloadLink && !_forceStream) ? _trackData.DownloadUrl : _trackData.StreamUrl;

            if (songDownload == null || _forceManual)
            {
                // There was no stream URL or download URL for the song, manually parse the resource stream link from the original URL
                BugSenseHandler.Instance.LeaveBreadCrumb("Manually downloading sound");

                // Manual was forced, on failure we should abort
                _forceManual = true;

                HttpWebResponse response;
                try
                {
                    var request = (HttpWebRequest)WebRequest.Create(_origUrl);
                    response = (HttpWebResponse)request.GetResponse();
                }
                catch (Exception e)
                {
                    CrashHandler.Throw("Song does not allow streaming and there was an issue manually downloading the song file!", e, false);
                    return null;
                }

                var doc = new HtmlDocument();
                doc.Load(response.GetResponseStream());
                var searchString = WebUtility.HtmlDecode(doc.DocumentNode.InnerHtml);
                var links = Regex.Matches(searchString, "((http:[/][/])(media.soundcloud.com/stream/)([a-z]|[A-Z]|[0-9]|[/.]|[~]|[?]|[_]|[=])*)");
                songDownload = links[0].Value;
            }

            // Pretend we forced stream, so on failure we attempt manual next
            if (songDownload.Equals(_trackData.StreamUrl))
                _forceStream = true;

            return songDownload + "?client_id=" + SCTrackData.ClientId;
        }
    }