From 49a33ef6dcfccda67c9afc54d4dc061a74dfbb6d Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Fri, 15 Jul 2016 17:56:01 +0200 Subject: progress messages now contain file title diff --git a/rhimport/converter.go b/rhimport/converter.go index 7c35c07..a116a8d 100644 --- a/rhimport/converter.go +++ b/rhimport/converter.go @@ -162,7 +162,7 @@ type BS1770FetchConverter struct { func NewBS1770FetchConverter(filename string, metadata map[string]string, channels uint) (bs *BS1770FetchConverter, newFilename string, err error) { bs = &BS1770FetchConverter{} - rhl.Printf("bs1770-converter: opening file '%s'", filename) + rhl.Printf("bs1770-converter: starting bs1770gain for file '%s'", filename) newFilename = filename bs.file, err = os.OpenFile(filename, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0600) @@ -240,7 +240,7 @@ func NewFFMpegBS1770FetchConverter(filename string, metadata map[string]string, ff = &FFMpegBS1770FetchConverter{} ext := filepath.Ext(filename) filenameFlac = strings.TrimSuffix(filename, ext) + ".flac" - rhl.Printf("ffmpeg-bs1770-converter: starting ffmpeg for file '%s' (had extension: '%s')", filenameFlac, ext) + rhl.Printf("ffmpeg-bs1770-converter: starting ffmpeg and bs1770gain for file '%s' (had extension: '%s')", filenameFlac, ext) ff.ffmpeg = exec.Command("ffmpeg", "-loglevel", "warning", "-i", "pipe:0", "-map_metadata", "0") if metadata != nil { for key, value := range metadata { diff --git a/rhimport/core.go b/rhimport/core.go index cf51c54..fc92f6a 100644 --- a/rhimport/core.go +++ b/rhimport/core.go @@ -29,6 +29,7 @@ import ( "io/ioutil" "log" "os" + "path" "code.helsinki.at/rhrd-go/rddb" "github.com/andelf/go-curl" @@ -60,7 +61,7 @@ func init() { fetcherInit() } -type ProgressCB func(step int, stepName string, current, total float64, cart, cut uint, userdata interface{}) bool +type ProgressCB func(step int, stepName string, current, total float64, title string, cart, cut uint, userdata interface{}) bool type DoneCB func(result Result, userdata interface{}) bool type Result struct { @@ -130,6 +131,7 @@ type Context struct { AttachmentChan <-chan []byte FetchConverter string OrigFilename string + Title string SourceFile string DeleteSourceFile bool DeleteSourceDir bool @@ -160,6 +162,7 @@ func NewContext(conf *Config, db *rddb.DBChan) *Context { ctx.AttachmentChan = nil ctx.FetchConverter = "ffmpeg-bs1770" ctx.OrigFilename = "" + ctx.Title = "" ctx.SourceFile = "" ctx.DeleteSourceFile = false ctx.DeleteSourceDir = false @@ -259,7 +262,14 @@ func (ctx *Context) updateCutCartTitle() (err error) { 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 { + title := ctx.Title + if title == "" { + title = path.Base(ctx.OrigFilename) + if title == "" { + title = path.Base(ctx.SourceFile) + } + } + if keep := ctx.ProgressCallBack(step, stepName, current, total, title, ctx.Cart, ctx.Cut, ctx.ProgressCallBackData); !keep { ctx.ProgressCallBack = nil } } diff --git a/rhimport/fetcher.go b/rhimport/fetcher.go index f176e03..45434a6 100644 --- a/rhimport/fetcher.go +++ b/rhimport/fetcher.go @@ -210,6 +210,15 @@ func fetchFileCurl(ctx *Context, res *Result, uri *url.URL) (err error) { } } + if info.Extractor != "generic" && info.Extractor != "dropbox" { + ctx.Title = info.ExtractorKey + ": " + info.Title + if info.Title == "" { + ctx.Title += info.ID + } + cbdata.metadata = make(map[string]string) + cbdata.metadata["TITLE"] = ctx.Title + } + easy.Setopt(curl.OPT_HEADERFUNCTION, curlHeaderCallback) easy.Setopt(curl.OPT_HEADERDATA, cbdata) @@ -303,7 +312,6 @@ func generateArchivFilePath(uri *url.URL) (file, path string, t time.Time, err e file = t.Format("2006-01-02-1504") + ".ogg" path = fmt.Sprintf("%s/%04d/%02d-%s/%02d-%s", ARCHIV_BASE_PATH, t.Year(), t.Month(), months[t.Month()-1], t.Day(), weekdays[t.Weekday()]) - return } @@ -351,8 +359,9 @@ func fetchFileArchiv(ctx *Context, res *Result, uri *url.URL) (err error) { easy.Setopt(curl.OPT_BUFFERSIZE, 1024*1024) + ctx.Title = fmt.Sprintf("Archiv vom %s - %s Uhr", start.Format("2.1.2006 15:04"), end.Format("15:04")) cbdata.metadata = make(map[string]string) - cbdata.metadata["TITLE"] = fmt.Sprintf("Archiv vom %s - %s Uhr", start.Format("2.1.2006 15:04"), end.Format("15:04")) + cbdata.metadata["TITLE"] = ctx.Title cbdata.metadata["ALBUM"] = "Radio Helsinki Archiv" cbdata.metadata["ORGANIZATION"] = "Radio Helsinki" cbdata.metadata["DATE"] = start.Format("2.1.2006") diff --git a/rhimport/session.go b/rhimport/session.go index a5f4a04..e0d6efb 100644 --- a/rhimport/session.go +++ b/rhimport/session.go @@ -72,6 +72,7 @@ type ProgressData struct { StepName string Current float64 Total float64 + Title string Cart uint Cut uint } @@ -96,9 +97,9 @@ type sessionAddDoneHandlerRequest struct { response chan<- sessionAddDoneHandlerResponse } -func sessionProgressCallback(step int, stepName string, current, total float64, cart, cut uint, userdata interface{}) bool { +func sessionProgressCallback(step int, stepName string, current, total float64, title string, cart, cut uint, userdata interface{}) bool { out := userdata.(chan<- ProgressData) - out <- ProgressData{step, stepName, current, total, cart, cut} + out <- ProgressData{step, stepName, current, total, title, cart, cut} return true } @@ -178,7 +179,7 @@ func (self *Session) addDoneHandler(userdata interface{}, cb DoneCB) (resp sessi func (self *Session) callProgressHandler(p *ProgressData) { for _, cb := range self.progressCBs { if cb.cb != nil { - if keep := cb.cb(p.Step, p.StepName, p.Current, p.Total, p.Cart, p.Cut, cb.userdata); !keep { + if keep := cb.cb(p.Step, p.StepName, p.Current, p.Total, p.Title, p.Cart, p.Cut, cb.userdata); !keep { cb.cb = nil } } -- cgit v0.10.2