summaryrefslogtreecommitdiff
path: root/rhimport
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2016-08-03 15:45:50 (GMT)
committerChristian Pointner <equinox@helsinki.at>2016-08-03 15:45:50 (GMT)
commit012102accf5a3422675bb471925f41f379a73f09 (patch)
tree326d16aa064c82d278069658c87f60e0079a24c9 /rhimport
parentfd6f2c85fc89f3d67038c3b60eb38061c50cfedc (diff)
added ExtraMetaData to context for converters who support this
Diffstat (limited to 'rhimport')
-rw-r--r--rhimport/converter.go30
-rw-r--r--rhimport/core.go2
-rw-r--r--rhimport/fetcher.go19
3 files changed, 23 insertions, 28 deletions
diff --git a/rhimport/converter.go b/rhimport/converter.go
index d9ac263..caef974 100644
--- a/rhimport/converter.go
+++ b/rhimport/converter.go
@@ -48,20 +48,20 @@ type fetchConverterResult struct {
loudnessCorr float64
}
-func newFetchConverter(ctx *Context, filename string, metadata map[string]string) (fetchConverter, string, error) {
+func newFetchConverter(ctx *Context, filename string) (fetchConverter, string, error) {
switch ctx.FetchConverter {
case "null":
// no support for loudness evaluation - leave normalization to Rivendell
- return newNullFetchConverter(ctx, filename, metadata)
+ return newNullFetchConverter(ctx, filename)
case "ffmpeg":
// no support for loudness evaluation - leave normalization to Rivendell
- return newFFMpegFetchConverter(ctx, filename, metadata)
+ return newFFMpegFetchConverter(ctx, filename)
case "bs1770":
ctx.NormalizationLevel = 0 // disable Rivendell normalization
- return newBS1770FetchConverter(ctx, filename, metadata)
+ return newBS1770FetchConverter(ctx, filename)
case "ffmpeg-bs1770":
ctx.NormalizationLevel = 0 // disable Rivendell normalization
- return newFFMpegBS1770FetchConverter(ctx, filename, metadata)
+ return newFFMpegBS1770FetchConverter(ctx, filename)
}
return nil, "", errors.New("unknown fetch converter type: " + ctx.FetchConverter)
}
@@ -74,7 +74,7 @@ type nullFetchConverter struct {
file *os.File
}
-func newNullFetchConverter(ctx *Context, filename string, metadata map[string]string) (n *nullFetchConverter, newFilename string, err error) {
+func newNullFetchConverter(ctx *Context, filename string) (n *nullFetchConverter, newFilename string, err error) {
n = &nullFetchConverter{}
newFilename = filepath.Dir(filename) + "/conv-null" + filepath.Ext(filename)
ctx.stdlog.Printf("null-converter: opening file '%s' -> '%s'", filename, newFilename)
@@ -104,15 +104,13 @@ type ffmpegFetchConverter struct {
result chan fetchConverterResult
}
-func newFFMpegFetchConverter(ctx *Context, filename string, metadata map[string]string) (ff *ffmpegFetchConverter, filenameFlac string, err error) {
+func newFFMpegFetchConverter(ctx *Context, filename string) (ff *ffmpegFetchConverter, filenameFlac string, err error) {
ff = &ffmpegFetchConverter{}
filenameFlac = filepath.Dir(filename) + "/conv-ffmpeg.flac"
ctx.stdlog.Printf("ffmpeg-converter: starting ffmpeg for file '%s' -> '%s'", filename, filenameFlac)
ff.cmd = exec.Command("ffmpeg", "-loglevel", "warning", "-i", "-", "-map_metadata", "0")
- if metadata != nil {
- for key, value := range metadata {
- ff.cmd.Args = append(ff.cmd.Args, "-metadata", fmt.Sprintf("%s=%s", key, value))
- }
+ for key, value := range ctx.ExtraMetaData {
+ ff.cmd.Args = append(ff.cmd.Args, "-metadata", fmt.Sprintf("%s=%s", key, value))
}
ff.cmd.Args = append(ff.cmd.Args, "-ar", strconv.FormatUint(uint64(ctx.conf.SampleRate), 10), "-ac", strconv.FormatUint(uint64(ctx.Channels), 10), "-f", "flac", filenameFlac)
if ff.pipe, err = ff.cmd.StdinPipe(); err != nil {
@@ -163,7 +161,7 @@ type bs1770FetchConverter struct {
result chan fetchConverterResult
}
-func newBS1770FetchConverter(ctx *Context, filename string, metadata map[string]string) (bs *bs1770FetchConverter, newFilename string, err error) {
+func newBS1770FetchConverter(ctx *Context, filename string) (bs *bs1770FetchConverter, newFilename string, err error) {
bs = &bs1770FetchConverter{}
newFilename = filepath.Dir(filename) + "/conv-bs1770" + filepath.Ext(filename)
ctx.stdlog.Printf("bs1770-converter: starting bs1770gain for file '%s' -> '%s'", filename, newFilename)
@@ -241,15 +239,13 @@ type ffmpegBS1770FetchConverter struct {
resultBS chan fetchConverterResult
}
-func newFFMpegBS1770FetchConverter(ctx *Context, filename string, metadata map[string]string) (ff *ffmpegBS1770FetchConverter, filenameFlac string, err error) {
+func newFFMpegBS1770FetchConverter(ctx *Context, filename string) (ff *ffmpegBS1770FetchConverter, filenameFlac string, err error) {
ff = &ffmpegBS1770FetchConverter{}
filenameFlac = filepath.Dir(filename) + "/conv-ffmpeg-bs1770.flac"
ctx.stdlog.Printf("ffmpeg-bs1770-converter: starting ffmpeg and bs1770gain for file '%s' -> '%s'", filename, filenameFlac)
ff.ffmpeg = exec.Command("ffmpeg", "-loglevel", "warning", "-i", "pipe:0", "-map_metadata", "0")
- if metadata != nil {
- for key, value := range metadata {
- ff.ffmpeg.Args = append(ff.ffmpeg.Args, "-metadata", fmt.Sprintf("%s=%s", key, value))
- }
+ for key, value := range ctx.ExtraMetaData {
+ ff.ffmpeg.Args = append(ff.ffmpeg.Args, "-metadata", fmt.Sprintf("%s=%s", key, value))
}
ff.ffmpeg.Args = append(ff.ffmpeg.Args, "-ar", strconv.FormatUint(uint64(ctx.conf.SampleRate), 10), "-ac", strconv.FormatUint(uint64(ctx.Channels), 10), "-f", "flac", filenameFlac)
ff.ffmpeg.Args = append(ff.ffmpeg.Args, "-ar", strconv.FormatUint(uint64(ctx.conf.SampleRate), 10), "-ac", strconv.FormatUint(uint64(ctx.Channels), 10), "-f", "flac", "pipe:1")
diff --git a/rhimport/core.go b/rhimport/core.go
index bf4a57e..6afcd9f 100644
--- a/rhimport/core.go
+++ b/rhimport/core.go
@@ -157,6 +157,7 @@ type Context struct {
SourceUri string
AttachmentChan chan AttachmentChunk
FetchConverter string
+ ExtraMetaData map[string]string
OrigFilename string
Title string
SourceFile string
@@ -197,6 +198,7 @@ func NewContext(conf *Config, db *rddb.DB, stdlog, dbglog *log.Logger) *Context
ctx.UseMetaData = conf.ImportParamDefaults.UseMetaData
ctx.AttachmentChan = make(chan AttachmentChunk, 32)
ctx.FetchConverter = "ffmpeg-bs1770"
+ ctx.ExtraMetaData = make(map[string]string)
ctx.OrigFilename = ""
ctx.Title = ""
ctx.SourceFile = ""
diff --git a/rhimport/fetcher.go b/rhimport/fetcher.go
index f8bfa0a..2b17951 100644
--- a/rhimport/fetcher.go
+++ b/rhimport/fetcher.go
@@ -51,7 +51,6 @@ type fetcherCurlCBData struct {
basepath string
filename string
remotename string
- metadata map[string]string
conv fetchConverter
totalSize float64
written uint64
@@ -84,7 +83,7 @@ func curlWriteCallback(ptr []byte, userdata interface{}) bool {
data.filename = filepath.Join(data.basepath, name)
}
data.ctx.OrigFilename = data.filename
- conv, newFilename, err := newFetchConverter(data.ctx, data.filename, data.metadata)
+ conv, newFilename, err := newFetchConverter(data.ctx, data.filename)
if err != nil {
data.ctx.stdlog.Printf("Unable to create converter for file %s: %s", data.filename, err)
data.writeError = err
@@ -223,8 +222,7 @@ func fetchFileCurl(ctx *Context, res *Result, uri *url.URL) (err error) {
if info.Title == "" {
ctx.Title += info.ID
}
- cbdata.metadata = make(map[string]string)
- cbdata.metadata["TITLE"] = ctx.Title
+ ctx.ExtraMetaData["TITLE"] = ctx.Title
}
}
@@ -369,11 +367,10 @@ 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"] = ctx.Title
- cbdata.metadata["ALBUM"] = "Radio Helsinki Archiv"
- cbdata.metadata["ORGANIZATION"] = "Radio Helsinki"
- cbdata.metadata["DATE"] = start.Format("2.1.2006")
+ ctx.ExtraMetaData["TITLE"] = ctx.Title
+ ctx.ExtraMetaData["ALBUM"] = "Radio Helsinki Archiv"
+ ctx.ExtraMetaData["ORGANIZATION"] = "Radio Helsinki"
+ ctx.ExtraMetaData["DATE"] = start.Format("2.1.2006")
ctx.dbglog.Printf("importing archiv file from %s", scpuri)
err = easy.Perform()
@@ -434,7 +431,7 @@ func fetchFileDirConvert(ctx *Context, res *Result, origSrc *os.File, sizeTotal
ctx.OrigFilename = ctx.SourceFile
var conv fetchConverter
- if conv, ctx.SourceFile, err = newFetchConverter(ctx, filepath.Join(basepath, origFile), nil); err != nil {
+ if conv, ctx.SourceFile, err = newFetchConverter(ctx, filepath.Join(basepath, origFile)); err != nil {
ctx.stdlog.Printf("Unable to create converter for file %s: %s", origDir+origFile, err)
return
}
@@ -674,7 +671,7 @@ func fetchFileAttachment(ctx *Context, res *Result, uri *url.URL) error {
var conv fetchConverter
ctx.OrigFilename = ctx.SourceFile
- if conv, ctx.SourceFile, err = newFetchConverter(ctx, ctx.SourceFile, nil); err != nil {
+ if conv, ctx.SourceFile, err = newFetchConverter(ctx, ctx.SourceFile); err != nil {
ctx.stdlog.Printf("Unable to create converter for file %s: %s", ctx.OrigFilename, err)
return err
}