From c2e2c6e81624d244c53598b399047343ac3bf953 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Thu, 5 Jan 2017 00:34:11 +0100 Subject: prepare now/next for pool name and show titles diff --git a/src/nopfetchd.conf b/src/nopfetchd.conf index a80d620..0338cb6 100644 --- a/src/nopfetchd.conf +++ b/src/nopfetchd.conf @@ -2,9 +2,6 @@ queue_name=/rhnop tcp_host=* tcp_port=2345 -music_carts_lo=400000 -music_carts_hi=499999 - rddb_db=rivendell rddb_host=127.0.0.1 #rddb_port=3306 diff --git a/src/playlog.lua b/src/playlog.lua index a748d1d..ddb31f3 100644 --- a/src/playlog.lua +++ b/src/playlog.lua @@ -67,15 +67,11 @@ function playlog:getLastCart() return cart end -function playlog:insertNowMusic(timestamp, cart, len, title, artist, album) +function playlog:insertNow(timestamp, cart, len, showtitle, title, artist, album, isMusic) cart = tonumber(cart) len = tonumber(len) - if cart < 400000 or cart > 450000 then - poolnum = 0 - else - poolnum = math.floor(cart/1000) - 399 - end - local cur, err = self.con:execute("INSERT into now VALUES(" .. self.con:escape(timestamp) .. ", " .. cart .. ", " .. len .. ", 'Musikpool " .. poolnum .. "', '" .. self.con:escape(title) .. "', '" .. self.con:escape(artist) .."', '" .. self.con:escape(album) .. "', 1)") + if isMusic then isMusic = '1' else isMusic = '0' end + local cur, err = self.con:execute("INSERT into now VALUES(" .. self.con:escape(timestamp) .. ", " .. cart .. ", " .. len .. ", '" .. self.con:escape(showtitle) .. "', '" .. self.con:escape(title) .. "', '" .. self.con:escape(artist) .."', '" .. self.con:escape(album) .. "', " .. isMusic .. ")") if cur == nil then return nil, err end diff --git a/src/qlistener.lua b/src/qlistener.lua index 8a696fe..a80dbac 100644 --- a/src/qlistener.lua +++ b/src/qlistener.lua @@ -33,28 +33,26 @@ conf = require "conf" local cnf = {} function init(conffile) cnf = conf.load(conffile) - if cnf.music_carts_lo == nil then - cnf.music_carts_lo = 400000 - end - if cnf.music_carts_hi == nil then - cnf.music_carts_hi = 499999 - end - cnf.music_carts_lo = tonumber(cnf.music_carts_lo) - cnf.music_carts_hi = tonumber(cnf.music_carts_hi) end function handle_now(timestamp, nowcart, nowlen) - local results, err = rddb:getCartInfo(nowcart); + local results, err = rddb:getCartInfo(nowcart) if results == nil then io.stderr:write("ERROR: can't fetch cart info: " .. err .. "\n") return nil else --- print(timestamp .. " Info: '" .. results.TITLE .. "' von '" .. results.ARTIST .. "' aus '" .. results.ALBUM .. "'") - local ret, err = playlog:insertNowMusic(timestamp, nowcart, nowlen, results.TITLE, results.ARTIST, results.ALBUM) - if ret == nil then - io.stderr:write("ERROR: can't insert music info: " .. err .. "\n") + -- print(timestamp .. " Info: '" .. results.TITLE .. "' von '" .. results.ARTIST .. "' aus '" .. results.ALBUM .. "'") + local showtitle, isMusic, err = rddb:getCartShowName(nowcart) + if showtitle == nil then + io.stderr:write("ERROR: can't fetch show/pool name: " .. err .. "\n") + return nil else - pipe.signal(timestamp) + local ret, err = playlog:insertNow(timestamp, nowcart, nowlen, showtitle, results.TITLE, results.ARTIST, results.ALBUM, isMusic) + if ret == nil then + io.stderr:write("ERROR: can't insert cart info: " .. err .. "\n") + else + pipe.signal(timestamp) + end end end @@ -68,7 +66,7 @@ function handle_message(msg, q) else nowcart = tonumber(nowcart) nowlen = tonumber(nowlen) - if last_cart ~= nowcart and nowcart >= cnf.music_carts_lo and nowcart <= cnf.music_carts_hi and nowlen > 0 then + if last_cart ~= nowcart and nowlen > 0 then last_cart = nowcart local ret = handle_now(timestamp, nowcart, nowlen) if ret == nil then diff --git a/src/rddb.lua b/src/rddb.lua index b92f767..fd755f7 100644 --- a/src/rddb.lua +++ b/src/rddb.lua @@ -65,6 +65,11 @@ function rddb:getCartInfo(cartnum) return results, err end +function rddb:getCartShowName(cartnum) + --TODO: implement this + return "unknown", true, nil +end + function rddb:close() if self.con then self.con:close() -- cgit v0.10.2