Class: Sing365

Inherits:
Lyrics show all
Defined in:
lib/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



43
44
45
# File 'lib/lyrics/lyrics_Sing365.rb', line 43

def Sing365.build_song_add_url( request )
	return build_google_feeling_lucky_url( request.artist )
end

.lyrics_test_dataObject



34
35
36
37
38
39
40
41
# File 'lib/lyrics/lyrics_Sing365.rb', line 34

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_hostObject



26
27
28
# File 'lib/lyrics/lyrics_Sing365.rb', line 26

def Sing365.site_host()
	return "www.sing365.com"
end

.site_nameObject



30
31
32
# File 'lib/lyrics/lyrics_Sing365.rb', line 30

def Sing365.site_name()
	return "Sing365"
end

Instance Method Details

#build_lyrics_fetch_data(request) ⇒ Object



47
48
49
# File 'lib/lyrics/lyrics_Sing365.rb', line 47

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



77
78
79
# File 'lib/lyrics/lyrics_Sing365.rb', line 77

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

Returns:

  • (Boolean)


51
52
53
54
55
56
57
# File 'lib/lyrics/lyrics_Sing365.rb', line 51

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



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/lyrics/lyrics_Sing365.rb', line 59

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



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/lyrics/lyrics_Sing365.rb', line 86

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

Returns:

  • (Boolean)


81
82
83
84
# File 'lib/lyrics/lyrics_Sing365.rb', line 81

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