mirror of
https://github.com/nxshock/promodj.git
synced 2024-11-27 03:01:01 +05:00
Add custom bitrate parser
This commit is contained in:
parent
87bc382747
commit
e8abe97992
@ -16,7 +16,7 @@ type Config struct {
|
|||||||
BufferSize uint `default:"32" validate:"required|min:1"`
|
BufferSize uint `default:"32" validate:"required|min:1"`
|
||||||
|
|
||||||
// Kb
|
// Kb
|
||||||
Bitrate uint `default:"32" validate:"required|min:8|max:320"`
|
Bitrate uint64 `default:"32" validate:"required|min:8|max:320"`
|
||||||
|
|
||||||
Codec string `default:"libopus" validate:"required"`
|
Codec string `default:"libopus" validate:"required"`
|
||||||
Format string `default:"opus" validate:"required" `
|
Format string `default:"opus" validate:"required" `
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
func handleGenres(w http.ResponseWriter, r *http.Request) {
|
func handleGenres(w http.ResponseWriter, r *http.Request) {
|
||||||
@ -90,7 +91,12 @@ func handleGetM3u(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func handleStream(w http.ResponseWriter, r *http.Request) {
|
func handleStream(w http.ResponseWriter, r *http.Request) {
|
||||||
err := stream(r.FormValue("url"), w)
|
bitrateKbps, err := strconv.ParseUint(r.FormValue("b"), 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
bitrateKbps = config.Bitrate
|
||||||
|
}
|
||||||
|
|
||||||
|
err = stream(r.FormValue("url"), w, bitrateKbps)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ import (
|
|||||||
"gopkg.in/djherbis/buffer.v1"
|
"gopkg.in/djherbis/buffer.v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
func stream(url string, w http.ResponseWriter) error {
|
func stream(url string, w http.ResponseWriter, bitrateKbps uint64) error {
|
||||||
if url == "" {
|
if url == "" {
|
||||||
err := errors.New("empty url")
|
err := errors.New("empty url")
|
||||||
|
|
||||||
@ -24,10 +24,10 @@ func stream(url string, w http.ResponseWriter) error {
|
|||||||
w.Header().Set("Accept-Ranges", "none")
|
w.Header().Set("Accept-Ranges", "none")
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
|
|
||||||
return encode(url, w)
|
return encode(url, w, bitrateKbps)
|
||||||
}
|
}
|
||||||
|
|
||||||
func encode(url string, w io.Writer) error {
|
func encode(url string, w io.Writer, bitrateKbps uint64) error {
|
||||||
cmd := exec.Command("ffmpeg",
|
cmd := exec.Command("ffmpeg",
|
||||||
"-i", url,
|
"-i", url,
|
||||||
"-vn",
|
"-vn",
|
||||||
|
Loading…
Reference in New Issue
Block a user