summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2016-07-15 13:10:29 (GMT)
committerChristian Pointner <equinox@helsinki.at>2016-07-15 13:14:03 (GMT)
commitb7456c5beafeeba5357db25eac195b93313647fe (patch)
tree9a8b32014d067abb7d8978980f3d9984798acc6d
parent032ef2074e691935a017d95fa5fd134317ef344f (diff)
simplified progress reports
-rw-r--r--rhimport/core.go8
-rw-r--r--rhimport/fetcher.go56
-rw-r--r--rhimport/importer.go6
-rw-r--r--rhimport/normalizer.go26
4 files changed, 23 insertions, 73 deletions
diff --git a/rhimport/core.go b/rhimport/core.go
index 92e798b..d5d7549 100644
--- a/rhimport/core.go
+++ b/rhimport/core.go
@@ -256,3 +256,11 @@ func (ctx *Context) updateCutCartTitle() (err error) {
}
return ctx.db.UpdateCutCartTitle(ctx.Cart, ctx.Cut, ctx.GroupName, filename)
}
+
+func (ctx *Context) reportProgress(step int, stepName string, current, total float64) {
+ if ctx.ProgressCallBack != nil {
+ if keep := ctx.ProgressCallBack(step, stepName, current, total, ctx.Cart, ctx.Cut, ctx.ProgressCallBackData); !keep {
+ ctx.ProgressCallBack = nil
+ }
+ }
+}
diff --git a/rhimport/fetcher.go b/rhimport/fetcher.go
index c9bfc2f..b4380fa 100644
--- a/rhimport/fetcher.go
+++ b/rhimport/fetcher.go
@@ -103,12 +103,7 @@ func curlWriteCallback(ptr []byte, userdata interface{}) bool {
data.writeError = fmt.Errorf("file exceeds maximum file size")
return false
}
-
- if data.ctx.ProgressCallBack != nil {
- if keep := data.ctx.ProgressCallBack(1, "downloading", float64(data.written), data.totalSize, 0, 0, data.ctx.ProgressCallBackData); !keep {
- data.ctx.ProgressCallBack = nil
- }
- }
+ data.ctx.reportProgress(1, "downloading", float64(data.written), data.totalSize)
return true
}
@@ -447,12 +442,7 @@ func fetchFileDirConvert(ctx *Context, res *Result, origSrc *os.File, sizeTotal
}
written += uint64(w)
- if ctx.ProgressCallBack != nil {
- if keep := ctx.ProgressCallBack(1, "fetching", float64(written), float64(sizeTotal), 0, 0, ctx.ProgressCallBackData); !keep {
- ctx.ProgressCallBack = nil
- }
- }
-
+ ctx.reportProgress(1, "fetching", float64(written), float64(sizeTotal))
if ctx.Cancel != nil && len(ctx.Cancel) > 0 {
res.ResponseCode = http.StatusNoContent
res.ErrorString = "canceled"
@@ -533,12 +523,7 @@ func fetchFileDir(ctx *Context, res *Result, uri *url.URL, dir string, convert b
return nil
}
- if ctx.ProgressCallBack != nil {
- if keep := ctx.ProgressCallBack(1, "fetching", 0.0, float64(size), 0, 0, ctx.ProgressCallBackData); !keep {
- ctx.ProgressCallBack = nil
- }
- }
-
+ ctx.reportProgress(1, "fetching", 0.0, float64(size))
if convert {
if err = fetchFileDirConvert(ctx, res, src, size); err != nil {
return
@@ -549,12 +534,7 @@ func fetchFileDir(ctx *Context, res *Result, uri *url.URL, dir string, convert b
ctx.DeleteSourceDir = false
}
}
-
- if ctx.ProgressCallBack != nil {
- if keep := ctx.ProgressCallBack(1, "fetching", float64(size), float64(size), 0, 0, ctx.ProgressCallBackData); !keep {
- ctx.ProgressCallBack = nil
- }
- }
+ ctx.reportProgress(1, "fetching", float64(size), float64(size))
return
}
@@ -575,18 +555,12 @@ func fetchFileFake(ctx *Context, res *Result, uri *url.URL) error {
res.ErrorString = "canceled"
return nil
}
- if ctx.ProgressCallBack != nil {
- if keep := ctx.ProgressCallBack(1, "faking", float64(i), float64(duration), 0, 0, ctx.ProgressCallBackData); !keep {
- ctx.ProgressCallBack = nil
- }
- }
+
+ ctx.reportProgress(1, "faking", float64(i), float64(duration))
time.Sleep(100 * time.Millisecond)
}
- if ctx.ProgressCallBack != nil {
- if keep := ctx.ProgressCallBack(1, "faking", float64(duration), float64(duration), 0, 0, ctx.ProgressCallBackData); !keep {
- ctx.ProgressCallBack = nil
- }
- }
+ ctx.reportProgress(1, "faking", float64(duration), float64(duration))
+
ctx.SourceFile = "/nonexistend/fake.mp3"
ctx.OrigFilename = ctx.SourceFile
if ctx.SourceFilePolicy == Auto {
@@ -626,12 +600,7 @@ func writeAttachmentFile(ctx *Context, res *Result, sizeTotal uint64, conv Fetch
}
written += uint64(w)
- if ctx.ProgressCallBack != nil {
- if keep := ctx.ProgressCallBack(1, "receiving", float64(written), float64(sizeTotal), 0, 0, ctx.ProgressCallBackData); !keep {
- ctx.ProgressCallBack = nil
- }
- }
-
+ ctx.reportProgress(1, "receiving", float64(written), float64(sizeTotal))
if uint64(written) >= sizeTotal {
return nil
}
@@ -672,12 +641,7 @@ func fetchFileAttachment(ctx *Context, res *Result, uri *url.URL) error {
return err
}
- if ctx.ProgressCallBack != nil {
- if keep := ctx.ProgressCallBack(1, "receiving", 0.0, float64(sizeTotal), 0, 0, ctx.ProgressCallBackData); !keep {
- ctx.ProgressCallBack = nil
- }
- }
-
+ ctx.reportProgress(1, "receiving", 0.0, float64(sizeTotal))
err = writeAttachmentFile(ctx, res, sizeTotal, conv)
conv.Close()
if res.ResponseCode == http.StatusNoContent {
diff --git a/rhimport/importer.go b/rhimport/importer.go
index bcaf84f..37bbc01 100644
--- a/rhimport/importer.go
+++ b/rhimport/importer.go
@@ -311,11 +311,7 @@ func importAudio(ctx *Context, res *Result) (err error) {
return false
}
- if ctx.ProgressCallBack != nil {
- if keep := ctx.ProgressCallBack(3, "importing", ulnow, ultotal, ctx.Cart, ctx.Cut, ctx.ProgressCallBackData); !keep {
- ctx.ProgressCallBack = nil
- }
- }
+ ctx.reportProgress(3, "importing", ulnow, ultotal)
return true
})
easy.Setopt(curl.OPT_PROGRESSDATA, ctx)
diff --git a/rhimport/normalizer.go b/rhimport/normalizer.go
index 3f56151..422acaa 100644
--- a/rhimport/normalizer.go
+++ b/rhimport/normalizer.go
@@ -71,11 +71,7 @@ func runNormalizer(ctx *Context, src *os.File, size int64) (err error) {
break
}
written += w
- if ctx.ProgressCallBack != nil {
- if keep := ctx.ProgressCallBack(2, "normalizing", float64(written), float64(size), 0, 0, ctx.ProgressCallBackData); !keep {
- ctx.ProgressCallBack = nil
- }
- }
+ ctx.reportProgress(2, "normalizing", float64(written), float64(size))
}
ffstdin.Close()
res := <-ffresult
@@ -91,11 +87,7 @@ func runNormalizer(ctx *Context, src *os.File, size int64) (err error) {
func NormalizeFile(ctx *Context) (err error) {
if ctx.LoudnessCorr == 0.0 {
rhl.Println("NormalizeFile: skipping normalization since the gain = 0.0dB")
- if ctx.ProgressCallBack != nil {
- if keep := ctx.ProgressCallBack(2, "normalizing", 1.0, 1.0, 0, 0, ctx.ProgressCallBackData); !keep {
- ctx.ProgressCallBack = nil
- }
- }
+ ctx.reportProgress(2, "normalizing", 1.0, 1.0)
return
}
@@ -114,12 +106,7 @@ func NormalizeFile(ctx *Context) (err error) {
size = info.Size()
}
- if ctx.ProgressCallBack != nil {
- if keep := ctx.ProgressCallBack(2, "normalizing", 0.0, float64(size), 0, 0, ctx.ProgressCallBackData); !keep {
- ctx.ProgressCallBack = nil
- }
- }
-
+ ctx.reportProgress(2, "normalizing", 0.0, float64(size))
if err = runNormalizer(ctx, src, size); err != nil {
rhl.Println("NormalizeFile error:", err)
if ctx.DeleteSourceFile {
@@ -130,12 +117,7 @@ func NormalizeFile(ctx *Context) (err error) {
}
return
}
-
- if ctx.ProgressCallBack != nil {
- if keep := ctx.ProgressCallBack(2, "normalizing", float64(size), float64(size), 0, 0, ctx.ProgressCallBackData); !keep {
- ctx.ProgressCallBack = nil
- }
- }
+ ctx.reportProgress(2, "normalizing", float64(size), float64(size))
return
}