mark as unplayable and availability check
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user