Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
01981114cb | ||
|
|
2ec0354881 |
@@ -54,4 +54,10 @@
|
|||||||
#### 0.2.2
|
#### 0.2.2
|
||||||
- Fix name mismatch in the cache
|
- Fix name mismatch in the cache
|
||||||
- Fix directory mapping with mounts
|
- Fix directory mapping with mounts
|
||||||
- Add Support for refreshing the *arrs
|
- Add Support for refreshing the *arrs
|
||||||
|
|
||||||
|
#### 0.2.3
|
||||||
|
|
||||||
|
- Delete uncached items from RD
|
||||||
|
- Fail if the torrent is not cached(optional)
|
||||||
|
- Fix cache not being updated
|
||||||
@@ -12,6 +12,7 @@ type Service interface {
|
|||||||
SubmitMagnet(torrent *Torrent) (*Torrent, error)
|
SubmitMagnet(torrent *Torrent) (*Torrent, error)
|
||||||
CheckStatus(torrent *Torrent) (*Torrent, error)
|
CheckStatus(torrent *Torrent) (*Torrent, error)
|
||||||
DownloadLink(torrent *Torrent) error
|
DownloadLink(torrent *Torrent) error
|
||||||
|
DeleteTorrent(torrent *Torrent)
|
||||||
IsAvailable(infohashes []string) map[string]bool
|
IsAvailable(infohashes []string) map[string]bool
|
||||||
GetMountPath() string
|
GetMountPath() string
|
||||||
GetDownloadUncached() bool
|
GetDownloadUncached() bool
|
||||||
@@ -134,7 +135,7 @@ func ProcessQBitTorrent(d Service, magnet *common.Magnet, arr *Arr) (*Torrent, e
|
|||||||
if !exists || !hash {
|
if !exists || !hash {
|
||||||
return debridTorrent, fmt.Errorf("torrent: %s is not cached", debridTorrent.Name)
|
return debridTorrent, fmt.Errorf("torrent: %s is not cached", debridTorrent.Name)
|
||||||
} else {
|
} else {
|
||||||
logger.Printf("Torrent: %s is cached", debridTorrent.Name)
|
logger.Printf("Torrent: %s is cached(or downloading)", debridTorrent.Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -201,12 +201,30 @@ func (r *RealDebrid) CheckStatus(torrent *Torrent) (*Torrent, error) {
|
|||||||
return torrent, err
|
return torrent, err
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
|
} else if status == "downloading" {
|
||||||
|
if !r.DownloadUncached {
|
||||||
|
go r.DeleteTorrent(torrent)
|
||||||
|
return torrent, fmt.Errorf("torrent: %s not cached", torrent.Name)
|
||||||
|
}
|
||||||
|
// Break out of the loop if the torrent is downloading.
|
||||||
|
// This is necessary to prevent infinite loop since we moved to sync downloading and async processing
|
||||||
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return torrent, nil
|
return torrent, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *RealDebrid) DeleteTorrent(torrent *Torrent) {
|
||||||
|
url := fmt.Sprintf("%s/torrents/delete/%s", r.Host, torrent.Id)
|
||||||
|
_, err := r.client.MakeRequest(http.MethodDelete, url, nil)
|
||||||
|
if err == nil {
|
||||||
|
r.logger.Printf("Torrent: %s deleted\n", torrent.Name)
|
||||||
|
} else {
|
||||||
|
r.logger.Printf("Error deleting torrent: %s", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (r *RealDebrid) DownloadLink(torrent *Torrent) error {
|
func (r *RealDebrid) DownloadLink(torrent *Torrent) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
package qbit
|
package qbit
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"goBlack/common"
|
|
||||||
"io"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -47,29 +45,21 @@ func (q *QBit) handleTorrentsAdd(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, url := range urlList {
|
for _, url := range urlList {
|
||||||
magnet, err := common.GetMagnetFromUrl(url)
|
if err := q.AddMagnet(ctx, url, category); err != nil {
|
||||||
if err != nil {
|
q.logger.Printf("Error adding magnet: %v\n", err)
|
||||||
q.logger.Printf("Error parsing magnet link: %v\n", err)
|
|
||||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
go q.Process(ctx, magnet, category)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if contentType == "multipart/form-data" {
|
if contentType == "multipart/form-data" {
|
||||||
files := r.MultipartForm.File["torrents"]
|
files := r.MultipartForm.File["torrents"]
|
||||||
for _, fileHeader := range files {
|
for _, fileHeader := range files {
|
||||||
file, _ := fileHeader.Open()
|
if err := q.AddTorrent(ctx, fileHeader, category); err != nil {
|
||||||
defer file.Close()
|
q.logger.Printf("Error adding torrent: %v\n", err)
|
||||||
var reader io.Reader = file
|
|
||||||
magnet, err := common.GetMagnetFromFile(reader, fileHeader.Filename)
|
|
||||||
if err != nil {
|
|
||||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||||
q.logger.Printf("Error reading file: %s", fileHeader.Filename)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
go q.Process(ctx, magnet, category)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,9 +2,12 @@ package qbit
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"goBlack/common"
|
"goBlack/common"
|
||||||
"goBlack/pkg/debrid"
|
"goBlack/pkg/debrid"
|
||||||
|
"io"
|
||||||
|
"mime/multipart"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -12,9 +15,39 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (q *QBit) Process(ctx context.Context, magnet *common.Magnet, category string) (*Torrent, error) {
|
func (q *QBit) AddMagnet(ctx context.Context, url, category string) error {
|
||||||
|
magnet, err := common.GetMagnetFromUrl(url)
|
||||||
|
if err != nil {
|
||||||
|
q.logger.Printf("Error parsing magnet link: %v\n", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = q.Process(ctx, magnet, category)
|
||||||
|
if err != nil {
|
||||||
|
q.logger.Println("Failed to process magnet:", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *QBit) AddTorrent(ctx context.Context, fileHeader *multipart.FileHeader, category string) error {
|
||||||
|
file, _ := fileHeader.Open()
|
||||||
|
defer file.Close()
|
||||||
|
var reader io.Reader = file
|
||||||
|
magnet, err := common.GetMagnetFromFile(reader, fileHeader.Filename)
|
||||||
|
if err != nil {
|
||||||
|
q.logger.Printf("Error reading file: %s", fileHeader.Filename)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = q.Process(ctx, magnet, category)
|
||||||
|
if err != nil {
|
||||||
|
q.logger.Println("Failed to process torrent:", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *QBit) Process(ctx context.Context, magnet *common.Magnet, category string) error {
|
||||||
torrent := q.CreateTorrentFromMagnet(magnet, category)
|
torrent := q.CreateTorrentFromMagnet(magnet, category)
|
||||||
go q.storage.AddOrUpdate(torrent)
|
|
||||||
arr := &debrid.Arr{
|
arr := &debrid.Arr{
|
||||||
Name: category,
|
Name: category,
|
||||||
Token: ctx.Value("token").(string),
|
Token: ctx.Value("token").(string),
|
||||||
@@ -22,16 +55,17 @@ func (q *QBit) Process(ctx context.Context, magnet *common.Magnet, category stri
|
|||||||
}
|
}
|
||||||
debridTorrent, err := debrid.ProcessQBitTorrent(q.debrid, magnet, arr)
|
debridTorrent, err := debrid.ProcessQBitTorrent(q.debrid, magnet, arr)
|
||||||
if err != nil || debridTorrent == nil {
|
if err != nil || debridTorrent == nil {
|
||||||
// Mark as failed
|
if err == nil {
|
||||||
q.logger.Printf("Failed to process torrent: %s: %v", magnet.Name, err)
|
err = fmt.Errorf("failed to process torrent")
|
||||||
q.MarkAsFailed(torrent)
|
}
|
||||||
return torrent, err
|
return err
|
||||||
}
|
}
|
||||||
torrent.ID = debridTorrent.Id
|
torrent.ID = debridTorrent.Id
|
||||||
torrent.DebridTorrent = debridTorrent
|
torrent.DebridTorrent = debridTorrent
|
||||||
torrent.Name = debridTorrent.Name
|
torrent.Name = debridTorrent.Name
|
||||||
q.processFiles(torrent, debridTorrent, arr)
|
q.storage.AddOrUpdate(torrent)
|
||||||
return torrent, nil
|
go q.processFiles(torrent, debridTorrent, arr) // We can send async for file processing not to delay the response
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *QBit) CreateTorrentFromMagnet(magnet *common.Magnet, category string) *Torrent {
|
func (q *QBit) CreateTorrentFromMagnet(magnet *common.Magnet, category string) *Torrent {
|
||||||
@@ -72,6 +106,7 @@ func (q *QBit) processFiles(torrent *Torrent, debridTorrent *debrid.Torrent, arr
|
|||||||
rCloneBase := q.debrid.GetMountPath()
|
rCloneBase := q.debrid.GetMountPath()
|
||||||
torrentPath, err := q.getTorrentPath(rCloneBase, debridTorrent) // /MyTVShow/
|
torrentPath, err := q.getTorrentPath(rCloneBase, debridTorrent) // /MyTVShow/
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
q.MarkAsFailed(torrent)
|
||||||
q.logger.Printf("Error: %v", err)
|
q.logger.Printf("Error: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -80,6 +115,7 @@ func (q *QBit) processFiles(torrent *Torrent, debridTorrent *debrid.Torrent, arr
|
|||||||
err = os.MkdirAll(torrentSymlinkPath, os.ModePerm)
|
err = os.MkdirAll(torrentSymlinkPath, os.ModePerm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
q.logger.Printf("Failed to create directory: %s\n", torrentSymlinkPath)
|
q.logger.Printf("Failed to create directory: %s\n", torrentSymlinkPath)
|
||||||
|
q.MarkAsFailed(torrent)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
torrentRclonePath := filepath.Join(rCloneBase, torrentPath)
|
torrentRclonePath := filepath.Join(rCloneBase, torrentPath)
|
||||||
|
|||||||
Reference in New Issue
Block a user