22package scraper
33
44import (
5+ "bytes"
56 "encoding/json"
67 "fmt"
78 "io"
89 "maps"
910 "net/http"
10- "net/url"
1111 "regexp"
1212 "sort"
1313 "strings"
@@ -19,7 +19,7 @@ import (
1919)
2020
2121const (
22- AllAnimeReferer = "https://allanime .to"
22+ AllAnimeReferer = "https://allmanga .to"
2323 AllAnimeBase = "allanime.day"
2424 AllAnimeAPI = "https://api.allanime.day/api"
2525 UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/121.0"
@@ -132,14 +132,21 @@ func (c *AllAnimeClient) SearchAnime(query string, options ...any) ([]*models.An
132132 return nil , fmt .Errorf ("failed to marshal variables: %w" , err )
133133 }
134134
135- // Build the request URL exactly like Curd
136- reqURL := fmt .Sprintf ("%s?variables=%s&query=%s" , c .apiBase , url .QueryEscape (string (variablesJSON )), url .QueryEscape (searchGql ))
135+ // Build the POST request body with variables and query
136+ reqBody , err := json .Marshal (map [string ]any {
137+ "variables" : json .RawMessage (variablesJSON ),
138+ "query" : searchGql ,
139+ })
140+ if err != nil {
141+ return nil , fmt .Errorf ("failed to marshal request body: %w" , err )
142+ }
137143
138- req , err := http .NewRequest ("GET " , reqURL , nil )
144+ req , err := http .NewRequest ("POST " , c . apiBase , bytes . NewReader ( reqBody ) )
139145 if err != nil {
140146 return nil , fmt .Errorf ("failed to create request: %w" , err )
141147 }
142148
149+ req .Header .Set ("Content-Type" , "application/json" )
143150 req .Header .Set ("User-Agent" , c .userAgent )
144151 req .Header .Set ("Referer" , c .referer )
145152
@@ -234,15 +241,21 @@ func (c *AllAnimeClient) GetEpisodesList(animeID string, mode string) ([]string,
234241 if err != nil {
235242 return nil , fmt .Errorf ("failed to marshal variables: %w" , err )
236243 }
237- reqURL := fmt .Sprintf ("%s?variables=%s&query=%s" ,
238- c .apiBase ,
239- url .QueryEscape (string (varsBytes )),
240- url .QueryEscape (episodesListGql ))
241244
242- req , err := http .NewRequest ("GET" , reqURL , nil )
245+ // Build the POST request body
246+ reqBody , err := json .Marshal (map [string ]any {
247+ "variables" : json .RawMessage (varsBytes ),
248+ "query" : episodesListGql ,
249+ })
250+ if err != nil {
251+ return nil , fmt .Errorf ("failed to marshal request body: %w" , err )
252+ }
253+
254+ req , err := http .NewRequest ("POST" , c .apiBase , bytes .NewReader (reqBody ))
243255 if err != nil {
244256 return nil , fmt .Errorf ("failed to create request: %w" , err )
245257 }
258+ req .Header .Set ("Content-Type" , "application/json" )
246259 req .Header .Set ("User-Agent" , c .userAgent )
247260 req .Header .Set ("Referer" , c .referer )
248261
@@ -480,18 +493,22 @@ func (c *AllAnimeClient) GetEpisodeURL(animeID string, episodeNo string, mode st
480493 if err != nil {
481494 return "" , nil , fmt .Errorf ("failed to marshal variables: %w" , err )
482495 }
483- variables := string (varsBytes )
484496
485- req , err := http .NewRequest ("GET" , c .apiBase + "/api" , nil )
497+ // Build the POST request body
498+ reqBody , err := json .Marshal (map [string ]any {
499+ "variables" : json .RawMessage (varsBytes ),
500+ "query" : episodeEmbedGQL ,
501+ })
486502 if err != nil {
487- return "" , nil , fmt .Errorf ("failed to create request: %w" , err )
503+ return "" , nil , fmt .Errorf ("failed to marshal request body : %w" , err )
488504 }
489505
490- q := req . URL . Query ( )
491- q . Add ( "variables" , variables )
492- q . Add ( "query " , episodeEmbedGQL )
493- req . URL . RawQuery = q . Encode ()
506+ req , err := http . NewRequest ( "POST" , c . apiBase , bytes . NewReader ( reqBody ) )
507+ if err != nil {
508+ return "" , nil , fmt . Errorf ( "failed to create request: %w " , err )
509+ }
494510
511+ req .Header .Set ("Content-Type" , "application/json" )
495512 req .Header .Set ("Referer" , c .referer )
496513 req .Header .Set ("User-Agent" , c .userAgent )
497514
0 commit comments