diff options
author | George Sedov <radist.morse@gmail.com> | 2015-12-16 18:26:56 +0300 |
---|---|---|
committer | Victor Toso <me@victortoso.com> | 2016-01-30 12:14:57 +0100 |
commit | 9b329f3e5246477f039a1fb2b129706370237c89 (patch) | |
tree | a9f82df12e7ba89ab6b22362ddba64dbdd6056e1 | |
parent | 93547ac94797cdea6670b0d458e838bcdb578f77 (diff) |
lua-factory: port grl-spotify-cover.lua to the new lua system
https://bugzilla.gnome.org/show_bug.cgi?id=753141
Acked-by: Victor Toso <me@victortoso.com>
-rw-r--r-- | src/lua-factory/sources/grl-spotify-cover.lua | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/src/lua-factory/sources/grl-spotify-cover.lua b/src/lua-factory/sources/grl-spotify-cover.lua index 1f7ad1c..638ca37 100644 --- a/src/lua-factory/sources/grl-spotify-cover.lua +++ b/src/lua-factory/sources/grl-spotify-cover.lua @@ -47,34 +47,34 @@ SPOTIFY_SEARCH_ALBUM = 'https://api.spotify.com/v1/search?q=album:%s+artist:%s&t -- Handlers of Grilo functions -- --------------------------------- -function grl_source_resolve() - local url, req +function grl_source_resolve(media, options, callback) + local url local artist, title - 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() + if not media or not media.artist or not media.album + or #media.artist == 0 or #media.album == 0 then + callback() return end -- Prepare artist and title strings to the url - artist = grl.encode(req.artist) - album = grl.encode(req.album) + artist = grl.encode(media.artist) + album = grl.encode(media.album) url = string.format(SPOTIFY_SEARCH_ALBUM, album, artist) - grl.fetch(url, "fetch_page_cb") + local userdata = {callback = callback, media = media} + grl.fetch(url, fetch_page_cb, userdata) end --------------- -- Utilities -- --------------- -function fetch_page_cb(result) +function fetch_page_cb(result, userdata) local json = {} if not result then - grl.callback() + userdata.callback() return end @@ -85,15 +85,14 @@ function fetch_page_cb(result) not json.albums.items or not #json.albums.items or not json.albums.items[1].images then - grl.callback() + userdata.callback() return end - local media = {} - media.thumbnail = {} + userdata.media.thumbnail = {} for i, item in ipairs(json.albums.items[1].images) do - table.insert(media.thumbnail, item.url) + table.insert(userdata.media.thumbnail, item.url) end - grl.callback(media, 0) + userdata.callback(userdata.media, 0) end |