summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2017-01-05 23:07:55 (GMT)
committerChristian Pointner <equinox@helsinki.at>2017-01-05 23:07:55 (GMT)
commit1d05cd83ccb6ab3d2efbda8a6981204966c2c6d3 (patch)
treef6e8bcaea7a5902bbeddb1c6481b93c98880cb2f
parent66539357003278513103acd6ce6d8ff23d8a9537 (diff)
use real pool and jingle name
-rw-r--r--src/qlistener.lua8
-rw-r--r--src/rddb.lua46
2 files changed, 48 insertions, 6 deletions
diff --git a/src/qlistener.lua b/src/qlistener.lua
index d3fc9fd..86004ee 100644
--- a/src/qlistener.lua
+++ b/src/qlistener.lua
@@ -39,12 +39,12 @@ function handle_now(timestamp, nowcart, nowlen)
local results, err = rddb:getCartInfo(nowcart)
if results == nil then
io.stderr:write("ERROR: can't fetch cart info: " .. err .. "\n")
- return nil
+ return true
else
- local showtitle, carttype, err = rddb:getCartShowName(nowcart)
+ local showtitle, carttype = rddb:getCartShowName(nowcart)
if showtitle == nil then
- io.stderr:write("ERROR: can't fetch show/pool name: " .. err .. "\n")
- return nil
+ io.stderr:write("ERROR: can't fetch show/pool name: " .. carttype .. "\n")
+ return true
else
local ret, err = playlog:insertNow(timestamp, nowcart, nowlen, showtitle, results.TITLE, results.ARTIST, results.ALBUM, carttype)
if ret == nil then
diff --git a/src/rddb.lua b/src/rddb.lua
index b18ae67..0827f62 100644
--- a/src/rddb.lua
+++ b/src/rddb.lua
@@ -65,9 +65,51 @@ function rddb:getCartInfo(cartnum)
return results, err
end
+function rddb:getGroupNameAndCartType(cartnum)
+ local cur, err = self.con:execute("select NAME,DESCRIPTION from GROUPS where DEFAULT_LOW_CART <= " .. self.con:escape(cartnum) .. " and DEFAULT_HIGH_CART >= " .. self.con:escape(cartnum))
+ if cur == nil then
+ return nil, err
+ end
+
+ local groupname = nil
+ local carttype = nil
+ local groupdesc = nil
+ while true do
+ local data = {}
+ data = cur:fetch(data, "a")
+ if data == nil then break end
+ if data.NAME == "ALL_SHOWS" then
+ carttype = "show"
+ elseif data.NAME == "ALL_POOLS" then
+ carttype = "pool"
+ elseif data.NAME == "ALL_JINGLE" then
+ carttype = "jingle"
+ else
+ groupname = data.NAME
+ groupdesc = data.DESCRIPTION
+ end
+ if groupname and carttype then break end
+ end
+ cur:close()
+
+ if carttype == nil then
+ return nil, "unable to detect group type for cart: " .. cartnum
+ end
+ if groupname == nil then
+ return nil, "can't find any group for cart: " .. cartnum
+ end
+ return carttype, groupname, groupdesc
+end
+
function rddb:getCartShowName(cartnum)
- --TODO: implement this
- return "unknown", "music", nil
+ local carttype, groupname, groupdesc = self:getGroupNameAndCartType(cartnum)
+ if carttype == nil then
+ return nil, groupname
+ end
+ if carttype == "show" then
+ return nil, "show carts not yet supported"
+ end
+ return groupdesc, carttype
end
function rddb:close()