fuse integreated

This commit is contained in:
Ben Sarmiento
2023-11-11 11:52:34 +01:00
29 changed files with 1074 additions and 1001 deletions

View File

@@ -9,8 +9,8 @@ import (
"time"
"github.com/debridmediamanager.com/zurg/internal/config"
"github.com/debridmediamanager.com/zurg/internal/torrent"
"github.com/debridmediamanager.com/zurg/pkg/logutil"
"github.com/debridmediamanager.com/zurg/pkg/realdebrid"
"go.uber.org/zap"
"golang.org/x/sys/unix"
)
@@ -23,13 +23,14 @@ type Downloader struct {
lock sync.Mutex
storage *Storage
c config.ConfigInterface
t *torrent.TorrentManager
log *zap.SugaredLogger
}
type DownloadCallback func(error, []byte)
// NewDownloader creates a new download manager
func NewDownloader(threads int, storage *Storage, bufferSize int64, c config.ConfigInterface) (*Downloader, error) {
func NewDownloader(threads int, storage *Storage, bufferSize int64, t *torrent.TorrentManager, c config.ConfigInterface) (*Downloader, error) {
rlog := logutil.NewLogger()
log := rlog.Named("downloader")
@@ -39,6 +40,7 @@ func NewDownloader(threads int, storage *Storage, bufferSize int64, c config.Con
callbacks: make(map[RequestID][]DownloadCallback, 100),
storage: storage,
c: c,
t: t,
log: log,
}
@@ -103,10 +105,7 @@ func (d *Downloader) downloadFromAPI(request *Request, buffer []byte, delay int6
time.Sleep(time.Duration(delay) * time.Second)
}
unrestrictFn := func() (*realdebrid.UnrestrictResponse, error) {
return realdebrid.UnrestrictLink(d.c.GetToken(), request.file.Link)
}
resp := realdebrid.RetryUntilOk(unrestrictFn)
resp := d.t.UnrestrictUntilOk(request.file.Link)
if resp == nil {
return fmt.Errorf("cannot unrestrict file %s %s", request.file.Path, request.file.Link)
}

View File

@@ -58,6 +58,7 @@ func NewManager(
checkThreads,
loadThreads,
maxChunks int,
t *torrent.TorrentManager,
c config.ConfigInterface) (*Manager, error) {
pageSize := int64(os.Getpagesize())
@@ -81,7 +82,7 @@ func NewManager(
return nil, err
}
downloader, err := NewDownloader(loadThreads, storage, chunkSize, c)
downloader, err := NewDownloader(loadThreads, storage, chunkSize, t, c)
if nil != err {
return nil, err
}