Example #1
0
        public static void Main(string [] args)
        {
            var output_path = Environment.CurrentDirectory;

            if (args.Length < 1) {
                Usage ();
                return;
            }

            var amz_files = new Queue<AmzXspfPlaylist> ();

            for (int i = 0; i < args.Length; i++) {
                if (args[i] == "-o") {
                    if (i < args.Length - 1) {
                        output_path = args[++i];
                    } else {
                        Usage ();
                        return;
                    }
                } else if (args[i] == "--help" || args[i] == "-h") {
                    Usage ();
                    return;
                } else {
                    try {
                        amz_files.Enqueue (new AmzXspfPlaylist (args[i]));
                    } catch {
                        Console.Error.WriteLine ("Invalid .amz file: {0}", args[i]);
                    }
                }
            }

            while (amz_files.Count > 0) {
                int i = 1;
                var playlist = amz_files.Dequeue ();

                var download_manager = new DownloadManager { MaxConcurrentDownloaders = 1 };

                download_manager.Finished += d => {
                    if (!d.State.Success) {
                        Console.WriteLine ("[{0}/{1}] {2}: {3}", i, playlist.DownloadableTrackCount,
                            d.Name, d.State.FailureException.Message);
                    } else {
                        Console.WriteLine ();
                    }
                    i++;
                };

                download_manager.Progress += d => {
                    int progress_bar_size = Console.WindowWidth - 65;
                    Console.Write ("\r{0} {1} |{2}| {3} {4}",
                        Field (String.Format ("[{0}/{1}]", i, playlist.DownloadableTrackCount), 7),
                        Field (d.Name, 35),
                        Field (String.Empty.PadRight ((int)Math.Ceiling (progress_bar_size
                            * d.State.PercentComplete), '='), progress_bar_size),
                        Field (((int)Math.Round (d.State.PercentComplete * 100)).ToString () + "%", 4),
                        Field (String.Format ("{0:0.00} KB/s", d.State.TransferRate / 1024), 12));
                };

                Console.WriteLine ("Downloading Album");

                foreach (var track in playlist.DownloadableTracks) {
                    download_manager.QueueDownloader (new AmzMp3Downloader (track) {
                        OutputPath = output_path
                    });
                }

                download_manager.WaitUntilFinished ();
            }
        }
 public DownloadManagerJob(DownloadManager manager)
 {
     this.manager      = manager;
     manager.Progress += OnDownloaderProgress;
     manager.Finished += OnDownloaderFinished;
 }
Example #3
0
 public DownloadManagerJob (DownloadManager manager)
 {
     this.manager = manager;
     manager.Progress += OnDownloaderProgress;
     manager.Finished += OnDownloaderFinished;
 }