]>
Commit | Line | Data |
---|---|---|
b8498f5c | 1 | require 'uri' |
178ffe13 | 2 | require 'cgi' |
b8498f5c BB |
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 | ||
d3e32008 BB |
15 | # Local Dependencies |
16 | require "lyricli/util" | |
17 | require "lyricli/configuration" | |
823e558b | 18 | require "lyricli/lyricli" |
d3e32008 BB |
19 | require "lyricli/lyrics_engine" |
20 | require "lyricli/source_manager" | |
76e96cc0 | 21 | require "lyricli/sources" |
d3e32008 BB |
22 | require "lyricli/sources/arguments" |
23 | require "lyricli/sources/rdio" | |
24 | require "lyricli/sources/itunes" | |
76e96cc0 BB |
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" | |
d3e32008 | 34 | |
823e558b BB |
35 | # The Lyricli module allows you to easily search for lyrics by looking for |
36 | # song and artist data from diverse sources. | |
d3e32008 | 37 | module Lyricli |
823e558b BB |
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 | |
d3e32008 | 42 | @lyricli = Lyricli.new |
b2ac6893 | 43 | @lyricli.get_lyrics(@show_title) |
d3e32008 | 44 | end |
b9f550e9 | 45 | |
4f3dbb13 BB |
46 | # Returns the version of the library |
47 | # @return [String] the version | |
b9f550e9 BB |
48 | def self.version |
49 | Gem.loaded_specs["lyricli"].version | |
50 | end | |
51 | ||
4f3dbb13 | 52 | # Returns a list of the available sources to enable or disable |
34d0bf15 BB |
53 | # @return [String] the list of available sources. Enabled sources have |
54 | # a star appended. | |
b9f550e9 BB |
55 | def self.sources |
56 | source_manager = SourceManager.new | |
4f3dbb13 | 57 | source_manager.available_sources(true).join(", ") |
b9f550e9 BB |
58 | end |
59 | ||
34d0bf15 | 60 | # Enables a source via the Source Manager |
4f3dbb13 BB |
61 | def self.enable(source_name) |
62 | source_manager = SourceManager.new | |
278e6d0a BB |
63 | begin |
64 | source_manager.enable(source_name) | |
65 | rescue Exceptions::UnknownSourceError | |
66 | "There is no such Source" | |
67 | end | |
b9f550e9 BB |
68 | end |
69 | ||
34d0bf15 | 70 | # Disables a source via the Source Manager |
4f3dbb13 BB |
71 | def self.disable(source_name) |
72 | source_manager = SourceManager.new | |
278e6d0a BB |
73 | begin |
74 | source_manager.disable(source_name) | |
75 | rescue Exceptions::UnknownSourceError | |
76 | "There is no such Source" | |
77 | end | |
b9f550e9 BB |
78 | end |
79 | ||
34d0bf15 | 80 | # Resets all configuration for a source via the Source Manager |
4f3dbb13 BB |
81 | def self.reset(source_name) |
82 | source_manager = SourceManager.new | |
278e6d0a BB |
83 | begin |
84 | source_manager.reset(source_name) | |
85 | rescue Exceptions::UnknownSourceError | |
86 | "There is no such Source" | |
87 | end | |
b9f550e9 | 88 | end |
ac4c2838 BB |
89 | |
90 | # Returns the root of the Gem. | |
91 | # | |
92 | # @return [String] the root path for this gem | |
93 | def self.root | |
94 | File.expand_path('../..',__FILE__) | |
95 | end | |
b2ac6893 BB |
96 | |
97 | # Sets the show_title instance variable so it requests the title | |
98 | def self.show_title | |
99 | @show_title = true | |
100 | end | |
b8498f5c | 101 | end |