Commit 7861f432d1
Unregistered key
Layout: unified · split
internal/episode_url.go +3 −16
| @@ -140,25 +140,12 @@ func decodeProviderID(encoded string) string { | |||
| 140 | func extractLinks(provider_id string) map[string]interface{} { | 140 | func extractLinks(provider_id string) map[string]interface{} { |
| 141 | // Check if provider_id is already a full URL (external link) | 141 | // Check if provider_id is already a full URL (external link) |
| 142 | if strings.HasPrefix(provider_id, "http://") || strings.HasPrefix(provider_id, "https://") { | 142 | if strings.HasPrefix(provider_id, "http://") || strings.HasPrefix(provider_id, "https://") { |
| 143 | // It's an external direct video link, return it as-is | 143 | // It's an external direct video link, preserve it exactly as provided. |
| 144 | cleanedURL := provider_id | 144 | Log(fmt.Sprintf("Direct external link detected: %s", provider_id)) |
| 145 | // Clean up any double slashes in the URL (except after protocol) | ||
| 146 | if strings.Contains(cleanedURL, "://") { | ||
| 147 | parts := strings.SplitN(cleanedURL, "://", 2) | ||
| 148 | if len(parts) == 2 { | ||
| 149 | protocol := parts[0] | ||
| 150 | rest := parts[1] | ||
| 151 | // Replace any double slashes in the rest of the URL | ||
| 152 | rest = strings.ReplaceAll(rest, "//", "/") | ||
| 153 | cleanedURL = protocol + "://" + rest | ||
| 154 | } | ||
| 155 | } | ||
| 156 | |||
| 157 | Log(fmt.Sprintf("Direct external link detected: %s -> %s", provider_id, cleanedURL)) | ||
| 158 | return map[string]interface{}{ | 145 | return map[string]interface{}{ |
| 159 | "links": []interface{}{ | 146 | "links": []interface{}{ |
| 160 | map[string]interface{}{ | 147 | map[string]interface{}{ |
| 161 | "link": cleanedURL, | 148 | "link": provider_id, |
| 162 | }, | 149 | }, |
| 163 | }, | 150 | }, |
| 164 | } | 151 | } |
internal/player.go +42
| @@ -15,6 +15,8 @@ import ( | |||
| 15 | 15 | ||
| 16 | var logFile = "debug.log" | 16 | var logFile = "debug.log" |
| 17 | 17 | ||
| 18 | const defaultStreamReferrer = "allanime.day" | ||
| 19 | |||
| 18 | func getBundledMPVPath() (string, error) { | 20 | func getBundledMPVPath() (string, error) { |
| 19 | exePath, err := os.Executable() | 21 | exePath, err := os.Executable() |
| 20 | if err != nil { | 22 | if err != nil { |
| @@ -146,6 +148,34 @@ func translateMPVArgsForIINA(mpvArgs []string) []string { | |||
| 146 | return translated | 148 | return translated |
| 147 | } | 149 | } |
| 148 | 150 | ||
| 151 | func isHTTPStreamLink(link string) bool { | ||
| 152 | trimmedLink := strings.ToLower(strings.TrimSpace(link)) | ||
| 153 | return strings.HasPrefix(trimmedLink, "http://") || strings.HasPrefix(trimmedLink, "https://") | ||
| 154 | } | ||
| 155 | |||
| 156 | func hasMPVReferrerArg(args []string) bool { | ||
| 157 | for i, arg := range args { | ||
| 158 | normalizedArg := strings.ToLower(strings.TrimSpace(arg)) | ||
| 159 | |||
| 160 | if strings.HasPrefix(normalizedArg, "--referrer=") || normalizedArg == "--referrer" { | ||
| 161 | return true | ||
| 162 | } | ||
| 163 | |||
| 164 | if strings.HasPrefix(normalizedArg, "--http-header-fields=") && strings.Contains(normalizedArg, "referer:") { | ||
| 165 | return true | ||
| 166 | } | ||
| 167 | |||
| 168 | if normalizedArg == "--http-header-fields" && i+1 < len(args) { | ||
| 169 | nextArg := strings.ToLower(strings.TrimSpace(args[i+1])) | ||
| 170 | if strings.Contains(nextArg, "referer:") { | ||
| 171 | return true | ||
| 172 | } | ||
| 173 | } | ||
| 174 | } | ||
| 175 | |||
| 176 | return false | ||
| 177 | } | ||
| 178 | |||
| 149 | func StartVideo(link string, args []string, title string, anime *Anime) (string, error) { | 179 | func StartVideo(link string, args []string, title string, anime *Anime) (string, error) { |
| 150 | var command *exec.Cmd | 180 | var command *exec.Cmd |
| 151 | var mpvSocketPath string | 181 | var mpvSocketPath string |
| @@ -158,11 +188,23 @@ func StartVideo(link string, args []string, title string, anime *Anime) (string, | |||
| 158 | args = append(args, userConfig.MpvArgs...) | 188 | args = append(args, userConfig.MpvArgs...) |
| 159 | } | 189 | } |
| 160 | 190 | ||
| 191 | shouldSetDefaultReferrer := isHTTPStreamLink(link) && !hasMPVReferrerArg(args) | ||
| 192 | if shouldSetDefaultReferrer { | ||
| 193 | args = append(args, fmt.Sprintf("--referrer=%s", defaultStreamReferrer)) | ||
| 194 | } | ||
| 195 | |||
| 161 | // Check if we have an existing socket and if MPV is still running | 196 | // Check if we have an existing socket and if MPV is still running |
| 162 | if anime.Ep.Player.SocketPath != "" && IsMPVRunning(anime.Ep.Player.SocketPath) { | 197 | if anime.Ep.Player.SocketPath != "" && IsMPVRunning(anime.Ep.Player.SocketPath) { |
| 163 | // Reuse existing socket | 198 | // Reuse existing socket |
| 164 | mpvSocketPath = anime.Ep.Player.SocketPath | 199 | mpvSocketPath = anime.Ep.Player.SocketPath |
| 165 | 200 | ||
| 201 | if shouldSetDefaultReferrer { | ||
| 202 | _, referrerErr := MPVSendCommand(mpvSocketPath, []interface{}{"set_property", "referrer", defaultStreamReferrer}) | ||
| 203 | if referrerErr != nil { | ||
| 204 | Log(fmt.Sprintf("Failed to set referrer property: %v", referrerErr)) | ||
| 205 | } | ||
| 206 | } | ||
| 207 | |||
| 166 | // Load the new file in the existing MPV instance | 208 | // Load the new file in the existing MPV instance |
| 167 | command := []interface{}{"loadfile", link} | 209 | command := []interface{}{"loadfile", link} |
| 168 | _, err = MPVSendCommand(mpvSocketPath, command) | 210 | _, err = MPVSendCommand(mpvSocketPath, command) |