bug fix: remove unregistered torrents

better handling of unregistered torrents by matching full word
This commit is contained in:
bobokun 2022-01-12 16:15:43 -05:00
parent add5ed05b2
commit 2e03283465
No known key found for this signature in database
GPG key ID: 9665BA6CF5DC2671
3 changed files with 27 additions and 12 deletions

View file

@ -8,4 +8,5 @@ ignore =
E272, # E272 Multiple spaces before keyword
C901 # C901 Function is too complex
E722 # E722 Do not use bare except, specify exception instead
W503 # W503 Line break occurred before a binary operator
max-line-length = 200

View file

@ -1,7 +1,7 @@
import logging, os, sys
from qbittorrentapi import Client, Version, LoginFailed, APIConnectionError, NotFound404Error, Conflict409Error
from modules import util
from modules.util import Failed, print_line, print_multiline, separator
from modules.util import Failed, print_line, print_multiline, separator, list_in_text
from datetime import timedelta
from collections import Counter
from fnmatch import fnmatch
@ -113,12 +113,12 @@ class Qbt:
if x.url.startswith('http'):
status = x.status
msg = x.msg.upper()
exception = ["DOWN", "UNREACHABLE", "BAD GATEWAY", "TRACKER UNAVAILABLE"]
exception = set(["DOWN", "UNREACHABLE", "BAD GATEWAY", "TRACKER UNAVAILABLE"])
if x.status == 2:
working_tracker = True
break
# Add any potential unregistered torrents to a list
if x.status == 4 and all(x not in msg for x in exception):
if x.status == 4 and not list_in_text(msg, exception):
issue['potential'] = True
issue['msg'] = msg
issue['status'] = status
@ -469,7 +469,7 @@ class Qbt:
if cfg_rem_unregistered or cfg_tag_error:
if cfg_tag_error: separator("Tagging Torrents with Tracker Errors", space=False, border=False)
elif cfg_rem_unregistered: separator("Removing Unregistered Torrents", space=False, border=False)
unreg_msgs = [
unreg_msgs = set([
'UNREGISTERED',
'TORRENT NOT FOUND',
'TORRENT IS NOT FOUND',
@ -480,13 +480,14 @@ class Qbt:
'RETITLED',
'TRUNCATED',
'TORRENT IS NOT AUTHORIZED FOR USE ON THIS TRACKER'
]
ignore_msgs = [
])
ignore_msgs = set([
'YOU HAVE REACHED THE CLIENT LIMIT FOR THIS TORRENT',
'MISSING PASSKEY',
'MISSING INFO_HASH',
'PASSKEY IS INVALID'
]
'PASSKEY IS INVALID',
'INVALID PASSKEY'
])
for torrent in self.torrentvalid:
check_tags = util.get_list(torrent.tags)
# Remove any error torrents Tags that are no longer unreachable.
@ -528,16 +529,16 @@ class Qbt:
tag_tracker_error()
if cfg_rem_unregistered:
# Tag any error torrents that are not unregistered
if not any(m in msg_up for m in unreg_msgs) and x.status == 4 and tag_error not in check_tags:
if not list_in_text(msg_up, unreg_msgs) and x.status == 4 and tag_error not in check_tags:
# Check for unregistered torrents using BHD API if the tracker is BHD
if 'tracker.beyond-hd.me' in tracker['url'] and self.config.BeyondHD is not None and all(x not in msg_up for x in ignore_msgs):
if 'tracker.beyond-hd.me' in tracker['url'] and self.config.BeyondHD is not None and not list_in_text(msg_up, ignore_msgs):
json = {"info_hash": torrent.hash}
response = self.config.BeyondHD.search(json)
if response['total_results'] <= 1:
del_unregistered()
break
tag_tracker_error()
if any(m in msg_up for m in unreg_msgs) and x.status == 4:
if list_in_text(msg_up, unreg_msgs) and x.status == 4:
del_unregistered()
break
except NotFound404Error:

View file

@ -1,4 +1,4 @@
import logging, os, shutil, traceback, time, signal, json
import logging, os, shutil, traceback, time, signal, json, re
from logging.handlers import RotatingFileHandler
from ruamel import yaml
from pathlib import Path
@ -189,6 +189,19 @@ def add_dict_list(keys, value, dict_map):
dict_map[key] = [value]
def list_in_text(text, search_list, all=False):
length = len(search_list)
num = 0
pattern = re.compile(r'\b'
+ r'\b|\b'.join(re.escape(x) for x in search_list)
+ r'\b')
for t in set(pattern.findall(text)):
num += 1
if not all: return True
if(num == length and all): return True
return False
def print_line(lines, loglevel='INFO'):
logger.log(getattr(logging, loglevel.upper()), str(lines))
return [str(lines)]