]> gitweb.michael.orlitzky.com - dead/whatever-dl.git/blob - lib/whatever-dl/configuration.rb
Update bin/whatever-dl and the configuration class for the other changes.
[dead/whatever-dl.git] / lib / whatever-dl / configuration.rb
1 require 'yaml'
2
3 module Configuration
4 # Configurable Options
5 #
6 # We support a couple of different download methods. The :openuri
7 # method utilizes the ruby open-uri library, and provides its own
8 # progress bar with no external dependencies. The :wget method, on the
9 # other hand, requires GNU Wget (http://www.gnu.org/software/wget/),
10 # but will support auto-resume of partially-downloaded files for
11 # example.
12
13 USERCONF_PATH = ENV['HOME'] + '/.whatever-dl.conf.yml'
14 @dict = {}
15
16 def initialize()
17 cfg = default_configuration()
18
19 # Now, load the user configuration which will override the
20 # variables defined above.
21 begin
22 user_config = YAML.load(File.open(USERCONF_PATH))
23
24 # We require ruby-1.9.x now so this should exist.
25 cfg.merge!(user_config)
26
27 rescue Errno::ENOENT
28 # If the user config file doesn't exist, whatever.
29 end
30
31 # Convert all of the keys to symbols.
32 cfg = cfg.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
33
34 @dict = cfg
35 end
36
37 def method_missing(sym, *args)
38 # Replace all missing method calls with dictionary lookups.
39 return @dict[sym]
40 end
41
42
43 private;
44
45 def default_configuration()
46 d = {}
47
48 d['download_method'] = 'openuri'
49 d['user_agent'] = 'whatever-dl'
50
51 return d
52 end
53
54 end