From ef771e903bb7c799de96224591dc7d46847bd47a Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Mon, 14 Dec 2015 02:57:21 +0100 Subject: fetch Music Pool import-params diff --git a/importer.go b/importer.go index 9a254fc..61c2b64 100644 --- a/importer.go +++ b/importer.go @@ -177,6 +177,21 @@ func (ctx *ImportContext) checkMusicGroup() (bool, error) { return res.ismusic, nil } +func (ctx *ImportContext) getMusicInfo() (err error) { + req := getMusicInfoRequest{} + req.group = ctx.GroupName + req.response = make(chan getMusicInfoResult) + ctx.RdDb.getMusicInfoChan <- req + + res := <-req.response + if res.err != nil { + return res.err + } + ctx.NormalizationLevel = res.norm_lvl + ctx.AutotrimLevel = res.trim_lvl + return +} + type ImportResult struct { ResponseCode int ErrorString string @@ -460,10 +475,10 @@ func ImportFile(ctx *ImportContext) (res *ImportResult, err error) { res.ResponseCode = 500 res.ErrorString = "Importing to shows using the show-id is not yet implemented" // TODO: fetch info from dropboxes (cartlist, groupname, import-params) + // - if (ctx.Cart not in cartlist) -> Error // - if (ClearShowCarts == true): foreach(cart in cartlist): remove_cart(cart) [200 || 404 -> OK] // - add_cart(ctx, res) [200 -> OK] // - add_cut(ctx, res) [200 -> OK] - // - import_audio(ctx, res) [200 -> OK] return } else if ctx.GroupName != "" { res.ResponseCode = 500 @@ -471,7 +486,7 @@ func ImportFile(ctx *ImportContext) (res *ImportResult, err error) { // TODO: fetch info from dropboxes (import-params) // - add_cart(ctx, res) [200 -> OK] // - add_cut(ctx, res) [200 -> OK] - // - import_audio(ctx, res) [200 -> OK] + return } else if ctx.Cart != 0 && ctx.Cut == 0 { res.ResponseCode = 500 res.ErrorString = "Importing to a Cart which might not exist is not yet implemented" @@ -480,8 +495,10 @@ func ImportFile(ctx *ImportContext) (res *ImportResult, err error) { // - remove_cart(ctx, res) [200 || 404 -> OK] // - add_cart(ctx, res) [200 -> OK] // - add_cut(ctx, res) [200 -> OK] - // - import_audio(ctx, res) [200 -> OK] - } else if ctx.Cart != 0 && ctx.Cut != 0 { + return + } + + if ctx.Cart != 0 && ctx.Cut != 0 { if err = import_audio(ctx, res); err != nil { return } diff --git a/rddb.go b/rddb.go index 03553b9..87ac17a 100644 --- a/rddb.go +++ b/rddb.go @@ -84,6 +84,17 @@ type checkMusicGroupRequest struct { response chan checkMusicGroupResult } +type getMusicInfoResult struct { + norm_lvl int + trim_lvl int + err error +} + +type getMusicInfoRequest struct { + group string + response chan getMusicInfoResult +} + type RdDb struct { dbh *sql.DB password_cache map[string]string @@ -95,6 +106,8 @@ type RdDb struct { getShowInfoStmt *sql.Stmt checkMusicGroupChan chan checkMusicGroupRequest checkMusicGroupStmt *sql.Stmt + getMusicInfoChan chan getMusicInfoRequest + getMusicInfoStmt *sql.Stmt quit chan bool done chan bool } @@ -128,6 +141,9 @@ func (self *RdDb) init(conf *Config) (err error) { if self.checkMusicGroupStmt, err = self.dbh.Prepare("select count(*) from DROPBOXES where GROUP_NAME = ? and SET_USER_DEFINED like \"M;%\";"); err != nil { return } + if self.getMusicInfoStmt, err = self.dbh.Prepare("select NORMALIZATION_LEVEL,AUTOTRIM_LEVEL from DROPBOXES where DROPBOXES.GROUP_NAME = ?;"); err != nil { + return + } return } @@ -220,7 +236,7 @@ func (self *RdDb) getShowInfo(showid int) (title string, carts []int, norm_lvl i func (self *RdDb) checkMusicGroup(group string) (ismusic bool, err error) { var cnt int - err = self.checkMusicGroupStmt.QueryRow(group).Scan(&cnt) + err = self.getMusicInfoStmt.QueryRow(group).Scan(&cnt) if err != nil { if err == sql.ErrNoRows { err = nil @@ -232,6 +248,17 @@ func (self *RdDb) checkMusicGroup(group string) (ismusic bool, err error) { return } +func (self *RdDb) getMusicInfo(group string) (norm_lvl, trim_lvl int, err error) { + err = self.checkMusicGroupStmt.QueryRow(group).Scan(&norm_lvl, &trim_lvl) + if err != nil { + if err == sql.ErrNoRows { + err = fmt.Errorf("music pool '%d' not found", group) + } + return + } + return +} + func (self *RdDb) dispatchRequests() { defer func() { self.done <- true }() for { @@ -250,6 +277,9 @@ func (self *RdDb) dispatchRequests() { case req := <-self.checkMusicGroupChan: ismusic, err := self.checkMusicGroup(req.group) req.response <- checkMusicGroupResult{ismusic, err} + case req := <-self.getMusicInfoChan: + norm_lvl, trim_lvl, err := self.getMusicInfo(req.group) + req.response <- getMusicInfoResult{norm_lvl, trim_lvl, err} } } } @@ -275,6 +305,9 @@ func (self *RdDb) Cleanup() { if self.checkMusicGroupStmt != nil { self.checkMusicGroupStmt.Close() } + if self.getMusicInfoStmt != nil { + self.getMusicInfoStmt.Close() + } } func NewRdDb(conf *Config) (db *RdDb, err error) { @@ -287,6 +320,7 @@ func NewRdDb(conf *Config) (db *RdDb, err error) { db.getGroupOfCartChan = make(chan getGroupOfCartRequest) db.getShowInfoChan = make(chan getShowInfoRequest) db.checkMusicGroupChan = make(chan checkMusicGroupRequest) + db.getMusicInfoChan = make(chan getMusicInfoRequest) if err = db.init(conf); err != nil { return -- cgit v0.10.2