Class: Sing365
- Inherits:
-
Lyrics
show all
- Defined in:
- lib/wiki_lyrics/lyrics_Sing365.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_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_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
42
43
44
|
# File 'lib/wiki_lyrics/lyrics_Sing365.rb', line 42
def Sing365.build_song_add_url( request )
return build_google_feeling_lucky_url( request.artist )
end
|
.lyrics_test_data ⇒ Object
33
34
35
36
37
38
39
40
|
# File 'lib/wiki_lyrics/lyrics_Sing365.rb', line 33
def Sing365.lyrics_test_data()
return [
Request.new( "Nirvana", "Smells Like Teen Spirit", "Nevermind" ),
Request.new( "The Cranberries", "Linger", "Everybody Else Is Doing It, So Why Can't We?" ),
Request.new( "Pearl Jam", "Porch", "Ten" ),
Request.new( "The Smashing Pumpkins", "Mayonaise", "Siamese Dream" ),
]
end
|
.site_host ⇒ Object
25
26
27
|
# File 'lib/wiki_lyrics/lyrics_Sing365.rb', line 25
def Sing365.site_host()
return "www.sing365.com"
end
|
.site_name ⇒ Object
29
30
31
|
# File 'lib/wiki_lyrics/lyrics_Sing365.rb', line 29
def Sing365.site_name()
return "Sing365"
end
|
Instance Method Details
#build_lyrics_fetch_data(request) ⇒ Object
46
47
48
|
# File 'lib/wiki_lyrics/lyrics_Sing365.rb', line 46
def build_lyrics_fetch_data( request )
return FetchPageData.new( build_google_feeling_lucky_url( request.artist, request.title ) )
end
|
#build_suggestions_fetch_data(request) ⇒ Object
76
77
78
|
# File 'lib/wiki_lyrics/lyrics_Sing365.rb', line 76
def build_suggestions_fetch_data( request )
return FetchPageData.new( build_google_feeling_lucky_url( request.artist ) )
end
|
#lyrics_page_valid?(request, page_body, page_url) ⇒ Boolean
50
51
52
53
54
55
56
|
# File 'lib/wiki_lyrics/lyrics_Sing365.rb', line 50
def lyrics_page_valid?( request, page_body, page_url )
md = /<title>([^<]+) - ([^<]+) LYRICS<\/title>/i.match( page_body )
return md ?
Strings.normalize( request.artist ) == Strings.normalize( md[1] ) &&
Strings.normalize( request.title ) == Strings.normalize( md[2] ) :
false
end
|
#parse_lyrics(response, page_body) ⇒ Object
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/wiki_lyrics/lyrics_Sing365.rb', line 58
def parse_lyrics( response, page_body )
page_body.tr_s!( " \n\r\t", " " )
if (md = /<meta name="Description" content="([^"]+) lyrics performed by ([^"]+)">/i.match( page_body ))
response.artist, response.title = md[1], md[2]
end
return if ! (md = /<img src="?http:\/\/#{site_host()}\/images\/phone2\.gif"? border="?0"?><br><br><\/div>(.*)<div align="?center"?><br><br><img src="?http:\/\/#{site_host()}\/images\/phone\.gif"?/i.match( page_body ))
page_body = md[1]
page_body.gsub!( /\ ?<br ?\/?> ?/i, "\n" )
page_body.gsub!( /\n{3,}/, "\n\n" )
response.lyrics = page_body
end
|
#parse_suggestions(request, page_body, page_url) ⇒ Object
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
# File 'lib/wiki_lyrics/lyrics_Sing365.rb', line 85
def parse_suggestions( request, page_body, page_url )
page_body.tr_s!( " \n\r\t", " " )
suggestions = []
return suggestions if ! (md = /<img src="?http:\/\/#{site_host()}\/images\/phone2\.gif"? border="?0"?><br><br><\/div>(.*)<\/lu><br><div align="?center"?><br><img src="?http:\/\/#{site_host()}\/images\/phone\.gif"?/i.match( page_body ))
md[1].split( "<li>" ).each() do |entry|
if (md = /<a href="([^"]+)"[^>]*>([^<]+) Lyrics<\/a>/i.match( entry ))
suggestions << Suggestion.new( request.artist, md[2], "http://#{site_host()}#{md[1]}" )
end
end
return suggestions
end
|
#suggestions_page_valid?(request, page_body, page_url) ⇒ Boolean
80
81
82
83
|
# File 'lib/wiki_lyrics/lyrics_Sing365.rb', line 80
def suggestions_page_valid?( request, page_body, page_url )
md = /<title>([^<]+) LYRICS<\/title>/i.match( page_body )
return md ? Strings.normalize( request.artist ) == Strings.normalize( md[1] ) : false
end
|