summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2016-08-03 16:02:12 (GMT)
committerChristian Pointner <equinox@helsinki.at>2016-08-03 16:02:12 (GMT)
commitcf13adfafa6c0fea9e5d4c99092e7e42c9eafa7c (patch)
tree3504c8f44b88ecb324d3e107720a7ccf0f927aec
parentc0f3d0458db57212319e7db1da4dbf82a053bb3b (diff)
use new ExtraMetaData field from rhimport.Context
made log output more beautiful
-rw-r--r--src/pool-import/main.go37
1 files changed, 28 insertions, 9 deletions
diff --git a/src/pool-import/main.go b/src/pool-import/main.go
index eb02756..ccd3b8f 100644
--- a/src/pool-import/main.go
+++ b/src/pool-import/main.go
@@ -44,9 +44,10 @@ func Done(res rhimport.Result, userdata interface{}) bool {
return true
}
-func HandleCart(cart uint, cut uint, artist, album, title, dstgroup string, sessions *rhimport.SessionStore, conf *rhimport.Config, stdlog, dbglog *log.Logger) {
+func HandleCart(cart uint, cut uint, artist, album, title, dstgroup string, sessions *rhimport.SessionStore, conf *rhimport.Config, stdlog, dbglog *log.Logger) bool {
filename := fmt.Sprintf("%06d_%03d.wav", cart, cut)
+ stdlog.Printf("")
stdlog.Printf("********* %s: '%s' / '%s' / '%s'", filename, artist, album, title)
ctx := rhimport.NewContext(conf, nil, stdlog, dbglog)
@@ -55,18 +56,20 @@ func HandleCart(cart uint, cut uint, artist, album, title, dstgroup string, sess
ctx.GroupName = dstgroup
ctx.SourceUri = "local:///" + filename
ctx.SourceFilePolicy = rhimport.Keep
+ ctx.ExtraMetaData["ARTIST"] = artist
+ ctx.ExtraMetaData["ALBUM"] = album
+ ctx.ExtraMetaData["TITLE"] = title
- id, s, code, errstring := sessions.New(ctx, "")
+ _, s, code, errstring := sessions.New(ctx, "")
if code != http.StatusOK {
stdlog.Printf(">>>>>>>> ERROR: creating session: %s", errstring)
- return
+ return false
}
- stdlog.Printf(">>>>>>>> got session: %s", id)
donechan := make(chan rhimport.Result, 1)
if err := s.AddDoneHandler((chan<- rhimport.Result)(donechan), Done); err != nil {
stdlog.Printf(">>>>>>> ERROR: adding done handler: %s", err.Error())
- return
+ return false
}
s.Run(10 * time.Minute)
@@ -74,9 +77,10 @@ func HandleCart(cart uint, cut uint, artist, album, title, dstgroup string, sess
if res.ResponseCode != http.StatusOK {
stdlog.Printf(">>>>>>> ERROR: adding done handler: %s", res.ErrorString)
- } else {
- stdlog.Printf(">>>>>>> SUCCESS: imported into: cart/cut %d/%d", res.Cart, res.Cut)
+ return false
}
+ stdlog.Printf(">>>>>>> SUCCESS: imported into: cart/cut %d/%d", res.Cart, res.Cut)
+ return true
}
func main() {
@@ -119,13 +123,19 @@ func main() {
log.Fatal("Error fetching Pool cart list:", err)
}
- stdlog.Printf("will import: %d carts from old:%s -> new:%s", len(carts), oldGroup, newGroup)
+ stdlog.Println("***************************************************************")
+ stdlog.Printf("*** will import: %d carts from old:%s -> new:%s", len(carts), oldGroup, newGroup)
+ stdlog.Println("***************************************************************")
var keys []int
for k := range carts {
keys = append(keys, int(k))
}
sort.Ints(keys)
+
+ start := time.Now()
+ successCnt := 0
+ errCnt := 0
for _, k := range keys {
cart := carts[uint(k)]
if len(cart.Cuts) == 0 {
@@ -135,6 +145,15 @@ func main() {
stdlog.Printf("Warning: Cart %d has multiple cuts - will only use the first", cart.Number)
}
cut := cart.Cuts[0].Number
- HandleCart(cart.Number, cut, cart.Artist, cart.Album, cart.Title, newGroup, sessions.GetInterface(), conf, stdlog, dbglog)
+ if HandleCart(cart.Number, cut, cart.Artist, cart.Album, cart.Title, newGroup, sessions.GetInterface(), conf, stdlog, dbglog) {
+ successCnt++
+ } else {
+ errCnt++
+ }
}
+ stdlog.Println("")
+ stdlog.Println("***************************************************************")
+ stdlog.Printf("*** %d files imported successfully, %d errors", successCnt, errCnt)
+ stdlog.Printf("*** process took %v", time.Since(start))
+ stdlog.Println("***************************************************************")
}