package realdebrid import ( "encoding/json" "math" "strings" ) type FileJSON struct { FileSize int `json:"filesize"` Link string `json:"link"` } type Download struct { Filename string `json:"filename"` Filesize int64 `json:"filesize"` // bytes, 0 if unknown Link string `json:"link"` // Original link Host string `json:"host"` // Host main domain Download string `json:"download"` // Generated link Streamable int `json:"streamable"` } type Torrent struct { ID string `json:"id"` Name string `json:"filename"` Progress int `json:"-"` Links []string `json:"links"` Added string `json:"-"` } func (i *Torrent) UnmarshalJSON(data []byte) error { type Alias Torrent aux := &struct { Progress float64 `json:"progress"` Added string `json:"added"` *Alias }{ Alias: (*Alias)(i), } if err := json.Unmarshal(data, &aux); err != nil { return err } i.Progress = int(math.Round(aux.Progress)) i.Added = strings.Replace(aux.Added, "Z", "+01:00", 1) return nil } type TorrentInfo struct { ID string `json:"id"` Name string `json:"filename"` Hash string `json:"hash"` Progress int `json:"-"` Status string `json:"status"` Added string `json:"-"` Ended string `json:"-"` Bytes int64 `json:"bytes"` Links []string `json:"links"` OriginalName string `json:"original_filename"` OriginalBytes int64 `json:"original_bytes"` Files []File `json:"files"` Version string `json:"-"` } func (i *TorrentInfo) UnmarshalJSON(data []byte) error { type Alias TorrentInfo aux := &struct { Progress float64 `json:"progress"` Added string `json:"added"` Ended string `json:"ended"` *Alias }{ Alias: (*Alias)(i), } if err := json.Unmarshal(data, &aux); err != nil { return err } i.Progress = int(math.Round(aux.Progress)) i.Added = strings.Replace(aux.Added, "Z", "+01:00", 1) if aux.Ended != "" { i.Ended = strings.Replace(aux.Ended, "Z", "+01:00", 1) } return nil } type File struct { ID int `json:"id"` Path string `json:"path"` Bytes int64 `json:"bytes"` Selected int `json:"selected"` } type MagnetResponse struct { ID string `json:"id"` URI string `json:"uri"` } type ActiveTorrentCountResponse struct { DownloadingCount int `json:"nb"` MaxNumberOfTorrents int `json:"limit"` }