X-Git-Url: http://gitweb.michael.orlitzky.com/?p=dead%2Fwhatever-dl.git;a=blobdiff_plain;f=lib%2Fwhatever-dl%2Fconfiguration.rb;fp=lib%2Fwhatever-dl%2Fconfiguration.rb;h=643479e771ff1fd5bc9ddc044b4f19207bee6857;hp=60066cca0c4ea652b87dc3714dbea961aba485b1;hb=097749b9e9d7ab29bb78f681f01865741aea9342;hpb=873bf451b10441d763128dd0a758a15b58b15ae4 diff --git a/lib/whatever-dl/configuration.rb b/lib/whatever-dl/configuration.rb index 60066cc..643479e 100644 --- a/lib/whatever-dl/configuration.rb +++ b/lib/whatever-dl/configuration.rb @@ -1,14 +1,54 @@ +require 'yaml' + module Configuration # Configurable Options - + # # We support a couple of different download methods. The :openuri # method utilizes the ruby open-uri library, and provides its own # progress bar with no external dependencies. The :wget method, on the # other hand, requires GNU Wget (http://www.gnu.org/software/wget/), # but will support auto-resume of partially-downloaded files for # example. - DOWNLOAD_METHOD = :openuri - #DOWNLOAD_METHOD = :wget - USER_AGENT = 'whatever-dl' + USERCONF_PATH = ENV['HOME'] + '/.whatever-dl.conf.yml' + @dict = {} + + def initialize() + cfg = default_configuration() + + # Now, load the user configuration which will override the + # variables defined above. + begin + user_config = YAML.load(File.open(USERCONF_PATH)) + + # We require ruby-1.9.x now so this should exist. + cfg.merge!(user_config) + + rescue Errno::ENOENT + # If the user config file doesn't exist, whatever. + end + + # Convert all of the keys to symbols. + cfg = cfg.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo} + + @dict = cfg + end + + def method_missing(sym, *args) + # Replace all missing method calls with dictionary lookups. + return @dict[sym] + end + + + private; + + def default_configuration() + d = {} + + d['download_method'] = 'openuri' + d['user_agent'] = 'whatever-dl' + + return d + end + end