files update, added torretbay
This commit is contained in:
parent
b17baba0a5
commit
4e8ca3192f
5 changed files with 226 additions and 101 deletions
|
@ -5,8 +5,6 @@ import (
|
|||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
|
@ -108,83 +106,3 @@ func (tg *TorrentGalaxy) Search(query string, category string) ([]TorrentResult,
|
|||
|
||||
return results, nil
|
||||
}
|
||||
|
||||
func parseInt(s string) int {
|
||||
s = strings.ReplaceAll(s, ",", "")
|
||||
result, err := strconv.Atoi(s)
|
||||
if err != nil {
|
||||
log.Printf("Error parsing integer: %v", err)
|
||||
return 0
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func parseSize(sizeStr string) int64 {
|
||||
sizeStr = strings.TrimSpace(sizeStr)
|
||||
if sizeStr == "" {
|
||||
return 0
|
||||
}
|
||||
|
||||
// Use regex to extract numeric value and unit separately
|
||||
re := regexp.MustCompile(`(?i)([\d.]+)\s*([KMGT]?B)`)
|
||||
matches := re.FindStringSubmatch(sizeStr)
|
||||
if len(matches) < 3 {
|
||||
log.Printf("Error parsing size: invalid format %s", sizeStr)
|
||||
return 0
|
||||
}
|
||||
|
||||
sizeStr = matches[1]
|
||||
unit := strings.ToUpper(matches[2])
|
||||
|
||||
var multiplier int64 = 1
|
||||
switch unit {
|
||||
case "KB":
|
||||
multiplier = 1024
|
||||
case "MB":
|
||||
multiplier = 1024 * 1024
|
||||
case "GB":
|
||||
multiplier = 1024 * 1024 * 1024
|
||||
case "TB":
|
||||
multiplier = 1024 * 1024 * 1024 * 1024
|
||||
default:
|
||||
log.Printf("Unknown unit: %s", unit)
|
||||
return 0
|
||||
}
|
||||
|
||||
size, err := strconv.ParseFloat(sizeStr, 64)
|
||||
if err != nil {
|
||||
log.Printf("Error parsing size: %v", err)
|
||||
return 0
|
||||
}
|
||||
return int64(size * float64(multiplier))
|
||||
}
|
||||
|
||||
//apparently this is needed so it can announce that magnet link is being used and people start seeding it, but I dont like the fact that I add trackers purusefully
|
||||
func applyTrackers(magnetLink string) string {
|
||||
if magnetLink == "" {
|
||||
return ""
|
||||
}
|
||||
trackers := []string{
|
||||
"udp://tracker.openbittorrent.com:80/announce",
|
||||
"udp://tracker.opentrackr.org:1337/announce",
|
||||
"udp://tracker.coppersurfer.tk:6969/announce",
|
||||
"udp://tracker.leechers-paradise.org:6969/announce",
|
||||
}
|
||||
for _, tracker := range trackers {
|
||||
magnetLink += "&tr=" + url.QueryEscape(tracker)
|
||||
}
|
||||
return magnetLink
|
||||
}
|
||||
|
||||
func formatSize(size int64) string {
|
||||
if size >= 1024*1024*1024*1024 {
|
||||
return fmt.Sprintf("%.2f TB", float64(size)/(1024*1024*1024*1024))
|
||||
} else if size >= 1024*1024*1024 {
|
||||
return fmt.Sprintf("%.2f GB", float64(size)/(1024*1024*1024))
|
||||
} else if size >= 1024*1024 {
|
||||
return fmt.Sprintf("%.2f MB", float64(size)/(1024*1024))
|
||||
} else if size >= 1024 {
|
||||
return fmt.Sprintf("%.2f KB", float64(size)/1024)
|
||||
}
|
||||
return fmt.Sprintf("%d B", size)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue