]> gitweb.michael.orlitzky.com - dead/whatever-dl.git/blobdiff - 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
index 60066cca0c4ea652b87dc3714dbea961aba485b1..643479e771ff1fd5bc9ddc044b4f19207bee6857 100644 (file)
@@ -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