new functions
This commit is contained in:
@@ -147,6 +147,13 @@ def _remember_auto_label(profile_id: int, torrent_hash: str, previous_label: str
|
||||
)
|
||||
|
||||
|
||||
def _read_label(client: Any, torrent_hash: str, fallback: str = '') -> str:
|
||||
try:
|
||||
return str(client.call('d.custom1', torrent_hash) or '')
|
||||
except Exception:
|
||||
return fallback
|
||||
|
||||
|
||||
def _restore_auto_label(client: Any, profile_id: int, torrent_hash: str, current_label: str | None = None) -> bool:
|
||||
with connect() as conn:
|
||||
row = conn.execute(
|
||||
@@ -156,8 +163,10 @@ def _restore_auto_label(client: Any, profile_id: int, torrent_hash: str, current
|
||||
if not row:
|
||||
return False
|
||||
previous = row.get('previous_label') or ''
|
||||
live_label = _read_label(client, torrent_hash, current_label or '')
|
||||
try:
|
||||
if current_label is None or current_label == SMART_QUEUE_LABEL:
|
||||
# Note: Before Smart Queue resumes a paused torrent, restore the user label only when the auto label is still present.
|
||||
if live_label == SMART_QUEUE_LABEL or current_label is None:
|
||||
client.call('d.custom1.set', torrent_hash, previous)
|
||||
conn.execute('DELETE FROM smart_queue_auto_labels WHERE profile_id=? AND torrent_hash=?', (profile_id, torrent_hash))
|
||||
return True
|
||||
@@ -301,9 +310,11 @@ def check(profile: dict | None = None, user_id: int | None = None, force: bool =
|
||||
pass
|
||||
for t in to_resume:
|
||||
try:
|
||||
# Note: Resume path explicitly removes Smart Queue auto label before and after start to cover stale cache labels.
|
||||
_restore_auto_label(c, profile_id, t['hash'], str(t.get('label') or ''))
|
||||
c.call('d.resume', t['hash'])
|
||||
c.call('d.start', t['hash'])
|
||||
_restore_auto_label(c, profile_id, t['hash'], None)
|
||||
resumed.append(t['hash'])
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user