Added Nyaa to file search
Some checks failed
Run Integration Tests / test (push) Failing after 44s

This commit is contained in:
partisan 2025-06-28 17:33:36 +02:00
parent 40f322ef01
commit 67eefc2c7a
3 changed files with 129 additions and 30 deletions

View file

@ -32,7 +32,7 @@ func initFileEngines() {
torrentGalaxy = nil
thePirateBay = nil
// nyaa = nil
nyaa = nil
// rutor = nil
for _, engineName := range config.MetaSearch.Files {
@ -41,8 +41,8 @@ func initFileEngines() {
torrentGalaxy = NewTorrentGalaxy()
case "ThePirateBay":
thePirateBay = NewThePirateBay()
// case "Nyaa":
// nyaa = NewNyaa()
case "Nyaa":
nyaa = NewNyaa()
// case "Rutor":
// rutor = NewRutor()
}
@ -174,33 +174,34 @@ func parseSize(sizeStr string) int64 {
return 0
}
// Use regex to extract numeric value and unit separately
re := regexp.MustCompile(`(?i)([\d.]+)\s*([KMGT]?B)`)
re := regexp.MustCompile(`(?i)([\d.]+)\s*(K?M?G?T?i?B)`)
matches := re.FindStringSubmatch(sizeStr)
if len(matches) < 3 {
printWarn("Error parsing size: invalid format %s", sizeStr)
return 0
}
sizeStr = matches[1]
numStr := matches[1]
unit := strings.ToUpper(matches[2])
var multiplier int64 = 1
switch unit {
case "KB":
case "B":
multiplier = 1
case "KB", "KIB":
multiplier = 1024
case "MB":
case "MB", "MIB":
multiplier = 1024 * 1024
case "GB":
case "GB", "GIB":
multiplier = 1024 * 1024 * 1024
case "TB":
case "TB", "TIB":
multiplier = 1024 * 1024 * 1024 * 1024
default:
printWarn("Unknown unit: %s", unit)
return 0
}
size, err := strconv.ParseFloat(sizeStr, 64)
size, err := strconv.ParseFloat(numStr, 64)
if err != nil {
printWarn("Error parsing size: %v", err)
return 0
@ -226,16 +227,16 @@ func applyTrackers(magnetLink string) string {
}
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)
const unit = 1024
if size < unit {
return fmt.Sprintf("%d B", size)
}
return fmt.Sprintf("%d B", size)
div, exp := unit, 0
for n := size / unit; n >= unit; n /= unit {
div *= unit
exp++
}
return fmt.Sprintf("%.1f %siB", float64(size)/float64(div), []string{"K", "M", "G", "T", "P", "E"}[exp])
}
func sanitizeFileName(name string) string {
@ -245,12 +246,3 @@ func sanitizeFileName(name string) string {
sanitized = regexp.MustCompile(`[^a-zA-Z0-9\-\(\)]`).ReplaceAllString(sanitized, "")
return sanitized
}
func contains(slice []string, item string) bool {
for _, v := range slice {
if v == item {
return true
}
}
return false
}