mark as unplayable and availability check
This commit is contained in:
@@ -22,11 +22,24 @@ func (t *TorrentManager) RepairAll() {
|
|||||||
|
|
||||||
func (t *TorrentManager) repairAll() {
|
func (t *TorrentManager) repairAll() {
|
||||||
allTorrents, _ := t.DirectoryMap.Get(INT_ALL)
|
allTorrents, _ := t.DirectoryMap.Get(INT_ALL)
|
||||||
|
|
||||||
|
hashes := make([]string, 0)
|
||||||
|
allTorrents.IterCb(func(_ string, torrent *Torrent) {
|
||||||
|
if torrent.AnyInProgress() || torrent.Unfixable {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
hashes = append(hashes, torrent.Hash)
|
||||||
|
})
|
||||||
|
|
||||||
var toRepair []*Torrent
|
var toRepair []*Torrent
|
||||||
allTorrents.IterCb(func(_ string, torrent *Torrent) {
|
allTorrents.IterCb(func(_ string, torrent *Torrent) {
|
||||||
if torrent.AnyInProgress() || torrent.Unfixable {
|
if torrent.AnyInProgress() || torrent.Unfixable {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check 1: for cached status
|
||||||
|
|
||||||
|
// check 2: for broken files
|
||||||
hasBrokenFiles := false
|
hasBrokenFiles := false
|
||||||
torrent.SelectedFiles.IterCb(func(_ string, file *File) {
|
torrent.SelectedFiles.IterCb(func(_ string, file *File) {
|
||||||
if file.Link == "repair" || file.Link == "" {
|
if file.Link == "repair" || file.Link == "" {
|
||||||
@@ -135,11 +148,7 @@ func (t *TorrentManager) repair(torrent *Torrent) {
|
|||||||
}
|
}
|
||||||
torrent.SelectedFiles.Set(unassigned.Filename, newFile)
|
torrent.SelectedFiles.Set(unassigned.Filename, newFile)
|
||||||
}
|
}
|
||||||
t.DirectoryMap.IterCb(func(directory string, torrents cmap.ConcurrentMap[string, *Torrent]) {
|
t.markAsUnplayable(torrent)
|
||||||
torrents.Remove(torrent.AccessKey)
|
|
||||||
})
|
|
||||||
torrents, _ := t.DirectoryMap.Get(config.UNPLAYABLE_TORRENTS)
|
|
||||||
torrents.Set(torrent.AccessKey, torrent)
|
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -177,7 +186,7 @@ func (t *TorrentManager) repair(torrent *Torrent) {
|
|||||||
t.log.Infof("Successfully downloaded torrent %s to repair it", torrent.AccessKey)
|
t.log.Infof("Successfully downloaded torrent %s to repair it", torrent.AccessKey)
|
||||||
} else {
|
} else {
|
||||||
t.log.Warnf("Failed to repair torrent %s", torrent.AccessKey)
|
t.log.Warnf("Failed to repair torrent %s", torrent.AccessKey)
|
||||||
torrent.Unfixable = true
|
t.markAsUnplayable(torrent)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
t.log.Warnf("Torrent %s has no broken files to repair", torrent.AccessKey)
|
t.log.Warnf("Torrent %s has no broken files to repair", torrent.AccessKey)
|
||||||
@@ -298,3 +307,13 @@ func (t *TorrentManager) canCapacityHandle() bool {
|
|||||||
retryCount++
|
retryCount++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *TorrentManager) markAsUnplayable(torrent *Torrent) {
|
||||||
|
t.log.Warnf("Marking torrent %s as unplayable", torrent.AccessKey)
|
||||||
|
torrent.Unfixable = true
|
||||||
|
t.DirectoryMap.IterCb(func(directory string, torrents cmap.ConcurrentMap[string, *Torrent]) {
|
||||||
|
torrents.Remove(torrent.AccessKey)
|
||||||
|
})
|
||||||
|
torrents, _ := t.DirectoryMap.Get(config.UNPLAYABLE_TORRENTS)
|
||||||
|
torrents.Set(torrent.AccessKey, torrent)
|
||||||
|
}
|
||||||
|
|||||||
@@ -390,3 +390,35 @@ func (rd *RealDebrid) GetUserInformation() (*User, error) {
|
|||||||
|
|
||||||
return &user, nil
|
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
|
Premium int `json:"premium"` // seconds left as a Premium user
|
||||||
Expiration string `json:"expiration"` // jsonDate
|
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