Skip to content

Commit

Permalink
Merge pull request #111 from sonroyaalmerol/fix-sorting
Browse files Browse the repository at this point in the history
Add zero padding on integer/float tvg-id or tvg-chno values to fix sorting
  • Loading branch information
sonroyaalmerol authored Aug 24, 2024
2 parents 4e3762c + 4571163 commit 01afbb7
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions database/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,19 +384,28 @@ func extractM3UIndex(key string) string {
func getSortingValue(s StreamInfo) string {
key := os.Getenv("SORTING_KEY")

var value string
switch key {
case "tvg-id":
return s.TvgID + s.Title
value = s.TvgID
case "tvg-chno":
return s.TvgChNo + s.Title
value = s.TvgChNo
default:
value = s.TvgID
}

return s.TvgID + s.Title
// Try to parse the value as a float.
if numValue, err := strconv.ParseFloat(value, 64); err == nil {
return fmt.Sprintf("%010.2f", numValue) + s.Title
}

// If parsing fails, fall back to using the original string value.
return value + s.Title
}

func calculateSortScore(s StreamInfo) float64 {
// Add to the sorted set with tvg_id as the score
maxLen := 20
maxLen := 40
base := float64(256)

// Normalize length by padding the string
Expand Down

0 comments on commit 01afbb7

Please sign in to comment.