- # The Downloader class is a factory; it should decide
- # which subclass we get.
- downloader = Downloader.create(Configuration::DOWNLOAD_METHOD)
-
- # Attempt to download the file, and rescue and report
- # any (predictable) exceptions. The wget downloader will
- # naturally not report any of these, since it will die in
- # its own process.
- begin
- downloader.download(video_url,
- site.get_video_filename(),
- site.headers(),
- continue=options[:continue])
- rescue Errno::ECONNREFUSED => e
- puts 'The connection to the server (to download the video file) was refused. Check your connection, and try again later.'
- Kernel.exit(EXIT_CONNECTION_REFUSED)
- rescue Errno::EACCES => e
- puts "Access denied. Check that you have write permission to the output file/directory. Details: #{e.message}."
- rescue OpenURI::HTTPError => e
- puts "An HTTP error occurred while downloading the video file: #{e.message}."
- Kernel.exit(EXIT_HTTP_ERROR)
- rescue IOError => e
- puts "Input/Output Error: #{e.message}"
- Kernel.exit(EXIT_IO_ERROR)
- end
+# The Downloader class is a factory; it should decide
+# which subclass we get.
+downloader = Downloader.create(Configuration::DOWNLOAD_METHOD)
+
+# Attempt to download the file, and rescue and report
+# any (predictable) exceptions. The wget downloader will
+# naturally not report any of these, since it will die in
+# its own process.
+begin
+ downloader.download(video_url,
+ site.get_video_filename(),
+ site.headers(),
+ continue=options[:continue])
+
+rescue Errno::ECONNREFUSED => e
+ msg = 'The connection to the server (to download the video file) '
+ msg += 'was refused. Check your connection, and try again later.'
+ log.error(msg)
+ Kernel.exit(ExitCodes::EXIT_CONNECTION_REFUSED)
+
+rescue Errno::EACCES => e
+ msg = 'Access denied. Check that you have write permission '
+ msg += "to the output file/directory. Details: #{e.message}."
+ log.error(msg)
+ Kernel.exit(ExitCodes::EXIT_ACCESS_DENIED)
+
+rescue OpenURI::HTTPError => e
+ msg = 'An HTTP error occurred while downloading '
+ msg += " the video file: #{e.message}."
+ log.error(msg)
+ Kernel.exit(ExitCodes::EXIT_HTTP_ERROR)
+
+rescue IOError => e
+ log.error("Input/Output Error: #{e.message}")
+ Kernel.exit(ExitCodes::EXIT_IO_ERROR)