#!/usr/bin/ruby -w # # whatever-dl, a script to download online (web-based) videos. # # Copyright Michael Orlitzky # # http://michael.orlitzky.com/ # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # http://www.fsf.org/licensing/licenses/gpl.html # # All of the website classes are located in one # directory, so we can 'require' them automatically. Dir.glob('src/websites/*.rb').each do |r| require r end # Only actually do something if this script was called # directly (i.e. not from the tests). if (__FILE__ == $0) then if (ARGV.length < 1) then # If the user didn't give us a URL, yell # at him or her. puts 'Usage: whatever-dl ' Kernel.exit(1) end # Check the URL against each website's class. # The class will know whether or not the URL # "belongs" to its website. site = nil Website.subclasses.each do |w| if w.owns_url?(ARGV[0]) site = w.new() break end end if site.nil? puts 'Invalid URL.' exit(1) end video_url = site.get_video_url(ARGV[0]) if video_url.nil? puts 'Error retrieving video URL.' exit(2) end # *classy* Kernel.exec("wget \"#{video_url}\"") end