Take control over your live stream video by running it yourself. Streaming + chat out of the box.
HTML activitypubbroadcastingchatdecentralizedfederationfediversegolanghacktoberfesthlslivelivestreamowncastrtmpself-hostedstreaming-videovideo
Add our own botlist for user-agent matching. Closes #51
Gabe Kangasef31401a83fc
diff --git a/controllers/index.go b/controllers/index.goindex 932e242d7a..40f6bb07bf 100644--- a/controllers/index.go+++ b/controllers/index.go@@ -8,7 +8,6 @@ import ("strings""text/template"- "github.com/mssola/user_agent"log "github.com/sirupsen/logrus""github.com/gabek/owncast/config"@@ -38,9 +37,7 @@ func IndexHandler(w http.ResponseWriter, r *http.Request) {return}- ua := user_agent.New(r.UserAgent())-- if ua != nil && ua.Bot() && isIndexRequest {+ if utils.IsUserAgentABot(r.UserAgent()) && isIndexRequest {handleScraperMetadataPage(w, r)return}diff --git a/utils/utils.go b/utils/utils.goindex 43b211d6e8..928abd81b5 100644--- a/utils/utils.go+++ b/utils/utils.go@@ -5,6 +5,8 @@ import ("os""path/filepath""strings"++ "github.com/mssola/user_agent")//GetTemporaryPipePath gets the temporary path for the streampipe.flv file@@ -41,3 +43,24 @@ func Copy(source, destination string) error {return ioutil.WriteFile(destination, input, 0644)}++// IsUserAgentABot returns if a web client user-agent is seen as a bot+func IsUserAgentABot(userAgent string) bool {+ if userAgent == "" {+ return false+ }++ botStrings := []string{+ "mastodon",+ "pleroma",+ }++ for _, botString := range botStrings {+ if strings.Contains(strings.ToLower(userAgent), botString) {+ return true+ }+ }++ ua := user_agent.New(userAgent)+ return ua.Bot()+}diff --git a/utils/utils_test.go b/utils/utils_test.gonew file mode 100644index 0000000000..bb25c5ba75--- /dev/null+++ b/utils/utils_test.go@@ -0,0 +1,16 @@+package utils++import "testing"++func TestUserAgent(t *testing.T) {+ testAgents := []string{+ "Pleroma 1.0.0-1168-ge18c7866-pleroma-dot-site; https://pleroma.site [email protected]",+ "Mastodon 1.2.3 Bot",+ }++ for _, agent := range testAgents {+ if !IsUserAgentABot(agent) {+ t.Error("Incorrect parsing of useragent", agent)+ }+ }+}