diff options
author | Victor Toso <me@victortoso.com> | 2016-03-08 23:29:46 +0100 |
---|---|---|
committer | Victor Toso <me@victortoso.com> | 2016-03-14 00:00:09 +0100 |
commit | c4506065c90fc109b3a34ba6c701d11d16d04c40 (patch) | |
tree | c14b49d1306d2c492f702573f9070f8b9a76e5e6 | |
parent | 976807cab4f3277e66fa62b7e1668c1a9b02477d (diff) |
Revert "lua-factory: port grl-lastfm-cover.lua to the new lua system"763046-lua-factory-keep-old-api
This reverts commit fbb244ee962ddcf483dc4c6adec30de6c2616436.
But keeps grl.fetch callback as function instead of string
https://bugzilla.gnome.org/show_bug.cgi?id=763046
-rw-r--r-- | src/lua-factory/sources/grl-lastfm-cover.lua | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/src/lua-factory/sources/grl-lastfm-cover.lua b/src/lua-factory/sources/grl-lastfm-cover.lua index 7729284..3b4fa79 100644 --- a/src/lua-factory/sources/grl-lastfm-cover.lua +++ b/src/lua-factory/sources/grl-lastfm-cover.lua @@ -49,35 +49,36 @@ LASTFM_SEARCH_ALBUM = 'http://ws.audioscrobbler.com/2.0/?method=album.getInfo&ap -- 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.album - or #media.artist == 0 or #media.album == 0 then - callback() + req = grl.get_media_keys() + if not req or not req.artist or not req.album + or #req.artist == 0 or #req.album == 0 then + grl.callback() return end -- Prepare artist and title strings to the url - artist = grl.encode(media.artist) - album = grl.encode(media.album) + artist = grl.encode(req.artist) + album = grl.encode(req.album) url = string.format(LASTFM_SEARCH_ALBUM, grl.goa_consumer_key(), artist, album) - local userdata = {callback = callback, media = media} - grl.fetch(url, fetch_page_cb, userdata) + grl.fetch(url, fetch_page_cb) end --------------- -- Utilities -- --------------- -function fetch_page_cb(result, userdata) +function fetch_page_cb(result) if not result then - userdata.callback() + grl.callback() return end - userdata.media.thumbnail = {} + local media = {} + media.thumbnail = {} local image_sizes = { "mega", "extralarge", "large", "medium", "small" } for _, size in pairs(image_sizes) do @@ -86,13 +87,13 @@ function fetch_page_cb(result, userdata) url = string.match(result, '<image size="' .. size .. '">(.-)</image>') if url ~= nil and url ~= '' then grl.debug ('Image size ' .. size .. ' = ' .. url) - table.insert(userdata.media.thumbnail, url) + table.insert(media.thumbnail, url) end end - if #userdata.media.thumbnail == 0 then - userdata.callback() + if #media.thumbnail == 0 then + grl.callback() else - userdata.callback(userdata.media, 0) + grl.callback(media, 0) end end |