summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/helsinki.at/rhimport/conf.go4
-rw-r--r--src/helsinki.at/rhimport/fetcher.go34
-rw-r--r--src/helsinki.at/rhimport/importer.go25
-rw-r--r--src/helsinki.at/rhimportd/ctrlWebSimple.go47
-rw-r--r--src/helsinki.at/rhimportd/rhimportd.go3
-rw-r--r--test/simple1.json10
6 files changed, 92 insertions, 31 deletions
diff --git a/src/helsinki.at/rhimport/conf.go b/src/helsinki.at/rhimport/conf.go
index 6dcbe84..8e373c0 100644
--- a/src/helsinki.at/rhimport/conf.go
+++ b/src/helsinki.at/rhimport/conf.go
@@ -45,6 +45,7 @@ type getPasswordRequest struct {
type Config struct {
configfile string
RDXportEndpoint string
+ TempDir string
db_host string
db_user string
db_passwd string
@@ -142,7 +143,7 @@ func (self *Config) Cleanup() {
}
}
-func NewConfig(configfile, rdxport_endpoint *string) (conf *Config, err error) {
+func NewConfig(configfile, rdxport_endpoint, temp_dir *string) (conf *Config, err error) {
conf = new(Config)
conf.configfile = *configfile
if err = conf.read_config_file(); err != nil {
@@ -151,6 +152,7 @@ func NewConfig(configfile, rdxport_endpoint *string) (conf *Config, err error) {
conf.quit = make(chan bool)
conf.done = make(chan bool)
conf.RDXportEndpoint = *rdxport_endpoint
+ conf.TempDir = *temp_dir
conf.password_cache = make(map[string]string)
conf.getPasswordChan = make(chan getPasswordRequest)
diff --git a/src/helsinki.at/rhimport/fetcher.go b/src/helsinki.at/rhimport/fetcher.go
new file mode 100644
index 0000000..ead9f5f
--- /dev/null
+++ b/src/helsinki.at/rhimport/fetcher.go
@@ -0,0 +1,34 @@
+//
+// rhimportd
+//
+// The Radio Helsinki Rivendell Import Daemon
+//
+//
+// Copyright (C) 2015 Christian Pointner <equinox@helsinki.at>
+//
+// This file is part of rhimportd.
+//
+// rhimportd is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// any later version.
+//
+// rhimportd is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with rhimportd. If not, see <http://www.gnu.org/licenses/>.
+//
+
+package rhimport
+
+func FetchFile(ctx *ImportContext) (err error) {
+
+ // TODO: fetch file from ctx.SourceUri and put it into ctx.Conf.TempDir
+
+ ctx.SourceFile = ctx.Conf.TempDir + "/source-file.ogg"
+ ctx.DeleteSourceFile = true
+ return
+}
diff --git a/src/helsinki.at/rhimport/importer.go b/src/helsinki.at/rhimport/importer.go
index e47bc05..95e3e73 100644
--- a/src/helsinki.at/rhimport/importer.go
+++ b/src/helsinki.at/rhimport/importer.go
@@ -25,12 +25,12 @@
package rhimport
import (
- // "bytes"
- // "fmt"
- // "io"
- // "mime/multipart"
- // "net/http"
- // "os"
+// "bytes"
+// "fmt"
+// "io"
+// "mime/multipart"
+// "net/http"
+// "os"
)
type ImportContext struct {
@@ -40,24 +40,27 @@ type ImportContext struct {
Trusted bool
GroupName string
Cart int
+ Cut int
Channels int
NormalizationLevel int
AutotrimLevel int
UseMetaData bool
+ SourceUri string
SourceFile string
DeleteSourceFile bool
}
-func NewImportContext(conf *Config, user string, group string, cart int) *ImportContext {
+func NewImportContext(conf *Config, user string, group string) *ImportContext {
ctx := new(ImportContext)
ctx.Conf = conf
ctx.UserName = user
ctx.Password = ""
ctx.Trusted = false
ctx.GroupName = group
- ctx.Cart = cart
+ ctx.Cart = 0
+ ctx.Cut = 0
ctx.Channels = 2
- ctx.NormalizationLevel = 1200
+ ctx.NormalizationLevel = -1200
ctx.AutotrimLevel = 0
ctx.UseMetaData = false
ctx.SourceFile = ""
@@ -137,9 +140,7 @@ func ImportFile(ctx *ImportContext) (err error) {
return
}
}
- rhdl.Printf("credentials: '%s':'%s'", ctx.UserName, ctx.Password)
-
-// err = fmt.Errorf("%+v", ctx)
+ rhdl.Printf("%+v", ctx)
return
}
diff --git a/src/helsinki.at/rhimportd/ctrlWebSimple.go b/src/helsinki.at/rhimportd/ctrlWebSimple.go
index eb781dd..8080514 100644
--- a/src/helsinki.at/rhimportd/ctrlWebSimple.go
+++ b/src/helsinki.at/rhimportd/ctrlWebSimple.go
@@ -26,11 +26,11 @@ package main
import (
"encoding/json"
+ "fmt"
"helsinki.at/rhimport"
"html"
"net/http"
_ "net/http/pprof"
- "fmt"
)
type webSimpleRequestData struct {
@@ -38,6 +38,7 @@ type webSimpleRequestData struct {
Password string `json:"PASSWORD"`
GroupName string `json:"GROUP_NAME"`
Cart int `json:"CART_NUMBER"`
+ Cut int `json:"CUT_NUMBER"`
Channels int `json:"CHANNELS"`
NormalizationLevel int `json:"NORMALIZATION_LEVEL"`
AutotrimLevel int `json:"AUTOTRIM_LEVEL"`
@@ -46,16 +47,15 @@ type webSimpleRequestData struct {
}
type webSimpleResponseData struct {
- ResponseCode int `json:"REPONSE_CODE"`
- ErrorString string `json:"ERROR_STRING"`
- AudioConvertError int `json:"AudioConvertError"`
+ ResponseCode int `json:"REPONSE_CODE"`
+ ErrorString string `json:"ERROR_STRING"`
}
-func webSimpleErrorResponse(w http.ResponseWriter, code int, error_str string, audio_err int) {
+func webSimpleErrorResponse(w http.ResponseWriter, code int, error_str string) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusInternalServerError)
encoder := json.NewEncoder(w)
- respdata := webSimpleResponseData{code, error_str, audio_err}
+ respdata := webSimpleResponseData{code, error_str}
encoder.Encode(respdata)
}
@@ -63,17 +63,16 @@ func webSimpleResponse(w http.ResponseWriter) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusInternalServerError)
encoder := json.NewEncoder(w)
- respdata := webSimpleResponseData{200, "SUCCESS", 0}
+ respdata := webSimpleResponseData{200, "SUCCESS"}
encoder.Encode(respdata)
}
-func webSimpleHandler(conf *rhimport.Config, trusted bool, w http.ResponseWriter, r *http.Request) {
- rhdl.Printf("SimpleHandler: request for '%s'", html.EscapeString(r.URL.Path))
+func webSimpleParseRequest(conf *rhimport.Config, trusted bool, r *http.Request) (ctx *rhimport.ImportContext, err error) {
decoder := json.NewDecoder(r.Body)
var reqdata webSimpleRequestData
- if err := decoder.Decode(&reqdata); err != nil {
- webSimpleErrorResponse(w, http.StatusInternalServerError, fmt.Sprintf("Error parsing JSON response: %s", err), 0)
+ if jsonerr := decoder.Decode(&reqdata); jsonerr != nil {
+ err = fmt.Errorf("Error parsing JSON response: %s", jsonerr)
return
}
@@ -81,22 +80,36 @@ func webSimpleHandler(conf *rhimport.Config, trusted bool, w http.ResponseWriter
if trusted {
username = r.Header.Get("X-Forwarded-User")
}
- ctx := rhimport.NewImportContext(conf, username, reqdata.GroupName, reqdata.Cart)
+ ctx = rhimport.NewImportContext(conf, username, reqdata.GroupName)
ctx.Password = reqdata.Password
ctx.Trusted = trusted
+ ctx.Cart = reqdata.Cart
+ ctx.Cut = reqdata.Cut
ctx.Channels = reqdata.Channels
ctx.NormalizationLevel = reqdata.NormalizationLevel
ctx.AutotrimLevel = reqdata.AutotrimLevel
ctx.UseMetaData = reqdata.UseMetaData
+ ctx.SourceUri = reqdata.SourceUri
+ return
+}
- // TODO: call the fetcher
+func webSimpleHandler(conf *rhimport.Config, trusted bool, w http.ResponseWriter, r *http.Request) {
+ rhdl.Printf("SimpleHandler: request for '%s'", html.EscapeString(r.URL.Path))
+
+ var ctx *rhimport.ImportContext
+ var err error
+ if ctx, err = webSimpleParseRequest(conf, trusted, r); err != nil {
+ webSimpleErrorResponse(w, http.StatusInternalServerError, err.Error())
+ return
+ }
- // TODO: the following should be returned by the fetcher
- ctx.SourceFile = "<undefined>"
- ctx.DeleteSourceFile = true
+ if err := rhimport.FetchFile(ctx); err != nil {
+ webSimpleErrorResponse(w, http.StatusInternalServerError, err.Error())
+ return
+ }
if err := rhimport.ImportFile(ctx); err != nil {
- webSimpleErrorResponse(w, http.StatusInternalServerError, err.Error(), 0)
+ webSimpleErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}
diff --git a/src/helsinki.at/rhimportd/rhimportd.go b/src/helsinki.at/rhimportd/rhimportd.go
index c1af87e..03d0340 100644
--- a/src/helsinki.at/rhimportd/rhimportd.go
+++ b/src/helsinki.at/rhimportd/rhimportd.go
@@ -36,6 +36,7 @@ func main() {
web_addr_s := flag.String("web-addr", ":4000", "addr:port to listen on, default: ':4000'")
rdconf_s := flag.String("rdconf", "/etc/rd.conf", "path to the Rivendell config file, default: '/etc/rd.conf'")
rdxport_url_s := flag.String("rdxport-url", "http://localhost/rd-bin/rdxport.cgi", "the url to the Rivendell web-api, default: 'http://localhost/rd-bin/rdxport.cgi'")
+ temp_dir_s := flag.String("tmp-dir", "/tmp", "path to temporary files, default: '/tmp'")
help := flag.Bool("help", false, "show usage")
flag.Parse()
@@ -44,7 +45,7 @@ func main() {
return
}
- conf, err := rhimport.NewConfig(rdconf_s, rdxport_url_s)
+ conf, err := rhimport.NewConfig(rdconf_s, rdxport_url_s, temp_dir_s)
if err != nil {
rhl.Println("Error reading configuration:", err)
return
diff --git a/test/simple1.json b/test/simple1.json
index 2c63c08..0efecec 100644
--- a/test/simple1.json
+++ b/test/simple1.json
@@ -1,2 +1,12 @@
{
+ "LOGIN_NAME": "heslinki",
+ "PASSWORD": "123456",
+ "GROUP_NAME": "test",
+ "CART_NUMBER": 10000,
+ "CUT_NUMBER": 1,
+ "CHANNELS": 2,
+ "NORMALIZATION_LEVEL": -1200,
+ "AUTOTRIM_LEVEL": 0,
+ "USE_METADATA": false,
+ "SOURCE_URI": "http://example.com/files/sendung.mp3"
}