]> git.r.bdr.sh - rbdr/lyricli.rb/blob - lib/lyricli.rb
32215d3c1681ad9f716f01612a454604f21f0205
[rbdr/lyricli.rb] / lib / lyricli.rb
1 #!/usr/bin/env ruby -w
2
3 require 'uri'
4 require 'net/http'
5 require 'multi_json'
6 require 'nokogiri'
7 require 'open-uri'
8 require 'launchy'
9
10 # This shit causes a lot of warnings. Quick Hack.
11 original_verbosity = $VERBOSE
12 $VERBOSE = nil
13 require 'rdio'
14 $VERBOSE = original_verbosity
15
16 # Add current path to include path
17 $:.unshift File.expand_path(File.dirname(__FILE__))
18
19 # Local Dependencies
20 require "lyricli/util"
21 require "lyricli/configuration"
22 require "lyricli/lyrics_engine"
23 require "lyricli/source_manager"
24 require "lyricli/sources/arguments"
25 require "lyricli/sources/rdio"
26 require "lyricli/sources/itunes"
27
28 module Lyricli
29 def self.execute
30 @lyricli = Lyricli.new
31 @lyricli.get_lyrics
32 end
33
34 class Lyricli
35
36 def initialize
37 @source_manager = SourceManager.new
38 end
39
40 def exit_with_error
41 abort "Usage: #{$0} artist song"
42 end
43
44 def get_lyrics
45 set_current_track
46 check_params
47
48 engine = LyricsEngine.new(@current_track[:artist], @current_track[:song])
49
50 begin
51 engine.get_lyrics
52 rescue LyricsNotFoundException
53 "Lyrics not found :("
54 end
55 end
56
57 def set_current_track
58 @current_track = @source_manager.current_track
59 end
60
61 def check_params
62 self.exit_with_error if @current_track[:artist].nil? or @current_track[:artist].empty?
63 self.exit_with_error if @current_track[:song].nil? or @current_track[:song].empty?
64 end
65 end
66 end