Skip to content

Commit

Permalink
feat(reannounce): add optional args
Browse files Browse the repository at this point in the history
  • Loading branch information
buroa committed Oct 9, 2024
1 parent afd5e6f commit 5548e2d
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions qbtools/commands/reannounce.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@
def __init__(app, logger):
logger.info("Starting reannounce process...")

max_tries = 18
max_age = 3600
interval = 5
retries = {}

def process_torrents(status):
torrents = app.client.torrents.info(status_filter=status, sort="time_active")
torrents_retries = retries.get(status, {})

if torrents:
torrents = list(filter(lambda t: t.time_active <= max_age, torrents))
torrents = list(filter(lambda t: t.time_active <= app.max_age, torrents))

if not torrents:
torrents_retries.clear()
Expand All @@ -31,16 +28,16 @@ def process_torrents(status):
continue

torrent_retries = torrents_retries.get(t.hash, 0)
if torrent_retries >= max_tries:
if torrent_retries >= app.max_retries:
logger.debug(
f"Torrent {t.name} ({t.hash}) has reached {retries} reannounce tries - not reannouncing",
f"Torrent {t.name} ({t.hash}) has reached {torrent_retries} reannounce tries - not reannouncing",
)
continue

t.reannounce()
torrents_retries[t.hash] = torrent_retries + 1
logger.info(
f"Reannounced torrent {t.name} ({t.hash}) {torrent_retries}/{max_tries}",
f"Reannounced torrent {t.name} ({t.hash}) {torrent_retries}/{app.max_retries}",
)

retries[status] = torrents_retries
Expand All @@ -53,7 +50,7 @@ def process_torrents(status):
except Exception as e:
logger.error(e)

time.sleep(interval)
time.sleep(app.interval)


def add_arguments(command, subparser):
Expand All @@ -64,8 +61,26 @@ def add_arguments(command, subparser):
qbtools.py reannounce --help
"""
parser = subparser.add_parser(command)
parser.add_argument(
"--max-age",
type=int,
default=3600,
help="The maximum age of a torrent in seconds to reannounce.",
)
parser.add_argument(
"--max-retries",
type=int,
default=18,
help="The maximum number of reannounce retries for a torrent.",
)
parser.add_argument(
"--interval",
type=int,
default=5,
help="The interval to process reannouncements in seconds.",
)
parser.add_argument(
"--process-seeding",
action="store_true",
help="Include seeding torrents for reannouncements.",
help="Process seeding torrents as well.",
)

0 comments on commit 5548e2d

Please sign in to comment.