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.
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
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
+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
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'