Skip to content

Commit

Permalink
Merge pull request #126 from sonroyaalmerol/nonstream-failover
Browse files Browse the repository at this point in the history
Prevent retry on EOF if mimetype is `application/x-mpegurl`
  • Loading branch information
sonroyaalmerol committed Aug 25, 2024
2 parents 9c0b5ad + e395cdc commit c7f0e10
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 10 deletions.
6 changes: 3 additions & 3 deletions stream_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 utils.IsPlaylistFile(r.RemoteAddr) {
if strings.ToLower(resp.Header.Get("Content-Type")) == "application/x-mpegurl" {
statusChan <- 2
return
}
Expand Down Expand Up @@ -283,8 +283,8 @@ 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 && utils.IsPlaylistFile(selectedUrl) {
log.Printf("Successfully proxied playlist (M3U) file: %s\n", r.RemoteAddr)
if streamExitCode == 2 && strings.ToLower(resp.Header.Get("Content-Type")) == "application/x-mpegurl" {
log.Printf("Successfully proxied playlist: %s\n", r.RemoteAddr)
cancel()
} else if streamExitCode == 1 || streamExitCode == 2 {
// Retry on server-side connection errors
Expand Down
7 changes: 0 additions & 7 deletions utils/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package utils

import (
"encoding/base64"
"strings"
)

func GetStreamUrl(slug string) string {
Expand All @@ -16,9 +15,3 @@ func GetStreamSlugFromUrl(streamUID string) string {
}
return string(decoded)
}

func IsPlaylistFile(url string) bool {
urlClean := strings.TrimSpace(strings.ToLower(url))

return strings.HasSuffix(urlClean, ".m3u") || strings.HasSuffix(urlClean, ".m3u8")
}

0 comments on commit c7f0e10

Please sign in to comment.