Class: Jamendo

Inherits:
Lyrics show all
Defined in:
lib/wiki_lyrics/lyrics_Jamendo.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, #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_test_data, #suggestions_test_data, #verbose_log?

Constructor Details

This class inherits a constructor from Lyrics

Class Method Details

.cleanup_artist_name(artist) ⇒ Object



45
46
47
48
49
50
51
52
53
54
# File 'lib/wiki_lyrics/lyrics_Jamendo.rb', line 45

def Jamendo.cleanup_artist_name( artist )
	artist = Strings.downcase( artist )
	Strings.remove_vocal_accents!( artist )
	artist.gsub!( /\[|\]|:/, "" )
	artist.gsub!( /_| |'|"|ø|&|@|\/|\*|\.|®|%|#/, " " ) # \' can also be ''
	artist.squeeze!( " " )
	artist.strip!()
	artist.gsub!( " ", "." )
	return artist
end

.lyrics_test_dataObject



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

def Jamendo.lyrics_test_data()
	return [
		Request.new( "Misantropía", "Hipócrita (Hypocrite)", "Misantropía" ),
		Request.new( "Inesperado", "Pez Gordo", "Maqueta Inesperada" ),
		Request.new( "Black Venus", "Vents de Mars", "Immortel" ),
		Request.new( "Punkamine", "Gora gerra", "Punkamine" ),
	]
end

.site_hostObject



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

def Jamendo.site_host()
	return "www.jamendo.com"
end

.site_nameObject



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

def Jamendo.site_name()
	return "Jamendo"
end

Instance Method Details

#build_lyrics_fetch_data(request) ⇒ Object



60
61
62
63
64
65
66
# File 'lib/wiki_lyrics/lyrics_Jamendo.rb', line 60

def build_lyrics_fetch_data( request )
	url =  "http://#{site_host()}/en/get/track/list/track-artist-album/lyricstext/plain/?"
	url << "searchterm=#{CGI.escape( request.title )}"
	url << "&artist_searchterm=#{CGI.escape( request.artist )}"
	url << "&album_searchterm=#{CGI.escape( request.album )}" if request.album
	return FetchPageData.new( url )
end

#build_suggestions_fetch_data(request) ⇒ Object



123
124
125
126
127
128
129
130
# File 'lib/wiki_lyrics/lyrics_Jamendo.rb', line 123

def build_suggestions_fetch_data( request )
	return FetchPageData.new(
		Strings.build_google_feeling_lucky_url(
			"artist " + Strings.google_search_quote( "albums of #{request.artist}" ),
			"#{site_host()}/en"
		)
	)
end

#cleanup_artist_name(artist) ⇒ Object



56
57
58
# File 'lib/wiki_lyrics/lyrics_Jamendo.rb', line 56

def cleanup_artist_name( artist )
	self.class.cleanup_artist_name( artist )
end

#parse_lyrics(response, page_body) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/wiki_lyrics/lyrics_Jamendo.rb', line 73

def parse_lyrics( response, page_body )

	if /track-artist-album/.match( response.url )

		page_body.tr_s!( " \r\t", " " )

		md = /[?&]searchterm=([^&]+)(&?|$)/.match( response.url )
		response.title = CGI.unescape( md[1] ) if md

		md = /[?&]artist_searchterm=([^&]+)(&?|$)/.match( response.url )
		response.artist = CGI.unescape( md[1] ) if md

		md = /[?&]album_searchterm=([^&]+)(&?|$)/.match( response.url )
		response.album = CGI.unescape( md[1] ) if md

		response.lyrics = page_body if ! page_body.empty?

	else

		page_body.tr_s!( " \n\r\t", " " )

		if (md = /<h1>([^<]+)<\/h1><p> by <a href="\/en\/artist\/[^"]+"[^<]*>([^<]+)<\/a>/.match( page_body ))
			response.title = md[1].strip()
			response.artist = md[2].strip()
		end

		if (md = /<a class="i l a" href="http:\/\/#{site_host()}\/en\/album\/[^"]+" ?>([^<]+)<\/a>/.match( page_body ))
			response.album = md[1].strip()
		end

		custom_data = {}
		["release", "genre"].each() do |key|
			md = /<tr class='[a|b]'> ?<td class='l'>#{key}<\/td> ?<td class='[^']+'>([^<]+)<\/td> ?<\/tr>/i.match( page_body )
			custom_data[key] = md[1].strip() if md
		end

		response.custom_data = custom_data
		response.year = custom_data["release"].gsub( /.*,/, "" ) if custom_data.include?( "release" )

		return if ! page_body.sub!( /^.*<div id="lyrics"[^>]*>/, "" )
		return if ! page_body.sub!( /<\/div>.*$/, "" )

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

		response.lyrics = page_body

	end

end

#parse_suggestions(request, page_body, page_url) ⇒ Object



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/wiki_lyrics/lyrics_Jamendo.rb', line 132

def parse_suggestions( request, page_body, page_url )

	page_body.tr_s!( " \n\r\t", " " )

	suggestions = []

	if page_url.index( "http://#{site_host()}/en/artist/" )

		return suggestions if ! page_body.sub!( /^.*<h2 class="seo_message" ?>Albums of [^<]+<\/h2>/, "" )
		return suggestions if ! page_body.sub!( /<h3>More information...<\/h3>.*$/, "" )

		page_body.split( /<h2 class='g_album_name'>/ ).each() do |album_entry|
			if (md = /<a title="[^"]+" href="(\/en\/album\/[0-9]+)" >([^<]+)<\/a>/.match( album_entry ))
				suggestions << FetchPageData.new( "http://#{site_host()}#{md[1]}" )
			end
		end

	elsif page_url.index( "http://#{site_host()}/en/album/" )

		return suggestions if ! page_body.sub!( /^.*<tbody>/, "" )
		return suggestions if ! page_body.sub!( /<\/tbody>.*$/, "" )

		page_body.split( "<td class=\"title_tracks\">" ).each() do |song_entry|
			if (md = /<a href="(\/en\/track\/[0-9]+)" title="[^"]*" ?>([^<]+)<\/a>/.match( song_entry ))
				suggestions << Suggestion.new( request.artist, md[2].strip(), "http://#{site_host()}#{md[1]}" )
			end
		end

	end

	return suggestions

end

#suggestions_page_valid?(request, page_body, page_url) ⇒ Boolean

Returns:

  • (Boolean)


68
69
70
71
# File 'lib/wiki_lyrics/lyrics_Jamendo.rb', line 68

def suggestions_page_valid?( request, page_body, page_url )
	return	page_url.index( "http://#{site_host()}/en/artist/" ) ||
			page_url.index( "http://#{site_host()}/en/album/" )
end