]> git.r.bdr.sh - rbdr/lyricli.rb/blob - lib/lyricli.rb
31571c8b8ce034047c0b12f42a797f6406994fa0
[rbdr/lyricli.rb] / lib / lyricli.rb
1 require 'uri'
2 require 'cgi'
3 require 'net/http'
4 require 'multi_json'
5 require 'nokogiri'
6 require 'open-uri'
7 require 'launchy'
8
9 # This shit causes a lot of warnings. Quick Hack.
10 original_verbosity = $VERBOSE
11 $VERBOSE = nil
12 require 'rdio'
13 $VERBOSE = original_verbosity
14
15 # Local Dependencies
16 require "lyricli/util"
17 require "lyricli/configuration"
18 require "lyricli/lyricli"
19 require "lyricli/lyrics_engine"
20 require "lyricli/source_manager"
21 require "lyricli/sources"
22 require "lyricli/sources/arguments"
23 require "lyricli/sources/rdio"
24 require "lyricli/sources/itunes"
25 require "lyricli/exceptions"
26 require "lyricli/exceptions/disable_source_error"
27 require "lyricli/exceptions/enable_source_error"
28 require "lyricli/exceptions/invalid_lyrics_error"
29 require "lyricli/exceptions/lyrics_not_found_error"
30 require "lyricli/exceptions/reset_source_error"
31 require "lyricli/exceptions/source_configuration_error"
32 require "lyricli/exceptions/start_source_error"
33 require "lyricli/exceptions/unknown_source_error"
34
35 # The Lyricli module allows you to easily search for lyrics by looking for
36 # song and artist data from diverse sources.
37 module Lyricli
38 # Creates a new Lyricli instance and returns lyrics by going through the
39 # sources.
40 # @return [String] the fetched lyrics
41 def self.lyrics
42 @lyricli = Lyricli.new
43 @lyricli.get_lyrics
44 end
45
46 # Returns the version of the library
47 # @return [String] the version
48 def self.version
49 Gem.loaded_specs["lyricli"].version
50 end
51
52 # Returns a list of the available sources to enable or disable
53 # @return [String] the list of available sources. Enabled sources have
54 # a star appended.
55 def self.sources
56 source_manager = SourceManager.new
57 source_manager.available_sources(true).join(", ")
58 end
59
60 # Enables a source via the Source Manager
61 def self.enable(source_name)
62 source_manager = SourceManager.new
63 begin
64 source_manager.enable(source_name)
65 rescue Exceptions::UnknownSourceError
66 "There is no such Source"
67 end
68 end
69
70 # Disables a source via the Source Manager
71 def self.disable(source_name)
72 source_manager = SourceManager.new
73 begin
74 source_manager.disable(source_name)
75 rescue Exceptions::UnknownSourceError
76 "There is no such Source"
77 end
78 end
79
80 # Resets all configuration for a source via the Source Manager
81 def self.reset(source_name)
82 source_manager = SourceManager.new
83 begin
84 source_manager.reset(source_name)
85 rescue Exceptions::UnknownSourceError
86 "There is no such Source"
87 end
88 end
89 end