use new qbitorrent api tracker status for

removing unregistered torrents instead of my own
This commit is contained in:
bobokun 2023-04-11 20:42:33 -04:00
parent 550e831564
commit c0467bf4ab
No known key found for this signature in database
GPG key ID: B73932169607D927
3 changed files with 31 additions and 34 deletions

View file

@ -1,4 +1,5 @@
from qbittorrentapi import NotFound404Error from qbittorrentapi import NotFound404Error
from qbittorrentapi import TrackerStatus
from modules import util from modules import util
from modules.util import list_in_text from modules.util import list_in_text
@ -65,6 +66,21 @@ class RemoveUnregistered:
} }
self.config.send_notifications(attr) self.config.send_notifications(attr)
def check_for_unregistered_torrents_using_bhd_api(self, tracker, msg_up, torrent_hash):
"""
Checks if a torrent is unregistered using the BHD API if the tracker is BHD.
"""
if (
"tracker.beyond-hd.me" in tracker["url"]
and self.config.beyond_hd is not None
and not list_in_text(msg_up, TorrentMessages.IGNORE_MSGS)
):
json = {"info_hash": torrent_hash}
response = self.config.beyond_hd.search(json)
if response["total_results"] == 0:
return True
return False
def process_torrent_issues(self): def process_torrent_issues(self):
for torrent in self.qbt.torrentissue: for torrent in self.qbt.torrentissue:
self.t_name = torrent.name self.t_name = torrent.name
@ -78,36 +94,22 @@ class RemoveUnregistered:
tracker = self.qbt.get_tags([trk]) tracker = self.qbt.get_tags([trk])
msg_up = trk.msg.upper() msg_up = trk.msg.upper()
msg = trk.msg msg = trk.msg
# Tag any error torrents if TrackerStatus(trk.status) == TrackerStatus.NOT_WORKING:
if self.cfg_tag_error: # Tag any error torrents
if trk.status == TorrentMessages.TORRENT_STATUS_NOT_WORKING and self.tag_error not in check_tags: if self.cfg_tag_error and self.tag_error not in check_tags:
self.tag_tracker_error(msg, tracker, torrent) self.tag_tracker_error(msg, tracker, torrent)
if self.cfg_rem_unregistered: # Check for unregistered torrents
# Tag any error torrents that are not unregistered if self.cfg_rem_unregistered:
if ( if list_in_text(msg_up, TorrentMessages.UNREGISTERED_MSGS) and not list_in_text(
not list_in_text(msg_up, TorrentMessages.UNREGISTERED_MSGS) msg_up, TorrentMessages.IGNORE_MSGS
and trk.status == TorrentMessages.TORRENT_STATUS_NOT_WORKING
and self.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.beyond_hd is not None
and not list_in_text(msg_up, TorrentMessages.IGNORE_MSGS)
): ):
json = {"info_hash": torrent.hash} self.del_unregistered(msg, tracker, torrent)
response = self.config.beyond_hd.search(json) break
if response["total_results"] == 0: else:
if self.check_for_unregistered_torrents_using_bhd_api(tracker, msg_up, torrent.hash):
self.del_unregistered(msg, tracker, torrent) self.del_unregistered(msg, tracker, torrent)
break break
self.tag_tracker_error(msg, tracker, torrent)
if (
list_in_text(msg_up, TorrentMessages.UNREGISTERED_MSGS)
and not list_in_text(msg_up, TorrentMessages.IGNORE_MSGS)
and trk.status == TorrentMessages.TORRENT_STATUS_NOT_WORKING
):
self.del_unregistered(msg, tracker, torrent)
break
except NotFound404Error: except NotFound404Error:
continue continue
except Exception as ex: except Exception as ex:

View file

@ -7,6 +7,7 @@ from qbittorrentapi import APIConnectionError
from qbittorrentapi import Client from qbittorrentapi import Client
from qbittorrentapi import LoginFailed from qbittorrentapi import LoginFailed
from qbittorrentapi import NotFound404Error from qbittorrentapi import NotFound404Error
from qbittorrentapi import TrackerStatus
from qbittorrentapi import Version from qbittorrentapi import Version
from modules import util from modules import util
@ -158,11 +159,11 @@ class Qbt:
if trk.url.startswith("http"): if trk.url.startswith("http"):
status = trk.status status = trk.status
msg = trk.msg.upper() msg = trk.msg.upper()
if trk.status == TorrentMessages.TORRENT_STATUS_WORKING: if TrackerStatus(trk.status) == TrackerStatus.WORKING:
working_tracker = True working_tracker = True
break break
# Add any potential unregistered torrents to a list # Add any potential unregistered torrents to a list
if trk.status == TorrentMessages.TORRENT_STATUS_NOT_WORKING and not list_in_text( if TrackerStatus(trk.status) == TrackerStatus.NOT_WORKING and not list_in_text(
msg, TorrentMessages.EXCEPTIONS_MSGS msg, TorrentMessages.EXCEPTIONS_MSGS
): ):
issue["potential"] = True issue["potential"] = True

View file

@ -70,12 +70,6 @@ class TorrentMessages:
"TRACKER UNAVAILABLE", "TRACKER UNAVAILABLE",
] ]
TORRENT_STATUS_DISABLED = 0 # Tracker is disabled (used for DHT, PeX, and LSD)
TORRENT_STATUS_NOT_CONTACTED = 1 # Tracker has not been contacted yet
TORRENT_STATUS_WORKING = 2 # Tracker has been contacted and is working
TORRENT_STATUS_UPDATING = 3 # Tracker is updating
TORRENT_STATUS_NOT_WORKING = 4 # Tracker has been contacted, but it is not working (or doesn't send proper replies)
class check: class check:
"""Check for attributes in config.""" """Check for attributes in config."""