package main import ( "crypto/sha1" "fmt" "net/http" "strings" "github.com/PuerkitoBio/goquery" ) func getLimeTorrentsDownloadUrl(url string) (string, error) { resp, err := http.Get(url) if err != nil { return "", fmt.Errorf("couldn't fetch html: %v", err) } defer resp.Body.Close() doc, err := goquery.NewDocumentFromReader(resp.Body) if err != nil { return "", fmt.Errorf("couldn't create document from response: %v", err) } href := "" doc.Find("a.csprite_dltorrent").Each(func(i int, s *goquery.Selection) { h, hasHref := s.Attr("href") if !hasHref { return } if strings.HasPrefix(h, "https://") { href = h } }) if href == "" { return "", fmt.Errorf("couldn't find download url") } return href, nil } func toSha1(b []byte) string { hash := sha1.New() hash.Write(b) return fmt.Sprintf("%x", hash.Sum(nil)) }