Implement metadata parsing on Icecast input.
parent
c0774e8ba6
commit
331286f9d0
|
@ -2,6 +2,7 @@ package icecast_input
|
|||
|
||||
import (
|
||||
"io"
|
||||
"strconv"
|
||||
|
||||
"git.icedream.tech/icedream/uplink/app/authentication"
|
||||
"git.icedream.tech/icedream/uplink/app/channels"
|
||||
|
@ -10,6 +11,15 @@ import (
|
|||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
var allowedCopyHeaders = []string{
|
||||
"icy-br",
|
||||
"icy-name",
|
||||
"icy-description",
|
||||
"icy-pub",
|
||||
"icy-url",
|
||||
"icy-genre",
|
||||
}
|
||||
|
||||
type pluginInstance struct {
|
||||
server *httpserver.Server
|
||||
authenticator authentication.Authenticator
|
||||
|
@ -47,6 +57,33 @@ func (instance *pluginInstance) Init() {
|
|||
return
|
||||
}
|
||||
|
||||
var sr io.Reader = ctx.Request.Body
|
||||
defer ctx.Request.Body.Close()
|
||||
if ctx.GetHeader("icy-metadata") == "1" {
|
||||
metaInt64, err := strconv.ParseInt(ctx.GetHeader("icy-metaint"), 10, 32)
|
||||
if err != nil {
|
||||
ctx.Status(400)
|
||||
return
|
||||
}
|
||||
metaInt := int(metaInt64)
|
||||
|
||||
// Client is sending metadata!
|
||||
mr := streams.NewMetadataExtractor(sr, metaInt)
|
||||
sr = mr
|
||||
|
||||
metadataChan := channel.Metadata()
|
||||
defer func() { metadataChan <- nil }()
|
||||
go func() {
|
||||
for metadata := range metadataChan {
|
||||
metadataToWrite := streams.Metadata{}
|
||||
if value, ok := metadata["StreamTitle"]; ok {
|
||||
metadataToWrite["StreamTitle"] = value
|
||||
}
|
||||
channel.SetMetadata(metadataToWrite)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
input := channel.AddInputStream("icecast")
|
||||
|
||||
io.Copy(input, sr)
|
||||
|
|
Loading…
Reference in New Issue