Use the chunk manager properly
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/debridmediamanager.com/zurg/internal/torrent"
|
||||
zurghttp "github.com/debridmediamanager.com/zurg/pkg/http"
|
||||
"github.com/debridmediamanager.com/zurg/pkg/logutil"
|
||||
"go.uber.org/zap"
|
||||
"golang.org/x/sys/unix"
|
||||
@@ -23,12 +24,13 @@ type Downloader struct {
|
||||
storage *Storage
|
||||
torMgr *torrent.TorrentManager
|
||||
log *zap.SugaredLogger
|
||||
client *zurghttp.HTTPClient
|
||||
}
|
||||
|
||||
type DownloadCallback func(error, []byte)
|
||||
|
||||
// NewDownloader creates a new download manager
|
||||
func NewDownloader(threads int, storage *Storage, bufferSize int64, torMgr *torrent.TorrentManager) (*Downloader, error) {
|
||||
func NewDownloader(threads int, storage *Storage, bufferSize int64, torMgr *torrent.TorrentManager, client *zurghttp.HTTPClient) (*Downloader, error) {
|
||||
rlog := logutil.NewLogger()
|
||||
log := rlog.Named("downloader")
|
||||
|
||||
@@ -38,6 +40,7 @@ func NewDownloader(threads int, storage *Storage, bufferSize int64, torMgr *torr
|
||||
callbacks: make(map[RequestID][]DownloadCallback, 100),
|
||||
storage: storage,
|
||||
torMgr: torMgr,
|
||||
client: client,
|
||||
log: log,
|
||||
}
|
||||
|
||||
@@ -76,7 +79,6 @@ func (d *Downloader) thread(n int) {
|
||||
}
|
||||
|
||||
func (d *Downloader) download(req *Request, buffer []byte) {
|
||||
d.log.Debugf("Starting download %v (preload: %v)", req.id, req.preload)
|
||||
err := d.downloadFromAPI(req, buffer, 0)
|
||||
|
||||
d.lock.Lock()
|
||||
@@ -137,7 +139,7 @@ func (d *Downloader) downloadFromAPI(request *Request, buffer []byte, delay int6
|
||||
d.log.Debugf("response read error: %v", err)
|
||||
return fmt.Errorf("could not read objects %s %s API response", request.file.Path, request.file.Link)
|
||||
}
|
||||
d.log.Debugf("Downloaded %v bytes of %s %s", n, request.file.Path, request.file.Link)
|
||||
d.log.Debugf("Downloaded %v bytes of %s", n, request.file.Path)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -6,8 +6,8 @@ import (
|
||||
"hash/fnv"
|
||||
"os"
|
||||
|
||||
"github.com/debridmediamanager.com/zurg/internal/config"
|
||||
"github.com/debridmediamanager.com/zurg/internal/torrent"
|
||||
zurghttp "github.com/debridmediamanager.com/zurg/pkg/http"
|
||||
)
|
||||
|
||||
// Manager manages chunks on disk
|
||||
@@ -59,7 +59,7 @@ func NewManager(
|
||||
loadThreads,
|
||||
maxChunks int,
|
||||
torMgr *torrent.TorrentManager,
|
||||
cfg config.ConfigInterface) (*Manager, error) {
|
||||
client *zurghttp.HTTPClient) (*Manager, error) {
|
||||
|
||||
pageSize := int64(os.Getpagesize())
|
||||
if chunkSize < pageSize {
|
||||
@@ -82,7 +82,7 @@ func NewManager(
|
||||
return nil, err
|
||||
}
|
||||
|
||||
downloader, err := NewDownloader(loadThreads, storage, chunkSize, torMgr)
|
||||
downloader, err := NewDownloader(loadThreads, storage, chunkSize, torMgr, client)
|
||||
if nil != err {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user