]> git.r.bdr.sh - rbdr/lyricli.rb/commitdiff
Integrates iTunes source
authorBen Beltran <redacted>
Sat, 6 Oct 2012 06:38:15 +0000 (01:38 -0500)
committerBen Beltran <redacted>
Sat, 6 Oct 2012 06:38:15 +0000 (01:38 -0500)
This pretty much gets us to where we were before the refactor.
But nicer. Also, arguments now has privilege, so if arguments
are present, they will be used even if other sources are giving
results.

lib/lyricli/source_manager.rb
lib/lyricli/sources/current_song.scpt [moved from current_song.scpt with 100% similarity]
lib/lyricli/sources/itunes.rb
lyricli-0.0.1.gem
lyricli.gemspec

index ac1cd7fcd01263a6b8bac00127e6ac1219b3f90f..3befbd2ab0b6037bd29b457c318d7e51a40b25a6 100644 (file)
@@ -59,12 +59,17 @@ module Lyricli
 
     def current_track
       track = nil
+      lock = false
       @enabled_sources.each do |source|
         begin
           current_track = source.current_track
 
+          # This is a special thing for arguments. The thing is, they need to
+          # be inputted manually. So, if they are present they won't allow
+          # anyone else to give results. Makes sense, yet a bit hacky.
           unless current_track[:artist].nil? || current_track[:artist].empty? || current_track[:song].nil? || current_track[:song].empty?
-            track = current_track
+            track = current_track unless lock
+            lock = true if source.class.name == "arguments"
           end
         rescue
           raise SourceConfigurationException
@@ -75,7 +80,7 @@ module Lyricli
 
     def available_sources(format = false)
       path_root = File.expand_path(File.dirname(__FILE__))
-      sources = Dir[path_root+"/sources/*"].map{ |s|
+      sources = Dir[path_root+"/sources/*.rb"].map{ |s|
         name = s.split("/").last.gsub(/\.rb/, "")
 
         # Add a star to denote enabled sources
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..2e647c88a94829b76c30e458f1b010378ae2f103 100644 (file)
@@ -0,0 +1,40 @@
+module Lyricli
+  module Sources
+    class Itunes
+
+      class << self
+        attr_accessor :name
+      end
+
+      @name = "itunes"
+
+      # The enable method should run all of the tasks needed to validate
+      # the source. In the case of Rdio it has to authenticate with OAuth.
+      def self.enable
+        # Nothing to do
+      end
+
+      # Instantiates everything it needs to run.
+      def initialize
+        @config = Configuration.instance
+        @script = "current_song.scpt"
+      end
+
+      # The current_track method should return the name of the current
+      # artist and song.
+      # @return [Hash] A hash containing the current `:song` and `:artist`.
+      def current_track
+        path_root = File.expand_path(File.dirname(__FILE__))
+        path = File.join(path_root, @script)
+        current = `osascript #{path}`
+        current = current.split("<-SEP->")
+        {artist: current[0], song: current[1]}
+      end
+
+      # The reset method resets any configurations it may have
+      def self.reset
+        # Nothing to do
+      end
+    end
+  end
+end
index 151cb466788e15d203d69f375acebd6c431c350f..bb1d4de068b8a585c43e6ba9b0e758131911544e 100644 (file)
Binary files a/lyricli-0.0.1.gem and b/lyricli-0.0.1.gem differ
index 41e6cf322c39400283d82cdbd8e543d1823a3264..44be23ba80c1f5d09ef7bbb6503e477eb34586c3 100644 (file)
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
 
   s.files = Dir['lib/**/*.rb'] + Dir['bin/*']
   s.files += Dir['[A-Z]*'] + Dir['spec/**/*']
-  s.files += Dir['lib/**/*.json']
+  s.files += Dir['lib/**/*.json', 'lib/**/*.scpt']
 
   s.executables << 'lrc'