Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 3 additions & 16 deletions internal/episode_url.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,25 +140,12 @@ func decodeProviderID(encoded string) string {
func extractLinks(provider_id string) map[string]interface{} {
// Check if provider_id is already a full URL (external link)
if strings.HasPrefix(provider_id, "http://") || strings.HasPrefix(provider_id, "https://") {
// It's an external direct video link, return it as-is
cleanedURL := provider_id
// Clean up any double slashes in the URL (except after protocol)
if strings.Contains(cleanedURL, "://") {
parts := strings.SplitN(cleanedURL, "://", 2)
if len(parts) == 2 {
protocol := parts[0]
rest := parts[1]
// Replace any double slashes in the rest of the URL
rest = strings.ReplaceAll(rest, "//", "/")
cleanedURL = protocol + "://" + rest
}
}

Log(fmt.Sprintf("Direct external link detected: %s -> %s", provider_id, cleanedURL))
// It's an external direct video link, preserve it exactly as provided.
Log(fmt.Sprintf("Direct external link detected: %s", provider_id))
return map[string]interface{}{
"links": []interface{}{
map[string]interface{}{
"link": cleanedURL,
"link": provider_id,
},
},
}
Expand Down
42 changes: 42 additions & 0 deletions internal/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (

var logFile = "debug.log"

const defaultStreamReferrer = "allanime.day"

func getBundledMPVPath() (string, error) {
exePath, err := os.Executable()
if err != nil {
Expand Down Expand Up @@ -146,6 +148,34 @@ func translateMPVArgsForIINA(mpvArgs []string) []string {
return translated
}

func isHTTPStreamLink(link string) bool {
trimmedLink := strings.ToLower(strings.TrimSpace(link))
return strings.HasPrefix(trimmedLink, "http://") || strings.HasPrefix(trimmedLink, "https://")
}

func hasMPVReferrerArg(args []string) bool {
for i, arg := range args {
normalizedArg := strings.ToLower(strings.TrimSpace(arg))

if strings.HasPrefix(normalizedArg, "--referrer=") || normalizedArg == "--referrer" {
return true
}

if strings.HasPrefix(normalizedArg, "--http-header-fields=") && strings.Contains(normalizedArg, "referer:") {
return true
Comment on lines +160 to +165
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Detect IINA-prefixed referrer flags before adding default

StartVideo uses hasMPVReferrerArg to decide whether to append a default referrer, but this helper only checks --referrer and --http-header-fields forms and does not recognize IINA-prefixed variants like --mpv-referrer/--mpv-http-header-fields. In the Player=iina path, users who already set those prefixed flags in MpvArgs will still get --referrer=allanime.day appended, and after argument translation the auto-added value can override their intended referer, causing stream failures on hosts that require a specific header.

Useful? React with 👍 / 👎.

}

if normalizedArg == "--http-header-fields" && i+1 < len(args) {
nextArg := strings.ToLower(strings.TrimSpace(args[i+1]))
if strings.Contains(nextArg, "referer:") {
return true
}
}
}

return false
}

func StartVideo(link string, args []string, title string, anime *Anime) (string, error) {
var command *exec.Cmd
var mpvSocketPath string
Expand All @@ -158,11 +188,23 @@ func StartVideo(link string, args []string, title string, anime *Anime) (string,
args = append(args, userConfig.MpvArgs...)
}

shouldSetDefaultReferrer := isHTTPStreamLink(link) && !hasMPVReferrerArg(args)
if shouldSetDefaultReferrer {
args = append(args, fmt.Sprintf("--referrer=%s", defaultStreamReferrer))
}

// Check if we have an existing socket and if MPV is still running
if anime.Ep.Player.SocketPath != "" && IsMPVRunning(anime.Ep.Player.SocketPath) {
// Reuse existing socket
mpvSocketPath = anime.Ep.Player.SocketPath

if shouldSetDefaultReferrer {
_, referrerErr := MPVSendCommand(mpvSocketPath, []interface{}{"set_property", "referrer", defaultStreamReferrer})
if referrerErr != nil {
Log(fmt.Sprintf("Failed to set referrer property: %v", referrerErr))
}
}

// Load the new file in the existing MPV instance
command := []interface{}{"loadfile", link}
_, err = MPVSendCommand(mpvSocketPath, command)
Expand Down
Loading