Add logs route, add rar handler
This commit is contained in:
@@ -6,7 +6,7 @@ import (
|
||||
"os/exec"
|
||||
|
||||
"github.com/debridmediamanager/zurg/internal/config"
|
||||
"go.uber.org/zap"
|
||||
"github.com/debridmediamanager/zurg/pkg/logutil"
|
||||
)
|
||||
|
||||
type ScriptExecutor struct {
|
||||
@@ -32,7 +32,7 @@ func (se *ScriptExecutor) Execute() (string, error) {
|
||||
return out.String(), nil
|
||||
}
|
||||
|
||||
func OnLibraryUpdateHook(paths []string, config config.ConfigInterface, log *zap.SugaredLogger) {
|
||||
func OnLibraryUpdateHook(paths []string, config config.ConfigInterface, log *logutil.Logger) {
|
||||
executor := &ScriptExecutor{
|
||||
Script: config.GetOnLibraryUpdate(),
|
||||
Args: paths,
|
||||
|
||||
@@ -7,12 +7,12 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/debridmediamanager/zurg/internal/config"
|
||||
"github.com/debridmediamanager/zurg/pkg/logutil"
|
||||
"github.com/debridmediamanager/zurg/pkg/realdebrid"
|
||||
cmap "github.com/orcaman/concurrent-map/v2"
|
||||
"github.com/panjf2000/ants/v2"
|
||||
"github.com/scylladb/go-set"
|
||||
"github.com/scylladb/go-set/strset"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -30,13 +30,13 @@ type TorrentManager struct {
|
||||
requiredVersion string
|
||||
workerPool *ants.Pool
|
||||
repairWorker *ants.Pool
|
||||
log *zap.SugaredLogger
|
||||
log *logutil.Logger
|
||||
}
|
||||
|
||||
// NewTorrentManager creates a new torrent manager
|
||||
// it will fetch all torrents and their info in the background
|
||||
// and store them in-memory and cached in files
|
||||
func NewTorrentManager(cfg config.ConfigInterface, api *realdebrid.RealDebrid, p *ants.Pool, log *zap.SugaredLogger) *TorrentManager {
|
||||
func NewTorrentManager(cfg config.ConfigInterface, api *realdebrid.RealDebrid, p *ants.Pool, log *logutil.Logger) *TorrentManager {
|
||||
initialSate := EmptyState()
|
||||
|
||||
t := &TorrentManager{
|
||||
|
||||
@@ -149,8 +149,26 @@ func (t *TorrentManager) getMoreInfo(rdTorrent realdebrid.Torrent) *Torrent {
|
||||
})
|
||||
}
|
||||
if len(selectedFiles) > len(info.Links) && info.Progress == 100 {
|
||||
t.log.Warnf("Torrent id=%s is partly expired, it has %d selected files but only %d links", info.ID, len(selectedFiles), len(info.Links))
|
||||
torrent.ForRepair = true
|
||||
if len(info.Links) == 1 {
|
||||
// this might be a rar file so let's check
|
||||
unrestrict := t.UnrestrictUntilOk(info.Links[0])
|
||||
if unrestrict != nil && strings.HasPrefix(strings.ToLower(unrestrict.Filename), ".rar") {
|
||||
if t.Config.ShouldDeleteRarFiles() {
|
||||
t.log.Warnf("Torrent %s id=%s is a rar file, it cannot be repaired. Deleting...", info.Name, info.ID)
|
||||
t.Api.DeleteTorrent(info.ID)
|
||||
return nil
|
||||
} else {
|
||||
t.log.Warnf("Torrent %s id=%s is a rar file, it cannot be repaired as it's a known Real-Debrid limitation. zurg recommends you delete this torrent or enable delete_rar_files in your config.yml", info.Name, info.ID)
|
||||
torrent.Unfixable = true
|
||||
}
|
||||
} else {
|
||||
t.log.Warnf("Torrent id=%s is partly expired. It has %d selected files but only 1 link", info.ID, len(selectedFiles), len(info.Links))
|
||||
torrent.ForRepair = true
|
||||
}
|
||||
} else {
|
||||
t.log.Warnf("Torrent id=%s is partly expired. It has %d selected files but only %d links", info.ID, len(selectedFiles), len(info.Links))
|
||||
torrent.ForRepair = true
|
||||
}
|
||||
} else if len(selectedFiles) == len(info.Links) {
|
||||
// all links are still intact! good!
|
||||
for i, file := range selectedFiles {
|
||||
|
||||
@@ -22,7 +22,7 @@ func (t *TorrentManager) repairAll() {
|
||||
if torrent.AnyInProgress() && torrent.ForRepair {
|
||||
t.log.Warnf("Skipping %s for repairs because it is in progress", torrent.AccessKey)
|
||||
return
|
||||
} else if torrent.ForRepair {
|
||||
} else if torrent.ForRepair && !torrent.Unfixable {
|
||||
toRepair = append(toRepair, torrent)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -18,6 +18,7 @@ type Torrent struct {
|
||||
SelectedFiles cmap.ConcurrentMap[string, *File] `json:"-"`
|
||||
LatestAdded string `json:"LatestAdded"`
|
||||
ForRepair bool `json:"ForRepair"`
|
||||
Unfixable bool `json:"Unfixable"`
|
||||
DownloadedIDs *strset.Set `json:"DownloadedIDs"`
|
||||
InProgressIDs *strset.Set `json:"InProgressIDs"`
|
||||
|
||||
|
||||
Reference in New Issue
Block a user