diff --git a/controllers/index.go b/controllers/index.go index ca2325a68..d19449566 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 73f79999b..0c09cf177 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(