You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.4 KiB

package main
import (
"bytes"
"flag"
"fmt"
"io/ioutil"
"net/http"
"path"
"strings"
"git.ramonr.ch/ramon/mediaconverter/converter"
"k8s.io/klog"
)
// set at compile time
var (
version = ""
commit = ""
)
const baseDir = "/mnt/data/media/downloads/music/"
func main() {
klog.InitFlags(nil)
postAddr := flag.String("post-addr", "http://localhost:8088", "the address where to post the request")
directory := flag.String("dir", "", "the directory that contains the flac files. If relative path, baseDir will be appendend automatically. baseDir: /mnt/data/media/downloads/music/")
artistName := flag.String("artist", "", "name of the artist")
flag.Parse()
fmt.Printf("Mediaconverter version %v, commit %v\n", version, commit)
if !strings.HasPrefix("/", *directory) {
*directory = path.Join(baseDir, *directory)
}
msg, err := converter.CreateMessage(*artistName, *directory)
if err != nil {
klog.Fatalf("could not create message: %v", err)
}
klog.Infof("sending request")
req, err := http.NewRequest("POST", *postAddr, bytes.NewBuffer(msg))
if err != nil {
panic(err)
}
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
klog.Infof("received answer")
fmt.Println("response Status:", resp.Status)
fmt.Println("response Headers:", resp.Header)
body, _ := ioutil.ReadAll(resp.Body)
fmt.Println("response Body:", string(body))
}