Class: Jamendo
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
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/lyrics/lyrics_Jamendo.rb', line 46
def Jamendo.cleanup_artist_name( artist )
artist = Strings.downcase( artist )
Strings.remove_vocal_accents!( artist )
artist.gsub!( /\[|\]|:/, "" )
artist.gsub!( /_| |'|"|ø|&|@|\/|\*|\.|®|%|#/, " " ) artist.squeeze!( " " )
artist.strip!()
artist.gsub!( " ", "." )
return artist
end
|
.lyrics_test_data ⇒ Object
37
38
39
40
41
42
43
44
|
# File 'lib/lyrics/lyrics_Jamendo.rb', line 37
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_host ⇒ Object
29
30
31
|
# File 'lib/lyrics/lyrics_Jamendo.rb', line 29
def Jamendo.site_host()
return "www.jamendo.com"
end
|
.site_name ⇒ Object
33
34
35
|
# File 'lib/lyrics/lyrics_Jamendo.rb', line 33
def Jamendo.site_name()
return "Jamendo"
end
|
Instance Method Details
#build_lyrics_fetch_data(request) ⇒ Object
61
62
63
64
65
66
67
|
# File 'lib/lyrics/lyrics_Jamendo.rb', line 61
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
#cleanup_artist_name(artist) ⇒ Object
57
58
59
|
# File 'lib/lyrics/lyrics_Jamendo.rb', line 57
def cleanup_artist_name( artist )
self.class.cleanup_artist_name( artist )
end
|
#parse_lyrics(response, page_body) ⇒ Object
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
122
|
# File 'lib/lyrics/lyrics_Jamendo.rb', line 74
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
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
165
|
# File 'lib/lyrics/lyrics_Jamendo.rb', line 133
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
69
70
71
72
|
# File 'lib/lyrics/lyrics_Jamendo.rb', line 69
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
|