play audio after catching it

This commit is contained in:
Wouter Groeneveld 2023-02-10 11:52:43 +01:00
parent ac4a9dbfa6
commit 8d7ced37ab
1 changed files with 7 additions and 1 deletions

View File

@ -8,6 +8,7 @@ import (
"net/http/httputil"
"net/url"
"os"
"os/exec"
"strings"
)
@ -49,7 +50,12 @@ func (pr Proxy) ServeHTTP(w http.ResponseWriter, req *http.Request) {
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.
resp.Body = io.NopCloser(bytes.NewReader(body))