Class: SeekLyrics
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
46
47
48
|
# File 'lib/lyrics/lyrics_SeekLyrics.rb', line 46
def SeekLyrics.build_song_add_url( request )
return "http://#{site_host()}/submit.php"
end
|
.lyrics_test_data ⇒ Object
37
38
39
40
41
42
43
44
|
# File 'lib/lyrics/lyrics_SeekLyrics.rb', line 37
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_host ⇒ Object
29
30
31
|
# File 'lib/lyrics/lyrics_SeekLyrics.rb', line 29
def SeekLyrics.site_host()
return "www.seeklyrics.com"
end
|
.site_name ⇒ Object
33
34
35
|
# File 'lib/lyrics/lyrics_SeekLyrics.rb', line 33
def SeekLyrics.site_name()
return "Seek Lyrics"
end
|
Instance Method Details
#build_lyrics_fetch_data(request) ⇒ Object
57
58
59
60
61
|
# File 'lib/lyrics/lyrics_SeekLyrics.rb', line 57
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
83
84
85
86
|
# File 'lib/lyrics/lyrics_SeekLyrics.rb', line 83
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
50
51
52
53
54
55
|
# File 'lib/lyrics/lyrics_SeekLyrics.rb', line 50
def cleanup_token( token )
token = token.tr( @@white_chars, " " )
token.strip!()
token.tr!( " ", "-" )
return token
end
|
#parse_lyrics(response, page_body) ⇒ Object
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/lyrics/lyrics_SeekLyrics.rb', line 63
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
# File 'lib/lyrics/lyrics_SeekLyrics.rb', line 88
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> - /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
|