Class: DarkLyrics

Inherits:
Lyrics show all
Defined in:
lib/wiki_lyrics/lyrics_DarkLyrics.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_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_google_feeling_lucky_url(artist, title = nil) ⇒ Object



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

def DarkLyrics.build_google_feeling_lucky_url( artist, title=nil )
	query = Strings.google_search_quote( artist )
	query << " " << Strings.google_search_quote( title ) if title
	query << " lyrics"
	return Strings.build_google_feeling_lucky_url( query, title ? "#{site_host()}/lyrics" : site_host() )
end

.build_song_add_url(request) ⇒ Object



43
44
45
# File 'lib/wiki_lyrics/lyrics_DarkLyrics.rb', line 43

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

.lyrics_test_dataObject



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

def DarkLyrics.lyrics_test_data()
	return [
		Request.new( "Opeth", "Hope Leaves", "Damnation" ),
		Request.new( "Megadeth", "À tout le monde", "Youthanasia" ),
		Request.new( "Metallica", "Master of Puppets", "Master of Puppets" ),
		Request.new( "Lacuna Coil", "Heaven's a Lie", "Comalies" ),
	]
end

.site_hostObject



26
27
28
# File 'lib/wiki_lyrics/lyrics_DarkLyrics.rb', line 26

def DarkLyrics.site_host()
	return "www.darklyrics.com"
end

.site_nameObject



30
31
32
# File 'lib/wiki_lyrics/lyrics_DarkLyrics.rb', line 30

def DarkLyrics.site_name()
	return "Dark Lyrics"
end

Instance Method Details

#build_lyrics_fetch_data(request) ⇒ Object



54
55
56
# File 'lib/wiki_lyrics/lyrics_DarkLyrics.rb', line 54

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



95
96
97
# File 'lib/wiki_lyrics/lyrics_DarkLyrics.rb', line 95

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)


58
59
60
61
# File 'lib/wiki_lyrics/lyrics_DarkLyrics.rb', line 58

def lyrics_page_valid?( request, page_body, page_url )
	md = /<title>([^<]+) LYRICS - [^<]+<\/title>/.match( page_body )
	return md ? Strings.normalize( request.artist ) == Strings.normalize( md[1] ) : false
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
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/wiki_lyrics/lyrics_DarkLyrics.rb', line 63

def parse_lyrics( response, page_body )

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

	if (md = /<FONT size=5 color=#FFFFCC>([^<]+) LYRICS<\/FONT><br>/.match( page_body ))
		response.artist = Strings.titlecase( md[1], true, true )
	end

	if (md = /<FONT size=3 color=white><b>([^<]+) \(([0-9]{4,4})( [^\)]+|)\)<\/b><\/FONT><br>/.match( page_body ))
		response.album, response.year = md[1], md[2]
	end

	return if ! page_body.sub!( /^.*<SCRIPT LANGUAGE="javascript" src="\.\.\/\.\.\/recban\.js"><\/SCRIPT><BR>/i, "" )
	return if ! page_body.sub!( /<FONT [^>]*size=.*$/i, "" )

	md = /.*#([0-9]+)$/.match( response.url )
	track = md ? md[1] : nil
	normalized_title = Strings.normalize( response.request.title )
	page_body.split( /<a name=[0-9]+><FONT color=#DDDDDD>/i ).each() do |song_content|
		md = /^<b>([0-9]+)\. ([^<]+)<\/b><\/font><br>(.*)$/.match( song_content )
		next if ! md || (track && track != md[1]) || (! track && normalized_title != Strings.normalize( md[2] ))
		response.title = md[2]
		page_body = md[3]
		page_body.gsub!( /\ ?<br ?\/?> ?/i, "\n" )
		page_body.gsub!( /\n{3,}/, "\n\n" )
		page_body.strip!()
		response.lyrics = page_body
	end

end

#parse_suggestions(request, page_body, page_url) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/wiki_lyrics/lyrics_DarkLyrics.rb', line 104

def parse_suggestions( request, page_body, page_url )

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

	suggestions = []

	return suggestions if ! page_body.sub!(/^.*<FONT FACE="Helvetica" COLOR=#FFFFCC SIZE=4><br>[^<]+ LYRICS<BR><\/FONT>/i,"")
	return suggestions if ! page_body.sub!( /<SCRIPT LANGUAGE="javascript".*$/i, "" )

	page_body.split( /<br>/i ).each() do |entry|
		if (md = /<a href="\.\.(\/lyrics\/[^"]+)" target="_blank"><FONT [^>]+>([^"]+)<\/FONT><\/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)


99
100
101
102
# File 'lib/wiki_lyrics/lyrics_DarkLyrics.rb', line 99

def suggestions_page_valid?( request, page_body, page_url )
	md = /<title>([^<]+) LYRICS<\/title>/.match( page_body )
	return md ? Strings.normalize( request.artist ) == Strings.normalize( md[1] ) : false
end