summaryrefslogtreecommitdiff
path: root/rhimport/fetcher.go
diff options
context:
space:
mode:
Diffstat (limited to 'rhimport/fetcher.go')
-rw-r--r--rhimport/fetcher.go35
1 files changed, 18 insertions, 17 deletions
diff --git a/rhimport/fetcher.go b/rhimport/fetcher.go
index fde9da8..f6e940c 100644
--- a/rhimport/fetcher.go
+++ b/rhimport/fetcher.go
@@ -47,16 +47,10 @@ type FetcherCurlCBData struct {
basepath string
filename string
remotename string
- conv Converter
+ conv FetchConverter
writeError error
}
-func (self *FetcherCurlCBData) Cleanup() {
- if self.conv != nil {
- self.conv.Close()
- }
-}
-
func curlHeaderCallback(ptr []byte, userdata interface{}) bool {
hdr := fmt.Sprintf("%s", ptr)
data := userdata.(*FetcherCurlCBData)
@@ -82,7 +76,7 @@ func curlWriteCallback(ptr []byte, userdata interface{}) bool {
}
data.filename = filepath.Join(data.basepath, name)
}
- nc, newFilename, err := NewFFMpegConverter(data.filename)
+ nc, newFilename, err := NewFetchConverter(data.ctx.FetchConverter, data.filename)
if err != nil {
rhl.Printf("Unable to create converter for file %s: %s", data.filename, err)
data.writeError = err
@@ -141,7 +135,6 @@ func fetchFileCurl(ctx *Context, res *Result, uri *url.URL) (err error) {
easy.Setopt(curl.OPT_USERAGENT, "Radio Helsinki Import")
cbdata := &FetcherCurlCBData{ctx: ctx, res: res, remotename: path.Base(uri.Path)}
- defer cbdata.Cleanup()
if cbdata.basepath, err = ioutil.TempDir(ctx.conf.TempDir, "rhimportd-"); err != nil {
return
}
@@ -157,9 +150,13 @@ func fetchFileCurl(ctx *Context, res *Result, uri *url.URL) (err error) {
easy.Setopt(curl.OPT_PROGRESSDATA, cbdata)
err = easy.Perform()
- cbdata.conv.Close()
- rhl.Printf("waiting for converter to finish...")
- convOut, convErr := cbdata.conv.GetResult()
+ var convOut string
+ var convErr error
+ if cbdata.conv != nil {
+ cbdata.conv.Close()
+ rhl.Printf("waiting for converter to finish...")
+ convOut, convErr = cbdata.conv.GetResult()
+ }
if err != nil || cbdata.writeError != nil || convErr != nil {
if cbdata.conv != nil {
rhdl.Printf("Removing stale file: %s", cbdata.filename)
@@ -257,12 +254,12 @@ func fetchFileArchiv(ctx *Context, res *Result, uri *url.URL) (err error) {
easy.Setopt(curl.OPT_SSH_PUBLIC_KEYFILE, fmt.Sprintf("%s/.ssh/id_rsa.pub", u.HomeDir))
easy.Setopt(curl.OPT_SSH_PRIVATE_KEYFILE, fmt.Sprintf("%s/.ssh/id_rsa", u.HomeDir))
- cbdata := &FetcherCurlCBData{ctx: ctx, res: res}
- defer cbdata.Cleanup()
var destpath string
if destpath, err = ioutil.TempDir(ctx.conf.TempDir, "rhimportd-"); err != nil {
return
}
+
+ cbdata := &FetcherCurlCBData{ctx: ctx, res: res}
cbdata.filename = fmt.Sprintf("%s/%s", destpath, srcfile)
easy.Setopt(curl.OPT_WRITEFUNCTION, curlWriteCallback)
@@ -274,9 +271,13 @@ func fetchFileArchiv(ctx *Context, res *Result, uri *url.URL) (err error) {
rhdl.Printf("importing archiv file from %s", scpuri)
err = easy.Perform()
- cbdata.conv.Close()
- rhl.Printf("waiting for converter to finish...")
- convOut, convErr := cbdata.conv.GetResult()
+ var convOut string
+ var convErr error
+ if cbdata.conv != nil {
+ cbdata.conv.Close()
+ rhl.Printf("waiting for converter to finish...")
+ convOut, convErr = cbdata.conv.GetResult()
+ }
if err != nil || cbdata.writeError != nil || convErr != nil {
if cbdata.conv != nil {
rhdl.Printf("Removing stale file: %s", cbdata.filename)