Proactive repair
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package realdebrid
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"math"
|
||||
"strings"
|
||||
|
||||
@@ -134,8 +135,11 @@ type User struct {
|
||||
// key: torrent hash
|
||||
type AvailabilityResponse map[string]HosterHash
|
||||
|
||||
// key: "rd"
|
||||
type HosterHash map[string][]SelectionVariant
|
||||
type HosterHash struct {
|
||||
// key: "rd"
|
||||
Variants map[string][]SelectionVariant
|
||||
Strings []string
|
||||
}
|
||||
|
||||
// key: file id
|
||||
type SelectionVariant map[int]FileData
|
||||
@@ -144,3 +148,21 @@ type FileData struct {
|
||||
Filename string `json:"filename"`
|
||||
Filesize int `json:"filesize"`
|
||||
}
|
||||
|
||||
func (h *HosterHash) UnmarshalJSON(data []byte) error {
|
||||
// First, try unmarshaling as map[string][]SelectionVariant
|
||||
var variants map[string][]SelectionVariant
|
||||
if err := json.Unmarshal(data, &variants); err == nil {
|
||||
h.Variants = variants
|
||||
return nil
|
||||
}
|
||||
|
||||
// If that fails, try unmarshaling as []string
|
||||
var strings []string
|
||||
if err := json.Unmarshal(data, &strings); err == nil {
|
||||
h.Strings = strings
|
||||
return nil
|
||||
}
|
||||
|
||||
return errors.New("availability json data did not match expected formats (map or array)")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user