[grilo-plugins/upstream: 2/3] lua-factory: change in metrolyrics website
- From: Victor Toso de Carvalho <victortoso src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [grilo-plugins/upstream: 2/3] lua-factory: change in metrolyrics website
- Date: Thu, 5 Mar 2015 17:25:44 +0000 (UTC)
commit c8ff2b900fb73bb6d1d5b3dce62a67648f1a89a1
Author: Victor Toso <me victortoso com>
Date: Wed Mar 4 15:21:50 2015 +0100
lua-factory: change in metrolyrics website
HTML part of the lyrics changed. I've changed the get_lyrics to clean up
HTML that came with the lyrics instead of matching it.
https://bugzilla.gnome.org/show_bug.cgi?id=741784
src/lua-factory/sources/grl-metrolyrics.lua | 27 +++++++++++++--------------
1 files changed, 13 insertions(+), 14 deletions(-)
---
diff --git a/src/lua-factory/sources/grl-metrolyrics.lua b/src/lua-factory/sources/grl-metrolyrics.lua
index c583c8e..bf923a3 100644
--- a/src/lua-factory/sources/grl-metrolyrics.lua
+++ b/src/lua-factory/sources/grl-metrolyrics.lua
@@ -86,24 +86,23 @@ end
function metrolyrics_get_lyrics(feed)
local media = {}
- local res = {}
- local lyrics_body = '<div class="lyrics%-body">(.-)</div>'
- local lyrics_verse = "<p class='verse'>(.-)</p>"
+ local lyrics_body = '<div id="lyrics%-body%-text">(.-)</div>'
+ local noise_array = {
+ { noise = "<p class='verse'><p class='verse'>", sub = "\n\n" },
+ { noise = "<p class='verse'>", sub = "" },
+ { noise = "<br/>", sub = "" },
+ }
- -- from html, get lyrics line by line into table res
+ -- remove html noise
feed = feed:match(lyrics_body)
- for verse in feed:gmatch(lyrics_verse) do
- local start = 1
- local e, s = verse:find("<br/>")
- while (e) do
- res[#res + 1] = verse:sub(start, e-1)
- start = s+1
- e, s = verse:find("<br/>", start)
- end
- res[#res + 1] = verse:sub(start, #verse) .. '\n\n'
+ for _, it in ipairs (noise_array) do
+ feed = feed:gsub(it.noise, it.sub)
end
+ -- strip the lyrics
+ feed = feed:gsub("^[%s%W]*(.-)[%s%W]*$", "%1")
+
-- switch table to string
- media.lyrics = table.concat(res)
+ media.lyrics = feed
return media
end
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]