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.
42 lines
930 B
42 lines
930 B
5 years ago
|
package main
|
||
|
|
||
|
import (
|
||
|
"flag"
|
||
|
"fmt"
|
||
|
"net/http"
|
||
|
|
||
|
"git.ramonr.ch/ramon/mediaconverter/converter"
|
||
|
"k8s.io/klog"
|
||
|
)
|
||
|
|
||
|
const iTunesDir = "/mnt/data/media/iTunes/iTunes Media/Automatically Add to Music.localized"
|
||
|
|
||
|
// set at compile time
|
||
|
var (
|
||
|
version = ""
|
||
|
commit = ""
|
||
|
)
|
||
|
|
||
|
func main() {
|
||
|
klog.InitFlags(nil)
|
||
|
listenAddr := flag.String("listen-addr", "127.0.0.1:8088", "the address where to listen on")
|
||
|
flag.Parse()
|
||
|
fmt.Printf("Mediaconverter version %v, commit %v\n", version, commit)
|
||
|
|
||
|
http.HandleFunc("/", conversionHandler())
|
||
|
fmt.Println("Starting to listen on", *listenAddr)
|
||
|
err := http.ListenAndServe(*listenAddr, nil)
|
||
|
fmt.Println(err)
|
||
|
}
|
||
|
|
||
|
func conversionHandler() http.HandlerFunc {
|
||
|
conv := converter.New(iTunesDir)
|
||
|
|
||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||
|
if err := conv.Process(r.Body); err != nil {
|
||
|
klog.Errorf("could not convert: %v", err)
|
||
|
fmt.Fprintf(w, "could not convert: %v", err)
|
||
|
}
|
||
|
}
|
||
|
}
|