]> git.r.bdr.sh - rbdr/lyricli.rb/blob - lib/lyricli/sources/itunes.rb
2bfe471f1c3e3ec291f9e29a35998b0f10e31f86
[rbdr/lyricli.rb] / lib / lyricli / sources / itunes.rb
1 module Lyricli
2 module Sources
3 # The source for iTunes
4 class Itunes
5
6 class << self
7 attr_accessor :name
8 end
9
10 @name = "itunes"
11
12 # The enable method should run all of the tasks needed to validate
13 # the source. In the case of Rdio it has to authenticate with OAuth.
14 def self.enable
15 # Nothing to do
16 end
17
18 # Instantiates everything it needs to run.
19 def initialize
20 @config = Configuration.instance
21 @script = "current_song.scpt"
22 end
23
24 # The current_track method should return the name of the current
25 # artist and song.
26 # @return [Hash] A hash containing the current `:song` and `:artist`.
27 def current_track
28 path_root = File.expand_path(File.dirname(__FILE__))
29 path = File.join(path_root, @script)
30 current = `osascript #{path}`
31 current = current.split("<-SEP->")
32 {artist: current[0], song: current[1]}
33 end
34
35 # The reset method resets any configurations it may have
36 def self.reset
37 # Nothing to do
38 end
39 end
40 end
41 end