Remove annoying logs
This commit is contained in:
@@ -50,17 +50,42 @@ func MainApp(configPath string) {
|
|||||||
|
|
||||||
premium.MonitorPremiumStatus(rd, zurglog)
|
premium.MonitorPremiumStatus(rd, zurglog)
|
||||||
|
|
||||||
// extra 1 worker for the refresh job
|
workerOptions := ants.Options{
|
||||||
workerPool, err := ants.NewPool(config.GetNumOfWorkers() + 1)
|
Nonblocking: true,
|
||||||
|
PanicHandler: func(i interface{}) {},
|
||||||
|
Logger: log.Named("worker"),
|
||||||
|
}
|
||||||
|
|
||||||
|
workerPool, err := ants.NewPool(config.GetNumOfWorkers(), ants.WithOptions(workerOptions))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
zurglog.Errorf("Failed to create worker pool: %v", err)
|
zurglog.Errorf("Failed to create worker pool: %v", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
defer workerPool.Release()
|
defer workerPool.Release()
|
||||||
|
|
||||||
|
refreshOptions := ants.Options{
|
||||||
|
Nonblocking: true,
|
||||||
|
PanicHandler: func(i interface{}) {},
|
||||||
|
Logger: log.Named("refreshworker"),
|
||||||
|
}
|
||||||
|
|
||||||
|
// extra 1 worker for the refresh job
|
||||||
|
refreshPool, err := ants.NewPool(1, ants.WithOptions(refreshOptions))
|
||||||
|
if err != nil {
|
||||||
|
zurglog.Errorf("Failed to create worker pool: %v", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
defer refreshPool.Release()
|
||||||
|
|
||||||
|
repairOptions := ants.Options{
|
||||||
|
Nonblocking: true,
|
||||||
|
PanicHandler: func(i interface{}) {},
|
||||||
|
Logger: log.Named("repairworker"),
|
||||||
|
}
|
||||||
|
|
||||||
var repairPool *ants.Pool
|
var repairPool *ants.Pool
|
||||||
if config.EnableRepair() {
|
if config.EnableRepair() {
|
||||||
repairPool, err = ants.NewPool(1)
|
repairPool, err = ants.NewPool(1, ants.WithOptions(repairOptions))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
zurglog.Errorf("Failed to create repair pool: %v", err)
|
zurglog.Errorf("Failed to create repair pool: %v", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
@@ -69,7 +94,7 @@ func MainApp(configPath string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
utils.EnsureDirExists("data") // Ensure the data directory exists
|
utils.EnsureDirExists("data") // Ensure the data directory exists
|
||||||
torrentMgr := torrent.NewTorrentManager(config, rd, workerPool, repairPool, log.Named("manager"))
|
torrentMgr := torrent.NewTorrentManager(config, rd, workerPool, refreshPool, repairPool, log.Named("manager"))
|
||||||
|
|
||||||
downloadClient := http.NewHTTPClient(config.GetToken(), config.GetRetriesUntilFailed(), config.GetDownloadTimeoutSecs(), true, config, log.Named("dlclient"))
|
downloadClient := http.NewHTTPClient(config.GetToken(), config.GetRetriesUntilFailed(), config.GetDownloadTimeoutSecs(), true, config, log.Named("dlclient"))
|
||||||
downloader := universal.NewDownloader(downloadClient)
|
downloader := universal.NewDownloader(downloadClient)
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ type TorrentManager struct {
|
|||||||
latestState *LibraryState
|
latestState *LibraryState
|
||||||
requiredVersion string
|
requiredVersion string
|
||||||
workerPool *ants.Pool
|
workerPool *ants.Pool
|
||||||
|
refreshPool *ants.Pool
|
||||||
repairPool *ants.Pool
|
repairPool *ants.Pool
|
||||||
repairTrigger chan *Torrent
|
repairTrigger chan *Torrent
|
||||||
repairSet mapset.Set[*Torrent]
|
repairSet mapset.Set[*Torrent]
|
||||||
@@ -43,7 +44,7 @@ type TorrentManager struct {
|
|||||||
// NewTorrentManager creates a new torrent manager
|
// NewTorrentManager creates a new torrent manager
|
||||||
// it will fetch all torrents and their info in the background
|
// it will fetch all torrents and their info in the background
|
||||||
// and store them in-memory and cached in files
|
// and store them in-memory and cached in files
|
||||||
func NewTorrentManager(cfg config.ConfigInterface, api *realdebrid.RealDebrid, workerPool, repairPool *ants.Pool, log *logutil.Logger) *TorrentManager {
|
func NewTorrentManager(cfg config.ConfigInterface, api *realdebrid.RealDebrid, workerPool, refreshPool, repairPool *ants.Pool, log *logutil.Logger) *TorrentManager {
|
||||||
t := &TorrentManager{
|
t := &TorrentManager{
|
||||||
Config: cfg,
|
Config: cfg,
|
||||||
Api: api,
|
Api: api,
|
||||||
@@ -56,6 +57,7 @@ func NewTorrentManager(cfg config.ConfigInterface, api *realdebrid.RealDebrid, w
|
|||||||
latestState: &LibraryState{},
|
latestState: &LibraryState{},
|
||||||
requiredVersion: "0.9.3-hotfix.3",
|
requiredVersion: "0.9.3-hotfix.3",
|
||||||
workerPool: workerPool,
|
workerPool: workerPool,
|
||||||
|
refreshPool: refreshPool,
|
||||||
repairPool: repairPool,
|
repairPool: repairPool,
|
||||||
log: log,
|
log: log,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -179,10 +179,13 @@ func (t *TorrentManager) repair(torrent *Torrent) {
|
|||||||
t.log.Infof("repair_method#1: Torrent %s is still in progress but it should work once done (torrent is temporarily hidden until download has completed)", t.GetKey(torrent))
|
t.log.Infof("repair_method#1: Torrent %s is still in progress but it should work once done (torrent is temporarily hidden until download has completed)", t.GetKey(torrent))
|
||||||
return
|
return
|
||||||
} else if info != nil && info.IsDone() && !t.isStillBroken(info, brokenFiles) {
|
} else if info != nil && info.IsDone() && !t.isStillBroken(info, brokenFiles) {
|
||||||
ix := 0
|
torrent.SelectedFiles.IterCb(func(_ string, oldFile *File) {
|
||||||
torrent.SelectedFiles.IterCb(func(_ string, file *File) {
|
for ix, newFile := range info.Files {
|
||||||
file.Link = info.Links[ix]
|
if oldFile.ID == newFile.ID {
|
||||||
ix++
|
oldFile.Link = info.Links[ix]
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
t.saveTorrentChangesToDisk(torrent, nil)
|
t.saveTorrentChangesToDisk(torrent, nil)
|
||||||
t.log.Infof("Successfully repaired torrent %s using repair_method#1", t.GetKey(torrent))
|
t.log.Infof("Successfully repaired torrent %s using repair_method#1", t.GetKey(torrent))
|
||||||
@@ -521,12 +524,10 @@ func (t *TorrentManager) handleFixers(fixer realdebrid.Torrent) *Torrent {
|
|||||||
|
|
||||||
if info.IsDone() {
|
if info.IsDone() {
|
||||||
if !t.isStillBroken(info, brokenFiles) {
|
if !t.isStillBroken(info, brokenFiles) {
|
||||||
ix := 0
|
torrent.SelectedFiles.IterCb(func(_ string, oldFile *File) {
|
||||||
torrent.SelectedFiles.IterCb(func(_ string, file *File) {
|
for ix, newFile := range info.Files {
|
||||||
for _, brokenFile := range brokenFiles {
|
if oldFile.ID == newFile.ID {
|
||||||
if file.ID == brokenFile.ID {
|
oldFile.Link = info.Links[ix]
|
||||||
file.Link = info.Links[ix]
|
|
||||||
ix++
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ func (dl *Downloader) DownloadFile(directory, torrentName, fileName string, resp
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debugf("Opening file %s from torrent %s (%s)", fileName, torMgr.GetKey(torrent), file.Link)
|
// log.Debugf("Opening file %s from torrent %s (%s)", fileName, torMgr.GetKey(torrent), file.Link)
|
||||||
|
|
||||||
unrestrict := torMgr.UnrestrictUntilOk(file.Link)
|
unrestrict := torMgr.UnrestrictUntilOk(file.Link)
|
||||||
if unrestrict == nil {
|
if unrestrict == nil {
|
||||||
@@ -102,7 +102,7 @@ func (dl *Downloader) DownloadLink(fileName, link string, resp http.ResponseWrit
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debugf("Opening file %s (%s)", fileName, link)
|
// log.Debugf("Opening file %s (%s)", fileName, link)
|
||||||
|
|
||||||
unrestrict := torMgr.UnrestrictUntilOk(link)
|
unrestrict := torMgr.UnrestrictUntilOk(link)
|
||||||
if unrestrict == nil {
|
if unrestrict == nil {
|
||||||
@@ -151,17 +151,17 @@ func (dl *Downloader) streamFileToResponse(torrent *intTor.Torrent, file *intTor
|
|||||||
}
|
}
|
||||||
|
|
||||||
// copy range header if it exists
|
// copy range header if it exists
|
||||||
rangeLog := ""
|
// rangeLog := ""
|
||||||
if req.Header.Get("Range") != "" {
|
if req.Header.Get("Range") != "" {
|
||||||
dlReq.Header.Add("Range", req.Header.Get("Range"))
|
dlReq.Header.Add("Range", req.Header.Get("Range"))
|
||||||
rangeLog = " (range: " + req.Header.Get("Range") + ")"
|
// rangeLog = " (range: " + req.Header.Get("Range") + ")"
|
||||||
}
|
}
|
||||||
|
|
||||||
if torrent != nil {
|
// if torrent != nil {
|
||||||
log.Debugf("Downloading unrestricted link %s from torrent %s (%s)%s", unrestrict.Download, torMgr.GetKey(torrent), unrestrict.Link, rangeLog)
|
// log.Debugf("Downloading unrestricted link %s from torrent %s (%s)%s", unrestrict.Download, torMgr.GetKey(torrent), unrestrict.Link, rangeLog)
|
||||||
} else {
|
// } else {
|
||||||
log.Debugf("Downloading unrestricted link %s (%s)%s", unrestrict.Download, unrestrict.Link, rangeLog)
|
// log.Debugf("Downloading unrestricted link %s (%s)%s", unrestrict.Download, unrestrict.Link, rangeLog)
|
||||||
}
|
// }
|
||||||
|
|
||||||
download, err := dl.client.Do(dlReq)
|
download, err := dl.client.Do(dlReq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -199,7 +199,7 @@ func (dl *Downloader) streamFileToResponse(torrent *intTor.Torrent, file *intTor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debugf("Serving file %s%s", unrestrict.Download, rangeLog)
|
// log.Debugf("Serving file %s%s", unrestrict.Download, rangeLog)
|
||||||
|
|
||||||
buf := make([]byte, cfg.GetNetworkBufferSize())
|
buf := make([]byte, cfg.GetNetworkBufferSize())
|
||||||
io.CopyBuffer(resp, download.Body, buf)
|
io.CopyBuffer(resp, download.Body, buf)
|
||||||
|
|||||||
@@ -150,9 +150,6 @@ func (r *HTTPClient) Do(req *http.Request) (*http.Response, error) {
|
|||||||
resp.Body.Close()
|
resp.Body.Close()
|
||||||
}
|
}
|
||||||
r.replaceHostIfNeeded(req) // needed for ipv6
|
r.replaceHostIfNeeded(req) // needed for ipv6
|
||||||
if !strings.Contains(req.URL.Host, "api.real-debrid.com") {
|
|
||||||
r.log.Debugf("downloading %s", req.URL)
|
|
||||||
}
|
|
||||||
resp, err = r.client.Do(req)
|
resp, err = r.client.Do(req)
|
||||||
if resp != nil && resp.StatusCode/100 >= 4 {
|
if resp != nil && resp.StatusCode/100 >= 4 {
|
||||||
body, _ := io.ReadAll(resp.Body)
|
body, _ := io.ReadAll(resp.Body)
|
||||||
|
|||||||
@@ -93,6 +93,10 @@ func NewLogger(logPath string) *Logger {
|
|||||||
return zLogger
|
return zLogger
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (l *Logger) Printf(format string, v ...interface{}) {
|
||||||
|
l.SugaredLogger.Infof(format, v...)
|
||||||
|
}
|
||||||
|
|
||||||
func (l *Logger) Named(name string) *Logger {
|
func (l *Logger) Named(name string) *Logger {
|
||||||
return &Logger{
|
return &Logger{
|
||||||
SugaredLogger: l.SugaredLogger.Named(name),
|
SugaredLogger: l.SugaredLogger.Named(name),
|
||||||
|
|||||||
Reference in New Issue
Block a user