From e8e21ca45bfc5276b824619ad6a79f4de22d8a25 Mon Sep 17 00:00:00 2001 From: Meisam <39205857+MFTabriz@users.noreply.github.com> Date: Tue, 31 Aug 2021 23:49:04 +0200 Subject: [PATCH] Add support for loading the owncast URL in mpv (#1356) * redirect players to hls link * add VLC to players list --- controllers/index.go | 5 +++++ utils/utils.go | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+) 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(