ppf: add format_duration helper and stale log improvements

- Add format_duration() for compact time display
- Improve stale proxy logging with duration info
This commit is contained in:
Username
2025-12-24 00:20:13 +01:00
parent 5e788c06d1
commit 9360c35add

20
ppf.py
View File

@@ -32,6 +32,23 @@ signal.signal(signal.SIGTERM, sigterm_handler)
config = Config()
def format_duration(seconds):
"""Format seconds into compact human-readable duration."""
if seconds < 60:
return '%ds' % seconds
elif seconds < 3600:
return '%dm' % (seconds // 60)
elif seconds < 86400:
h, m = divmod(seconds, 3600)
m = m // 60
return '%dh %dm' % (h, m) if m else '%dh' % h
else:
d, rem = divmod(seconds, 86400)
h = rem // 3600
return '%dd %dh' % (d, h) if h else '%dd' % d
def import_from_file(fn, sqlite):
with open(fn, 'r') as f:
urls = [ url for url in f.read().split('\n') if url ]
@@ -156,7 +173,8 @@ class Leechered(threading.Thread):
self.hash_unchanged = True
self.proxylist = []
self.stale_count += 1
_log('%s: unchanged (hash match)' % self.url.split('/')[2], 'stale')
next_check = config.ppf.checktime + (self.error + self.stale_count) * config.ppf.perfail_checktime
_log('%s: unchanged (hash match), next in %s' % (self.url.split('/')[2], format_duration(next_check)), 'stale')
# Content unchanged - increment stale_count, update check_time
self.execute = (self.error, self.stale_count, int(time.time()), self.retrievals, self.proxies_added, self.content_type, self.url)
self.status = 'ok'