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