Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for loading the owncast URL in mpv #1356

Merged
merged 2 commits into from Aug 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions controllers/index.go
Expand Up @@ -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)
Expand Down
21 changes: 21 additions & 0 deletions utils/utils.go
Expand Up @@ -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(
Expand Down