Commit 7584ad3c28

7584ad3c285813471f2481e047f0a0e0e3a4e5dc

parent: 3456a74860

Unsigned

Wraient <wraient.911@gmail.com> · 2024-10-19 21:06 UTC

Fix: Structure change

Layout: unified · split

internal/episode_url.go +7 −49
@@ -11,14 +11,6 @@ import (
1111 "unicode"
1212)
1313
14type config struct {
15 Agent string
16 AllanimeRefr string
17 AllanimeBase string
18 AllanimeAPI string
19 Mode string
20 Quality string
21}
2214
2315type allanimeResponse struct {
2416 Data struct {
@@ -30,17 +22,6 @@ type allanimeResponse struct {
3022 } `json:"data"`
3123}
3224
33func GetDefaultAllanimeConfig() config {
34 return config{
35 Agent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/121.0",
36 AllanimeRefr: "https://allanime.to",
37 AllanimeBase: "allanime.day",
38 AllanimeAPI: "https://api.allanime.day",
39 Mode: "sub",
40 Quality: "best",
41 }
42}
43
4425func decodeProviderID(encoded string) string {
4526 // Split the string into pairs of characters (.. equivalent of 'sed s/../&\n/g')
4627 re := regexp.MustCompile("..")
@@ -124,13 +105,13 @@ func extractLinks(provider_id string) map[string]interface{} {
124105// Returns:
125106// - []string: a list of links for specified episode.
126107// - error: an error if the episode is not found or if there is an issue during the search.
127func GetEpisodeURL(config config, id, epNo string) ([]string, error) {
108func GetEpisodeURL(config CurdConfig, id string, epNo int) ([]string, error) {
128109 query := `query($showId:String!,$translationType:VaildTranslationTypeEnumType!,$episodeString:String!){episode(showId:$showId,translationType:$translationType,episodeString:$episodeString){episodeString sourceUrls}}`
129110
130111 variables := map[string]string{
131112 "showId": id,
132 "translationType": config.Mode,
133 "episodeString": epNo,
113 "translationType": config.SubOrDub,
114 "episodeString": fmt.Sprintf("%d", epNo),
134115 }
135116
136117 variablesJSON, err := json.Marshal(variables)
@@ -142,7 +123,7 @@ func GetEpisodeURL(config config, id, epNo string) ([]string, error) {
142123 values.Set("query", query)
143124 values.Set("variables", string(variablesJSON))
144125
145 reqURL := fmt.Sprintf("%s/api?%s", config.AllanimeAPI, values.Encode())
126 reqURL := fmt.Sprintf("%s/api?%s", "https://api.allanime.day", values.Encode())
146127
147128 client := &http.Client{}
148129 req, err := http.NewRequest("GET", reqURL, nil)
@@ -150,8 +131,8 @@ func GetEpisodeURL(config config, id, epNo string) ([]string, error) {
150131 return nil, err
151132 }
152133
153 req.Header.Set("User-Agent", config.Agent)
154 req.Header.Set("Referer", config.AllanimeRefr)
134 req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/121.0")
135 req.Header.Set("Referer", "https://allanime.to")
155136
156137 resp, err := client.Do(req)
157138 if err != nil {
@@ -195,27 +176,4 @@ func GetEpisodeURL(config config, id, epNo string) ([]string, error) {
195176 }
196177
197178 return allinks, nil
198}
199
200// func main() {
201// config := getDefaultConfig()
202
203// id := "ReooPAxPMsHM4KPMY" // One piece
204// // id := "RezHft5pjutwWcE3B" // Death note
205// epNo := "945"
206
207// links, err := getEpisodeURL(config, id, epNo)
208// if err != nil {
209// fmt.Printf("Error: %v\n", err)
210// if strings.Contains(err.Error(), "no source URLs found") {
211// fmt.Println("Episode not released!")
212// }
213// os.Exit(1)
214// }
215
216// // Print all found links
217// // fmt.Println("links:", links)
218// for _, link := range links {
219// fmt.Println(link)
220// }
221// }
\ No newline at end of file
179}
\ No newline at end of file