/// <summary>
        /// Parse the given link and send it to the appropriate stream downloader
        /// </summary>
        /// <param name="url">The link provided to the application from the view</param>
        /// <param name="view">The view to report progress back to</param>
        /// <param name="exit">Exit after download?</param>
        public static async void DownloadTrack(String url, InfoReportProxy view, bool exit = false)
        {
            CrashHandler.AddExtra("stream_url", url);
            try
            {
                BaseStream sound;
                if (url.Contains(@"/sets/"))
                    sound = new SCSetStream(url, view);
                else
                    sound = new SCTrackStream(url, view);

                var download = sound.Download();

                if (download != null && await download)
                    sound.Finish();
            }
            catch (Exception e)
            {
                CrashHandler.Throw("There was an issue downloading the stream!", e);
            }
            finally
            {
                CrashHandler.ClearExtras();
                if (exit)
                {
                    Application.Exit();
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Gathers and prepares all of the tracks in the set for download
        /// </summary>
        /// <param name="url">The url to the set</param>
        /// <param name="view">The view to report progress back to</param>
        public SCSetStream(string url, InfoReportProxy view) : base(url, view)
        {
            var playlistData = SCPlaylistData.LoadData(url);

            if (playlistData == null)
            {
                throw new HandledException("Downloaded set information was corrupted!", true);
            }

            if (playlistData.Tracks.Length < 1)
            {
                throw new HandledException("Playlist does not contain any tracks!", true);
            }

            for (var index = 0; index < playlistData.Tracks.Length; index++)
            {
                View.Report(String.Format("Processing track {0}/{1}", index + 1, playlistData.Tracks.Length));
                var track           = playlistData.Tracks[index];
                var setItemReporter = new SetItemReportProxy(this, playlistData.Tracks.Length);
                try
                {
                    var trackHandler = new SCTrackStream(track.PermalinkUrl, setItemReporter, track);
                    _downloads.Add(trackHandler, null);
                }
                catch (Exception)
                {
                    // Mark the item failed if it couldn't be processed
                    setItemReporter.Close();
                }
            }
        }
Exemple #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);
        }
Exemple #4
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);
        }
Exemple #5
0
        /// <summary>
        /// Gathers and prepares all of the tracks in the set for download
        /// </summary>
        /// <param name="url">The url to the set</param>
        /// <param name="view">The view to report progress back to</param>
        public SCSetStream(string url, InfoReportProxy view) : base(url, view)
        {
            var playlistData = SCPlaylistData.LoadData(url);
            if (playlistData == null)
                throw new HandledException("Downloaded set information was corrupted!", true);

            if (playlistData.Tracks.Length < 1)
                throw new HandledException("Playlist does not contain any tracks!", true);

            for (var index = 0; index < playlistData.Tracks.Length; index++)
            {
                View.Report(String.Format("Processing track {0}/{1}", index+1, playlistData.Tracks.Length));
                var track = playlistData.Tracks[index];
                var setItemReporter = new SetItemReportProxy(this, playlistData.Tracks.Length);
                try
                {
                    var trackHandler = new SCTrackStream(track.PermalinkUrl, setItemReporter, track);
                    _downloads.Add(trackHandler, null);
                }
                catch (Exception)
                {
                    // Mark the item failed if it couldn't be processed
                    setItemReporter.Close();
                }
            }
        }
Exemple #6
0
        /// <summary>
        /// Creates a base stream that downloads from a remote url
        /// </summary>
        /// <param name="url">The url to process</param>
        /// <param name="view">The view to report information back to</param>
        protected BaseStream(String url, InfoReportProxy view)
        {
            View = view;

            View.Report("Processing");
        }
Exemple #7
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>
 public SCTrackStream(String url, InfoReportProxy view) : this(url, view, SCTrackData.LoadData(url))
 {
 }
Exemple #8
0
        /// <summary>
        /// Creates a base stream that downloads from a remote url
        /// </summary>
        /// <param name="url">The url to process</param>
        /// <param name="view">The view to report information back to</param>
        protected BaseStream(String url, InfoReportProxy view)
        {
            View = view;

            View.Report("Processing");
        }
Exemple #9
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>
 public SCTrackStream(String url, InfoReportProxy view) : this(url, view, SCTrackData.LoadData(url))
 {
 }