diff options
Diffstat (limited to 'src/helsinki.at/rhimport')
-rw-r--r-- | src/helsinki.at/rhimport/importer.go | 44 |
1 files changed, 33 insertions, 11 deletions
diff --git a/src/helsinki.at/rhimport/importer.go b/src/helsinki.at/rhimport/importer.go index 55fbe62..e29e4df 100644 --- a/src/helsinki.at/rhimport/importer.go +++ b/src/helsinki.at/rhimport/importer.go @@ -117,16 +117,33 @@ func (ctx *ImportContext) getShowInfo() (err error) { return } +type ImportResult struct { + ResponseCode int + ErrorString string + Cart int + Cut int +} + +func NewImportResult(rdres *RDWebResult) *ImportResult { + res := new(ImportResult) + res.ResponseCode = rdres.ResponseCode + res.ErrorString = rdres.ErrorString + if rdres.AudioConvertError != 0 { + res.ErrorString += fmt.Sprint(", Audio Convert Error: %d", rdres.AudioConvertError) + } + return res +} + type RDWebResult struct { ResponseCode int `xml:"ResponseCode"` ErrorString string `xml:"ErrorString"` - AudioConvertError string `xml:"AudioConvertError"` + AudioConvertError int `xml:"AudioConvertError"` } -func decodeRDWebResult(data io.Reader) (result *RDWebResult, err error) { +func NewRDWebResultFromXML(data io.Reader) (res *RDWebResult, err error) { decoder := xml.NewDecoder(data) - result = &RDWebResult{} - if xmlerr := decoder.Decode(result); xmlerr != nil { + res = &RDWebResult{} + if xmlerr := decoder.Decode(res); xmlerr != nil { err = fmt.Errorf("Error parsing XML response: %s", xmlerr) return } @@ -220,7 +237,7 @@ func send_post_request(url string, b *bytes.Buffer, contenttype string) (result defer res.Body.Close() // TODO: some commands might return something else... - return decodeRDWebResult(res.Body) + return NewRDWebResultFromXML(res.Body) } func import_audio_create_request(ctx *ImportContext, easy *curl.CURL) (form *curl.Form, err error) { @@ -302,7 +319,7 @@ func import_audio(ctx *ImportContext) (result *RDWebResult, err error) { // if status_code, err = easy.Getinfo(curl.INFO_RESPONSE_CODE); err != nil { // return // } - return decodeRDWebResult(bufio.NewReader(&resbody)) + return NewRDWebResultFromXML(bufio.NewReader(&resbody)) } else { err = fmt.Errorf("Error initializing libcurl") } @@ -328,7 +345,7 @@ func cleanup_files(ctx *ImportContext) { return } -func ImportFile(ctx *ImportContext) (err error) { +func ImportFile(ctx *ImportContext) (res *ImportResult, err error) { rhl.Println("ImportFile called for", ctx.SourceFile) defer cleanup_files(ctx) @@ -342,16 +359,21 @@ func ImportFile(ctx *ImportContext) (err error) { } } - var result *RDWebResult - if result, err = import_audio(ctx); err != nil { + var rdres *RDWebResult + if rdres, err = import_audio(ctx); err != nil { return } if ctx.ProgressCallBack != nil { ctx.ProgressCallBack(2, "importing", 1.0, ctx.ProgressCallBackData) } - rhdl.Printf("StatusCode: %d, ErrorString: '%s', AudioConverterError: %s\n", result.ResponseCode, result.ErrorString, result.AudioConvertError) + res = NewImportResult(rdres) + rhdl.Printf("StatusCode: %d, ErrorString: '%s'\n", res.ResponseCode, res.ErrorString) - rhl.Println("ImportFile succesfully imported", ctx.SourceFile) + if res.ResponseCode == http.StatusOK { + rhl.Println("ImportFile succesfully imported", ctx.SourceFile) + } else { + rhl.Println("ImportFile import of", ctx.SourceFile, "was unsuccesful") + } return } |