summaryrefslogtreecommitdiff
path: root/rhimport
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2016-07-13 21:48:21 (GMT)
committerChristian Pointner <equinox@helsinki.at>2016-07-13 21:48:21 (GMT)
commit139e9fae3956443bcdeaa120d7f9349901275e82 (patch)
treeed6defd6c2b740cfd6660b9b07e481d06da0a043 /rhimport
parentad1bdf53d70e7aee7a092602526ab380452338ac (diff)
also reduce/increase channels from source file
Diffstat (limited to 'rhimport')
-rw-r--r--rhimport/converter.go24
-rw-r--r--rhimport/fetcher.go6
2 files changed, 16 insertions, 14 deletions
diff --git a/rhimport/converter.go b/rhimport/converter.go
index dab3309..f842ef3 100644
--- a/rhimport/converter.go
+++ b/rhimport/converter.go
@@ -32,6 +32,7 @@ import (
"os"
"os/exec"
"path/filepath"
+ "strconv"
"strings"
)
@@ -46,16 +47,16 @@ type FetchConverterResult struct {
loudnessCorr float64
}
-func NewFetchConverter(convType, filename string, metadata map[string]string) (FetchConverter, string, error) {
+func NewFetchConverter(convType, filename string, metadata map[string]string, channels uint) (FetchConverter, string, error) {
switch convType {
case "null":
- return NewNullFetchConverter(filename, metadata)
+ return NewNullFetchConverter(filename, metadata, channels)
case "ffmpeg":
- return NewFFMpegFetchConverter(filename, metadata)
+ return NewFFMpegFetchConverter(filename, metadata, channels)
case "bs1770":
- return NewBS1770FetchConverter(filename, metadata)
+ return NewBS1770FetchConverter(filename, metadata, channels)
case "ffmpeg-bs1770":
- return NewFFMpegBS1770FetchConverter(filename, metadata)
+ return NewFFMpegBS1770FetchConverter(filename, metadata, channels)
}
return nil, "", errors.New("unknown fetch converter type: " + convType)
}
@@ -68,7 +69,7 @@ type NullFetchConverter struct {
file *os.File
}
-func NewNullFetchConverter(filename string, metadata map[string]string) (n *NullFetchConverter, newFilename string, err error) {
+func NewNullFetchConverter(filename string, metadata map[string]string, channels uint) (n *NullFetchConverter, newFilename string, err error) {
n = &NullFetchConverter{}
rhl.Printf("null-converter: opening file '%s'", filename)
newFilename = filename
@@ -98,7 +99,7 @@ type FFMpegFetchConverter struct {
result chan FetchConverterResult
}
-func NewFFMpegFetchConverter(filename string, metadata map[string]string) (ff *FFMpegFetchConverter, filenameFlac string, err error) {
+func NewFFMpegFetchConverter(filename string, metadata map[string]string, channels uint) (ff *FFMpegFetchConverter, filenameFlac string, err error) {
ff = &FFMpegFetchConverter{}
ext := filepath.Ext(filename)
filenameFlac = strings.TrimSuffix(filename, ext) + ".flac"
@@ -109,7 +110,7 @@ func NewFFMpegFetchConverter(filename string, metadata map[string]string) (ff *F
ff.cmd.Args = append(ff.cmd.Args, "-metadata", fmt.Sprintf("%s=%s", key, value))
}
}
- ff.cmd.Args = append(ff.cmd.Args, "-f", "flac", filenameFlac)
+ ff.cmd.Args = append(ff.cmd.Args, "-ac", strconv.FormatUint(uint64(channels), 10), "-f", "flac", filenameFlac)
if ff.pipe, err = ff.cmd.StdinPipe(); err != nil {
return nil, "", err
}
@@ -150,7 +151,7 @@ type BS1770FetchConverter struct {
result chan FetchConverterResult
}
-func NewBS1770FetchConverter(filename string, metadata map[string]string) (bs *BS1770FetchConverter, newFilename string, err error) {
+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)
newFilename = filename
@@ -218,7 +219,7 @@ type FFMpegBS1770FetchConverter struct {
resultBS chan FetchConverterResult
}
-func NewFFMpegBS1770FetchConverter(filename string, metadata map[string]string) (ff *FFMpegBS1770FetchConverter, filenameFlac string, err error) {
+func NewFFMpegBS1770FetchConverter(filename string, metadata map[string]string, channels uint) (ff *FFMpegBS1770FetchConverter, filenameFlac string, err error) {
ff = &FFMpegBS1770FetchConverter{}
ext := filepath.Ext(filename)
filenameFlac = strings.TrimSuffix(filename, ext) + ".flac"
@@ -229,7 +230,8 @@ func NewFFMpegBS1770FetchConverter(filename string, metadata map[string]string)
ff.ffmpeg.Args = append(ff.ffmpeg.Args, "-metadata", fmt.Sprintf("%s=%s", key, value))
}
}
- ff.ffmpeg.Args = append(ff.ffmpeg.Args, "-f", "flac", filenameFlac, "-f", "flac", "pipe:1")
+ ff.ffmpeg.Args = append(ff.ffmpeg.Args, "-ac", strconv.FormatUint(uint64(channels), 10), "-f", "flac", filenameFlac)
+ ff.ffmpeg.Args = append(ff.ffmpeg.Args, "-ac", strconv.FormatUint(uint64(channels), 10), "-f", "flac", "pipe:1")
if ff.pipe, err = ff.ffmpeg.StdinPipe(); err != nil {
return nil, "", err
}
diff --git a/rhimport/fetcher.go b/rhimport/fetcher.go
index 74cd1fa..469d36b 100644
--- a/rhimport/fetcher.go
+++ b/rhimport/fetcher.go
@@ -81,7 +81,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.FetchConverter, data.filename, data.metadata)
+ conv, newFilename, err := NewFetchConverter(data.ctx.FetchConverter, data.filename, data.metadata, data.ctx.Channels)
if err != nil {
rhl.Printf("Unable to create converter for file %s: %s", data.filename, err)
data.writeError = err
@@ -359,7 +359,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.FetchConverter, filepath.Join(basepath, origFile), nil); err != nil {
+ if conv, ctx.SourceFile, err = NewFetchConverter(ctx.FetchConverter, filepath.Join(basepath, origFile), nil, ctx.Channels); err != nil {
rhl.Printf("Unable to create converter for file %s: %s", origDir+origFile, err)
return
}
@@ -598,7 +598,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.FetchConverter, ctx.SourceFile, nil); err != nil {
+ if conv, ctx.SourceFile, err = NewFetchConverter(ctx.FetchConverter, ctx.SourceFile, nil, ctx.Channels); err != nil {
rhl.Printf("Unable to create converter for file %s: %s", ctx.OrigFilename, err)
return err
}