[grilo-plugins] Revert "lua-factory: port grl-metrolyrics.lua to the new lua system"



commit c3c5462e8fd07093151686394396a265eb0a355a
Author: Victor Toso <me victortoso com>
Date:   Tue Mar 8 23:28:04 2016 +0100

    Revert "lua-factory: port grl-metrolyrics.lua to the new lua system"
    
    This reverts commit 0e71278f1616a55e4e0a3b719abbe978a4ad71af.
    
    But keeps grl.fetch callback as function instead of string
    
    https://bugzilla.gnome.org/show_bug.cgi?id=763046

 src/lua-factory/sources/grl-metrolyrics.lua |   35 +++++++++++++--------------
 1 files changed, 17 insertions(+), 18 deletions(-)
---
diff --git a/src/lua-factory/sources/grl-metrolyrics.lua b/src/lua-factory/sources/grl-metrolyrics.lua
index 448ac23..72f9195 100644
--- a/src/lua-factory/sources/grl-metrolyrics.lua
+++ b/src/lua-factory/sources/grl-metrolyrics.lua
@@ -52,43 +52,40 @@ METROLYRICS_DEFAULT_QUERY = "http://www.metrolyrics.com/%s-lyrics-%s.html";
 -- Handlers of Grilo functions --
 ---------------------------------
 
-function grl_source_resolve(media, options, callback)
-  local url
+function grl_source_resolve()
+  local url, req
   local artist, title
 
-  if not media or not media.artist or not media.title
-    or #media.artist == 0 or #media.title == 0 then
-    callback()
+  req = grl.get_media_keys()
+  if not req or not req.artist or not req.title
+    or #req.artist == 0 or #req.title == 0 then
+    grl.callback()
     return
   end
 
   -- Prepare artist and title strings to the url
-  artist = media.artist:gsub(METROLYRICS_INVALID_URL_CHARS, "")
+  artist = req.artist:gsub(METROLYRICS_INVALID_URL_CHARS, "")
   artist = artist:gsub("%s+", "-")
-  title = media.title:gsub(METROLYRICS_INVALID_URL_CHARS, "")
+  title = req.title:gsub(METROLYRICS_INVALID_URL_CHARS, "")
   title = title:gsub("%s+", "-")
   url = string.format(METROLYRICS_DEFAULT_QUERY, title, artist)
-  local userdata = {callback = callback, media = media}
-  grl.fetch(url, netopts, fetch_page_cb, userdata)
+  grl.fetch(url, fetch_page_cb, netopts)
 end
 
 ---------------
 -- Utilities --
 ---------------
 
-function fetch_page_cb(feed, userdata)
+function fetch_page_cb(feed)
+  local media = nil
   if feed and not feed:find("notfound") then
-    local lyrics = metrolyrics_get_lyrics(feed)
-    if not lyrics then
-      userdata.callback()
-      return
-    end
-    userdata.media.lyrics = lyrics
+    media = metrolyrics_get_lyrics(feed)
   end
-  userdata.callback(userdata.media, 0)
+  grl.callback(media, 0)
 end
 
 function metrolyrics_get_lyrics(feed)
+  local media = {}
   local lyrics_body = '<div id="lyrics%-body%-text".->(.-)</div>'
   local noise_array = {
     { noise = "</p>",  sub = "\n\n" },
@@ -112,5 +109,7 @@ function metrolyrics_get_lyrics(feed)
   -- strip the lyrics
   feed = feed:gsub("^[%s%W]*(.-)[%s%W]*$", "%1")
 
-  return feed
+  -- switch table to string
+  media.lyrics = feed
+  return media
 end


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]