GitBucket
4.20.0
Toggle navigation
Sign in
Files
Branches
1
Tags
Issues
Pull requests
Labels
Priorities
Milestones
Wiki
Forks
frozendragon
/
anime-fetcher
Browse code
Added support for one more source
master
1 parent
fb18efa
commit
461bcf86a29a9dcbdc46f8bb28b458bdc988c963
Simon Lindgren
authored
18 hours ago
Patch
Showing
2 changed files
.gitignore
main.go
Ignore Space
Show notes
View
.gitignore
Download/ storage .idea
Download/ .idea
Ignore Space
Show notes
View
main.go
package main import ( "encoding/json" "fmt" "html" "io" "log" "net/http" "net/url" "os" "os/exec" "strings" "time" "github.com/PuerkitoBio/goquery" chi "github.com/go-chi/chi/v5" "github.com/go-chi/chi/v5/middleware" "github.com/samber/oops" ) func main() { requestChan := make(chan Request, 1000) r := chi.NewRouter() r.Use(middleware.Logger) r.Get("/", func(w http.ResponseWriter, r *http.Request) { file, err := os.ReadFile("frontend/index.html") if err != nil { panic(err) } w.Write(file) }) r.Post("/success", func(w http.ResponseWriter, r *http.Request) { file, err := os.ReadFile("frontend/success.html") if err != nil { panic(err) } w.Write(file) }) r.Post("/failed", func(w http.ResponseWriter, r *http.Request) { file, err := os.ReadFile("frontend/failed.html") if err != nil { panic(err) } w.Write(file) }) //r.Get("/session", func(w http.ResponseWriter, r *http.Request) { // m1 := make(map[string]Request) // // m.Range(func(key, value any) bool { // // Type assertion is required since Range returns 'any' types // k := key.(string) // v := value.(Request) // // m1[k] = v // // return true // Return true to continue iterating // }) // // data, err := json.Marshal(m1) // if err != nil { // http.Error(w, "Failed to submit request", http.StatusInternalServerError) // return // } // // _, err = w.Write(data) // if err != nil { // http.Error(w, "Failed to submit request", http.StatusInternalServerError) // return // } // w.WriteHeader(http.StatusOK) //}) r.Post("/session", func(w http.ResponseWriter, r *http.Request) { if err := r.ParseForm(); err != nil { http.Error(w, "Failed to parse form", http.StatusBadRequest) return } // Retrieve input values by their HTML "name" attribute u := r.FormValue("url") name := r.FormValue("name") season := r.FormValue("season") //UUID, err := uuid.NewUUID() //if err != nil { // http.Error(w, "Failed to submit request", http.StatusInternalServerError) // return //} requestChan <- Request{ URL: u, Name: name, Season: season, } http.Redirect(w, r, "/success", http.StatusTemporaryRedirect) }) go processRequest(requestChan) http.ListenAndServe(":3000", r) close(requestChan) } type Request struct { URL string `json:"url"` Name string `json:"name"` Season string `json:"season"` } func processRequest(requestChan chan Request) { for { v := <-requestChan Download(v) time.Sleep(time.Second * 30) } } const streamPrimary = 4 const streamSecondary = 2 const streamSecondary2 = 1 func Download(request Request) { seasonID, err := extractSeasonID(request.URL) if err != nil { log.Printf("%+v\n", err) return } episodeCount, err := getEpisodeList(seasonID) if err != nil { log.Printf("%+v\n", err) return } //retries with a different source for i := 1; i < episodeCount+1; i++ { sourceID, err := getAniwaveSourceID(seasonID, i, streamPrimary) if err != nil { log.Printf("%+v\n", err) return } sourceUrl, err := getAniwavesSource(request.URL, sourceID) if err != nil { log.Printf("%+v\n", err) return } parsedSourceUrl, err := url.Parse(sourceUrl) if err != nil { log.Printf("%+v\n", err) return } cmd := exec.Command("") if parsedSourceUrl.Host == "play.vhscdn.to" { externalSourceID, err := extractSourceID(sourceUrl) if err != nil { log.Printf("%+v\n", err) return } playVhscdnToSourceUrl, err := getPlayVhscdnToSource(externalSourceID) if err != nil { log.Printf("%+v\n", err) return } name := "storage/Anime/" + fmt.Sprintf("%s/%s/%s - %02d", request.Name, request.Season, request.Name, i) + ".%(ext)s" cmd = exec.Command("./yt-dlp_linux", "-o", name, "--referer", "https://play.vhscdn.to/", "--add-header", "Origin: https://play.vhscdn.to", playVhscdnToSourceUrl) } else { externalSourceID, err := extractSourceID(sourceUrl) if err != nil { log.Printf("%+v\n", err) return } playEchoVideoSourceUrl, err := getPlayEchoVideoSource(externalSourceID) if err != nil { log.Printf("%+v\n", err) return } playEchoVideoSourceUrl = strings.Replace(playEchoVideoSourceUrl, "hlsx3cdn.burntburst45.store", "hlsx4cdn.burntburst45.store", 1) name := "storage/Anime/" + fmt.Sprintf("%s/%s/%s - %02d", request.Name, request.Season, request.Name, i) + ".%(ext)s" cmd = exec.Command("./yt-dlp_linux", "-o", name, "--referer", "https://play.echovideo.ru/", "--add-header", "Origin: https://play.echovideo.ru", playEchoVideoSourceUrl) } // Redirect binary I/O directly to the terminal cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr cmd.Stdin = os.Stdin // Run blocks until the command completes if err := cmd.Run(); err != nil { log.Printf("%+v\n", oops.Wrap(err)) } } } func extractSeasonID(u string) (string, error) { parsed, err := url.Parse(u) if err != nil { return "", oops.Wrap(err) } path := parsed.Path resource := strings.Split(path, "/") seasonID := resource[2][strings.LastIndex(resource[2], "-")+1:] return seasonID, nil } type GetEpisodeListResponse struct { Status int `json:"status"` Result string `json:"result"` } func getEpisodeList(seasonID string) (int, error) { client := &http.Client{Timeout: 10 * time.Second} req, err := http.NewRequest("GET", fmt.Sprintf("https://aniwaves.ru/ajax/episode/list/%s?vrf=", seasonID), nil) if err != nil { return 0, oops.Wrap(err) } req.Header.Add("User-Agent", "Mozilla/5.0 (X11; Linux x86_64; rv:151.0) Gecko/20100101 Firefox/151.0") response, err := client.Do(req) if err != nil { return 0, oops.Wrap(err) } defer response.Body.Close() // Essential: Close the body body, err := io.ReadAll(response.Body) if err != nil { return 0, oops.Wrap(err) } lsr := GetEpisodeListResponse{} err = json.Unmarshal(body, &lsr) if err != nil { return 0, oops.Wrap(err) } clean := html.UnescapeString(lsr.Result) wrapped := "<html><body>" + clean + "</body></html>" doc, err := goquery.NewDocumentFromReader(strings.NewReader(wrapped)) if err != nil { return 0, oops.Wrap(err) } count := doc.Find("ul[class='ep-range'] li").Length() return count, nil } type ListServersResponse struct { Status int `json:"status"` Result string `json:"result"` } func getAniwaveSourceID(seasonID string, episode int, streamingID int) (string, error) { client := &http.Client{Timeout: 10 * time.Second} req, err := http.NewRequest("GET", fmt.Sprintf("https://aniwaves.ru/ajax/server/list?servers=%s&eps=%d", seasonID, episode), nil) if err != nil { return "", oops.Wrap(err) } req.Header.Add("User-Agent", "Mozilla/5.0 (X11; Linux x86_64; rv:151.0) Gecko/20100101 Firefox/151.0") response, err := client.Do(req) if err != nil { return "", oops.Wrap(err) } defer response.Body.Close() // Essential: Close the body body, err := io.ReadAll(response.Body) if err != nil { return "", oops.Wrap(err) } lsr := ListServersResponse{} err = json.Unmarshal(body, &lsr) if err != nil { return "", oops.Wrap(err) } clean := html.UnescapeString(lsr.Result) wrapped := "<html><body>" + clean + "</body></html>" doc, err := goquery.NewDocumentFromReader(strings.NewReader(wrapped)) if err != nil { return "", oops.Wrap(err) } id, exist := doc.Find(fmt.Sprintf("div.type[data-type='dub'] ul li[data-sv-id='%d']", streamingID)).Attr("data-link-id") if !exist { return "", oops.New("failed to find") } return id, nil } type SourceResponse struct { Status int `json:"status"` Result struct { Url string `json:"url"` Server int `json:"server"` SkipData struct { Intro []int `json:"intro"` Outro []int `json:"outro"` } `json:"skip_data"` Sources []interface{} `json:"sources"` Tracks []interface{} `json:"tracks"` HtmlGuide string `json:"htmlGuide"` } `json:"result"` } func getAniwavesSource(originalUrl, sourceID string) (string, error) { u := fmt.Sprintf("https://aniwaves.ru/ajax/sources?id=%s&asi=0&autoPlay=0", sourceID) client := &http.Client{Timeout: 10 * time.Second} req, err := http.NewRequest("GET", u, nil) if err != nil { return "", oops.Wrap(err) } //GET /ajax/sources?id=UWxwb05ERkJXU1pUV1ZYT1k1b0FBQXQvLzl4TndCYk85aUtBc2tJeUpJd3d5Yzd3QzBCQzBnaWdVRWdIM2tzb0FnYUFvQUIwT0FBQUFHZ0FBQUFCazB4QWVtVFU5STlKNm1neWVvMEdtUU5BMDBCb0JvTkdnd2pSb1pQS0F5QTBCaHdCQU1NeUFja2pOTkxNcHRicTdmMkp4NFl4UDNFQXRKeUcxc3E0clpNTUl2bmhBdlphVzNJRDA5QTIvT2pqMTdBSmUySzkxVTBrUkVXYURKSmJjb1lXUWtYWUEzQXA0V1VRWFNHSWhoSno4ZnMzb3BTc1o3dnhFMjM2eit1ZnhkeVJUaFFrRlhPWTVvQT0=&asi=0&autoPlay=0 HTTP/2 //Host: aniwaves.ru //User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:151.0) Gecko/20100101 Firefox/151.0 //Accept: application/json, text/javascript, */*; q=0.01 //Accept-Language: en-US,en;q=0.9 //Accept-Encoding: gzip, deflate, br, zstd //Referer: https://aniwaves.ru/watch/re-zero-kara-hajimeru-isekai-seikatsu-4th-season-82570/ep-1 //X-Requested-With: XMLHttpRequest //Sec-Fetch-Dest: empty //Sec-Fetch-Mode: cors //Sec-Fetch-Site: same-origin //Connection: keep-alive //Cookie: cf_clearance=E7EaYC.6t5eW.AiGWFA4dGhrVUHTO7X8IiaRkfJTAco-1780105219-1.2.1.1-MJ0WuQfXydhynpkJCtY1Q719ENTQz4VLOfYm3pIdw7pfD41mgVQaml14Ca3gIw7pb.YmpANb8l5LPr9Boav4XmsH0pr0Ip58lVK5hkowCFzvMSFqJDdu_a43B9Km.FA5Ql3uPbXZeNU3rSlJuJ1wBDvKhhVFo4yIaxaWoIcfsqwNdmwuz81b_yWoIge0K0ciDAVKcwV.8uv9XfHP1T4Rrs_OKdKFRZ6cp0TBYjiLOe4NwFbWBviDIxsR8tDEhxKTof0UEVq9R0mBosRPelxr3YxIxH5QyFrCKdpghW.kDOeLXGfP13cYVkwZFwT0jXVhkLZvCkHEgpEZ9stzMERj0Y2P2xUx9WMKJRQaRyPMJWKUCn9FtZSvHrvuW23TaWOx9ll00D_ZPzmTHdtESQrc8MTgZ5wBDvPaXbyH1ksv2RA; prefered_server_id=4; prefered_server_type=dub; _ga_2BSQBMWMM9=GS2.1.s1780942892$o1$g1$t1780942910$j42$l0$h0; _ga=GA1.1.764185913.1780942893 //Priority: u=0 //Pragma: no-cache //Cache-Control: no-cache //TE: trailers req.Header.Add("Referer", originalUrl) req.Header.Add("User-Agent", "Mozilla/5.0 (X11; Linux x86_64; rv:151.0) Gecko/20100101 Firefox/151.0") resp, err := client.Do(req) if err != nil { return "", oops.Wrap(err) } defer resp.Body.Close() // Essential: Close the body body, err := io.ReadAll(resp.Body) if err != nil { return "", oops.Wrap(err) } sr := SourceResponse{} err = json.Unmarshal(body, &sr) if err != nil { return "", oops.Wrap(err) } return sr.Result.Url, nil } func extractSourceID(u string) (string, error) { parsedURL, err := url.Parse(u) if err != nil { return "", oops.Wrap(err) } path := parsedURL.Path id := path[strings.LastIndex(path, "/")+1:] return id, nil } type PlayEchoVideoSourceResponse struct { Sources string `json:"sources"` Intro struct { Start int `json:"start"` End int `json:"end"` } `json:"intro"` Outro struct { Start int `json:"start"` End int `json:"end"` } `json:"outro"` } func getPlayEchoVideoSource(id string) (string, error) { url := fmt.Sprintf("https://play.echovideo.ru/embed-1/getSources?id=%s", id) client := &http.Client{Timeout: 10 * time.Second} req, err := http.NewRequest("GET", url, nil) if err != nil { return "", oops.Wrap(err) } //GET /embed-1/klWckIBLnXT4frE2luSItljniglYlCJ9tDJbV_5sxYmo5yjXD6VZeNTT5toWN0qhMBKKskFNg3dlLbGApyFea8Kh-XYBMGtLlRb56LesWMgRmjJUy0SbY44JWPjGndCd1I3Xao2FFgY0Szy6zxNGF9ygRRJOyg-Wjkx2EYcVIW2Smi397fWCRZX4bhrD_OxDwCIVZPeEM2aJ596URhgcStqSHUHv0ABvXsBcvUxixzA?v=1&asi=0&autoPlay=0&ao=0&autostart=true HTTP/2 //Host: play.echovideo.ru //User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:156.0) Gecko/20100101 Firefox/156.0 //Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 //Accept-Language: en-US,en;q=0.9 //Accept-Encoding: gzip, deflate, br, zstd //Sec-Fetch-Storage-Access: none //Connection: keep-alive //Referer: https://aniwaves.ru/ //Upgrade-Insecure-Requests: 1 //Sec-Fetch-Dest: iframe //Sec-Fetch-Mode: navigate //Sec-Fetch-Site: cross-site //Priority: u=4 //TE: trailers req.Header.Add("Host", "play.echovideo.ru") req.Header.Add("User-Agent", "Mozilla/5.0 (X11; Linux x86_64; rv:156.0) Gecko/20100101 Firefox/156.0") req.Header.Add("Referer", fmt.Sprintf("https://play.echovideo.ru/embed-1/%s?v=1&asi=0&autoPlay=0&ao=0&autostart=true", id)) req.Header.Add("Priority", "u=4") req.Header.Add("TE", "trailers") resp, err := client.Do(req) if err != nil { return "", oops.Wrap(err) } defer resp.Body.Close() // Essential: Close the body body, err := io.ReadAll(resp.Body) if err != nil { return "", oops.Wrap(err) } sr := PlayEchoVideoSourceResponse{} err = json.Unmarshal(body, &sr) if err != nil { return "", oops.Wrap(err) } return sr.Sources, nil } type PlayVhscdnToSourceResponse struct { Sources string `json:"sources"` Tracks []struct { File string `json:"file"` Label string `json:"label"` Kind string `json:"kind"` } `json:"tracks"` Intro struct { Start int `json:"start"` End int `json:"end"` } `json:"intro"` Outro struct { Start int `json:"start"` End int `json:"end"` } `json:"outro"` } func getPlayVhscdnToSource(id string) (string, error) { url := fmt.Sprintf("https://play.vhscdn.to/embed-1/getSources?id=%s", id) client := &http.Client{Timeout: 10 * time.Second} req, err := http.NewRequest("GET", url, nil) if err != nil { return "", oops.Wrap(err) } req.Header.Add("Host", "play.vhscdn.to") req.Header.Add("User-Agent", "Mozilla/5.0 (X11; Linux x86_64; rv:156.0) Gecko/20100101 Firefox/156.0") req.Header.Add("Referer", fmt.Sprintf("https://play.vhscdn.to/embed-1/%s?asi=0&autoPlay=0&ao=0&autostart=true", id)) req.Header.Add("Priority", "u=4") req.Header.Add("TE", "trailers") resp, err := client.Do(req) if err != nil { return "", oops.Wrap(err) } defer resp.Body.Close() // Essential: Close the body body, err := io.ReadAll(resp.Body) if err != nil { return "", oops.Wrap(err) } sr := PlayVhscdnToSourceResponse{} err = json.Unmarshal(body, &sr) if err != nil { return "", oops.Wrap(err) } return sr.Sources, nil } func getGn1r5nVideoSource(sourceUrl string) (string, error) { client := &http.Client{Timeout: 10 * time.Second} req, err := http.NewRequest("GET", sourceUrl, nil) if err != nil { return "", oops.Wrap(err) } //GET /embed-1/klWckIBLnXT4frE2luSItljniglYlCJ9tDJbV_5sxYmo5yjXD6VZeNTT5toWN0qhMBKKskFNg3dlLbGApyFea8Kh-XYBMGtLlRb56LesWMgRmjJUy0SbY44JWPjGndCd1I3Xao2FFgY0Szy6zxNGF9ygRRJOyg-Wjkx2EYcVIW2Smi397fWCRZX4bhrD_OxDwCIVZPeEM2aJ596URhgcStqSHUHv0ABvXsBcvUxixzA?v=1&asi=0&autoPlay=0&ao=0&autostart=true HTTP/2 //Host: play.echovideo.ru //User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:156.0) Gecko/20100101 Firefox/156.0 //Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 //Accept-Language: en-US,en;q=0.9 //Accept-Encoding: gzip, deflate, br, zstd //Sec-Fetch-Storage-Access: none //Connection: keep-alive //Referer: https://aniwaves.ru/ //Upgrade-Insecure-Requests: 1 //Sec-Fetch-Dest: iframe //Sec-Fetch-Mode: navigate //Sec-Fetch-Site: cross-site //Priority: u=4 //TE: trailers req.Header.Add("Host", "play.echovideo.ru") req.Header.Add("User-Agent", "Mozilla/5.0 (X11; Linux x86_64; rv:156.0) Gecko/20100101 Firefox/156.0") //req.Header.Add("Referer", fmt.Sprintf("https://play.echovideo.ru/embed-1/%s?v=1&asi=0&autoPlay=0&ao=0&autostart=true", id)) req.Header.Add("Priority", "u=4") req.Header.Add("TE", "trailers") resp, err := client.Do(req) if err != nil { return "", oops.Wrap(err) } defer resp.Body.Close() // Essential: Close the body body, err := io.ReadAll(resp.Body) if err != nil { return "", oops.Wrap(err) } sr := PlayEchoVideoSourceResponse{} err = json.Unmarshal(body, &sr) if err != nil { return "", oops.Wrap(err) } return sr.Sources, nil }
package main import ( "encoding/json" "fmt" "html" "io" "log" "net/http" "net/url" "os" "os/exec" "strings" "time" "github.com/PuerkitoBio/goquery" chi "github.com/go-chi/chi/v5" "github.com/go-chi/chi/v5/middleware" "github.com/samber/oops" ) func main() { requestChan := make(chan Request, 1000) r := chi.NewRouter() r.Use(middleware.Logger) r.Get("/", func(w http.ResponseWriter, r *http.Request) { file, err := os.ReadFile("frontend/index.html") if err != nil { panic(err) } w.Write(file) }) r.Post("/success", func(w http.ResponseWriter, r *http.Request) { file, err := os.ReadFile("frontend/success.html") if err != nil { panic(err) } w.Write(file) }) r.Post("/failed", func(w http.ResponseWriter, r *http.Request) { file, err := os.ReadFile("frontend/failed.html") if err != nil { panic(err) } w.Write(file) }) //r.Get("/session", func(w http.ResponseWriter, r *http.Request) { // m1 := make(map[string]Request) // // m.Range(func(key, value any) bool { // // Type assertion is required since Range returns 'any' types // k := key.(string) // v := value.(Request) // // m1[k] = v // // return true // Return true to continue iterating // }) // // data, err := json.Marshal(m1) // if err != nil { // http.Error(w, "Failed to submit request", http.StatusInternalServerError) // return // } // // _, err = w.Write(data) // if err != nil { // http.Error(w, "Failed to submit request", http.StatusInternalServerError) // return // } // w.WriteHeader(http.StatusOK) //}) r.Post("/session", func(w http.ResponseWriter, r *http.Request) { if err := r.ParseForm(); err != nil { http.Error(w, "Failed to parse form", http.StatusBadRequest) return } // Retrieve input values by their HTML "name" attribute u := r.FormValue("url") name := r.FormValue("name") season := r.FormValue("season") //UUID, err := uuid.NewUUID() //if err != nil { // http.Error(w, "Failed to submit request", http.StatusInternalServerError) // return //} requestChan <- Request{ URL: u, Name: name, Season: season, } http.Redirect(w, r, "/success", http.StatusTemporaryRedirect) }) go processRequest(requestChan) http.ListenAndServe(":3000", r) close(requestChan) } type Request struct { URL string `json:"url"` Name string `json:"name"` Season string `json:"season"` } func processRequest(requestChan chan Request) { for { v := <-requestChan Download(v) time.Sleep(time.Second * 30) } } func Download(request Request) { seasonID, err := extractSeasonID(request.URL) if err != nil { log.Printf("%+v\n", err) return } episodeCount, err := getEpisodeList(seasonID) if err != nil { log.Printf("%+v\n", err) return } for i := 1; i < episodeCount+1; i++ { sourceID, err := getAniwaveSourceID(seasonID, i) if err != nil { log.Printf("%+v\n", err) return } sourceUrl, err := getAniwavesSource(request.URL, sourceID) if err != nil { log.Printf("%+v\n", err) return } playEchoVideoSourceeID, err := extractSourceID(sourceUrl) if err != nil { log.Printf("%+v\n", err) return } playEchoVideoSourceUrl, err := getPlayEchoVideoSource(playEchoVideoSourceeID) if err != nil { log.Printf("%+v\n", err) return } playEchoVideoSourceUrl = strings.Replace(playEchoVideoSourceUrl, "hlsx3cdn.burntburst45.store", "hlsx4cdn.burntburst45.store", 1) name := "storage/Anime/" + fmt.Sprintf("%s/%s/%s - %02d", request.Name, request.Season, request.Name, i) + ".%(ext)s" cmd := exec.Command("./yt-dlp_linux", "-o", name, "--referer", "https://play.echovideo.ru/", "--add-header", "Origin: https://play.echovideo.ru", playEchoVideoSourceUrl) // Redirect binary I/O directly to the terminal cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr cmd.Stdin = os.Stdin // Run blocks until the command completes if err := cmd.Run(); err != nil { log.Printf("%+v\n", err) return } } } func extractSeasonID(u string) (string, error) { parsed, err := url.Parse(u) if err != nil { return "", oops.Wrap(err) } path := parsed.Path resource := strings.Split(path, "/") seasonID := resource[2][strings.LastIndex(resource[2], "-")+1:] return seasonID, nil } type GetEpisodeListResponse struct { Status int `json:"status"` Result string `json:"result"` } func getEpisodeList(seasonID string) (int, error) { client := &http.Client{Timeout: 10 * time.Second} req, err := http.NewRequest("GET", fmt.Sprintf("https://aniwaves.ru/ajax/episode/list/%s?vrf=", seasonID), nil) if err != nil { return 0, oops.Wrap(err) } req.Header.Add("User-Agent", "Mozilla/5.0 (X11; Linux x86_64; rv:151.0) Gecko/20100101 Firefox/151.0") response, err := client.Do(req) if err != nil { return 0, oops.Wrap(err) } defer response.Body.Close() // Essential: Close the body body, err := io.ReadAll(response.Body) if err != nil { return 0, oops.Wrap(err) } lsr := GetEpisodeListResponse{} err = json.Unmarshal(body, &lsr) if err != nil { return 0, oops.Wrap(err) } clean := html.UnescapeString(lsr.Result) wrapped := "<html><body>" + clean + "</body></html>" doc, err := goquery.NewDocumentFromReader(strings.NewReader(wrapped)) if err != nil { return 0, oops.Wrap(err) } count := doc.Find("ul[class='ep-range'] li").Length() return count, nil } type ListServersResponse struct { Status int `json:"status"` Result string `json:"result"` } func getAniwaveSourceID(seasonID string, episode int) (string, error) { client := &http.Client{Timeout: 10 * time.Second} req, err := http.NewRequest("GET", fmt.Sprintf("https://aniwaves.ru/ajax/server/list?servers=%s&eps=%d", seasonID, episode), nil) if err != nil { return "", oops.Wrap(err) } req.Header.Add("User-Agent", "Mozilla/5.0 (X11; Linux x86_64; rv:151.0) Gecko/20100101 Firefox/151.0") response, err := client.Do(req) if err != nil { return "", oops.Wrap(err) } defer response.Body.Close() // Essential: Close the body body, err := io.ReadAll(response.Body) if err != nil { return "", oops.Wrap(err) } lsr := ListServersResponse{} err = json.Unmarshal(body, &lsr) if err != nil { return "", oops.Wrap(err) } clean := html.UnescapeString(lsr.Result) wrapped := "<html><body>" + clean + "</body></html>" doc, err := goquery.NewDocumentFromReader(strings.NewReader(wrapped)) if err != nil { return "", oops.Wrap(err) } id, exist := doc.Find("div.type[data-type='dub'] ul li[data-sv-id='4']").Attr("data-link-id") if !exist { return "", oops.New("failed to find") } return id, nil } type SourceResponse struct { Status int `json:"status"` Result struct { Url string `json:"url"` Server int `json:"server"` SkipData struct { Intro []int `json:"intro"` Outro []int `json:"outro"` } `json:"skip_data"` Sources []interface{} `json:"sources"` Tracks []interface{} `json:"tracks"` HtmlGuide string `json:"htmlGuide"` } `json:"result"` } func getAniwavesSource(originalUrl, sourceID string) (string, error) { u := fmt.Sprintf("https://aniwaves.ru/ajax/sources?id=%s&asi=0&autoPlay=0", sourceID) client := &http.Client{Timeout: 10 * time.Second} req, err := http.NewRequest("GET", u, nil) if err != nil { return "", oops.Wrap(err) } //GET /ajax/sources?id=UWxwb05ERkJXU1pUV1ZYT1k1b0FBQXQvLzl4TndCYk85aUtBc2tJeUpJd3d5Yzd3QzBCQzBnaWdVRWdIM2tzb0FnYUFvQUIwT0FBQUFHZ0FBQUFCazB4QWVtVFU5STlKNm1neWVvMEdtUU5BMDBCb0JvTkdnd2pSb1pQS0F5QTBCaHdCQU1NeUFja2pOTkxNcHRicTdmMkp4NFl4UDNFQXRKeUcxc3E0clpNTUl2bmhBdlphVzNJRDA5QTIvT2pqMTdBSmUySzkxVTBrUkVXYURKSmJjb1lXUWtYWUEzQXA0V1VRWFNHSWhoSno4ZnMzb3BTc1o3dnhFMjM2eit1ZnhkeVJUaFFrRlhPWTVvQT0=&asi=0&autoPlay=0 HTTP/2 //Host: aniwaves.ru //User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:151.0) Gecko/20100101 Firefox/151.0 //Accept: application/json, text/javascript, */*; q=0.01 //Accept-Language: en-US,en;q=0.9 //Accept-Encoding: gzip, deflate, br, zstd //Referer: https://aniwaves.ru/watch/re-zero-kara-hajimeru-isekai-seikatsu-4th-season-82570/ep-1 //X-Requested-With: XMLHttpRequest //Sec-Fetch-Dest: empty //Sec-Fetch-Mode: cors //Sec-Fetch-Site: same-origin //Connection: keep-alive //Cookie: cf_clearance=E7EaYC.6t5eW.AiGWFA4dGhrVUHTO7X8IiaRkfJTAco-1780105219-1.2.1.1-MJ0WuQfXydhynpkJCtY1Q719ENTQz4VLOfYm3pIdw7pfD41mgVQaml14Ca3gIw7pb.YmpANb8l5LPr9Boav4XmsH0pr0Ip58lVK5hkowCFzvMSFqJDdu_a43B9Km.FA5Ql3uPbXZeNU3rSlJuJ1wBDvKhhVFo4yIaxaWoIcfsqwNdmwuz81b_yWoIge0K0ciDAVKcwV.8uv9XfHP1T4Rrs_OKdKFRZ6cp0TBYjiLOe4NwFbWBviDIxsR8tDEhxKTof0UEVq9R0mBosRPelxr3YxIxH5QyFrCKdpghW.kDOeLXGfP13cYVkwZFwT0jXVhkLZvCkHEgpEZ9stzMERj0Y2P2xUx9WMKJRQaRyPMJWKUCn9FtZSvHrvuW23TaWOx9ll00D_ZPzmTHdtESQrc8MTgZ5wBDvPaXbyH1ksv2RA; prefered_server_id=4; prefered_server_type=dub; _ga_2BSQBMWMM9=GS2.1.s1780942892$o1$g1$t1780942910$j42$l0$h0; _ga=GA1.1.764185913.1780942893 //Priority: u=0 //Pragma: no-cache //Cache-Control: no-cache //TE: trailers req.Header.Add("Referer", originalUrl) req.Header.Add("User-Agent", "Mozilla/5.0 (X11; Linux x86_64; rv:151.0) Gecko/20100101 Firefox/151.0") resp, err := client.Do(req) if err != nil { return "", oops.Wrap(err) } defer resp.Body.Close() // Essential: Close the body body, err := io.ReadAll(resp.Body) if err != nil { return "", oops.Wrap(err) } sr := SourceResponse{} err = json.Unmarshal(body, &sr) if err != nil { return "", oops.Wrap(err) } return sr.Result.Url, nil } func extractSourceID(u string) (string, error) { parsedURL, err := url.Parse(u) if err != nil { return "", oops.Wrap(err) } path := parsedURL.Path id := path[strings.LastIndex(path, "/")+1:] return id, nil } type PlayEchoVideoSourceResponse struct { Sources string `json:"sources"` Intro struct { Start int `json:"start"` End int `json:"end"` } `json:"intro"` Outro struct { Start int `json:"start"` End int `json:"end"` } `json:"outro"` } func getPlayEchoVideoSource(id string) (string, error) { url := fmt.Sprintf("https://play.echovideo.ru/embed-1/getSources?id=%s", id) client := &http.Client{Timeout: 10 * time.Second} req, err := http.NewRequest("GET", url, nil) if err != nil { return "", oops.Wrap(err) } //GET /embed-1/klWckIBLnXT4frE2luSItljniglYlCJ9tDJbV_5sxYmo5yjXD6VZeNTT5toWN0qhMBKKskFNg3dlLbGApyFea8Kh-XYBMGtLlRb56LesWMgRmjJUy0SbY44JWPjGndCd1I3Xao2FFgY0Szy6zxNGF9ygRRJOyg-Wjkx2EYcVIW2Smi397fWCRZX4bhrD_OxDwCIVZPeEM2aJ596URhgcStqSHUHv0ABvXsBcvUxixzA?v=1&asi=0&autoPlay=0&ao=0&autostart=true HTTP/2 //Host: play.echovideo.ru //User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:156.0) Gecko/20100101 Firefox/156.0 //Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 //Accept-Language: en-US,en;q=0.9 //Accept-Encoding: gzip, deflate, br, zstd //Sec-Fetch-Storage-Access: none //Connection: keep-alive //Referer: https://aniwaves.ru/ //Upgrade-Insecure-Requests: 1 //Sec-Fetch-Dest: iframe //Sec-Fetch-Mode: navigate //Sec-Fetch-Site: cross-site //Priority: u=4 //TE: trailers req.Header.Add("Host", "play.echovideo.ru") req.Header.Add("User-Agent", "Mozilla/5.0 (X11; Linux x86_64; rv:156.0) Gecko/20100101 Firefox/156.0") req.Header.Add("Referer", fmt.Sprintf("https://play.echovideo.ru/embed-1/%s?v=1&asi=0&autoPlay=0&ao=0&autostart=true", id)) req.Header.Add("Priority", "u=4") req.Header.Add("TE", "trailers") resp, err := client.Do(req) if err != nil { return "", oops.Wrap(err) } defer resp.Body.Close() // Essential: Close the body body, err := io.ReadAll(resp.Body) if err != nil { return "", oops.Wrap(err) } sr := PlayEchoVideoSourceResponse{} err = json.Unmarshal(body, &sr) if err != nil { return "", oops.Wrap(err) } return sr.Sources, nil }
Show line notes below