Random Fixes:
- Fix uncached error - Fix naming and race conditions
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
+9
-1
@@ -217,6 +217,13 @@ func (item Item) getHash() string {
|
||||
//if err == nil && magnet != nil && magnet.InfoHash != "" {
|
||||
// log.Printf("Magnet: %s", magnet.InfoHash)
|
||||
//}
|
||||
|
||||
if strings.Contains(magnetLink, "http") {
|
||||
h, _ := common.GetInfohashFromURL(magnetLink)
|
||||
if h != "" {
|
||||
infohash = h
|
||||
}
|
||||
}
|
||||
}
|
||||
return infohash
|
||||
|
||||
@@ -249,7 +256,6 @@ func (p *Proxy) ProcessXMLResponse(resp *http.Response) *http.Response {
|
||||
if len(rss.Channel.Items) > 0 {
|
||||
indexer = rss.Channel.Items[0].ProwlarrIndexer.Text
|
||||
} else {
|
||||
p.logger.Println("No items found in RSS feed")
|
||||
resp.Body = io.NopCloser(bytes.NewReader(body))
|
||||
return resp
|
||||
}
|
||||
@@ -283,6 +289,8 @@ func (p *Proxy) ProcessXMLResponse(resp *http.Response) *http.Response {
|
||||
p.logger.Printf("[%s Report]: %d/%d items are cached || Found %d infohash", indexer, len(newItems), len(rss.Channel.Items), len(hashes))
|
||||
} else {
|
||||
// This will prevent the indexer from being disabled by the arr
|
||||
//filename := common.RandomString(10) + ".xml"
|
||||
//_ = os.WriteFile(filename, body, 0644)
|
||||
p.logger.Printf("[%s Report]: No Items are cached; Return only first item with [UnCached]", indexer)
|
||||
item := rss.Channel.Items[0]
|
||||
item.Title = fmt.Sprintf("%s [UnCached]", item.Title)
|
||||
|
||||
@@ -37,15 +37,9 @@ func (q *QBit) handleTorrentsAdd(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
files := r.MultipartForm.File["torrents"]
|
||||
urls := r.FormValue("urls")
|
||||
category := r.FormValue("category")
|
||||
|
||||
if len(files) == 0 && urls == "" {
|
||||
http.Error(w, "No torrent provided", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
var urlList []string
|
||||
if urls != "" {
|
||||
urlList = strings.Split(urls, "\n")
|
||||
@@ -62,18 +56,22 @@ func (q *QBit) handleTorrentsAdd(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
}
|
||||
|
||||
for _, fileHeader := range files {
|
||||
file, _ := fileHeader.Open()
|
||||
defer file.Close()
|
||||
var reader io.Reader = file
|
||||
magnet, err := common.GetMagnetFromFile(reader, fileHeader.Filename)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
q.logger.Printf("Error reading file: %s", fileHeader.Filename)
|
||||
return
|
||||
if contentType == "multipart/form-data" {
|
||||
files := r.MultipartForm.File["torrents"]
|
||||
for _, fileHeader := range files {
|
||||
file, _ := fileHeader.Open()
|
||||
defer file.Close()
|
||||
var reader io.Reader = file
|
||||
magnet, err := common.GetMagnetFromFile(reader, fileHeader.Filename)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
q.logger.Printf("Error reading file: %s", fileHeader.Filename)
|
||||
return
|
||||
}
|
||||
go q.Process(magnet, category)
|
||||
}
|
||||
go q.Process(magnet, category)
|
||||
}
|
||||
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
||||
|
||||
+4
-1
@@ -17,11 +17,14 @@ func (q *QBit) Process(magnet *common.Magnet, category string) (*Torrent, error)
|
||||
debridTorrent, err := debrid.ProcessQBitTorrent(q.debrid, magnet, category)
|
||||
if err != nil || debridTorrent == nil {
|
||||
// Mark as failed
|
||||
q.logger.Printf("Failed to process torrent: %s: %v", magnet.Name, err)
|
||||
q.MarkAsFailed(torrent)
|
||||
return torrent, err
|
||||
}
|
||||
torrent.ID = debridTorrent.Id
|
||||
q.processFiles(torrent, debridTorrent)
|
||||
torrent.Name = debridTorrent.Name // Update the name before adding it to *arrs storage
|
||||
torrent.DebridTorrent = debridTorrent
|
||||
go q.processFiles(torrent, debridTorrent)
|
||||
return torrent, nil
|
||||
}
|
||||
|
||||
|
||||
+4
-1
@@ -1,5 +1,7 @@
|
||||
package qbit
|
||||
|
||||
import "goBlack/pkg/debrid"
|
||||
|
||||
type BuildInfo struct {
|
||||
Libtorrent string `json:"libtorrent"`
|
||||
Bitness int `json:"bitness"`
|
||||
@@ -167,7 +169,8 @@ type TorrentCategory struct {
|
||||
}
|
||||
|
||||
type Torrent struct {
|
||||
ID string `json:"-"`
|
||||
ID string `json:"-"`
|
||||
DebridTorrent *debrid.Torrent `json:"-"`
|
||||
|
||||
AddedOn int64 `json:"added_on,omitempty"`
|
||||
AmountLeft int64 `json:"amount_left,omitempty"`
|
||||
|
||||
+1
-1
@@ -49,7 +49,7 @@ func (q *QBit) UpdateTorrent(t *Torrent, debridTorrent *debrid.Torrent) *Torrent
|
||||
t.Uploaded = sizeCompleted
|
||||
t.UploadedSession = sizeCompleted
|
||||
t.AmountLeft = totalSize - sizeCompleted
|
||||
t.Progress = 100
|
||||
t.Progress = float32(progress)
|
||||
t.SavePath = savePath
|
||||
t.ContentPath = torrentPath
|
||||
t.Eta = eta
|
||||
|
||||
Reference in New Issue
Block a user