lyrics 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,113 @@
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
+ $LOAD_PATH << File.expand_path(File.dirname(__FILE__))
20
+
21
+ require "utils/strings"
22
+ require "lyrics"
23
+
24
+ class AZLyrics < Lyrics
25
+
26
+ def AZLyrics.site_host()
27
+ return "www.azlyrics.com"
28
+ end
29
+
30
+ def AZLyrics.site_name()
31
+ return "AZ Lyrics"
32
+ end
33
+
34
+ def AZLyrics.lyrics_test_data()
35
+ return [
36
+ Request.new( "Radiohead", "Optimistic", "Kid A" ),
37
+ Request.new( "Pearl Jam", "Alive", "Ten" ),
38
+ Request.new( "Massive Attack", "Protection", "Protection" ),
39
+ Request.new( "Portishead", "Wandering Star", "Dummy" ),
40
+ ]
41
+ end
42
+
43
+ def AZLyrics.build_song_add_url( request )
44
+ return "http://#{site_host()}/add.html"
45
+ end
46
+
47
+ def AZLyrics.build_google_feeling_lucky_url( artist, title=nil )
48
+ query = Strings.google_search_quote( artist )
49
+ query << " " << Strings.google_search_quote( title ) if title
50
+ query << " lyrics"
51
+ return Strings.build_google_feeling_lucky_url( query, title ? "#{site_host()}/lyrics" : site_host() )
52
+ end
53
+
54
+ def build_lyrics_fetch_data( request )
55
+ return FetchPageData.new( build_google_feeling_lucky_url( request.artist, request.title ) )
56
+ end
57
+
58
+ def lyrics_page_valid?( request, page_body, page_url )
59
+ md = /<TITLE>([^<]+) LYRICS - ([^<]+)<\/TITLE>/.match( page_body )
60
+ return md ?
61
+ Strings.normalize( request.artist ) == Strings.normalize( md[1] ) &&
62
+ Strings.normalize( request.title ) == Strings.normalize( md[2] ) :
63
+ false
64
+ end
65
+
66
+ def parse_lyrics( response, page_body )
67
+
68
+ page_body = Strings.latin12utf8( page_body )
69
+ page_body.tr_s!( " \n\r\t", " " )
70
+
71
+ if (md = /<B>([^<]+) LYRICS ?<\/B> ?<BR> ?<BR> ?<FONT size=2> ?<B> ?"([^<]+)" ?<\/b>/.match( page_body ))
72
+ response.artist, response.title = Strings.titlecase( md[1], true, true ), md[2]
73
+ end
74
+
75
+ return if ! page_body.sub!( /^.*"<\/b><BR> ?<BR> ?/i, "" )
76
+ return if ! page_body.sub!( /\ ?<BR> ?<BR> ?\[ <a href=.*$/i, "" )
77
+
78
+ page_body.gsub!( /<i>\[Thanks to.*$/i, "" )
79
+ page_body.gsub!( /\ ?<br ?\/?> ?/i, "\n" )
80
+ page_body.gsub!( /\n{3,}/, "\n\n" )
81
+
82
+ response.lyrics = page_body
83
+ end
84
+
85
+ def build_suggestions_fetch_data( request )
86
+ return FetchPageData.new( build_google_feeling_lucky_url( request.artist ) )
87
+ end
88
+
89
+ def suggestions_page_valid?( request, page_body, page_url )
90
+ md = /<TITLE>([^<]+) lyrics<\/TITLE>/.match( page_body )
91
+ return md ? Strings.normalize( request.artist ) == Strings.normalize( md[1] ) : false
92
+ end
93
+
94
+ def parse_suggestions( request, page_body, page_url )
95
+
96
+ page_body = Strings.latin12utf8( page_body )
97
+ page_body.tr_s!( " \n\r\t", " " )
98
+
99
+ suggestions = []
100
+
101
+ return suggestions if ! page_body.gsub!( /.*<tr><td align=center valign=top> <font face=verdana size=5><br> ?<b>[^<]+ lyrics<\/b>/i, "" )
102
+ return suggestions if ! page_body.gsub!( /<\/font> ?<\/font> ?<\/td> ?<\/tr> ?<\/table>.*$/i, "" )
103
+
104
+ page_body.split( /<br>/i ).each() do |entry|
105
+ if (md = /<a href="\.\.([^"]+)" target="_blank">([^<]+)<\/a>/i.match( entry ))
106
+ suggestions << Suggestion.new( request.artist, md[2], "http://#{site_host()}#{md[1]}" )
107
+ end
108
+ end
109
+
110
+ return suggestions
111
+ end
112
+
113
+ end
@@ -0,0 +1,124 @@
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
+ $LOAD_PATH << File.expand_path(File.dirname(__FILE__))
20
+
21
+ require "utils/strings"
22
+ require "lyrics"
23
+
24
+ class DarkLyrics < Lyrics
25
+
26
+ def DarkLyrics.site_host()
27
+ return "www.darklyrics.com"
28
+ end
29
+
30
+ def DarkLyrics.site_name()
31
+ return "Dark Lyrics"
32
+ end
33
+
34
+ def DarkLyrics.lyrics_test_data()
35
+ return [
36
+ Request.new( "Opeth", "Hope Leaves", "Damnation" ),
37
+ Request.new( "Megadeth", "À tout le monde", "Youthanasia" ),
38
+ Request.new( "Metallica", "Master of Puppets", "Master of Puppets" ),
39
+ Request.new( "Lacuna Coil", "Heaven's a Lie", "Comalies" ),
40
+ ]
41
+ end
42
+
43
+ def DarkLyrics.build_song_add_url( request )
44
+ return "http://#{site_host()}/submit.html"
45
+ end
46
+
47
+ def DarkLyrics.build_google_feeling_lucky_url( artist, title=nil )
48
+ query = Strings.google_search_quote( artist )
49
+ query << " " << Strings.google_search_quote( title ) if title
50
+ query << " lyrics"
51
+ return Strings.build_google_feeling_lucky_url( query, title ? "#{site_host()}/lyrics" : site_host() )
52
+ end
53
+
54
+ def build_lyrics_fetch_data( request )
55
+ return FetchPageData.new( build_google_feeling_lucky_url( request.artist, request.title ) )
56
+ end
57
+
58
+ def lyrics_page_valid?( request, page_body, page_url )
59
+ md = /<title>([^<]+) LYRICS - [^<]+<\/title>/.match( page_body )
60
+ return md ? Strings.normalize( request.artist ) == Strings.normalize( md[1] ) : false
61
+ end
62
+
63
+ def parse_lyrics( response, page_body )
64
+
65
+ # page_body = Strings.latin12utf8( page_body )
66
+ page_body.tr_s!( " \n\r\t", " " )
67
+
68
+ if (md = /<FONT size=5 color=#FFFFCC>([^<]+) LYRICS<\/FONT><br>/.match( page_body ))
69
+ response.artist = Strings.titlecase( md[1], true, true )
70
+ end
71
+
72
+ if (md = /<FONT size=3 color=white><b>([^<]+) \(([0-9]{4,4})( [^\)]+|)\)<\/b><\/FONT><br>/.match( page_body ))
73
+ response.album, response.year = md[1], md[2]
74
+ end
75
+
76
+ return if ! page_body.sub!( /^.*<SCRIPT LANGUAGE="javascript" src="\.\.\/\.\.\/recban\.js"><\/SCRIPT><BR>/i, "" )
77
+ return if ! page_body.sub!( /<FONT [^>]*size=.*$/i, "" )
78
+
79
+ md = /.*#([0-9]+)$/.match( response.url )
80
+ track = md ? md[1] : nil
81
+ normalized_title = Strings.normalize( response.request.title )
82
+ page_body.split( /<a name=[0-9]+><FONT color=#DDDDDD>/i ).each() do |song_content|
83
+ md = /^<b>([0-9]+)\. ([^<]+)<\/b><\/font><br>(.*)$/.match( song_content )
84
+ next if ! md || (track && track != md[1]) || (! track && normalized_title != Strings.normalize( md[2] ))
85
+ response.title = md[2]
86
+ page_body = md[3]
87
+ page_body.gsub!( /\ ?<br ?\/?> ?/i, "\n" )
88
+ page_body.gsub!( /\n{3,}/, "\n\n" )
89
+ page_body.strip!()
90
+ response.lyrics = page_body
91
+ end
92
+
93
+ end
94
+
95
+ def build_suggestions_fetch_data( request )
96
+ return FetchPageData.new( build_google_feeling_lucky_url( request.artist ) )
97
+ end
98
+
99
+ def suggestions_page_valid?( request, page_body, page_url )
100
+ md = /<title>([^<]+) LYRICS<\/title>/.match( page_body )
101
+ return md ? Strings.normalize( request.artist ) == Strings.normalize( md[1] ) : false
102
+ end
103
+
104
+ def parse_suggestions( request, page_body, page_url )
105
+
106
+ # page_body = Strings.latin12utf8( page_body )
107
+ page_body.tr_s!( " \n\r\t", " " )
108
+
109
+ suggestions = []
110
+
111
+ return suggestions if ! page_body.sub!(/^.*<FONT FACE="Helvetica" COLOR=#FFFFCC SIZE=4><br>[^<]+ LYRICS<BR><\/FONT>/i,"")
112
+ return suggestions if ! page_body.sub!( /<SCRIPT LANGUAGE="javascript".*$/i, "" )
113
+
114
+ page_body.split( /<br>/i ).each() do |entry|
115
+ if (md = /<a href="\.\.(\/lyrics\/[^"]+)" target="_blank"><FONT [^>]+>([^"]+)<\/FONT><\/a>/i.match( entry ))
116
+ suggestions << Suggestion.new( request.artist, md[2], "http://#{site_host()}#{md[1]}" )
117
+ end
118
+ end
119
+
120
+ return suggestions
121
+
122
+ end
123
+
124
+ end
@@ -0,0 +1,124 @@
1
+ # Copyright (C) 2007-2008 by
2
+ # Swapan Sarkar <swapan@yahoo.com>
3
+ # Sergio Pistone <sergio_pistone@yahoo.com.ar>
4
+ #
5
+ # This program is free software; you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation; either version 2 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this program; if not, write to the
17
+ # Free Software Foundation, Inc.,
18
+ # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
+
20
+ $LOAD_PATH << File.expand_path(File.dirname(__FILE__))
21
+
22
+ require "utils/strings"
23
+ require "utils/itrans"
24
+ require "lyrics"
25
+
26
+ require "cgi"
27
+
28
+ class Giitaayan < Lyrics
29
+
30
+ # @@prefix = "http://s94437128.onlinehome.us/isb/cisb/"
31
+ # @@prefix = "http://gaane.giitaayan.com/cisb/"
32
+ @@prefix = "http://thaxi.hsc.usc.edu/rmim/giitaayan/cisb/"
33
+ @@prefix_regexp = /<a href=" *(#{@@prefix.gsub( "\\", "\\\\" ).gsub( ".", "\\." )}[^"]+.isb)">/
34
+
35
+ def Giitaayan.site_host()
36
+ return "www.giitaayan.com"
37
+ end
38
+
39
+ def Giitaayan.site_name()
40
+ return "Giitaayan"
41
+ end
42
+
43
+ def Giitaayan.lyrics_test_data()
44
+ return [
45
+ Request.new( "Abhijit, Kavita Subramaniam", ITRANS.to_devanagari( "a.ndherii raat me.n ham aur tum" ), "Juhi" ),
46
+ Request.new( "Poornima, Chorus", ITRANS.to_devanagari( "a aa ii u u uu meraa dil na to.Do" ), "Raajaa Baabu" ),
47
+ Request.new( "Sonu Nigam, Chorus", ITRANS.to_devanagari("gayaa gayaa dil jaane de" ), "Fizaa" ),
48
+ Request.new( "Lata, Hemant", ITRANS.to_devanagari( "ulajh gaye do nainaa, dekho" ), "Ek Saal" ),
49
+ ]
50
+ end
51
+
52
+ def Giitaayan.known_url?( url )
53
+ return url.index( @@prefix ) == 0
54
+ end
55
+
56
+ def Giitaayan.build_song_add_url( request )
57
+ return "http://#{site_host()}/submit.asp"
58
+ end
59
+
60
+ def parse_lyrics( response, page_body )
61
+
62
+ custom_data = {}
63
+
64
+ ["stitle", "film", "year", "starring", "singer", "music", "lyrics"].each() do |key|
65
+ if (md = /\\#{key}\{(.+)\}%/.match( page_body ))
66
+ custom_data[key] = md[1]
67
+ end
68
+ end
69
+
70
+ response.artist = custom_data["singer"]
71
+ response.album = custom_data["film"]
72
+ response.year = custom_data["year"]
73
+
74
+ custom_data["lyricist"] = custom_data["lyrics"] if ! Strings.empty?( custom_data["lyrics"] )
75
+ if ! Strings.empty?( custom_data["music"] ) || ! Strings.empty?( custom_data["lyrics"] )
76
+ custom_data["credits"] = "#{custom_data["music"]} #{custom_data["lyrics"]}".strip()
77
+ end
78
+ if ! Strings.empty?( custom_data["stitle"] )
79
+ custom_data["stitle"] = ITRANS.to_devanagari( custom_data["stitle"] )
80
+ response.title = custom_data["stitle"]
81
+ end
82
+
83
+ response.custom_data = custom_data
84
+
85
+ return if ! page_body.gsub!( /^.*\n#indian\s*\n%?/m, "" )
86
+ return if ! page_body.gsub!( /%?\s*\n#endindian.*$/m, "" )
87
+
88
+ page_body.gsub!( "\\threedots", "..." )
89
+ page_body.gsub!( "\\-", "-" )
90
+ page_body.gsub!( "\\:", ":" )
91
+ page_body.gsub!( /%[^\n]*/, "" )
92
+
93
+ response.lyrics = ITRANS.to_devanagari( page_body )
94
+
95
+ end
96
+
97
+ def build_suggestions_fetch_data( request )
98
+ title = CGI.escape( ITRANS.from_devanagari( request.title ) )
99
+ return FetchPageData.new( "http://#{site_host()}/search.asp?browse=stitle&s=#{title}" )
100
+ end
101
+
102
+ def parse_suggestions( request, page_body, page_url )
103
+
104
+ page_body.tr_s!( " \n\r\t", " " )
105
+
106
+ suggestions = []
107
+
108
+ return suggestions if page_body.include?( "Sorry, no song found for your search!" )
109
+ return suggestions if ! page_body.sub!( /^.*<div align="center"><b>Lyrics<\/b><\/div> ?<\/td> ?<\/tr> ?<tr>/, "" )
110
+ return suggestions if ! page_body.sub!( /<form name="form1" method="get" action="search\.asp".*$/, "" )
111
+
112
+ page_body.gsub!( /<br> ?Page <b>1<\/b> ?<a href="search.asp\?PageNo=2&s=na&browse=stitle">.*$/, "" )
113
+
114
+ page_body.split( /<\/tr> ?<tr> ?/ ).each() do |sugg|
115
+ if (md1 = /^ ?<td>([^<]+) - <a/.match( sugg )) && (md2 = @@prefix_regexp.match( sugg ))
116
+ suggestions << Suggestion.new( request.artist, ITRANS.to_devanagari( md1[1] ), md2[1] )
117
+ end
118
+ end
119
+
120
+ return suggestions
121
+
122
+ end
123
+
124
+ end
@@ -0,0 +1,166 @@
1
+ # Copyright (C) 2006-2008 by
2
+ # Eduardo Robles Elvira <edulix@gmail.com>
3
+ # Sergio Pistone <sergio_pistone@yahoo.com.ar>
4
+ #
5
+ # This program is free software; you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation; either version 2 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this program; if not, write to the
17
+ # Free Software Foundation, Inc.,
18
+ # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
+
20
+ $LOAD_PATH << File.expand_path(File.dirname(__FILE__))
21
+
22
+ require "utils/strings"
23
+ require "utils/http"
24
+ require "lyrics"
25
+
26
+ class Jamendo < Lyrics
27
+
28
+ def Jamendo.site_host()
29
+ return "www.jamendo.com"
30
+ end
31
+
32
+ def Jamendo.site_name()
33
+ return "Jamendo"
34
+ end
35
+
36
+ def Jamendo.lyrics_test_data()
37
+ return [
38
+ Request.new( "Misantropía", "Hipócrita (Hypocrite)", "Misantropía" ),
39
+ Request.new( "Inesperado", "Pez Gordo", "Maqueta Inesperada" ),
40
+ Request.new( "Black Venus", "Vents de Mars", "Immortel" ),
41
+ Request.new( "Punkamine", "Gora gerra", "Punkamine" ),
42
+ ]
43
+ end
44
+
45
+ def Jamendo.cleanup_artist_name( artist )
46
+ artist = Strings.downcase( artist )
47
+ Strings.remove_vocal_accents!( artist )
48
+ artist.gsub!( /\[|\]|:/, "" )
49
+ artist.gsub!( /_| |'|"|ø|&|@|\/|\*|\.|®|%|#/, " " ) # \' can also be ''
50
+ artist.squeeze!( " " )
51
+ artist.strip!()
52
+ artist.gsub!( " ", "." )
53
+ return artist
54
+ end
55
+
56
+ def cleanup_artist_name( artist )
57
+ self.class.cleanup_artist_name( artist )
58
+ end
59
+
60
+ def build_lyrics_fetch_data( request )
61
+ url = "http://#{site_host()}/en/get/track/list/track-artist-album/lyricstext/plain/?"
62
+ url << "searchterm=#{CGI.escape( request.title )}"
63
+ url << "&artist_searchterm=#{CGI.escape( request.artist )}"
64
+ url << "&album_searchterm=#{CGI.escape( request.album )}" if request.album
65
+ return FetchPageData.new( url )
66
+ end
67
+
68
+ def suggestions_page_valid?( request, page_body, page_url )
69
+ return page_url.index( "http://#{site_host()}/en/artist/" ) ||
70
+ page_url.index( "http://#{site_host()}/en/album/" )
71
+ end
72
+
73
+ def parse_lyrics( response, page_body )
74
+
75
+ if /track-artist-album/.match( response.url )
76
+
77
+ page_body.tr_s!( " \r\t", " " )
78
+
79
+ md = /[?&]searchterm=([^&]+)(&?|$)/.match( response.url )
80
+ response.title = CGI.unescape( md[1] ) if md
81
+
82
+ md = /[?&]artist_searchterm=([^&]+)(&?|$)/.match( response.url )
83
+ response.artist = CGI.unescape( md[1] ) if md
84
+
85
+ md = /[?&]album_searchterm=([^&]+)(&?|$)/.match( response.url )
86
+ response.album = CGI.unescape( md[1] ) if md
87
+
88
+ response.lyrics = page_body if ! page_body.empty?
89
+
90
+ else
91
+
92
+ page_body.tr_s!( " \n\r\t", " " )
93
+
94
+ if (md = /<h1>([^<]+)<\/h1><p> by <a href="\/en\/artist\/[^"]+"[^<]*>([^<]+)<\/a>/.match( page_body ))
95
+ response.title = md[1].strip()
96
+ response.artist = md[2].strip()
97
+ end
98
+
99
+ if (md = /<a class="i l a" href="http:\/\/#{site_host()}\/en\/album\/[^"]+" ?>([^<]+)<\/a>/.match( page_body ))
100
+ response.album = md[1].strip()
101
+ end
102
+
103
+ custom_data = {}
104
+ ["release", "genre"].each() do |key|
105
+ md = /<tr class='[a|b]'> ?<td class='l'>#{key}<\/td> ?<td class='[^']+'>([^<]+)<\/td> ?<\/tr>/i.match( page_body )
106
+ custom_data[key] = md[1].strip() if md
107
+ end
108
+
109
+ response.custom_data = custom_data
110
+ response.year = custom_data["release"].gsub( /.*,/, "" ) if custom_data.include?( "release" )
111
+
112
+ return if ! page_body.sub!( /^.*<div id="lyrics"[^>]*>/, "" )
113
+ return if ! page_body.sub!( /<\/div>.*$/, "" )
114
+
115
+ page_body.gsub!( /\ ?<br ?\/?> ?/i, "\n" )
116
+
117
+ response.lyrics = page_body
118
+
119
+ end
120
+
121
+ end
122
+
123
+ def build_suggestions_fetch_data( request )
124
+ return FetchPageData.new(
125
+ Strings.build_google_feeling_lucky_url(
126
+ "artist " + Strings.google_search_quote( "albums of #{request.artist}" ),
127
+ "#{site_host()}/en"
128
+ )
129
+ )
130
+ end
131
+
132
+ def parse_suggestions( request, page_body, page_url )
133
+
134
+ page_body.tr_s!( " \n\r\t", " " )
135
+
136
+ suggestions = []
137
+
138
+ if page_url.index( "http://#{site_host()}/en/artist/" )
139
+
140
+ return suggestions if ! page_body.sub!( /^.*<h2 class="seo_message" ?>Albums of [^<]+<\/h2>/, "" )
141
+ return suggestions if ! page_body.sub!( /<h3>More information...<\/h3>.*$/, "" )
142
+
143
+ page_body.split( /<h2 class='g_album_name'>/ ).each() do |album_entry|
144
+ if (md = /<a title="[^"]+" href="(\/en\/album\/[0-9]+)" >([^<]+)<\/a>/.match( album_entry ))
145
+ suggestions << FetchPageData.new( "http://#{site_host()}#{md[1]}" )
146
+ end
147
+ end
148
+
149
+ elsif page_url.index( "http://#{site_host()}/en/album/" )
150
+
151
+ return suggestions if ! page_body.sub!( /^.*<tbody>/, "" )
152
+ return suggestions if ! page_body.sub!( /<\/tbody>.*$/, "" )
153
+
154
+ page_body.split( "<td class=\"title_tracks\">" ).each() do |song_entry|
155
+ if (md = /<a href="(\/en\/track\/[0-9]+)" title="[^"]*" ?>([^<]+)<\/a>/.match( song_entry ))
156
+ suggestions << Suggestion.new( request.artist, md[2].strip(), "http://#{site_host()}#{md[1]}" )
157
+ end
158
+ end
159
+
160
+ end
161
+
162
+ return suggestions
163
+
164
+ end
165
+
166
+ end