mark as unplayable and availability check

This commit is contained in:
Ben Sarmiento
2024-01-07 18:24:12 +01:00
parent 769c4a6803
commit cfb0f12fff
3 changed files with 71 additions and 6 deletions

View File

@@ -390,3 +390,35 @@ func (rd *RealDebrid) GetUserInformation() (*User, error) {
return &user, nil
}
// AvailabilityCheck checks the instant availability of torrents
func (rd *RealDebrid) AvailabilityCheck(hashes []string) (AvailabilityResponse, error) {
if len(hashes) == 0 {
return nil, fmt.Errorf("no hashes provided")
}
baseURL := "https://api.real-debrid.com/rest/1.0"
url := fmt.Sprintf("%s/torrents/instantAvailability/%s", baseURL, strings.Join(hashes, "/"))
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return nil, err
}
resp, err := rd.client.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("error, got response status code %d", resp.StatusCode)
}
var response AvailabilityResponse
err = json.NewDecoder(resp.Body).Decode(&response)
if err != nil {
return nil, err
}
return response, nil
}

View File

@@ -130,3 +130,17 @@ type User struct {
Premium int `json:"premium"` // seconds left as a Premium user
Expiration string `json:"expiration"` // jsonDate
}
// key: torrent hash
type AvailabilityResponse map[string]HosterHash
// key: "rd"
type HosterHash map[string][]SelectionVariant
// key: file id
type SelectionVariant map[int]FileData
type FileData struct {
Filename string `json:"filename"`
Filesize int `json:"filesize"`
}