Random Fixes:

- Fix uncached error
- Fix naming and race conditions
This commit is contained in:
Mukhtar Akere
2024-09-14 01:42:52 +01:00
parent 9511f3e99e
commit f622cbfe63
12 changed files with 108 additions and 75 deletions

View File

@@ -12,7 +12,6 @@ type Service interface {
SubmitMagnet(torrent *Torrent) (*Torrent, error)
CheckStatus(torrent *Torrent) (*Torrent, error)
DownloadLink(torrent *Torrent) error
Process(arr *Arr, magnet string) (*Torrent, error)
IsAvailable(infohashes []string) map[string]bool
GetMountPath() string
GetDownloadUncached() bool
@@ -132,17 +131,19 @@ func ProcessQBitTorrent(d Service, magnet *common.Magnet, category string) (*Tor
Size: magnet.Size,
}
logger := d.GetLogger()
logger.Printf("Torrent Name: %s", debridTorrent.Name)
logger.Printf("Torrent Hash: %s", debridTorrent.InfoHash)
if !d.GetDownloadUncached() {
hash, exists := d.IsAvailable([]string{debridTorrent.InfoHash})[debridTorrent.InfoHash]
if !exists || !hash {
return debridTorrent, fmt.Errorf("torrent is not cached")
return debridTorrent, fmt.Errorf("torrent: %s is not cached", debridTorrent.Name)
} else {
logger.Printf("Torrent: %s is cached", debridTorrent.Name)
}
logger.Printf("Torrent: %s is cached", debridTorrent.Name)
}
debridTorrent, err := d.SubmitMagnet(debridTorrent)
if err != nil || debridTorrent.Id == "" {
logger.Printf("Error submitting magnet: %s", err)
return nil, err
}
return d.CheckStatus(debridTorrent)

View File

@@ -55,28 +55,6 @@ func GetTorrentFiles(data structs.RealDebridTorrentInfo) []TorrentFile {
return files
}
func (r *RealDebrid) Process(arr *Arr, magnet string) (*Torrent, error) {
torrent, err := GetTorrentInfo(magnet)
torrent.Arr = arr
if err != nil {
return torrent, err
}
log.Printf("Torrent Name: %s", torrent.Name)
if !r.DownloadUncached {
hash, exists := r.IsAvailable([]string{torrent.InfoHash})[torrent.InfoHash]
if !exists || !hash {
return torrent, fmt.Errorf("torrent is not cached")
}
log.Printf("Torrent: %s is cached", torrent.Name)
}
torrent, err = r.SubmitMagnet(torrent)
if err != nil || torrent.Id == "" {
return nil, err
}
return r.CheckStatus(torrent)
}
func (r *RealDebrid) IsAvailable(infohashes []string) map[string]bool {
// Check if the infohashes are available in the local cache
hashes, result := GetLocalCache(infohashes, r.cache)
@@ -183,7 +161,9 @@ func (r *RealDebrid) CheckStatus(torrent *Torrent) (*Torrent, error) {
var data structs.RealDebridTorrentInfo
err = json.Unmarshal(resp, &data)
status := data.Status
torrent.Folder = common.RemoveExtension(data.OriginalFilename)
name := common.RemoveExtension(data.OriginalFilename)
torrent.Name = name // Important because some magnet changes the name
torrent.Folder = name
torrent.Bytes = data.Bytes
torrent.Progress = data.Progress
torrent.Speed = data.Speed