Class: LeosLyrics

Inherits:
Lyrics show all
Defined in:
lib/wiki_lyrics/lyrics_LeosLyrics.rb

Instance Attribute Summary

Attributes inherited from Lyrics

#cleanup_lyrics

Class Method Summary collapse

Instance Method Summary collapse

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



48
49
50
51
52
# File 'lib/wiki_lyrics/lyrics_LeosLyrics.rb', line 48

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_dataObject



37
38
39
40
41
42
43
44
45
46
# File 'lib/wiki_lyrics/lyrics_LeosLyrics.rb', line 37

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_hostObject



29
30
31
# File 'lib/wiki_lyrics/lyrics_LeosLyrics.rb', line 29

def LeosLyrics.site_host()
	return "www.leoslyrics.com"
end

.site_nameObject



33
34
35
# File 'lib/wiki_lyrics/lyrics_LeosLyrics.rb', line 33

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



88
89
90
91
92
# File 'lib/wiki_lyrics/lyrics_LeosLyrics.rb', line 88

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

Returns:

  • (Boolean)


54
55
56
57
58
59
# File 'lib/wiki_lyrics/lyrics_LeosLyrics.rb', line 54

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



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/wiki_lyrics/lyrics_LeosLyrics.rb', line 61

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



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/wiki_lyrics/lyrics_LeosLyrics.rb', line 120

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