play audio after catching it
This commit is contained in:
parent
ac4a9dbfa6
commit
8d7ced37ab
8
main.go
8
main.go
|
@ -8,6 +8,7 @@ import (
|
||||||
"net/http/httputil"
|
"net/http/httputil"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -49,7 +50,12 @@ func (pr Proxy) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
os.WriteFile(strings.ReplaceAll(req.RequestURI, "/", "_")+".txt", body, 0666)
|
go func() {
|
||||||
|
mp3 := strings.ReplaceAll(req.RequestURI, "/", "_") + ".mp3"
|
||||||
|
os.WriteFile(mp3, body, 0666)
|
||||||
|
// on Mac: "sudo ln -s /usr/bin/open /usr/local/bin/play"
|
||||||
|
go exec.Command("play", mp3).Run()
|
||||||
|
}()
|
||||||
|
|
||||||
// pass on the original body into a new body 'cause the original one has been read out already.
|
// pass on the original body into a new body 'cause the original one has been read out already.
|
||||||
resp.Body = io.NopCloser(bytes.NewReader(body))
|
resp.Body = io.NopCloser(bytes.NewReader(body))
|
||||||
|
|
Loading…
Reference in New Issue