Skip to content

Commit

Permalink
#58 add issue tag to potential unreg
Browse files Browse the repository at this point in the history
  • Loading branch information
bobokun committed Dec 19, 2021
1 parent 5a51ed4 commit 6036e2e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 21 deletions.
24 changes: 12 additions & 12 deletions config/config.yml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,23 @@ tags:
# max_seeding_time: 129600
# <OPTIONAL> Will limit the upload speed KiB/s (KiloBytes/second) (-1 sets the limit to infinity)
# limit_upload_speed: 150
# <OPTIONAL> Set this to the notifiarr react. If using custom indexer you must specify the entire reaction id, otherwise just specify the reaction name
# <OPTIONAL> Set this to the notifiarr react name. This is used to add indexer reactions to the notifications sent by Notifiarr
# notifiarr: <notifiarr indexer>
animebytes.tv:
tag: AnimeBytes
notifiarr: animebytes:#############
notifiarr: animebytes
avistaz:
tag: Avistaz
max_ratio: 5.0
max_seeding_time: 129600
limit_upload_speed: 150
notifiarr: avistaz:#############
notifiarr: avistaz
beyond-hd:
tag: Beyond-HD
notifiarr: beyondhd
blutopia:
tag: Blutopia
notifiarr: blutopia:#############
notifiarr: blutopia
cartoonchaos:
tag: CartoonChaos
digitalcore:
Expand Down Expand Up @@ -152,11 +152,11 @@ webhooks:
run_start: notifiarr
run_end: apprise
function:
cross_seed:
recheck:
cat_update:
tag_update:
rem_unregistered:
rem_orphaned:
tag_nohardlinks:
empty_recyclebin:
cross_seed: https://mywebhookurl.com/qbt_manage
recheck: notifiarr
cat_update: apprise
tag_update: notifiarr
rem_unregistered: notifiarr
rem_orphaned: notifiarr
tag_nohardlinks: notifiarr
empty_recyclebin: notifiarr
35 changes: 26 additions & 9 deletions modules/qbittorrent.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def __init__(self, config, params):
def get_torrent_info(torrent_list):
torrentdict = {}
t_obj_unreg = []
t_obj_valid = []
for torrent in alive_it(torrent_list):
is_complete = False
msg = None
Expand Down Expand Up @@ -79,16 +80,19 @@ def get_torrent_info(torrent_list):
#Add any potential unregistered torrents to a list
if x.status == 4 and 'DOWN' not in msg and 'UNREACHABLE' not in msg:
t_obj_unreg.append(torrent)
if x.status == 2:
t_obj_valid.append(torrent)
if msg is not None: msg_list.append(msg)
if status is not None: status_list.append(status)
torrentattr = {'torrents': t_obj_list, 'Category': category, 'save_path': save_path, 'count': t_count, 'msg': msg_list, 'status': status_list, 'is_complete': is_complete, 'first_hash':first_hash}
torrentdict[torrent_name] = torrentattr
return torrentdict,t_obj_unreg
return torrentdict,t_obj_unreg,t_obj_valid
self.torrentinfo = None
self.torrentissue = None
self.torrentvalid = None
if config.args['recheck'] or config.args['cross_seed'] or config.args['rem_unregistered']:
#Get an updated torrent dictionary information of the torrents
self.torrentinfo,self.torrentissue = get_torrent_info(self.torrent_list)
self.torrentinfo,self.torrentissue,self.torrentvalid = get_torrent_info(self.torrent_list)

def get_torrents(self,params):
return self.client.torrents.info(**params)
Expand Down Expand Up @@ -129,10 +133,12 @@ def tags(self):
dry_run = self.config.args['dry_run']
loglevel = 'DRYRUN' if dry_run else 'INFO'
num_tags = 0
ignore_tags = ['noHL','issue','cross-seed']
if self.config.args['tag_update']:
separator(f"Updating Tags", space=False, border=False)
for torrent in self.torrent_list:
if torrent.tags == '' or ('cross-seed' in torrent.tags and len([e for e in torrent.tags.split(",") if not 'noHL' in e]) == 1):
check_tags = util.get_list(torrent.tags)
if torrent.tags == '' or (len([x for x in check_tags if x not in ignore_tags]) == 0):
tags = self.config.get_tags([x.url for x in torrent.trackers if x.url.startswith('http')])
if tags["new_tag"]:
num_tags += 1
Expand Down Expand Up @@ -324,9 +330,9 @@ def rem_unregistered(self):
loglevel = 'DRYRUN' if dry_run else 'INFO'
del_tor = 0
del_tor_cont = 0
pot_unr_summary = ''
if self.config.args['rem_unregistered']:
separator(f"Removing Unregistered Torrents", space=False, border=False)
pot_unr = ''
unreg_msgs = [
'UNREGISTERED',
'TORRENT NOT FOUND',
Expand All @@ -344,33 +350,44 @@ def rem_unregistered(self):
'PRE-RETAIL',
'FULL SEASON',
]
for torrent in self.torrentvalid:
check_tags = util.get_list(torrent.tags)
#Remove any potential unregistered torrents Tags that are no longer unreachable.
if 'issue' in check_tags:
if not dry_run: torrent.remove_tags(tags='issue')
for torrent in self.torrentissue:
t_name = torrent.name
t_cat = self.torrentinfo[t_name]['Category']
t_count = self.torrentinfo[t_name]['count']
t_msg = self.torrentinfo[t_name]['msg']
t_status = self.torrentinfo[t_name]['status']
check_tags = util.get_list(torrent.tags)
for x in torrent.trackers:
if x.url.startswith('http'):
tags = self.config.get_tags([x.url])
msg_up = x.msg.upper()
#Add any potential unregistered torrents to a list
if not any(m in msg_up for m in unreg_msgs) and x.status == 4 and 'DOWN' not in msg_up and 'UNREACHABLE' not in msg_up:
#Tag any potential unregistered torrents
if not any(m in msg_up for m in unreg_msgs) and x.status == 4 and 'issue' not in check_tags:
pot_unr = ''
pot_unr += (util.insert_space(f'Torrent Name: {t_name}',3)+'\n')
pot_unr += (util.insert_space(f'Status: {msg_up}',9)+'\n')
pot_unr += (util.insert_space(f'Tracker: {tags["url"]}',8)+'\n')
pot_unr += (util.insert_space(f"Added Tag: 'issue'",6)+'\n')
pot_unr_summary += pot_unr
attr = {
"function":"potential_rem_unregistered",
"title":"Potential Unregistered Torrents",
"body": pot_unr,
"torrent_name":t_name,
"torrent_category":t_cat,
"torrent_add_tag": "issue",
"torrent_status": msg_up,
"torrent_tracker": tags["url"],
"notifiarr_indexer": tags["notifiarr"],
}
self.config.send_notifications(attr)
if any(m in msg_up for m in unreg_msgs) and x.status == 4 and 'DOWN' not in msg_up and 'UNREACHABLE' not in msg_up:
if not dry_run: torrent.add_tags(tags='issue')
if any(m in msg_up for m in unreg_msgs) and x.status == 4:
body = []
body += print_line(util.insert_space(f'Torrent Name: {t_name}',3),loglevel)
body += print_line(util.insert_space(f'Status: {msg_up}',9),loglevel)
Expand Down Expand Up @@ -409,9 +426,9 @@ def rem_unregistered(self):
else:
print_line('No unregistered torrents found.',loglevel)

if (len(pot_unr) > 0):
if (len(pot_unr_summary) > 0):
separator(f"Potential Unregistered torrents", space=False, border=False,loglevel=loglevel)
print_multiline(pot_unr.rstrip(),loglevel)
print_multiline(pot_unr_summary.rstrip(),loglevel)
return del_tor,del_tor_cont

# Function used to move any torrents from the cross seed directory to the correct save directory
Expand Down
1 change: 1 addition & 0 deletions qbit_manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ def fmt_filter(record):
break

if os.path.exists(log_file):
print(f"Log Warning: Log Path {log_file} does not exist. Logs will be saved in the default path: {os.path.join(default_dir, os.path.basename(log_file))}")
file_logger = log_file
else:
file_logger = os.path.join(default_dir, os.path.basename(log_file))
Expand Down

0 comments on commit 6036e2e

Please sign in to comment.