Class: LeosLyrics
Instance Attribute Summary
Attributes inherited from Lyrics
Class Method Summary collapse
- .build_song_add_url(request) ⇒ Object
- .lyrics_test_data ⇒ Object
- .site_host ⇒ Object
- .site_name ⇒ Object
Instance Method Summary collapse
-
#build_suggestions_fetch_data(request) ⇒ Object
# site’s search is currently disabled def build_suggestions_fetch_data( request ) artist = CGI.escape( Strings.utf82latin1( request.artist ) ) title = CGI.escape( Strings.utf82latin1( request.title ) ) return FetchPageData.new( “http://#site_host()/advanced.php?artistmode=1&artist=#artist&songmode=1&song=#title&mode=0” ) end.
- #lyrics_page_valid?(request, page_body, page_url) ⇒ Boolean
- #parse_lyrics(response, page_body) ⇒ Object
-
#parse_suggestions(request, page_body, page_url) ⇒ Object
def parse_suggestions( request, page_body, page_url ).
Methods inherited from Lyrics
build_google_feeling_lucky_url, #build_google_feeling_lucky_url, #build_lyrics_fetch_data, #build_song_add_url, #decrease_tabulation_level, #fetch_lyrics_page, #fetch_suggestions_page, #increase_tabulation_level, #initialize, #known_url?, known_url?, #log, #log?, #logger=, #lyrics_direct_search, #lyrics_from_suggestions, #lyrics_from_url, #lyrics_full_search, #lyrics_test_data, #notify, #site_host, #site_name, #suggestions, #suggestions_page_valid?, suggestions_test_data, #suggestions_test_data, #verbose_log?
Constructor Details
This class inherits a constructor from Lyrics
Class Method Details
.build_song_add_url(request) ⇒ Object
49 50 51 52 53 |
# File 'lib/lyrics/lyrics_LeosLyrics.rb', line 49 def LeosLyrics.build_song_add_url( request ) add_url = "http://#{site_host()}/submit.php?artist=#{CGI.escape( request.artist )}&song=#{CGI.escape( request.title )}" add_url << "&album=#{CGI.escape( request.album )}" if request.album return add_url end |
.lyrics_test_data ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/lyrics/lyrics_LeosLyrics.rb', line 38 def LeosLyrics.lyrics_test_data() return [ Request.new( "Cat Power", "Good Woman", "You Are Free" ), Request.new( "Blur", "No Distance Left To Run", "13" ), Request.new( "Massive Attack", "Angel", "Mezzanine" ), Request.new( "Nirvana", "All Apologies", "In Utero" ), # Request.new( "System Of A Down", "Chop Suey", "Toxicity" ), # Request.new( "A Perfect Circle", "The Noose", "Thirteen Step" ), ] end |
.site_host ⇒ Object
30 31 32 |
# File 'lib/lyrics/lyrics_LeosLyrics.rb', line 30 def LeosLyrics.site_host() return "www.leoslyrics.com" end |
.site_name ⇒ Object
34 35 36 |
# File 'lib/lyrics/lyrics_LeosLyrics.rb', line 34 def LeosLyrics.site_name() return "Leos Lyrics" end |
Instance Method Details
#build_suggestions_fetch_data(request) ⇒ Object
# site’s search is currently disabled def build_suggestions_fetch_data( request ) artist = CGI.escape( Strings.utf82latin1( request.artist ) ) title = CGI.escape( Strings.utf82latin1( request.title ) ) return FetchPageData.new( “http://#site_host()/advanced.php?artistmode=1&artist=#artist&songmode=1&song=#title&mode=0” ) end
89 90 91 92 93 |
# File 'lib/lyrics/lyrics_LeosLyrics.rb', line 89 def build_suggestions_fetch_data( request ) artist = CGI.escape( Strings.utf82latin1( request.artist ) ) title = CGI.escape( Strings.utf82latin1( request.title ) ) return FetchPageData.new( "http://#{site_host()}/search.php?search=#{artist}+#{title}&sartist=1&ssongtitle=1" ) end |
#lyrics_page_valid?(request, page_body, page_url) ⇒ Boolean
55 56 57 58 59 60 |
# File 'lib/lyrics/lyrics_LeosLyrics.rb', line 55 def lyrics_page_valid?( request, page_body, page_url ) md = /<TITLE>([^<]+)-\s*([^<]+)\s*lyrics\s*<\/TITLE>/im.match( page_body ) return false if ! md return Strings.normalize( request.artist ) == Strings.normalize( md[1] ) && Strings.normalize( request.title ) == Strings.normalize( md[2] ) end |
#parse_lyrics(response, page_body) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/lyrics/lyrics_LeosLyrics.rb', line 62 def parse_lyrics( response, page_body ) page_body = Strings.latin12utf8( page_body ) page_body.tr_s!( " \n\r\t", " " ) HTMLEntities.decode!( page_body ) if (md = /<TITLE> ?(.+) ?- ?(.+) ?lyrics ?<\/TITLE>/.match( page_body )) response.artist, response.title = md[1].strip(), md[2].strip() end if (md = /<font face="[^"]+" size=-1>(.+)<\/font>/.match( page_body )) page_body = md[1] page_body.gsub!( /<\/font>.*/, "" ) page_body.gsub!( /\ ?<br ?\/?> ?/i, "\n" ) page_body.gsub!( /\n{3,}/, "\n\n" ) response.lyrics = page_body end end |
#parse_suggestions(request, page_body, page_url) ⇒ Object
def parse_suggestions( request, page_body, page_url )
page_body = Strings.latin12utf8( page_body ) page_body.tr_s!( “ nrt”, “ ” ) HTMLEntities.decode!( page_body )
suggestions = []
md = /<ul>(.*)</ul>/i.match( page_body ) return suggestions if ! md
md.split( “<li>” ).each do |entry| if (md = /<a href=“(/listlyrics.php;jsessionid=)”>([^<]) Lyrics</a>/.match( entry )) suggestions << Suggestion.new( request.artist, md, “http://#site_host()#1” ) end end
return suggestions
end
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/lyrics/lyrics_LeosLyrics.rb', line 121 def parse_suggestions( request, page_body, page_url ) page_body = Strings.latin12utf8( page_body ) page_body.tr_s!( " \n\r\t", " " ) HTMLEntities.decode!( page_body ) suggestions = [] return suggestions if ! page_body.sub!( /^.*<table border=0 width="100%">/, "" ) return suggestions if ! page_body.sub!( /<\/table>.*$/, "" ) page_body.split( /<tr> ?<td>/ ).each do |entry| entry.gsub!( /\ *<\/?(td|b|font)[^>]*> */, "" ) if (md = /<a href="\/artists\/[^"]+">([^<]+)<\/a><a href="([^"]+)">([^<]+)<\/a>/.match( entry )) suggestions << Suggestion.new( md[1], md[3], "http://#{site_host()}#{md[2]}" ) end end return suggestions end |