lyrics-ebook 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +340 -0
- data/README +46 -0
- data/bin/lyrics-ebook +47 -0
- data/lib/eeepub/LICENSE +20 -0
- data/lib/eeepub/README.md +77 -0
- data/lib/eeepub/Rakefile +49 -0
- data/lib/eeepub/VERSION +1 -0
- data/lib/eeepub/examples/files/bar.html +42 -0
- data/lib/eeepub/examples/files/foo.html +42 -0
- data/lib/eeepub/examples/simple_epub.rb +25 -0
- data/lib/eeepub/lib/eeepub.rb +17 -0
- data/lib/eeepub/lib/eeepub/container_item.rb +108 -0
- data/lib/eeepub/lib/eeepub/easy.rb +100 -0
- data/lib/eeepub/lib/eeepub/maker.rb +127 -0
- data/lib/eeepub/lib/eeepub/ncx.rb +68 -0
- data/lib/eeepub/lib/eeepub/ocf.rb +112 -0
- data/lib/eeepub/lib/eeepub/opf.rb +148 -0
- data/lib/eeepub/spec/eeepub/easy_spec.rb +66 -0
- data/lib/eeepub/spec/eeepub/maker_spec.rb +124 -0
- data/lib/eeepub/spec/eeepub/ncx_spec.rb +80 -0
- data/lib/eeepub/spec/eeepub/ocf_spec.rb +43 -0
- data/lib/eeepub/spec/eeepub/opf_spec.rb +262 -0
- data/lib/eeepub/spec/eeepub_spec.rb +4 -0
- data/lib/eeepub/spec/spec_helper.rb +12 -0
- data/lib/lyrics_ebook.rb +71 -0
- data/lib/lyrics_ebook/cache2html.rb +33 -0
- data/lib/lyrics_ebook/cache_manager.rb +77 -0
- data/lib/lyrics_ebook/lyric.rb +32 -0
- data/lib/lyrics_ebook/lyric_download.rb +50 -0
- data/lib/lyrics_ebook/lyrics2html.rb +106 -0
- data/lib/lyrics_ebook/mini_lyrics_parser.rb +26 -0
- data/lib/lyrics_ebook/mp3_parser.rb +37 -0
- data/lib/wiki_lyrics/amarok/COPYING +340 -0
- data/lib/wiki_lyrics/amarok/README +51 -0
- data/lib/wiki_lyrics/amarok/amarok.rb +355 -0
- data/lib/wiki_lyrics/amarok/pluginadapter.rb +113 -0
- data/lib/wiki_lyrics/amarok/plugins.rb +95 -0
- data/lib/wiki_lyrics/amarok/wikilyrics.rb +578 -0
- data/lib/wiki_lyrics/amarok/wikilyrics.spec +4 -0
- data/lib/wiki_lyrics/amarok/wikipluginadapter.rb +392 -0
- data/lib/wiki_lyrics/cli/optionsparser.rb +228 -0
- data/lib/wiki_lyrics/cli/pluginadapter.rb +56 -0
- data/lib/wiki_lyrics/cli/plugins.rb +79 -0
- data/lib/wiki_lyrics/cli/wikilyrics.rb +178 -0
- data/lib/wiki_lyrics/cli/wikipluginadapter.rb +140 -0
- data/lib/wiki_lyrics/docs/COPYING +340 -0
- data/lib/wiki_lyrics/docs/ChangeLog +293 -0
- data/lib/wiki_lyrics/docs/HOWTO.pdf +0 -0
- data/lib/wiki_lyrics/docs/HOWTO.tex +151 -0
- data/lib/wiki_lyrics/docs/HOWTO.txt +139 -0
- data/lib/wiki_lyrics/docs/README +45 -0
- data/lib/wiki_lyrics/docs/TODO +12 -0
- data/lib/wiki_lyrics/gui/gui-gtk.rb +945 -0
- data/lib/wiki_lyrics/gui/gui-qt3.rb +785 -0
- data/lib/wiki_lyrics/gui/gui-qt4.rb +845 -0
- data/lib/wiki_lyrics/gui/gui-tk.rb +1104 -0
- data/lib/wiki_lyrics/gui/gui.rb +268 -0
- data/lib/wiki_lyrics/gui/test.rb +74 -0
- data/lib/wiki_lyrics/i18n/README +1 -0
- data/lib/wiki_lyrics/i18n/en.rb +181 -0
- data/lib/wiki_lyrics/i18n/es.rb +181 -0
- data/lib/wiki_lyrics/i18n/i18n.rb +126 -0
- data/lib/wiki_lyrics/i18n/sk.rb +174 -0
- data/lib/wiki_lyrics/itrans/COPYRIGHT +31 -0
- data/lib/wiki_lyrics/itrans/itrans +0 -0
- data/lib/wiki_lyrics/itrans/itrans.txt +8 -0
- data/lib/wiki_lyrics/itrans/lyric.txt +23 -0
- data/lib/wiki_lyrics/itrans/udvng.ifm +206 -0
- data/lib/wiki_lyrics/lyrics.rb +567 -0
- data/lib/wiki_lyrics/lyrics_AZLyrics.rb +113 -0
- data/lib/wiki_lyrics/lyrics_DarkLyrics.rb +124 -0
- data/lib/wiki_lyrics/lyrics_Giitaayan.rb +124 -0
- data/lib/wiki_lyrics/lyrics_Jamendo.rb +166 -0
- data/lib/wiki_lyrics/lyrics_LeosLyrics.rb +142 -0
- data/lib/wiki_lyrics/lyrics_LoudSongs.rb +135 -0
- data/lib/wiki_lyrics/lyrics_LyricWiki.rb +329 -0
- data/lib/wiki_lyrics/lyrics_LyricsDownload.rb +118 -0
- data/lib/wiki_lyrics/lyrics_LyricsMania.rb +141 -0
- data/lib/wiki_lyrics/lyrics_Lyriki.rb +287 -0
- data/lib/wiki_lyrics/lyrics_SeekLyrics.rb +108 -0
- data/lib/wiki_lyrics/lyrics_Sing365.rb +103 -0
- data/lib/wiki_lyrics/lyrics_TerraLetras.rb +126 -0
- data/lib/wiki_lyrics/mediawikilyrics.rb +1464 -0
- data/lib/wiki_lyrics/tests/plugin_tests.rb +161 -0
- data/lib/wiki_lyrics/tests/tests.rb +74 -0
- data/lib/wiki_lyrics/utils/formdata.rb +56 -0
- data/lib/wiki_lyrics/utils/htmlentities.rb +291 -0
- data/lib/wiki_lyrics/utils/http.rb +198 -0
- data/lib/wiki_lyrics/utils/itrans.rb +160 -0
- data/lib/wiki_lyrics/utils/kde.rb +88 -0
- data/lib/wiki_lyrics/utils/logger.rb +123 -0
- data/lib/wiki_lyrics/utils/strings.rb +378 -0
- data/lib/wiki_lyrics/utils/xmlhash.rb +111 -0
- data/lib/wiki_lyrics/wikilyrics.kdevelop +152 -0
- data/lib/wiki_lyrics/wikilyrics.kdevses +18 -0
- data/lib/wiki_lyrics/win/gtk_fix.bat +3 -0
- data/lib/wiki_lyrics/win/tk_fix.bat +3 -0
- data/lib/wiki_lyrics/win/wikilyrics.bat +4 -0
- data/lib/wiki_lyrics/win/win_fix.rb +52 -0
- data/templates/art_.erb.xhtml +29 -0
- data/templates/artists.erb.xhtml +19 -0
- data/templates/cover.erb.xhtml +22 -0
- data/test/cache_manager_test.rb +73 -0
- data/test/data/artist name/title name.lyric +6 -0
- data/test/lyric_test.rb +41 -0
- metadata +194 -0
@@ -0,0 +1,56 @@
|
|
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 "cgi"
|
20
|
+
|
21
|
+
module PluginAdapter
|
22
|
+
|
23
|
+
# Hack to make module methods become class methods when the module gets included
|
24
|
+
def PluginAdapter.included( including )
|
25
|
+
if including.is_a?( Class )
|
26
|
+
including.extend( ClassMethods ) # adds class methods
|
27
|
+
else # if including.is_a?( Module )
|
28
|
+
including::ClassMethods.append_class_methods( self )
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# Methods under this module will became class methods when the module gets included
|
33
|
+
# Note: don't use def self.<method name> but just <method name>
|
34
|
+
module ClassMethods
|
35
|
+
def ClassMethods.append_class_methods( mod )
|
36
|
+
include mod::ClassMethods
|
37
|
+
end
|
38
|
+
|
39
|
+
def plugin_name()
|
40
|
+
return site_name()
|
41
|
+
end
|
42
|
+
|
43
|
+
def notify( message )
|
44
|
+
puts plugin_name() + ": " + message.gsub( /\/?<[^>]+>/, "" )
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def plugin_name()
|
49
|
+
return self.class.plugin_name()
|
50
|
+
end
|
51
|
+
|
52
|
+
def notify( message )
|
53
|
+
self.class.notify( message )
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# Copyright (C) 2007 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__ ) + "/../mediawikilyrics" )
|
20
|
+
require File.expand_path( File.dirname( __FILE__ ) + "/pluginadapter" )
|
21
|
+
require File.expand_path( File.dirname( __FILE__ ) + "/wikipluginadapter" )
|
22
|
+
|
23
|
+
module Plugins
|
24
|
+
|
25
|
+
@@ALL = []
|
26
|
+
@@WIKI = []
|
27
|
+
|
28
|
+
def Plugins.find_plugins()
|
29
|
+
plugins = {}
|
30
|
+
Dir.new( File.expand_path( File.dirname( __FILE__ ) + "/.." ) ).each() do |filename|
|
31
|
+
filename = File.expand_path( File.dirname( __FILE__ ) + "/../" + filename )
|
32
|
+
if File.file?( filename ) && (md = /\/lyrics_([A-Za-z_0-9]*)\.rb$/.match( filename ))
|
33
|
+
plugins[md[1]] = filename
|
34
|
+
end
|
35
|
+
end
|
36
|
+
return plugins
|
37
|
+
end
|
38
|
+
|
39
|
+
def Plugins.load_plugins( plugins )
|
40
|
+
plugins.each() do |classname, filename|
|
41
|
+
require( filename ? filename : File.expand_path( File.dirname( __FILE__ ) + "/../lyrics_#{classname}.rb" ) )
|
42
|
+
classobj = eval( classname )
|
43
|
+
if classobj.ancestors().include?( MediaWikiLyrics )
|
44
|
+
eval( "class CLI#{classname} < #{classname}\ninclude WikiPluginAdapter\nend" )
|
45
|
+
plugin = eval( "CLI#{classname}.new()" )
|
46
|
+
@@WIKI << plugin
|
47
|
+
else
|
48
|
+
eval( "class CLI#{classname} < #{classname}\ninclude PluginAdapter\nend" )
|
49
|
+
plugin = eval( "CLI#{classname}.new()" )
|
50
|
+
end
|
51
|
+
@@ALL << plugin
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
def Plugins.all_plugins()
|
57
|
+
return @@ALL
|
58
|
+
end
|
59
|
+
|
60
|
+
def Plugins.all_names()
|
61
|
+
return @@ALL.collect(){ |plugin| plugin.plugin_name() }
|
62
|
+
end
|
63
|
+
|
64
|
+
def Plugins.wiki_plugins()
|
65
|
+
return @@WIKI
|
66
|
+
end
|
67
|
+
|
68
|
+
def Plugins.wiki_names()
|
69
|
+
return @@WIKI.collect(){ |plugin| plugin.plugin_name() }
|
70
|
+
end
|
71
|
+
|
72
|
+
def Plugins.plugin_by_name( name )
|
73
|
+
@@ALL.each() do |plugin|
|
74
|
+
return plugin if plugin.plugin_name() == name
|
75
|
+
end
|
76
|
+
return nil
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
@@ -0,0 +1,178 @@
|
|
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
|
+
require File.expand_path( File.dirname( __FILE__ ) + "/../i18n/i18n" )
|
22
|
+
require File.expand_path( File.dirname( __FILE__ ) + "/../utils/strings" )
|
23
|
+
require File.expand_path( File.dirname( __FILE__ ) + "/../utils/logger" )
|
24
|
+
require File.expand_path( File.dirname( __FILE__ ) + "/optionsparser" )
|
25
|
+
require File.expand_path( File.dirname( __FILE__ ) + "/plugins" )
|
26
|
+
|
27
|
+
class Application
|
28
|
+
|
29
|
+
def initialize( featuring_fix, cleanup_lyrics, submit, review=true,
|
30
|
+
prompt_autogen=false, prompt_no_lyrics=false, username=nil, password=nil )
|
31
|
+
@featuring_fix = featuring_fix
|
32
|
+
@submit_plugin = nil
|
33
|
+
@logger = Logger.new( "#{ENV["HOME"]}/.wikilyrics.log" )
|
34
|
+
Plugins.all_plugins().each() do |plugin|
|
35
|
+
plugin.cleanup_lyrics = cleanup_lyrics
|
36
|
+
plugin.logger = @logger
|
37
|
+
if plugin.plugin_name() == submit
|
38
|
+
@submit_plugin = plugin
|
39
|
+
@submit_plugin.set_submit_settings( username, password, review, prompt_autogen, prompt_no_lyrics )
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def finalize()
|
45
|
+
@logger.finalize() if @logger
|
46
|
+
end
|
47
|
+
|
48
|
+
def Application.notify( message )
|
49
|
+
puts "Wiki-Lyrics: " + message.gsub( /\/?<[^>]+>/, "" )
|
50
|
+
end
|
51
|
+
|
52
|
+
def notify( message )
|
53
|
+
self.class.notify( message )
|
54
|
+
end
|
55
|
+
|
56
|
+
def restore_session( session_file )
|
57
|
+
@submit_plugin.restore_session( session_file ) if @submit_plugin
|
58
|
+
end
|
59
|
+
|
60
|
+
def save_session( session_file )
|
61
|
+
@submit_plugin.save_session( session_file ) if @submit_plugin
|
62
|
+
end
|
63
|
+
|
64
|
+
def fetch_lyrics( request )
|
65
|
+
|
66
|
+
used_plugins = Plugins.all_plugins()
|
67
|
+
|
68
|
+
response = nil
|
69
|
+
response_plugin = nil
|
70
|
+
shown_review_dialog = false
|
71
|
+
submit_plugin_searched = false
|
72
|
+
|
73
|
+
used_plugins.each() do |plugin|
|
74
|
+
begin
|
75
|
+
submit_plugin_searched = true if plugin == @submit_plugin
|
76
|
+
response = plugin.lyrics_full_search( request )
|
77
|
+
if response.lyrics
|
78
|
+
response_plugin = plugin
|
79
|
+
break
|
80
|
+
end
|
81
|
+
rescue TimeoutError
|
82
|
+
notify( I18n.get( "cli.application.plugintimeout", plugin.plugin_name(), plugin.site_host() ) )
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
if @submit_plugin
|
87
|
+
shown_review_dialog = @submit_plugin.wiki_process_response( response, response_plugin, submit_plugin_searched )
|
88
|
+
end
|
89
|
+
|
90
|
+
return response, response_plugin, shown_review_dialog
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
def process( artist, title, album, year )
|
95
|
+
|
96
|
+
if @featuring_fix
|
97
|
+
artist = Strings.cleanup_artist( artist, title )
|
98
|
+
title = Strings.cleanup_title( title )
|
99
|
+
end
|
100
|
+
|
101
|
+
notify( I18n.get( "cli.application.searchinglyrics", title, artist ) )
|
102
|
+
|
103
|
+
request = Lyrics::Request.new( artist, title, album, year )
|
104
|
+
response, response_plugin, shown_review_dialog = fetch_lyrics( request )
|
105
|
+
|
106
|
+
if response.lyrics
|
107
|
+
artist = response.artist ? response.artist : response.request.artist
|
108
|
+
title = response.title ? response.title : response.request.title
|
109
|
+
notify( I18n.get( "cli.application.lyricsfound", title, artist, response_plugin.site_name ) )
|
110
|
+
if ! shown_review_dialog
|
111
|
+
if GUI.get_current_toolkit()
|
112
|
+
GUI.show_lyrics_dialog( {
|
113
|
+
"artist" => artist,
|
114
|
+
"title" => title,
|
115
|
+
"lyrics" => response.lyrics,
|
116
|
+
"site_name" => response_plugin.site_name
|
117
|
+
} )
|
118
|
+
else
|
119
|
+
puts "\n#{response.lyrics}\n\n"
|
120
|
+
end
|
121
|
+
end
|
122
|
+
else
|
123
|
+
notify( I18n.get( "cli.application.nolyricsfound", request.title, request.artist ) )
|
124
|
+
end
|
125
|
+
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
129
|
+
|
130
|
+
if $0 == __FILE__
|
131
|
+
|
132
|
+
options = OptionsParser.parse( ARGV )
|
133
|
+
|
134
|
+
Plugins.load_plugins( options.sites )
|
135
|
+
|
136
|
+
HTTP.set_proxy_settings( options.proxy ) if options.proxy
|
137
|
+
GUI.set_toolkit_priority( options.toolkits ) if options.toolkits.size > 0
|
138
|
+
|
139
|
+
app = Application.new(
|
140
|
+
options.feat_fix,
|
141
|
+
options.cleanup,
|
142
|
+
options.submit,
|
143
|
+
options.review,
|
144
|
+
options.prompt_autogen,
|
145
|
+
options.prompt_no_lyrics,
|
146
|
+
options.username,
|
147
|
+
options.password
|
148
|
+
)
|
149
|
+
|
150
|
+
begin
|
151
|
+
|
152
|
+
app.restore_session( options.session_file ) if options.session_file
|
153
|
+
|
154
|
+
if options.batch_file
|
155
|
+
app.notify( I18n.get( "cli.application.batchmode" ) )
|
156
|
+
file = File.new( options.batch_file, "r" )
|
157
|
+
count = 0
|
158
|
+
while ( line = file.gets )
|
159
|
+
params = line.split( ";" )
|
160
|
+
next if params.length < 2
|
161
|
+
app.process( params[0], params[1], params[2], params[3] )
|
162
|
+
count += 1
|
163
|
+
end
|
164
|
+
notify( I18n.get( "cli.application.processedcount", count ) )
|
165
|
+
file.close()
|
166
|
+
else
|
167
|
+
app.process( options.artist, options.title, options.album, options.year )
|
168
|
+
end
|
169
|
+
|
170
|
+
app.save_session( options.session_file ) if options.session_file
|
171
|
+
|
172
|
+
ensure
|
173
|
+
|
174
|
+
app.finalize()
|
175
|
+
|
176
|
+
end
|
177
|
+
|
178
|
+
end
|
@@ -0,0 +1,140 @@
|
|
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__ ) + "/../utils/strings" )
|
20
|
+
require File.expand_path( File.dirname( __FILE__ ) + "/../i18n/i18n" )
|
21
|
+
require File.expand_path( File.dirname( __FILE__ ) + "/../gui/gui" )
|
22
|
+
require File.expand_path( File.dirname( __FILE__ ) + "/pluginadapter" )
|
23
|
+
require File.expand_path( File.dirname( __FILE__ ) + "/plugins" )
|
24
|
+
|
25
|
+
require "md5"
|
26
|
+
require "uri"
|
27
|
+
|
28
|
+
module WikiPluginAdapter
|
29
|
+
|
30
|
+
# Hack to make module methods become class methods when the module gets included
|
31
|
+
def WikiPluginAdapter.included( including )
|
32
|
+
if including.is_a?( Class )
|
33
|
+
including.extend( ClassMethods ) # adds class methods
|
34
|
+
else # including.is_a?( Module )
|
35
|
+
including::ClassMethods.append_class_methods( self )
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# Methods under this module will became class methods when the module gets included
|
40
|
+
# Note: don't use def self.<method name> but just <method name>
|
41
|
+
module ClassMethods
|
42
|
+
def ClassMethods.append_class_methods( mod )
|
43
|
+
include mod::ClassMethods
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
include PluginAdapter
|
48
|
+
|
49
|
+
def submit?()
|
50
|
+
return @wpa_submit
|
51
|
+
end
|
52
|
+
|
53
|
+
def check_submit_conditions()
|
54
|
+
if @wpa_submit
|
55
|
+
login( @wpa_username, @wpa_password, false )
|
56
|
+
else
|
57
|
+
logout()
|
58
|
+
end
|
59
|
+
|
60
|
+
if ! logged_in?
|
61
|
+
@wpa_submit = false
|
62
|
+
end
|
63
|
+
|
64
|
+
if ! @wpa_submit || ! @wpa_review
|
65
|
+
@wpa_prompt_no_lyrics = false
|
66
|
+
@wpa_prompt_autogen = false
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def set_submit_settings( username, password, review, prompt_autogen, prompt_no_lyrics )
|
71
|
+
@wpa_submit = true
|
72
|
+
@wpa_review = review
|
73
|
+
@wpa_prompt_autogen = prompt_autogen
|
74
|
+
@wpa_prompt_no_lyrics = prompt_no_lyrics
|
75
|
+
@wpa_username = username
|
76
|
+
@wpa_password = password
|
77
|
+
if ! @wpa_submit || ! @wpa_review
|
78
|
+
@wpa_prompt_no_lyrics = false
|
79
|
+
@wpa_prompt_autogen = false
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
# returns true if the review contents page is shown to the user (which can only happen when there was something to submit)
|
84
|
+
def wiki_process_response( response, response_plugin, wiki_searched )
|
85
|
+
|
86
|
+
return false if ! submit?() || ! authorized?
|
87
|
+
|
88
|
+
lyrics_found_on_site = response.lyrics && response_plugin == self
|
89
|
+
lyrics_autogenerated = lyrics_found_on_site && ! response.custom_data["reviewed"]
|
90
|
+
|
91
|
+
return false if lyrics_found_on_site && ! lyrics_autogenerated # we have nothing to do
|
92
|
+
return false if (! @wpa_prompt_autogen && lyrics_autogenerated) || (! @wpa_prompt_no_lyrics && ! response.lyrics)
|
93
|
+
|
94
|
+
begin
|
95
|
+
|
96
|
+
check_submit_conditions()
|
97
|
+
|
98
|
+
song_data = MediaWikiLyrics::SongData.new(
|
99
|
+
response.artist ? response.artist : response.request.artist,
|
100
|
+
response.title ? response.title : response.request.title,
|
101
|
+
response.lyrics,
|
102
|
+
response.album ? response.album : response.request.album,
|
103
|
+
response.year ? response.year : response.request.year,
|
104
|
+
response.custom_data["credits"],
|
105
|
+
response.custom_data["lyricist"]
|
106
|
+
)
|
107
|
+
|
108
|
+
submitted_url, submitted_data = submit_song_page(
|
109
|
+
song_data,
|
110
|
+
lyrics_autogenerated ? response.url : nil, # are we editing an existing page or creating a new one?
|
111
|
+
song_data.artist == response.request.artist && song_data.title == response.request.title &&
|
112
|
+
wiki_searched && ! lyrics_found_on_site, # do we KNOW FOR SURE the page doesn't exists?
|
113
|
+
@wpa_review || lyrics_autogenerated, # should we show the review contents dialog?
|
114
|
+
lyrics_autogenerated # should user be forced to review contents? (true causes the operation to abort otherwise)
|
115
|
+
)
|
116
|
+
|
117
|
+
# transfer summited data to response
|
118
|
+
if submitted_data
|
119
|
+
response.artist = submitted_data["artist"] if ! Strings.empty?( submitted_data["artist"] )
|
120
|
+
response.title = submitted_data["title"] if ! Strings.empty?( submitted_data["title"] )
|
121
|
+
response.album = submitted_data["album"] if ! Strings.empty?( submitted_data["album"] )
|
122
|
+
response.year = submitted_data["year"] if ! Strings.empty?( submitted_data["year"] )
|
123
|
+
response.lyrics = submitted_data["lyrics"] if ! Strings.empty?( submitted_data["lyrics"] )
|
124
|
+
custom_data = {}
|
125
|
+
custom_data.merge( response.custom_data )
|
126
|
+
custom_data["credits"] = submitted_data["credits"] if ! Strings.empty?( submitted_data["credits"] )
|
127
|
+
custom_data["lyricst"] = submitted_data["lyricst"] if ! Strings.empty?( submitted_data["lyricst"] )
|
128
|
+
response.custom_data = custom_data
|
129
|
+
end
|
130
|
+
|
131
|
+
return (@wpa_review || lyrics_autogenerated) && submitted_data
|
132
|
+
|
133
|
+
rescue TimeoutError
|
134
|
+
notify( I18n.get( "cli.application.plugintimeout", plugin_name(), site_host() ) )
|
135
|
+
return false
|
136
|
+
end
|
137
|
+
|
138
|
+
end
|
139
|
+
|
140
|
+
end
|