[grilo-plugins] lua-factory: port grl-appletrailers.lua to the new lua system
- From: Victor Toso de Carvalho <victortoso src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [grilo-plugins] lua-factory: port grl-appletrailers.lua to the new lua system
- Date: Sat, 30 Jan 2016 11:25:04 +0000 (UTC)
commit bea8e082da513d90660de84f9213a4fd9552d2eb
Author: George Sedov <radist morse gmail com>
Date: Wed Dec 16 18:26:56 2015 +0300
lua-factory: port grl-appletrailers.lua to the new lua system
https://bugzilla.gnome.org/show_bug.cgi?id=753141
Acked-by: Victor Toso <me victortoso com>
src/lua-factory/sources/grl-appletrailers.lua | 37 ++++++++++++-------------
1 files changed, 18 insertions(+), 19 deletions(-)
---
diff --git a/src/lua-factory/sources/grl-appletrailers.lua b/src/lua-factory/sources/grl-appletrailers.lua
index 3458e51..aa350fb 100644
--- a/src/lua-factory/sources/grl-appletrailers.lua
+++ b/src/lua-factory/sources/grl-appletrailers.lua
@@ -53,9 +53,11 @@ end
APPLE_TRAILERS_CURRENT_SD = "http://trailers.apple.com/trailers/home/xml/current_480p.xml"
APPLE_TRAILERS_CURRENT_HD = "http://trailers.apple.com/trailers/home/xml/current_720p.xml"
-function grl_source_browse()
- local skip = grl.get_options("skip")
- local count = grl.get_options("count")
+function grl_source_browse(media, options, callback)
+ local skip = options.skip
+ local count = options.count
+ local userdata = {callback = callback, skip = skip, count = count}
+
-- Make sure to reset the cache when browsing again
if skip == 0 then
@@ -63,7 +65,7 @@ function grl_source_browse()
end
if cached_xml then
- parse_results(cached_xml)
+ parse_results(cached_xml, userdata)
else
local url = APPLE_TRAILERS_CURRENT_SD
if ldata.hd then
@@ -71,7 +73,7 @@ function grl_source_browse()
end
grl.debug('Fetching URL: ' .. url .. ' (count: ' .. count .. ' skip: ' .. skip .. ')')
- grl.fetch(url, "fetch_results_cb")
+ grl.fetch(url, fetch_results_cb, userdata)
end
end
@@ -79,21 +81,18 @@ end
-- Utilities --
---------------
-function fetch_results_cb(results)
+function fetch_results_cb(results, userdata)
if not results then
grl.warning('Failed to fetch XML file')
- grl.callback()
+ userdata.callback()
return
end
cached_xml = grl.lua.xml.string_to_table(results)
- parse_results(cached_xml)
+ parse_results(cached_xml, userdata)
end
-function parse_results(results)
- local count = grl.get_options("count")
- local skip = grl.get_options("skip")
-
+function parse_results(results, userdata)
for i, item in pairs(results.records.movieinfo) do
local media = {}
@@ -124,18 +123,18 @@ function parse_results(results)
local mins, secs = item.info.runtime.xml:match('(%d):(%d)')
media.duration = tonumber(mins) * 60 + tonumber(secs)
- if skip > 0 then
- skip = skip - 1
+ if userdata.skip > 0 then
+ userdata.skip = userdata.skip - 1
else
- count = count - 1
- grl.callback(media, count)
- if count == 0 then
+ userdata.count = userdata.count - 1
+ userdata.callback(media, userdata.count)
+ if userdata.count == 0 then
return
end
end
end
- if count ~= 0 then
- grl.callback()
+ if userdata.count ~= 0 then
+ userdata.callback()
end
end
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]