2022-09-03 15:02:40 -05:00
|
|
|
def build_tor_list(self):
|
2022-07-29 16:02:19 -05:00
|
|
|
"""Builds multiple lists of torrents to be sorted. Also adds tags to the torents.
|
|
|
|
There are more effecient ways of doing things but I did this rather quickly.
|
|
|
|
V2 will certainly be more performant. The reason two lists were used was so that torrents
|
|
|
|
that are in public trackers woudln't be around as long as torrents from a private tracker.
|
|
|
|
"""
|
2022-09-03 18:55:51 -05:00
|
|
|
self.total_torrents = len(self.torrent_list)
|
|
|
|
while self.torrent_list:
|
|
|
|
torrent = self.torrent_list.pop()
|
2022-07-29 16:02:19 -05:00
|
|
|
if self.use_log:
|
|
|
|
self.tl.debug(f'["{torrent["name"][0:20]}..."] {torrent["infohash_v1"]}')
|
2022-09-03 15:02:40 -05:00
|
|
|
if is_ignored_tag(self.ignored_tags.values(),torrent['tags']):
|
2022-09-02 20:22:04 -05:00
|
|
|
self.ignored_counter += 1
|
|
|
|
continue
|
2022-08-26 17:28:47 -05:00
|
|
|
# if torrent['added_on'] + self.minimum_age >= self.t.time():
|
2022-09-03 15:02:40 -05:00
|
|
|
if is_preme(torrent['added_on'], self.minimum_age, self.t.time()):
|
2022-07-29 16:02:19 -05:00
|
|
|
self.preme_tor_counter += 1
|
|
|
|
continue
|
2022-08-26 17:28:47 -05:00
|
|
|
# if torrent['category'] in self.cat_whitelist.values():
|
2022-09-03 15:02:40 -05:00
|
|
|
if is_cat_ignored(torrent['category'], self.cat_whitelist.values()):
|
2022-07-29 16:02:19 -05:00
|
|
|
self.tl.info(f'Ignored torrent:["{torrent["name"][0:20]}..."]')
|
|
|
|
self.ignored_counter += 1
|
|
|
|
continue
|
2022-08-26 17:28:47 -05:00
|
|
|
# if torrent['tracker'] == '':
|
2022-09-03 15:02:40 -05:00
|
|
|
if is_tracker_blank(torrent['tracker']):
|
2022-07-29 16:02:19 -05:00
|
|
|
if self.use_log:
|
|
|
|
self.tl.warning(f'Torrent doesn\'t have a tracker ["{torrent["name"][0:20]}..."] [{torrent["tracker"]}]hash: {torrent["hash"]}')
|
|
|
|
self.ignored_counter += 1
|
|
|
|
continue
|
2022-08-26 17:28:47 -05:00
|
|
|
# if torrent['tracker'].split('/')[2] in self.tracker_whitelist.values():
|
2022-09-03 15:02:40 -05:00
|
|
|
if is_protected_tracker(torrent['tracker'], self.tracker_whitelist.values()):
|
2022-07-29 16:02:19 -05:00
|
|
|
if self.use_log:
|
|
|
|
self.tl.debug(f'Protected torrent: {torrent["tracker"]}hash: {torrent["hash"]}')
|
2022-08-26 17:28:47 -05:00
|
|
|
# if torrent['tags'] == '':
|
2022-09-03 15:02:40 -05:00
|
|
|
if is_tag_blank(torrent['tags']):
|
2022-07-29 16:02:19 -05:00
|
|
|
self.qbt_client.torrents_add_tags(self.tracker_protected_tag,torrent['hash'])
|
|
|
|
self.tracker_list.append(torrent)
|
2022-09-03 15:02:40 -05:00
|
|
|
if is_not_protected_tracker(torrent['tracker'], self.tracker_whitelist.values()):
|
2022-07-29 16:02:19 -05:00
|
|
|
if self.use_log:
|
|
|
|
self.tl.debug(f'Non-protected torrent: {torrent["tracker"]}hash: {torrent["hash"]}')
|
2022-08-26 17:28:47 -05:00
|
|
|
# if torrent['tags'] == '':
|
2022-09-03 15:02:40 -05:00
|
|
|
if is_tag_blank(torrent['tags']):
|
2022-07-29 16:02:19 -05:00
|
|
|
self.qbt_client.torrents_add_tags(self.tracker_non_protected_tag,torrent['hash'])
|
2022-08-26 17:28:47 -05:00
|
|
|
self.tracker_list.append(torrent)
|
|
|
|
|
2022-09-03 15:02:40 -05:00
|
|
|
def is_preme(added, minage, time):
|
2022-08-26 17:28:47 -05:00
|
|
|
if added + minage >= time:
|
|
|
|
return True
|
|
|
|
|
2022-09-03 15:02:40 -05:00
|
|
|
def is_cat_ignored(cat, catlist):
|
2022-08-26 17:28:47 -05:00
|
|
|
if cat in catlist:
|
|
|
|
return True
|
|
|
|
|
2022-09-03 15:02:40 -05:00
|
|
|
def is_tracker_blank(tracker):
|
2022-08-26 17:28:47 -05:00
|
|
|
if tracker == '':
|
|
|
|
return True
|
|
|
|
|
2022-09-03 15:02:40 -05:00
|
|
|
def is_protected_tracker(tracker, trackerlist):
|
2022-08-26 17:28:47 -05:00
|
|
|
if tracker.split('/')[2] in trackerlist:
|
|
|
|
return True
|
|
|
|
|
2022-09-03 15:02:40 -05:00
|
|
|
def is_not_protected_tracker(tracker, trackerlist):
|
2022-08-26 17:28:47 -05:00
|
|
|
if tracker.split('/')[2] not in trackerlist:
|
|
|
|
return True
|
|
|
|
|
2022-09-03 15:02:40 -05:00
|
|
|
def is_tag_blank(tag):
|
2022-08-26 17:28:47 -05:00
|
|
|
if tag == '':
|
|
|
|
return True
|
2022-09-02 20:22:04 -05:00
|
|
|
|
2022-09-03 15:02:40 -05:00
|
|
|
def is_ignored_tag(igtags, tortags):
|
2022-09-02 20:22:04 -05:00
|
|
|
for igt in igtags:
|
|
|
|
if igt in tortags:
|
|
|
|
return True
|