summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2017-01-05 23:57:47 (GMT)
committerChristian Pointner <equinox@helsinki.at>2017-01-05 23:57:47 (GMT)
commitf093e02546f1752f2c9fea5581aa20d0e8bfb848 (patch)
tree84038a4063e427d2f67e5e88608e778ae16c66ea
parent1d05cd83ccb6ab3d2efbda8a6981204966c2c6d3 (diff)
fetching title of show carts works now as well
-rw-r--r--src/rddb.lua67
1 files changed, 66 insertions, 1 deletions
diff --git a/src/rddb.lua b/src/rddb.lua
index 0827f62..5bf9db2 100644
--- a/src/rddb.lua
+++ b/src/rddb.lua
@@ -51,6 +51,7 @@ function rddb:getCartInfo(cartnum)
end
if cur:numrows() ~= 1 then
+ cur:close()
return nil, "nothing found in rivendell db"
end
@@ -101,13 +102,77 @@ function rddb:getGroupNameAndCartType(cartnum)
return carttype, groupname, groupdesc
end
+local getShowType = function(params)
+ local n = 0
+ for p in string.gmatch(params, "([^;]+)") do
+ if n == 5 then
+ return p
+ end
+ n = n + 1
+ end
+ return "n"
+end
+
+local getShowLog = function(macros)
+ local log = string.match(macros, "^LL 1 ([^ ]+) 0!$")
+ if log == nil then
+ return nil, "invalid show macro"
+ end
+ log = string.gsub(log, "-", "_") .. "_LOG"
+ if string.match(log, "^[_0-9a-zA-Z-]+$") == nil then
+ return nil, "invalid show log-name: " .. log
+ end
+ return log
+end
+
+function rddb:__showHasCart(showlog, cartnum)
+ local cur, err = self.con:execute("select CART_NUMBER from " .. showlog .. " where CART_NUMBER = " .. tonumber(cartnum))
+ if cur == nil then
+ return nil, err
+ end
+ local nresults = cur:numrows()
+ cur:close()
+
+ return nresults > 0
+end
+
+function rddb:__getShowNameForShowCart(cartnum, groupname)
+ local cur, err = self.con:execute("select CART.TITLE,CART.MACROS,DROPBOXES.SET_USER_DEFINED as PARAMS from CART,DROPBOXES where CART.NUMBER = DROPBOXES.TO_CART and DROPBOXES.GROUP_NAME = '" .. self.con:escape(groupname) .. "'")
+ if cur == nil then
+ return nil, err
+ end
+
+ while true do
+ local data = {}
+ data = cur:fetch(data, "a")
+ if data == nil then break end
+
+ local showtype = getShowType(data.PARAMS)
+ if showtype == "r" then
+ data.TITLE = data.TITLE .. " (Wiederholung)"
+ elseif showtype == "s" then
+ data.TITLE = data.TITLE .. " (Sondersendung)"
+ end
+
+ local log = getShowLog(data.MACROS)
+
+ if self:__showHasCart(log, cartnum) then
+ cur:close()
+ return data.TITLE, "show"
+ end
+ end
+ cur:close()
+
+ return nil, "can't find any show for cart: " .. cartnum
+end
+
function rddb:getCartShowName(cartnum)
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"
+ return rddb:__getShowNameForShowCart(cartnum, groupname)
end
return groupdesc, carttype
end