Commit 7861f432d1

7861f432d1d3e7ab91811f8e14a403f28083cf44

parent: be5a65dc86

Unregistered key

Rushikesh Gaikwad <81632222+Wraient@users.noreply.github.com> · 2026-04-22 17:37 UTC
committer: <noreply@github.com>

fix: allanime link parsing (#91)

Layout: unified · split

internal/episode_url.go +3 −16
@@ -140,25 +140,12 @@ func decodeProviderID(encoded string) string {
140140func extractLinks(provider_id string) map[string]interface{} {
141141 // Check if provider_id is already a full URL (external link)
142142 if strings.HasPrefix(provider_id, "http://") || strings.HasPrefix(provider_id, "https://") {
143 // It's an external direct video link, return it as-is
144 cleanedURL := 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))
143 // It's an external direct video link, preserve it exactly as provided.
144 Log(fmt.Sprintf("Direct external link detected: %s", provider_id))
158145 return map[string]interface{}{
159146 "links": []interface{}{
160147 map[string]interface{}{
161 "link": cleanedURL,
148 "link": provider_id,
162149 },
163150 },
164151 }
internal/player.go +42
@@ -15,6 +15,8 @@ import (
1515
1616var logFile = "debug.log"
1717
18const defaultStreamReferrer = "allanime.day"
19
1820func getBundledMPVPath() (string, error) {
1921 exePath, err := os.Executable()
2022 if err != nil {
@@ -146,6 +148,34 @@ func translateMPVArgsForIINA(mpvArgs []string) []string {
146148 return translated
147149}
148150
151func isHTTPStreamLink(link string) bool {
152 trimmedLink := strings.ToLower(strings.TrimSpace(link))
153 return strings.HasPrefix(trimmedLink, "http://") || strings.HasPrefix(trimmedLink, "https://")
154}
155
156func 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
149179func StartVideo(link string, args []string, title string, anime *Anime) (string, error) {
150180 var command *exec.Cmd
151181 var mpvSocketPath string
@@ -158,11 +188,23 @@ func StartVideo(link string, args []string, title string, anime *Anime) (string,
158188 args = append(args, userConfig.MpvArgs...)
159189 }
160190
191 shouldSetDefaultReferrer := isHTTPStreamLink(link) && !hasMPVReferrerArg(args)
192 if shouldSetDefaultReferrer {
193 args = append(args, fmt.Sprintf("--referrer=%s", defaultStreamReferrer))
194 }
195
161196 // Check if we have an existing socket and if MPV is still running
162197 if anime.Ep.Player.SocketPath != "" && IsMPVRunning(anime.Ep.Player.SocketPath) {
163198 // Reuse existing socket
164199 mpvSocketPath = anime.Ep.Player.SocketPath
165200
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
166208 // Load the new file in the existing MPV instance
167209 command := []interface{}{"loadfile", link}
168210 _, err = MPVSendCommand(mpvSocketPath, command)