summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2015-12-12 01:41:25 (GMT)
committerChristian Pointner <equinox@helsinki.at>2015-12-12 01:41:25 (GMT)
commitd5450bb18ea879ca9a63aa1d16a5c647e8ecf692 (patch)
treea6e934caee5f96b686a9a4b8d677a9eacbae067c
parent6ceb3358b6ffbe803e4fe1d811b5a2f266fc49d9 (diff)
ImportFile now passes through result from RDXport
-rw-r--r--src/helsinki.at/rhimport/importer.go44
-rw-r--r--src/helsinki.at/rhimportd/ctrlWebSimple.go11
-rw-r--r--test/empty.mp30
-rw-r--r--test/silence1s.wavbin0 -> 88244 bytes
-rw-r--r--test/simple4.json12
-rw-r--r--test/simple5.json12
6 files changed, 63 insertions, 16 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
}
diff --git a/src/helsinki.at/rhimportd/ctrlWebSimple.go b/src/helsinki.at/rhimportd/ctrlWebSimple.go
index 4cac593..9b25dad 100644
--- a/src/helsinki.at/rhimportd/ctrlWebSimple.go
+++ b/src/helsinki.at/rhimportd/ctrlWebSimple.go
@@ -59,11 +59,11 @@ func webSimpleErrorResponse(w http.ResponseWriter, code int, error_str string) {
encoder.Encode(respdata)
}
-func webSimpleResponse(w http.ResponseWriter) {
+func webSimpleResponse(w http.ResponseWriter, result *rhimport.ImportResult) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusInternalServerError)
encoder := json.NewEncoder(w)
- respdata := webSimpleResponseData{200, "SUCCESS"}
+ respdata := webSimpleResponseData{result.ResponseCode, result.ErrorString}
encoder.Encode(respdata)
}
@@ -108,16 +108,17 @@ func webSimpleHandler(conf *rhimport.Config, rddb *rhimport.RdDb, trusted bool,
return
}
- if err := rhimport.FetchFile(ctx); err != nil {
+ if err = rhimport.FetchFile(ctx); err != nil {
webSimpleErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}
- if err := rhimport.ImportFile(ctx); err != nil {
+ var result *rhimport.ImportResult
+ if result, err = rhimport.ImportFile(ctx); err != nil {
webSimpleErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}
- webSimpleResponse(w)
+ webSimpleResponse(w, result)
return
}
diff --git a/test/empty.mp3 b/test/empty.mp3
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/empty.mp3
diff --git a/test/silence1s.wav b/test/silence1s.wav
new file mode 100644
index 0000000..f24be56
--- /dev/null
+++ b/test/silence1s.wav
Binary files differ
diff --git a/test/simple4.json b/test/simple4.json
new file mode 100644
index 0000000..472c8db
--- /dev/null
+++ b/test/simple4.json
@@ -0,0 +1,12 @@
+{
+ "LOGIN_NAME": "heslinki",
+ "PASSWORD": "123456",
+ "GROUP_NAME": "test",
+ "CART_NUMBER": 100000,
+ "CUT_NUMBER": 1,
+ "CHANNELS": 2,
+ "NORMALIZATION_LEVEL": -1200,
+ "AUTOTRIM_LEVEL": 0,
+ "USE_METADATA": true,
+ "SOURCE_URI": "local:///home/equinox/helsinki/rivenhell/contrib/rhimportd/test/empty.mp3"
+}
diff --git a/test/simple5.json b/test/simple5.json
new file mode 100644
index 0000000..ad0ff98
--- /dev/null
+++ b/test/simple5.json
@@ -0,0 +1,12 @@
+{
+ "LOGIN_NAME": "heslinki",
+ "PASSWORD": "123456",
+ "GROUP_NAME": "test",
+ "CART_NUMBER": 100000,
+ "CUT_NUMBER": 1,
+ "CHANNELS": 2,
+ "NORMALIZATION_LEVEL": -1200,
+ "AUTOTRIM_LEVEL": 0,
+ "USE_METADATA": true,
+ "SOURCE_URI": "local:///home/equinox/helsinki/rivenhell/contrib/rhimportd/test/silence1s.wav"
+}