]> gitweb.michael.orlitzky.com - dead/whatever-dl.git/blob - bin/whatever-dl
Initial commit.
[dead/whatever-dl.git] / bin / whatever-dl
1 #!/usr/bin/ruby -w
2 #
3 # whatever-dl, a script to download online (web-based) videos.
4 #
5 # Copyright Michael Orlitzky
6 #
7 # http://michael.orlitzky.com/
8 #
9 # This program is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, either version 3 of the License, or
12 # (at your option) any later version.
13 #
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
18 #
19 # http://www.fsf.org/licensing/licenses/gpl.html
20 #
21
22 # All of the website classes are located in one
23 # directory, so we can 'require' them automatically.
24 Dir.glob('src/websites/*.rb').each do |r|
25 require r
26 end
27
28
29 # Only actually do something if this script was called
30 # directly (i.e. not from the tests).
31 if (__FILE__ == $0) then
32 if (ARGV.length < 1) then
33 # If the user didn't give us a URL, yell
34 # at him or her.
35 puts 'Usage: whatever-dl <url>'
36 Kernel.exit(1)
37 end
38
39 # Check the URL against each website's class.
40 # The class will know whether or not the URL
41 # "belongs" to its website.
42
43 site = nil
44
45 Website.subclasses.each do |w|
46 if w.owns_url?(ARGV[0])
47 site = w.new()
48 break
49 end
50 end
51
52 if site.nil?
53 puts 'Invalid URL.'
54 exit(1)
55 end
56
57 video_url = site.get_video_url(ARGV[0])
58
59 if video_url.nil?
60 puts 'Error retrieving video URL.'
61 exit(2)
62 end
63
64 # *classy*
65 Kernel.exec("wget \"#{video_url}\"")
66 end