viddl-rb:
Created by Marc Seeger (@rb2k)
Repo: http://github.com/rb2k/viddl-rb
Installation:
gem install viddl-rb
Usage:
Download a video:
viddl-rb http://www.youtube.com/watch?v=QH2-TGUlwu4
Download a video and extract the audio:
viddl-rb http://www.youtube.com/watch?v=QH2-TGUlwu4 --extract-audio
In both cases we'll name the output file according to the video title.
Youtube plugin specifics:
Download all videos on a playlist:
viddl-rb http://www.youtube.com/playlist?list=PL7E8DA0A515924126
Download all videos from a user:
viddl-rb http://www.youtube.com/user/tedtalksdirector
Filter videos to download from a user/playlist:
viddl-rb http://www.youtube.com/user/tedtalksdirector --filter=internet/i
The --filter argument accepts a regular expression and will only download videos where the title matches the regex. The /i option does a case-insensitive search.
Library Usage:
require 'viddl-rb'
download_urls = ViddlRb.get_urls("http://www.youtube.com/watch?v=QH2-TGUlwu4")
download_urls.first # => "http://o-o.preferred.arn06s04.v3.lscac ..."
The ViddlRb module has the following module public methods:
-
get_urls_names(url) -- Returns an array of one or more hashes that has the keys :url which points to the download url and :name which points to the name (which is a filename safe version of the video title with a file extension). Returns nil if the url is not recognized by any plugins.
-
get_urls_exts(url) -- Same as get_urls_names but with just the file extension (for example ".mp4") instead of the full filename, and the :name key is replaced with :ext. Returns nil if the url is not recognized by any plugins.
-
get_urls(url) -- Returns an array of download urls for the specified video url. Returns nil if the url is not recognized by any plugins.
-
get_names(url) -- Returns an array of filenames for the specified video url. Returns nil if the url is not recognized by any plugins.
-
io=(io_object) -- By default all plugin output to stdout will be suppressed when the library is used. If you are interested in the output of a plugin, you can set an IO object that will receive all plugin output using this method. For example:
require 'viddl-rb'
ViddlRb.io = $stdout # plugins will now write their output to $stdout
All the get methods in the ViddlRb module will raise either a ViddlRb::PluginError or a ViddlRb::DownloadError if the plugin fails. A ViddlRb::PluginError is raised if the plugin fails in an unexpected way, and a ViddlRb::DownloadError is raised if the video could not be downloaded for some reason. An example of that is if a Youtube video is not embeddable - then it can't be downloaded.
begin
ViddlRb.get_urls(video_url)
rescue ViddlRb::DownloadError => e
puts "Could not get download url: #{e.message}"
rescue ViddlRb::PluginError => e
puts "Plugin blew up! #{e.message}\n" +
"Backtrace:\n#{e.backtrace.join("\n")}"
end
Requirements:
- curl/wget or the progress bar gem
- Nokogiri
- Mechanize
- ffmpeg if you want to extract audio tracks from the videos
Contributors:
- kl: Windows support (who knew!), bug fixes, veoh plugin, metacafe plugin
- divout aka Ivan K: blip.tv plugin, bugfixes
- Sniper: bugfixes
- Serabe aka Sergio Arbeo: packaging viddl as a binary
- laserlemon: Adding gemnasium images to readme