diff options
-rw-r--r-- | fetcher.go | 1 | ||||
-rw-r--r-- | importer.go | 13 | ||||
-rw-r--r-- | rddb.go | 64 |
3 files changed, 52 insertions, 26 deletions
@@ -115,6 +115,7 @@ func FetchFileCurl(ctx *ImportContext, uri *url.URL) (err error) { easy.Setopt(curl.OPT_PROGRESSDATA, ctx) if err = easy.Perform(); err != nil { + err = fmt.Errorf("fetcher('%s'): %s", ctx.SourceUri, err) return } diff --git a/importer.go b/importer.go index 8206082..9a254fc 100644 --- a/importer.go +++ b/importer.go @@ -155,7 +155,12 @@ func (ctx *ImportContext) getShowInfo() (err error) { err = res.err return } - rhdl.Printf("Title of show %d is '%s'", ctx.ShowId, res.title) + + rhdl.Printf("Show %d:\n", ctx.ShowId) + rhdl.Printf(" Title: '%s'\n", res.title) + rhdl.Printf(" Normalization Level: %d\n", res.norm_lvl) + rhdl.Printf(" Autotrim Level: %d\n", res.trim_lvl) + rhdl.Printf(" Carts: %v\n", res.carts) return } @@ -401,13 +406,10 @@ func import_audio(ctx *ImportContext, result *ImportResult) (err error) { easy.Setopt(curl.OPT_PROGRESSDATA, ctx) if err = easy.Perform(); err != nil { + err = fmt.Errorf("importer: %s", err) return } - // var status_code interface{} - // if status_code, err = easy.Getinfo(curl.INFO_RESPONSE_CODE); err != nil { - // return - // } var rdres *RDWebResult if rdres, err = NewRDWebResultFromXML(bufio.NewReader(&resbody)); err != nil { return @@ -459,7 +461,6 @@ func ImportFile(ctx *ImportContext) (res *ImportResult, err error) { res.ErrorString = "Importing to shows using the show-id is not yet implemented" // TODO: fetch info from dropboxes (cartlist, groupname, import-params) // - if (ClearShowCarts == true): foreach(cart in cartlist): remove_cart(cart) [200 || 404 -> OK] - // - ctx.cart = 0 // - add_cart(ctx, res) [200 -> OK] // - add_cut(ctx, res) [200 -> OK] // - import_audio(ctx, res) [200 -> OK] @@ -28,6 +28,12 @@ import ( "database/sql" "fmt" _ "github.com/go-sql-driver/mysql" + "regexp" + "strings" +) + +var ( + showMacroRe = regexp.MustCompile(`^LL 1 ([^ ]+) 0\!$`) ) type getPasswordResult struct { @@ -52,9 +58,11 @@ type getGroupOfCartRequest struct { } type getShowInfoResult struct { - title string - carts map[int]int - err error + title string + carts []int + norm_lvl int + trim_lvl int + err error } type getShowInfoRequest struct { @@ -92,13 +100,15 @@ func (self *RdDb) init(conf *Config) (err error) { if self.dbh, err = sql.Open("mysql", dsn); err != nil { return } + //TODO: check if we have a compatible DB version + if self.getPasswordStmt, err = self.dbh.Prepare("select PASSWORD from USERS where LOGIN_NAME = ?;"); err != nil { return } if self.getGroupOfCartStmt, err = self.dbh.Prepare("select NAME,DEFAULT_LOW_CART,DEFAULT_HIGH_CART from GROUPS where DEFAULT_LOW_CART <= ? and DEFAULT_HIGH_CART >= ?;"); err != nil { return } - if self.getShowInfoStmt, err = self.dbh.Prepare("select TITLE,MACROS from CART where NUMBER = ?;"); err != nil { + if self.getShowInfoStmt, err = self.dbh.Prepare("select CART.TITLE,CART.MACROS,DROPBOXES.NORMALIZATION_LEVEL,DROPBOXES.AUTOTRIM_LEVEL,GROUPS.DEFAULT_LOW_CART,GROUPS.DEFAULT_HIGH_CART from CART, DROPBOXES, GROUPS where CART.NUMBER = DROPBOXES.TO_CART and GROUPS.NAME = DROPBOXES.GROUP_NAME and CART.NUMBER = ?;"); err != nil { return } if self.checkMusicGroupStmt, err = self.dbh.Prepare("select count(*) from DROPBOXES where GROUP_NAME = ? and SET_USER_DEFINED like \"M;%\";"); err != nil { @@ -156,19 +166,41 @@ func (self *RdDb) getGroupOfCart(cart uint) (group string, err error) { return } -func (self *RdDb) getShowInfo(showid int) (title string, carts map[int]int, err error) { +func (self *RdDb) getLogTableName(log string) string { + return strings.Replace(log, " ", "_", -1) + "_LOG" // TODO: this should get escaped fir mySQL but golang doesn't support it!!! +} + +func (self *RdDb) getShowCarts(log string, low_cart, high_cart int) (carts []int, err error) { + q := fmt.Sprintf("select CART_NUMBER from %s where CART_NUMBER >= %d and CART_NUMBER <= %d order by COUNT;", self.getLogTableName(log), low_cart, high_cart) + var rows *sql.Rows + if rows, err = self.dbh.Query(q); err != nil { + return + } + defer rows.Close() + for rows.Next() { + var cart int + if err = rows.Scan(&cart); err != nil { + return + } + carts = append(carts, cart) + } + err = rows.Err() + return +} + +func (self *RdDb) getShowInfo(showid int) (title string, carts []int, norm_lvl int, trim_lvl int, err error) { var macros string - err = self.getShowInfoStmt.QueryRow(showid).Scan(&title, ¯os) + var low_cart, high_cart int + err = self.getShowInfoStmt.QueryRow(showid).Scan(&title, ¯os, &norm_lvl, &trim_lvl, &low_cart, &high_cart) if err != nil { if err == sql.ErrNoRows { err = fmt.Errorf("show '%d' not found", showid) } return } - - rhdl.Printf("RdDb: macros for showid '%d' are set to '%s'", showid, macros) - // TODO: also fetch cart list and import params (norm_level, ...) - carts = make(map[int]int) + norm_lvl /= 100 + trim_lvl /= 100 + carts, err = self.getShowCarts(showMacroRe.FindStringSubmatch(macros)[1], low_cart, high_cart) return } @@ -193,23 +225,15 @@ func (self *RdDb) dispatchRequests() { case <-self.quit: return case req := <-self.getPasswordChan: - if req.cached { - rhdl.Println("RdDb: got getPassword request for", req.username, "(cached)") - } else { - rhdl.Println("RdDb: got getPassword request for", req.username, "(not cached)") - } pwd, err := self.getPassword(req.username, req.cached) req.response <- getPasswordResult{pwd, err} case req := <-self.getGroupOfCartChan: - rhdl.Println("RdDb: got getGroupOfCart request for", req.cart) group, err := self.getGroupOfCart(req.cart) req.response <- getGroupOfCartResult{group, err} case req := <-self.getShowInfoChan: - rhdl.Println("RdDb: got getShowInfo request for", req.showid) - title, carts, err := self.getShowInfo(req.showid) - req.response <- getShowInfoResult{title, carts, err} + title, carts, norm_lvl, trim_lvl, err := self.getShowInfo(req.showid) + req.response <- getShowInfoResult{title, carts, norm_lvl, trim_lvl, err} case req := <-self.checkMusicGroupChan: - rhdl.Println("RdDb: got checkMusicGroup request for", req.group) ismusic, err := self.checkMusicGroup(req.group) req.response <- checkMusicGroupResult{ismusic, err} } |