fix(releases): set freeleech from downloadVolumeFactor (#1873)

* fix(releases): set freeleech from downloadVolumeFactor

* fix(releases): set freeleechpercent from downloadVolumeFactor
This commit is contained in:
ze0s 2024-12-11 16:44:09 +01:00 committed by GitHub
parent 24f31574e5
commit e808edab50
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -10,6 +10,7 @@ import (
"fmt" "fmt"
"html" "html"
"io" "io"
"math"
"net/http" "net/http"
"net/http/cookiejar" "net/http/cookiejar"
"os" "os"
@ -786,8 +787,7 @@ func (r *Release) MapVars(def *IndexerDefinition, varMap map[string]string) erro
} }
} }
//if downloadVolumeFactor, err := getStringMapValue(varMap, "downloadVolumeFactor"); err == nil { if downloadVolumeFactorVar, ok := varMap["downloadVolumeFactor"]; ok {
if downloadVolumeFactor, ok := varMap["downloadVolumeFactor"]; ok {
// special handling for BHD to map their freeleech into percent // special handling for BHD to map their freeleech into percent
//if def.Identifier == "beyondhd" { //if def.Identifier == "beyondhd" {
// if freeleechPercent == "Capped FL" { // if freeleechPercent == "Capped FL" {
@ -799,14 +799,24 @@ func (r *Release) MapVars(def *IndexerDefinition, varMap map[string]string) erro
//r.downloadVolumeFactor = downloadVolumeFactor //r.downloadVolumeFactor = downloadVolumeFactor
value, parseErr := strconv.ParseInt(downloadVolumeFactor, 10, 64) // Parse the value as decimal number
downloadVolumeFactor, parseErr := strconv.ParseFloat(downloadVolumeFactorVar, 64)
if parseErr == nil { if parseErr == nil {
percentage := value * 100 // Values below 0.0 and above 1.0 are rejected
r.FreeleechPercent = int(percentage) if downloadVolumeFactor >= 0 || downloadVolumeFactor <= 1 {
} // Multiply by 100 to convert from ratio to percentage and round it
// to the nearest integer value
downloadPercentage := math.Round(downloadVolumeFactor * 100)
// To convert from download percentage to freeleech percentage the
// value is inverted
r.FreeleechPercent = 100 - int(downloadPercentage)
if r.FreeleechPercent > 0 {
r.Freeleech = true r.Freeleech = true
} }
}
}
}
//if uploadVolumeFactor, err := getStringMapValue(varMap, "uploadVolumeFactor"); err == nil { //if uploadVolumeFactor, err := getStringMapValue(varMap, "uploadVolumeFactor"); err == nil {
// // special handling for BHD to map their freeleech into percent // // special handling for BHD to map their freeleech into percent