func getListFromSlug(slug string) (*List, error) { list := List{} client := &http.Client{Transport: &http.Transport{}} data := url.Values{} data.Set("entity_slug", slug) data.Set("platform", "web") data.Add("ui", "012021") encodedData := data.Encode() req, err := newRequest("POST", "https://api.vieon.vn/backend/cm/v5/slug/episode", encodedData, "limit=50&platform=web&ui=012021") if err != nil { return nil, err } res, err := client.Do(req) if err != nil { return nil, err } defer res.Body.Close() if err := decoder.NewStreamDecoder(res.Body).Decode(&list); err != nil { return nil, err } totalPages := (list.Metadata.Total + 49) / 50 for i := 1; i < totalPages; i++ { temp := List{} req, err := newRequest("POST", "https://api.vieon.vn/backend/cm/v5/slug/episode", encodedData, fmt.Sprintf("page=%d&limit=50&platform=web&ui=012021", i)) if err != nil { return nil, err } res, err := client.Do(req) if err != nil { return nil, err } defer res.Body.Close() if res.StatusCode == 200 { if err := json.NewDecoder(res.Body).Decode(&temp); err != nil { return nil, err } list.Episodes = append(list.Episodes, temp.Episodes...) } } return &list, nil } func newRequest(method, urlStr, data, query string) (*http.Request, error) { u, err := url.Parse(urlStr) if err != nil { return nil, err } u.RawQuery = query req, err := http.NewRequest(method, u.String(), strings.NewReader(data)) if err != nil { return nil, err } req.Header.Set("Content-Type", "application/x-www-form-urlencoded") return req, nil } func getHls(url string) (string, error) { req, err := http.NewRequest("GET", url, nil) if err != nil { return "", err } req.Header = header res, err := httpClient.Do(req) if err != nil { return "", err } defer res.Body.Close() if res.StatusCode != http.StatusOK { return "", fmt.Errorf("unexpected status code: %d", res.StatusCode) } link := Link{} err = decoder.NewStreamDecoder(res.Body).Decode(&link) if err != nil { return "", err } if link.PlayLinks.H265.Hls != "" { return link.PlayLinks.H265.Hls, nil } return link.PlayLinks.H264.Hls, nil }