Skip to content

Take control over your live stream video by running it yourself. Streaming + chat out of the box.

Add support for loading the owncast URL in mpv (#1356)

Meisamc938693a7265
diff --git a/controllers/index.go b/controllers/index.go
index ca2325a683..d194495667 100644
--- a/controllers/index.go
+++ b/controllers/index.go
@@ -44,6 +44,11 @@ func IndexHandler(w http.ResponseWriter, r *http.Request) {
return
}
+ if utils.IsUserAgentAPlayer(r.UserAgent()) && isIndexRequest {
+ http.Redirect(w, r, "/hls/stream.m3u8", http.StatusTemporaryRedirect)
+ return
+ }
+
// If the ETags match then return a StatusNotModified
if responseCode := middleware.ProcessEtags(w, r); responseCode != 0 {
w.WriteHeader(responseCode)
diff --git a/utils/utils.go b/utils/utils.go
index 73f79999b9..0c09cf1779 100644
--- a/utils/utils.go
+++ b/utils/utils.go
@@ -86,6 +86,27 @@ func IsUserAgentABot(userAgent string) bool {
return ua.Bot()
}
+// IsUserAgentAPlayer returns if a web client user-agent is seen as a media player.
+func IsUserAgentAPlayer(userAgent string) bool {
+ if userAgent == "" {
+ return false
+ }
+
+ playerStrings := []string{
+ "mpv",
+ "player",
+ "vlc",
+ }
+
+ for _, playerString := range playerStrings {
+ if strings.Contains(strings.ToLower(userAgent), playerString) {
+ return true
+ }
+ }
+
+ return false
+}
+
func RenderSimpleMarkdown(raw string) string {
markdown := goldmark.New(
goldmark.WithRendererOptions(