lyrics 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. data/.document +5 -0
  2. data/.gitignore +21 -0
  3. data/LICENSE +20 -0
  4. data/README.rdoc +17 -0
  5. data/Rakefile +45 -0
  6. data/VERSION +1 -0
  7. data/bin/lyrics +66 -0
  8. data/lib/lyrics.rb +4 -0
  9. data/lib/lyrics/cli/application.rb +99 -0
  10. data/lib/lyrics/cli/optionsparser.rb +228 -0
  11. data/lib/lyrics/cli/pluginadapter.rb +56 -0
  12. data/lib/lyrics/cli/plugins.rb +79 -0
  13. data/lib/lyrics/cli/wikipluginadapter.rb +139 -0
  14. data/lib/lyrics/i18n/README +1 -0
  15. data/lib/lyrics/i18n/en.rb +181 -0
  16. data/lib/lyrics/i18n/es.rb +181 -0
  17. data/lib/lyrics/i18n/i18n.rb +126 -0
  18. data/lib/lyrics/i18n/sk.rb +174 -0
  19. data/lib/lyrics/itrans/COPYRIGHT +31 -0
  20. data/lib/lyrics/itrans/itrans +0 -0
  21. data/lib/lyrics/itrans/itrans.txt +8 -0
  22. data/lib/lyrics/itrans/lyric.txt +23 -0
  23. data/lib/lyrics/itrans/udvng.ifm +206 -0
  24. data/lib/lyrics/lyrics.rb +567 -0
  25. data/lib/lyrics/lyrics_AZLyrics.rb +113 -0
  26. data/lib/lyrics/lyrics_DarkLyrics.rb +124 -0
  27. data/lib/lyrics/lyrics_Giitaayan.rb +124 -0
  28. data/lib/lyrics/lyrics_Jamendo.rb +166 -0
  29. data/lib/lyrics/lyrics_LeosLyrics.rb +142 -0
  30. data/lib/lyrics/lyrics_LoudSongs.rb +135 -0
  31. data/lib/lyrics/lyrics_LyricWiki.rb +328 -0
  32. data/lib/lyrics/lyrics_LyricsDownload.rb +118 -0
  33. data/lib/lyrics/lyrics_LyricsMania.rb +141 -0
  34. data/lib/lyrics/lyrics_Lyriki.rb +286 -0
  35. data/lib/lyrics/lyrics_SeekLyrics.rb +108 -0
  36. data/lib/lyrics/lyrics_Sing365.rb +103 -0
  37. data/lib/lyrics/lyrics_TerraLetras.rb +126 -0
  38. data/lib/lyrics/mediawikilyrics.rb +1417 -0
  39. data/lib/lyrics/utils/formdata.rb +56 -0
  40. data/lib/lyrics/utils/htmlentities.rb +291 -0
  41. data/lib/lyrics/utils/http.rb +198 -0
  42. data/lib/lyrics/utils/itrans.rb +160 -0
  43. data/lib/lyrics/utils/logger.rb +123 -0
  44. data/lib/lyrics/utils/strings.rb +378 -0
  45. data/lib/lyrics/utils/xmlhash.rb +111 -0
  46. data/lyrics.gemspec +98 -0
  47. data/spec/lyrics_spec.rb +7 -0
  48. data/spec/spec.opts +1 -0
  49. data/spec/spec_helper.rb +9 -0
  50. metadata +137 -0
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 David A. Cuadrado
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,17 @@
1
+ = lyrics
2
+
3
+ Description goes here.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
+ * Send me a pull request. Bonus points for topic branches.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2010 David A. Cuadrado. See LICENSE for details.
@@ -0,0 +1,45 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "lyrics"
8
+ gem.summary = %Q{lib and cli to fetch lyrics}
9
+ gem.description = %Q{lib and cli to fetch lyrics}
10
+ gem.email = "krawek@gmail.com"
11
+ gem.homepage = "http://github.com/dcu/lyrics"
12
+ gem.authors = ["David A. Cuadrado"]
13
+ gem.add_development_dependency "rspec", ">= 1.2.9"
14
+ gem.add_development_dependency "yard", ">= 0"
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
20
+ end
21
+
22
+ require 'spec/rake/spectask'
23
+ Spec::Rake::SpecTask.new(:spec) do |spec|
24
+ spec.libs << 'lib' << 'spec'
25
+ spec.spec_files = FileList['spec/**/*_spec.rb']
26
+ end
27
+
28
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
29
+ spec.libs << 'lib' << 'spec'
30
+ spec.pattern = 'spec/**/*_spec.rb'
31
+ spec.rcov = true
32
+ end
33
+
34
+ task :spec => :check_dependencies
35
+
36
+ task :default => :spec
37
+
38
+ begin
39
+ require 'yard'
40
+ YARD::Rake::YardocTask.new
41
+ rescue LoadError
42
+ task :yardoc do
43
+ abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
44
+ end
45
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.2
@@ -0,0 +1,66 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Copyright (C) 2006-2008 by Sergio Pistone
4
+ # sergio_pistone@yahoo.com.ar
5
+ #
6
+ # This program is free software; you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation; either version 2 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with this program; if not, write to the
18
+ # Free Software Foundation, Inc.,
19
+ # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
+
21
+ $:.unshift File.dirname(__FILE__)+"/../lib"
22
+
23
+ require "lyrics"
24
+
25
+ options = OptionsParser.parse( ARGV )
26
+
27
+ HTTP.set_proxy_settings( options.proxy ) if options.proxy
28
+
29
+ app = Application.new(
30
+ :featuring_fix => options.feat_fix,
31
+ :sites => options.sites,
32
+ :cleanup_lyrics => options.cleanup,
33
+ :submit => options.submit,
34
+ :review => options.review,
35
+ :prompt_autogen => options.prompt_autogen,
36
+ :prompt_no_lyrics => options.prompt_no_lyrics,
37
+ :username => options.username,
38
+ :password => options.password
39
+ )
40
+
41
+ begin
42
+ app.restore_session( options.session_file ) if options.session_file
43
+
44
+ if options.batch_file
45
+ notify( I18n.get( "cli.application.batchmode" ) )
46
+ file = File.new( options.batch_file, "r" )
47
+ count = 0
48
+ while ( line = file.gets )
49
+ params = line.split( ";" )
50
+ next if params.length < 2
51
+ app.process( params[0], params[1], params[2], params[3] )
52
+ count += 1
53
+ end
54
+ notify( I18n.get( "cli.application.processedcount", count ) )
55
+ file.close()
56
+ else
57
+ app.process( options.artist, options.title, options.album, options.year )
58
+ end
59
+
60
+ app.save_session( options.session_file ) if options.session_file
61
+
62
+ ensure
63
+
64
+ app.finalize()
65
+
66
+ end
@@ -0,0 +1,4 @@
1
+ $:.unshift File.dirname(__FILE__)+"/../lib/lyrics"
2
+
3
+ require 'lyrics/lyrics'
4
+ require 'cli/application'
@@ -0,0 +1,99 @@
1
+ require "i18n/i18n"
2
+ require "utils/strings"
3
+ require "utils/logger"
4
+ require "cli/optionsparser"
5
+ require "cli/plugins"
6
+
7
+ class Application
8
+ def initialize(options = {})
9
+ Plugins.load_plugins( options[:sites] || Plugins.find_plugins() )
10
+
11
+ @featuring_fix = options[:featuring_fix] || true
12
+ @submit_plugin = nil
13
+ @logger = Logger.new( "#{ENV["HOME"]}/.wikilyrics.log" )
14
+ Plugins.all_plugins().each() do |plugin|
15
+ plugin.cleanup_lyrics = options[:cleanup_lyrics] || true
16
+ plugin.logger = @logger
17
+ if plugin.plugin_name() == options[:submit]
18
+ @submit_plugin = plugin
19
+ @submit_plugin.set_submit_settings( options[:username],
20
+ options[:password],
21
+ options[:review] || true,
22
+ options[:prompt_autogen] || false,
23
+ options[:prompt_no_lyrics] || false)
24
+ end
25
+ end
26
+ end
27
+
28
+ def finalize()
29
+ @logger.finalize() if @logger
30
+ end
31
+
32
+ def Application.notify( message )
33
+ $stderr.puts "Wiki-Lyrics: " + message.gsub( /\/?<[^>]+>/, "" )
34
+ end
35
+
36
+ def notify( message )
37
+ self.class.notify( message )
38
+ end
39
+
40
+ def restore_session( session_file )
41
+ @submit_plugin.restore_session( session_file ) if @submit_plugin
42
+ end
43
+
44
+ def save_session( session_file )
45
+ @submit_plugin.save_session( session_file ) if @submit_plugin
46
+ end
47
+
48
+ def fetch_lyrics( request )
49
+
50
+ used_plugins = Plugins.all_plugins()
51
+
52
+ response = nil
53
+ response_plugin = nil
54
+ submit_plugin_searched = false
55
+
56
+ used_plugins.each() do |plugin|
57
+ begin
58
+ submit_plugin_searched = true if plugin == @submit_plugin
59
+ response = plugin.lyrics_full_search( request )
60
+ if response.lyrics
61
+ response_plugin = plugin
62
+ break
63
+ end
64
+ rescue TimeoutError
65
+ notify( I18n.get( "cli.application.plugintimeout", plugin.plugin_name(), plugin.site_host() ) )
66
+ end
67
+ end
68
+
69
+ return response, response_plugin
70
+
71
+ end
72
+
73
+ def fetch(artist, title, album = nil, year = nil)
74
+ if @featuring_fix
75
+ artist = Strings.cleanup_artist( artist, title )
76
+ title = Strings.cleanup_title( title )
77
+ end
78
+
79
+ request = Lyrics::Request.new( artist, title, album, year )
80
+ response, response_plugin = fetch_lyrics( request )
81
+ response
82
+ end
83
+
84
+ def process( artist, title, album, year )
85
+ notify( I18n.get( "cli.application.searchinglyrics", title, artist ) )
86
+
87
+ response = fetch(artist, title, album, year)
88
+
89
+ if response.lyrics
90
+ artist = response.artist ? response.artist : response.request.artist
91
+ title = response.title ? response.title : response.request.title
92
+ puts "\n#{response.lyrics}\n\n"
93
+ else
94
+ notify( I18n.get( "cli.application.nolyricsfound", request.title, request.artist ) )
95
+ end
96
+
97
+ end
98
+
99
+ end
@@ -0,0 +1,228 @@
1
+ # Copyright (C) 2006-2008 by Sergio Pistone
2
+ # sergio_pistone@yahoo.com.ar
3
+ #
4
+ # This program is free software; you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation; either version 2 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program; if not, write to the
16
+ # Free Software Foundation, Inc.,
17
+ # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
+
19
+ require File.expand_path( File.dirname( __FILE__ ) + "/../i18n/i18n" )
20
+ require File.expand_path( File.dirname( __FILE__ ) + "/plugins" )
21
+ require File.expand_path( File.dirname( __FILE__ ) + "/../mediawikilyrics" )
22
+
23
+ require "optparse"
24
+ require "ostruct"
25
+ require "uri"
26
+
27
+ WIKILYRICS_VERSION = "Wiki-Lyrics v#{MediaWikiLyrics.version()}"
28
+ TOOLKITS_DEFAULT = ["qt3", "qt4", "gtk", "tk"]
29
+
30
+ module OptionsParser
31
+
32
+ @@max_chunksize = 80
33
+ begin
34
+ require "curses"
35
+ @@max_chunksize = Curses::Window.new( 0, 0, 0, 0 ).maxx() - 38
36
+ Curses::close_screen()
37
+ rescue Exception
38
+ @@max_chunksize = 80
39
+ end
40
+
41
+ def self.get_text_chunk( text, start_idx )
42
+
43
+ # find first non empty character in chunk:
44
+ while ( start_idx < (text.size-1) && "\n ".index( text[start_idx] ) )
45
+ start_idx += 1
46
+ end
47
+
48
+ # no more chunks left
49
+ return nil if start_idx >= text.size
50
+
51
+ # buscar el ultimo " " o el primer "\n "
52
+ end_idx = nil
53
+ idx = start_idx
54
+ while ( idx < text.size && idx < start_idx + @@max_chunksize + 1 )
55
+ if text[idx] == "\n"[0]
56
+ end_idx = idx
57
+ break
58
+ elsif text[idx] == " "[0]
59
+ end_idx = idx
60
+ end
61
+ idx += 1
62
+ end
63
+ end_idx = idx if ! end_idx || idx == text.size
64
+ return text.slice( start_idx..end_idx-1 ), end_idx
65
+
66
+ end
67
+
68
+ def self.split( text )
69
+ ret = []
70
+ start_idx = 0
71
+ while ( (chunk, start_idx = get_text_chunk( text, start_idx )) && chunk != nil )
72
+ ret << chunk
73
+ end
74
+ return ret
75
+ end
76
+
77
+ def self.parse( args )
78
+
79
+ opts = OpenStruct.new()
80
+ opts.cleanup = true
81
+ opts.feat_fix = true
82
+ opts.meta = true
83
+ opts.sites = ["Lyriki", "LyricWiki"]
84
+ opts.submit = nil
85
+ opts.review = true
86
+ opts.prompt_autogen = false
87
+ opts.prompt_no_lyrics = false
88
+ opts.proxy = nil
89
+ opts.toolkits = TOOLKITS_DEFAULT
90
+
91
+ parser = OptionParser.new() do |parser|
92
+ parser.banner = I18n.get( "cli.usage", "wikilyrics.rb" )
93
+ parser.separator I18n.get( "cli.description" )
94
+
95
+ parser.separator ""
96
+ parser.separator I18n.get( "cli.options" )
97
+ parser.on( "-a", "--artist [ARTIST]", *split( I18n.get( "cli.options.artist", "batch-file" ) ) ) do |artist|
98
+ opts.artist = artist
99
+ end
100
+ parser.on( "-t", "--title [TITLE]", *split( I18n.get( "cli.options.title", "batch-file" ) ) ) do |title|
101
+ opts.title = title
102
+ end
103
+ parser.on( "-l", "--album [ALBUM]", *split( I18n.get( "cli.options.album" ) ) ) { |album| opts.album = album }
104
+ parser.on( "-y", "--year [YEAR]", *split( I18n.get( "cli.options.year" ) ) ) { |year| opts.year = year }
105
+ parser.on( "-f", "--[no-]featfix", *split( I18n.get( "cli.options.featfix", I18n.get( "cli.values.true" ) ) ) ) do |feat_fix|
106
+ opts.feat_fix = feat_fix
107
+ end
108
+
109
+ parser.separator ""
110
+ parser.on( "-b", "--batch-file [FILE]", *split( I18n.get( "cli.options.batchfile" ) ) ) do |batch_file|
111
+ opts.batch_file = batch_file
112
+ end
113
+
114
+ parser.separator ""
115
+ parser.on( "-c", "--[no-]cleanup", *split( I18n.get( "cli.options.cleanup", I18n.get( "cli.values.true" ) ) ) ) do |cleanup|
116
+ opts.cleanup = cleanup
117
+ end
118
+ parser.separator ""
119
+ parser.on( "--sites [SITE1,SITE2...]", Array, *split( I18n.get( "cli.options.sites", opts.sites.join( "," ), "sites-list" ) ) ) { |sites| opts.sites = sites }
120
+ parser.on( "--sites-list", *split( I18n.get( "cli.options.sites.list" ) ) ) do
121
+ puts I18n.get( "cli.options.sites.list.available" )
122
+ Plugins.load_plugins( Plugins.find_plugins() )
123
+ plugins = Plugins.all_plugins().sort { |a,b| a.class.name <=> b.class.name }
124
+ plugins.each() { |plugin| puts " - #{plugin.class.name.slice(12..-1)} (#{plugin.site_host})" }
125
+ exit
126
+ end
127
+
128
+ parser.separator ""
129
+ parser.on( "-s", "--submit [Lyriki|LyricWiki]", *split( I18n.get( "cli.options.submit", "username", "password" ) ) ) do |submit|
130
+ opts.submit = submit
131
+ end
132
+ parser.on( "-u", "--username [USERNAME]", *split( I18n.get( "cli.options.username", "submit" ) ) ) do |username|
133
+ opts.username = username
134
+ end
135
+ parser.on( "-p", "--password [PASSWORD]", *split( I18n.get( "cli.options.password", "submit" ) ) ) do |password|
136
+ opts.password = password
137
+ end
138
+ parser.on( "--persist [SESSIONFILE]", *split( I18n.get( "cli.options.persist", "username", "password" ) ) ) do |file|
139
+ opts.session_file = file
140
+ end
141
+
142
+ parser.on( "-r", "--[no-]review", *split( I18n.get( "cli.options.prompt.review", I18n.get( "cli.values.true" ), "submit" ) ) ) { |review| opts.review = review }
143
+ parser.on( "-g", "--[no-]autogen", *split( I18n.get( "cli.options.prompt.autogen", I18n.get( "cli.values.false" ), "review" ) ) ) { |autogen| opts.prompt_autogen = autogen }
144
+ parser.on( "-n", "--[no-]new", *split( I18n.get( "cli.options.prompt.nolyrics", I18n.get( "cli.values.false" ), "review" ) ) ) { |prompt_no_lyrics| opts.prompt_no_lyrics = prompt_no_lyrics }
145
+
146
+ parser.separator ""
147
+ parser.on( "-x", "--proxy [PROXY]", *split( I18n.get( "cli.options.proxy" ) ) ) { |proxy| opts.proxy = proxy }
148
+
149
+ parser.separator ""
150
+ parser.on( "-k", "--toolkits [TK1,TK2...]", Array, *split( I18n.get( "cli.options.toolkits", TOOLKITS_DEFAULT.join( "," ) ) ) ) { |toolkits| opts.toolkits = toolkits ? toolkits : [] }
151
+
152
+ parser.separator ""
153
+ parser.on_tail( "-h", "--help", *split( I18n.get( "cli.options.help" ) ) ) { puts parser; exit }
154
+ parser.on_tail( "-v", "--version", *split( I18n.get( "cli.options.version" ) ) ) { puts "#{WIKILYRICS_VERSION}"; exit }
155
+ end
156
+
157
+ begin
158
+
159
+ parser.parse!( args )
160
+
161
+ raise ArgumentError, I18n.get( "cli.error.missingoption", "--artist" ) if ! opts.artist && ! opts.batch_file
162
+ raise ArgumentError, I18n.get( "cli.error.missingoption", "--title" ) if ! opts.title && ! opts.batch_file
163
+
164
+ raise ArgumentError, I18n.get( "cli.error.missingoption", "--username" ) if opts.submit && ! opts.username
165
+ raise ArgumentError, I18n.get( "cli.error.missingoption", "--password" ) if opts.submit && ! opts.password
166
+
167
+ if opts.batch_file && (opts.artist || opts.title || opts.album || opts.year)
168
+ raise ArgumentError, I18n.get( "cli.error.incompatibleoptions", "-b", "-a/-t/-l/-y" )
169
+ end
170
+
171
+ if opts.prompt_autogen && ( ! opts.submit || ! opts.review )
172
+ raise ArgumentError, I18n.get( "cli.error.missingdependency", "-g", "-r" )
173
+ end
174
+
175
+ if opts.prompt_no_lyrics && ( ! opts.submit || ! opts.review )
176
+ raise ArgumentError, I18n.get( "cli.error.missingdependency", "-n", "-r" )
177
+ end
178
+
179
+ opts.toolkits.each() do |toolkit|
180
+ if ! TOOLKITS_DEFAULT.include?( toolkit )
181
+ raise ArgumentError, I18n.get( "cli.error.invalidoptionvalue", "toolkit", toolkit )
182
+ end
183
+ end
184
+
185
+ if opts.submit && opts.review && opts.toolkits.empty?
186
+ raise ArgumentError, I18n.get( "cli.error.notoolkit" )
187
+ end
188
+
189
+ if opts.submit
190
+ if ! ["Lyriki","LyrikiLocal","LyricWiki"].include?( opts.submit )
191
+ raise ArgumentError, I18n.get( "cli.error.invalidoptionvalue", "submit", opts.submit )
192
+ end
193
+ opts.sites = [] if ! opts.sites
194
+ opts.sites << opts.submit
195
+ end
196
+
197
+ if ! opts.sites || opts.sites.empty?
198
+ raise ArgumentError, I18n.get( "cli.error.nosite" )
199
+ else
200
+ found_plugins = Plugins.find_plugins()
201
+ opts.sites.uniq!()
202
+ opts.sites.each() do |site|
203
+ if ! found_plugins.include?( site )
204
+ raise ArgumentError, I18n.get( "cli.error.invalidoptionvalue", "site", site )
205
+ end
206
+ end
207
+ end
208
+
209
+ if opts.proxy
210
+ begin
211
+ # TODO is this correct?
212
+ opts.proxy = nil if URI.parse( opts.proxy ).to_s() != ""
213
+ rescue Exception
214
+ raise ArgumentError, I18n.get( "cli.error.invalidoptionvalue", "proxy", opts.proxy )
215
+ end
216
+ end
217
+
218
+ return opts
219
+
220
+ rescue OptionParser::InvalidOption, OptionParser::AmbiguousOption, ArgumentError => ex
221
+ puts ex.is_a?( ArgumentError ) ? "error: #{ex}" : ex
222
+ puts parser
223
+ exit 1
224
+ end
225
+
226
+ end
227
+
228
+ end