This commit is contained in:
2026-02-02 23:00:03 +03:00
commit be8ea42808
27 changed files with 3598 additions and 0 deletions

47
utils.go Normal file
View File

@@ -0,0 +1,47 @@
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))
}