From 19c3fa009c3f3779c1fa7a1f000cee7d3d3faade Mon Sep 17 00:00:00 2001 From: Son Roy Almerol Date: Sun, 25 Aug 2024 20:10:46 -0400 Subject: [PATCH] add list of possible m3u mimetypes --- stream_handler.go | 4 ++-- utils/url.go | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/stream_handler.go b/stream_handler.go index 0b1aecf..ddc9a97 100644 --- a/stream_handler.go +++ b/stream_handler.go @@ -140,7 +140,7 @@ func proxyStream(ctx context.Context, m3uIndex int, resp *http.Response, r *http if err != nil { if err == io.EOF { log.Printf("Stream ended (EOF reached): %s\n", r.RemoteAddr) - if strings.ToLower(resp.Header.Get("Content-Type")) == "application/x-mpegurl" { + if utils.IsPlaylist(resp) { statusChan <- 2 return } @@ -283,7 +283,7 @@ func streamHandler(w http.ResponseWriter, r *http.Request, db *database.Instance streamExitCode := <-exitStatus log.Printf("Exit code %d received from %s\n", streamExitCode, selectedUrl) - if streamExitCode == 2 && strings.ToLower(resp.Header.Get("Content-Type")) == "application/x-mpegurl" { + if streamExitCode == 2 && utils.IsPlaylist(resp) { log.Printf("Successfully proxied playlist: %s\n", r.RemoteAddr) cancel() } else if streamExitCode == 1 || streamExitCode == 2 { diff --git a/utils/url.go b/utils/url.go index 7b96b11..4bc1332 100644 --- a/utils/url.go +++ b/utils/url.go @@ -2,6 +2,9 @@ package utils import ( "encoding/base64" + "net/http" + "slices" + "strings" ) func GetStreamUrl(slug string) string { @@ -15,3 +18,15 @@ func GetStreamSlugFromUrl(streamUID string) string { } return string(decoded) } + +func IsPlaylist(resp *http.Response) bool { + knownMimeTypes := []string{ + "application/x-mpegurl", + "text/plain", + "audio/x-mpegurl", + "audio/mpegurl", + "application/vnd.apple.mpegurl", + } + + return slices.Contains(knownMimeTypes, strings.ToLower(resp.Header.Get("Content-Type"))) +}