Skip to content

Commit 7a35e88

Browse files
committed
fix(download): add Referer header for AllAnime CDN URLs
allanime.day CDN requires Referer: https://allanime.to for authenticated requests. Without it, HEAD and Range GET requests return 401, breaking multi-part downloads and content-length detection. - Add allanime.day to isKnownStreamURL check in getContentLength() - Set Referer on HEAD request in getContentLength() for allanime URLs - Set Referer on Range GET request in downloadPart() for allanime URLs
1 parent 0daf6d7 commit 7a35e88

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

internal/player/download.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ func downloadPart(url string, from, to int64, part int, client *http.Client, des
7474
return err
7575
}
7676
req.Header.Set("Range", fmt.Sprintf("bytes=%d-%d", current, to))
77+
if strings.Contains(url, "allanime.day") || strings.Contains(url, "allanime.pro") {
78+
req.Header.Set("Referer", "https://allanime.to")
79+
}
7780

7881
resp, err := client.Do(req) // #nosec G704
7982
if err != nil {

internal/player/scraper.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ func getContentLength(url string, client *http.Client) (int64, error) {
8585
strings.Contains(url, "master.m3u8") ||
8686
strings.Contains(url, ".m3u8") ||
8787
strings.Contains(url, "allanime.pro") ||
88+
strings.Contains(url, "allanime.day") ||
8889
strings.Contains(url, "animefire") ||
8990
strings.Contains(url, "blogger.com") ||
9091
strings.Contains(url, "animesfire") ||
@@ -96,6 +97,9 @@ func getContentLength(url string, client *http.Client) (int64, error) {
9697
// Returns 0 and the error if the request creation fails.
9798
return 0, err
9899
}
100+
if strings.Contains(url, "allanime.day") || strings.Contains(url, "allanime.pro") {
101+
req.Header.Set("Referer", "https://allanime.to")
102+
}
99103

100104
// Sends the HEAD request to the server.
101105
resp, err := client.Do(req) // #nosec G704

0 commit comments

Comments
 (0)