summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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("***************************************************************")
}