Commit 7584ad3c28
Unsigned
Layout: unified · split
internal/episode_url.go +7 −49
| @@ -11,14 +11,6 @@ import ( | ||
| 11 | 11 | "unicode" |
| 12 | 12 | ) |
| 13 | 13 | |
| 14 | type config struct { | |
| 15 | Agent string | |
| 16 | AllanimeRefr string | |
| 17 | AllanimeBase string | |
| 18 | AllanimeAPI string | |
| 19 | Mode string | |
| 20 | Quality string | |
| 21 | } | |
| 22 | 14 | |
| 23 | 15 | type allanimeResponse struct { |
| 24 | 16 | Data struct { |
| @@ -30,17 +22,6 @@ type allanimeResponse struct { | ||
| 30 | 22 | } `json:"data"` |
| 31 | 23 | } |
| 32 | 24 | |
| 33 | func 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 | ||
| 44 | 25 | func decodeProviderID(encoded string) string { |
| 45 | 26 | // Split the string into pairs of characters (.. equivalent of 'sed s/../&\n/g') |
| 46 | 27 | re := regexp.MustCompile("..") |
| @@ -124,13 +105,13 @@ func extractLinks(provider_id string) map[string]interface{} { | ||
| 124 | 105 | // Returns: |
| 125 | 106 | // - []string: a list of links for specified episode. |
| 126 | 107 | // - error: an error if the episode is not found or if there is an issue during the search. |
| 127 | func GetEpisodeURL(config config, id, epNo string) ([]string, error) { | |
| 108 | func GetEpisodeURL(config CurdConfig, id string, epNo int) ([]string, error) { | |
| 128 | 109 | query := `query($showId:String!,$translationType:VaildTranslationTypeEnumType!,$episodeString:String!){episode(showId:$showId,translationType:$translationType,episodeString:$episodeString){episodeString sourceUrls}}` |
| 129 | 110 | |
| 130 | 111 | variables := map[string]string{ |
| 131 | 112 | "showId": id, |
| 132 | "translationType": config.Mode, | |
| 133 | "episodeString": epNo, | |
| 113 | "translationType": config.SubOrDub, | |
| 114 | "episodeString": fmt.Sprintf("%d", epNo), | |
| 134 | 115 | } |
| 135 | 116 | |
| 136 | 117 | variablesJSON, err := json.Marshal(variables) |
| @@ -142,7 +123,7 @@ func GetEpisodeURL(config config, id, epNo string) ([]string, error) { | ||
| 142 | 123 | values.Set("query", query) |
| 143 | 124 | values.Set("variables", string(variablesJSON)) |
| 144 | 125 | |
| 145 | reqURL := fmt.Sprintf("%s/api?%s", config.AllanimeAPI, values.Encode()) | |
| 126 | reqURL := fmt.Sprintf("%s/api?%s", "https://api.allanime.day", values.Encode()) | |
| 146 | 127 | |
| 147 | 128 | client := &http.Client{} |
| 148 | 129 | req, err := http.NewRequest("GET", reqURL, nil) |
| @@ -150,8 +131,8 @@ func GetEpisodeURL(config config, id, epNo string) ([]string, error) { | ||
| 150 | 131 | return nil, err |
| 151 | 132 | } |
| 152 | 133 | |
| 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") | |
| 155 | 136 | |
| 156 | 137 | resp, err := client.Do(req) |
| 157 | 138 | if err != nil { |
| @@ -195,27 +176,4 @@ func GetEpisodeURL(config config, id, epNo string) ([]string, error) { | ||
| 195 | 176 | } |
| 196 | 177 | |
| 197 | 178 | 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 | ||