Class: SeekLyrics

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

Constant Summary collapse

@@white_chars =
"'\"¿?¡!()[].,;:-/& "

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_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_page_valid?, #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



45
46
47
# File 'lib/wiki_lyrics/lyrics_SeekLyrics.rb', line 45

def SeekLyrics.build_song_add_url( request )
	return "http://#{site_host()}/submit.php"
end

.lyrics_test_dataObject



36
37
38
39
40
41
42
43
# File 'lib/wiki_lyrics/lyrics_SeekLyrics.rb', line 36

def SeekLyrics.lyrics_test_data()
	return [
		Request.new( "Nirvana", "Smells Like Teen Spirit", "Nevermind" ),
		Request.new( "Radiohead", "Optimistic", "Kid A" ),
		Request.new( "Massive Attack", "Protection", "Protection" ),
		Request.new( "Portishead", "Wandering Star", "Dummy" ),
	]
end

.site_hostObject



28
29
30
# File 'lib/wiki_lyrics/lyrics_SeekLyrics.rb', line 28

def SeekLyrics.site_host()
	return "www.seeklyrics.com"
end

.site_nameObject



32
33
34
# File 'lib/wiki_lyrics/lyrics_SeekLyrics.rb', line 32

def SeekLyrics.site_name()
	return "Seek Lyrics"
end

Instance Method Details

#build_lyrics_fetch_data(request) ⇒ Object



56
57
58
59
60
# File 'lib/wiki_lyrics/lyrics_SeekLyrics.rb', line 56

def build_lyrics_fetch_data( request )
	artist = cleanup_token( request.artist.gsub( /^the /i, "" ) )
	title = cleanup_token( request.title )
	return FetchPageData.new( "http://#{site_host()}/lyrics/#{artist}/#{title}.html", nil, { "Cookie"=>"pass=deleted" } )
end

#build_suggestions_fetch_data(request) ⇒ Object



82
83
84
85
# File 'lib/wiki_lyrics/lyrics_SeekLyrics.rb', line 82

def build_suggestions_fetch_data( request )
	artist = cleanup_token( request.artist.gsub( /^the /i, "" ) )
	return FetchPageData.new( "http://#{site_host()}/lyrics/#{artist}/showall.html", nil, { "Cookie"=>"pass=deleted" } )
end

#cleanup_token(token) ⇒ Object



49
50
51
52
53
54
# File 'lib/wiki_lyrics/lyrics_SeekLyrics.rb', line 49

def cleanup_token( token )
	token = token.tr( @@white_chars, " " )
	token.strip!()
	token.tr!( " ", "-" )
	return token
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/wiki_lyrics/lyrics_SeekLyrics.rb', line 62

def parse_lyrics( response, page_body )

	page_body = Strings.latin12utf8( page_body )
	page_body.tr_s!( " \n\r\t", " " )
	page_body.tr_s!( "’", "'" )

	if (md = /<b><h2>([^<-]+) - ([^<]+) Lyrics<\/h2><\/b>/i.match( page_body ))
		response.artist, response.title = md[1].strip(), md[2].strip()
	end

	return if ! page_body.sub!( /^(.*)<a href="http:\/\/www\.ringtonematcher\.com.*$/i, "\\1" )
	return if ! page_body.sub!( /^.*<img src="\/images\/phone-right\.gif" [^<]+><\/a>/i, "" )

	page_body.gsub!( /\ ?<br ?\/?> ?/i, "\n" )
	page_body.strip!()

	response.lyrics = page_body

end

#parse_suggestions(request, page_body, page_url) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/wiki_lyrics/lyrics_SeekLyrics.rb', line 87

def parse_suggestions( request, page_body, page_url )

	page_body = Strings.latin12utf8( page_body )
	page_body.tr_s!( " \n\r\t", " " )
	page_body.tr_s!( "’", "'" )

	suggestions = []

	return suggestions if ! page_body.gsub!( /.*<tr><td width="50%"><\/td><td width="50%"><\/td><\/tr>/, "" )
	return suggestions if ! page_body.gsub!( /<\/table>.*$/, "" )

	page_body.split( /<td>&nbsp;-&nbsp;&nbsp;/i ).each() do |entry|
		if (md = /<a href="([^"]+)"[^>]*>([^<]+)<\/a><\/td>/i.match( entry ))
			suggestions << Suggestion.new( request.artist, md[2], "http://#{site_host()}#{md[1]}" )
		end
	end

	return suggestions

end