mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 08:49:13 +00:00
fix: improve qbit re-announce (#140)
This commit is contained in:
parent
78f83c674b
commit
43c42a7ee8
2 changed files with 18 additions and 20 deletions
|
@ -47,9 +47,9 @@ func (s *service) qbittorrent(qbt *qbittorrent.Client, action domain.Action, has
|
||||||
}
|
}
|
||||||
|
|
||||||
if !action.Paused && hash != "" {
|
if !action.Paused && hash != "" {
|
||||||
err = checkTrackerStatus(*qbt, hash)
|
err = checkTrackerStatus(qbt, hash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Stack().Err(err).Msgf("could not get tracker status for torrent: %v", hash)
|
log.Error().Stack().Err(err).Msgf("could not reannounce torrent: %v", hash)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -130,17 +130,15 @@ func (s *service) qbittorrentCheckRulesCanDownload(action domain.Action) (bool,
|
||||||
return true, qbt, nil
|
return true, qbt, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkTrackerStatus(qb qbittorrent.Client, hash string) error {
|
func checkTrackerStatus(qb *qbittorrent.Client, hash string) error {
|
||||||
announceOK := false
|
announceOK := false
|
||||||
attempts := 0
|
attempts := 0
|
||||||
|
|
||||||
// initial sleep to give tracker a head start
|
// initial sleep to give tracker a head start
|
||||||
time.Sleep(4 * time.Second)
|
time.Sleep(6 * time.Second)
|
||||||
|
|
||||||
for attempts < ReannounceMaxAttempts {
|
for attempts < ReannounceMaxAttempts {
|
||||||
if attempts > 0 {
|
log.Debug().Msgf("qBittorrent - run re-announce %v attempt: %v", hash, attempts)
|
||||||
log.Debug().Msgf("qBittorrent - run re-announce %v attempt: %v", hash, attempts)
|
|
||||||
}
|
|
||||||
|
|
||||||
trackers, err := qb.GetTorrentTrackers(hash)
|
trackers, err := qb.GetTorrentTrackers(hash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -148,12 +146,12 @@ func checkTrackerStatus(qb qbittorrent.Client, hash string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Trace().Msgf("qBittorrent - run re-announce %v attempt: %v trackers (%+v)", hash, attempts, trackers)
|
||||||
|
|
||||||
// check if status not working or something else
|
// check if status not working or something else
|
||||||
working := findTrackerStatus(trackers, qbittorrent.TrackerStatusOK)
|
working := findTrackerStatus(trackers)
|
||||||
if working {
|
if working {
|
||||||
if attempts > 0 {
|
log.Debug().Msgf("qBittorrent - re-announce for %v OK", hash)
|
||||||
log.Debug().Msgf("qBittorrent - re-announce for %v OK", hash)
|
|
||||||
}
|
|
||||||
|
|
||||||
announceOK = true
|
announceOK = true
|
||||||
|
|
||||||
|
@ -168,12 +166,10 @@ func checkTrackerStatus(qb qbittorrent.Client, hash string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
attempts++
|
|
||||||
|
|
||||||
// add delay for next run
|
// add delay for next run
|
||||||
time.Sleep(ReannounceInterval * time.Millisecond)
|
time.Sleep(ReannounceInterval * time.Millisecond)
|
||||||
|
|
||||||
continue
|
attempts++
|
||||||
}
|
}
|
||||||
|
|
||||||
// add extra delay before delete
|
// add extra delay before delete
|
||||||
|
@ -200,14 +196,16 @@ func checkTrackerStatus(qb qbittorrent.Client, hash string) error {
|
||||||
// 2 Tracker has been contacted and is working
|
// 2 Tracker has been contacted and is working
|
||||||
// 3 Tracker is updating
|
// 3 Tracker is updating
|
||||||
// 4 Tracker has been contacted, but it is not working (or doesn't send proper replies)
|
// 4 Tracker has been contacted, but it is not working (or doesn't send proper replies)
|
||||||
func findTrackerStatus(slice []qbittorrent.TorrentTracker, status qbittorrent.TrackerStatus) bool {
|
func findTrackerStatus(slice []qbittorrent.TorrentTracker) bool {
|
||||||
for _, item := range slice {
|
for _, item := range slice {
|
||||||
// if updating skip and give some more time
|
if item.Status == qbittorrent.TrackerStatusDisabled {
|
||||||
if item.Status == qbittorrent.TrackerStatusUpdating {
|
continue
|
||||||
return false
|
}
|
||||||
} else if item.Status == status {
|
|
||||||
|
if item.Status == qbittorrent.TrackerStatusOK {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
|
@ -144,7 +144,7 @@ func (c *Client) GetTorrentsActiveDownloads() ([]Torrent, error) {
|
||||||
for _, torrent := range torrents {
|
for _, torrent := range torrents {
|
||||||
// qbit counts paused torrents as downloading as well by default
|
// qbit counts paused torrents as downloading as well by default
|
||||||
// so only add torrents with state downloading, and not pausedDl, stalledDl etc
|
// so only add torrents with state downloading, and not pausedDl, stalledDl etc
|
||||||
if torrent.State == TorrentStateDownloading {
|
if torrent.State == TorrentStateDownloading || torrent.State == TorrentStateStalledDl {
|
||||||
res = append(res, torrent)
|
res = append(res, torrent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue