From: Ben Beltran Date: Sat, 6 Oct 2012 06:38:15 +0000 (-0500) Subject: Integrates iTunes source X-Git-Url: https://git.r.bdr.sh/rbdr/lyricli.rb/commitdiff_plain/6f33706c59d73cfae04fc2e799502522de10f1c1 Integrates iTunes source 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. --- diff --git a/lib/lyricli/source_manager.rb b/lib/lyricli/source_manager.rb index ac1cd7f..3befbd2 100644 --- a/lib/lyricli/source_manager.rb +++ b/lib/lyricli/source_manager.rb @@ -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 diff --git a/current_song.scpt b/lib/lyricli/sources/current_song.scpt similarity index 100% rename from current_song.scpt rename to lib/lyricli/sources/current_song.scpt diff --git a/lib/lyricli/sources/itunes.rb b/lib/lyricli/sources/itunes.rb index e69de29..2e647c8 100644 --- a/lib/lyricli/sources/itunes.rb +++ b/lib/lyricli/sources/itunes.rb @@ -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 diff --git a/lyricli-0.0.1.gem b/lyricli-0.0.1.gem index 151cb46..bb1d4de 100644 Binary files a/lyricli-0.0.1.gem and b/lyricli-0.0.1.gem differ diff --git a/lyricli.gemspec b/lyricli.gemspec index 41e6cf3..44be23b 100644 --- a/lyricli.gemspec +++ b/lyricli.gemspec @@ -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'