summaryrefslogtreecommitdiff
path: root/nopsyncd/qlistener.lua
diff options
context:
space:
mode:
Diffstat (limited to 'nopsyncd/qlistener.lua')
-rwxr-xr-xnopsyncd/qlistener.lua21
1 files changed, 15 insertions, 6 deletions
diff --git a/nopsyncd/qlistener.lua b/nopsyncd/qlistener.lua
index e5cd4ab..1e02df2 100755
--- a/nopsyncd/qlistener.lua
+++ b/nopsyncd/qlistener.lua
@@ -20,6 +20,7 @@
--
local queue_name = "/rhnop"
+local last_cart = nil
mq = require "luamq"
tempstorage = require "tempstorage"
@@ -30,9 +31,13 @@ function handle_now(timestamp, nowcart, nowlen)
if results == nil then
io.stderr:write("can't fetch cart info: " .. err .. "\n")
else
- -- TODO: insert into tempstorage
- print(timestamp .. " Info: '" .. results.TITLE .. "' von '" .. results.ARTIST .. "' aus '" .. results.ALBUM .. "'")
- pipe.signal()
+-- print(timestamp .. " Info: '" .. results.TITLE .. "' von '" .. results.ARTIST .. "' aus '" .. results.ALBUM .. "'")
+ local ret, err = tempstorage:insertMusic(timestamp, nowcart, nowlen, results.TITLE, results.ARTIST, results.ALBUM)
+ if ret == nil then
+ io.stderr:write("can't insert music info: " .. err .. "\n")
+ else
+ pipe.signal()
+ end
end
end
@@ -41,8 +46,11 @@ function handle_message(msg)
if not timestamp or not nowcart or not nowlen or not nextcart or not nextlen then
io.stderr:write("ignoring malformed message\n")
else
- -- TODO sanity checks: is now info new or just next?
- handle_now(timestamp, nowcart, nowlen)
+ -- TODO better sanity checks: is now info new or just next?
+ if last_cart ~= nowcart then
+ last_cart = nowcart
+ handle_now(timestamp, nowcart, nowlen)
+ end
-- TODO handle next info
end
end
@@ -59,7 +67,8 @@ function main_loop()
io.stderr:write("creation of tempstorage failed: " .. err .. "\n")
os.exit(1)
end
-
+ last_cart = assert(tempstorage:getLastCart())
+
local ret, err = rddb:init()
if ret == nil then
io.stderr:write("opening rivendell db failed: " .. err .. "\n")