2022-07-14 19:03:06 -05:00
|
|
|
#The second file shall contain functions to build out a list of torrents.
|
|
|
|
def buildtorlist(self):
|
2022-07-20 11:34:13 -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-07-14 19:03:06 -05:00
|
|
|
self.protected_count = 0
|
|
|
|
self.nonprotected_count = 0
|
|
|
|
while self.torrentlist:
|
|
|
|
torrent = self.torrentlist.pop()
|
2022-07-20 11:06:11 -05:00
|
|
|
if self.use_log:
|
|
|
|
self.tl.debug(f'{torrent["name"]} {torrent["infohash_v1"]}')
|
2022-07-15 20:33:51 -05:00
|
|
|
if torrent['tracker'] == '':
|
2022-07-20 11:06:11 -05:00
|
|
|
if self.use_log:
|
|
|
|
self.tl.warning(f"Torrent doesn't have a tracker{torrent['name']} [{torrent['tracker']}]hash: {torrent['hash']}")
|
2022-07-15 20:33:51 -05:00
|
|
|
break
|
2022-07-14 19:03:06 -05:00
|
|
|
if self.tracker_whitelist['iptorrents-empirehost'] in torrent['tracker']:
|
2022-07-20 11:06:11 -05:00
|
|
|
if self.use_log:
|
|
|
|
self.tl.debug(f'Protected torrent: {torrent["tracker"]}hash: {torrent["hash"]}')
|
2022-07-14 19:03:06 -05:00
|
|
|
self.protected_count += 1
|
|
|
|
self.qbt_client.torrents_add_tags(self.tracker_protected_tag,torrent['hash'])
|
|
|
|
self.tracker_protected_list.append(torrent)
|
|
|
|
elif self.tracker_whitelist["iptorrents-stackoverflow"] in torrent['tracker']:
|
2022-07-20 11:06:11 -05:00
|
|
|
if self.use_log:
|
|
|
|
self.tl.debug(f'Protected torrent: {torrent["tracker"]}hash: {torrent["hash"]}')
|
2022-07-14 19:03:06 -05:00
|
|
|
self.protected_count += 1
|
|
|
|
self.qbt_client.torrents_add_tags(self.tracker_protected_tag,torrent['hash'])
|
|
|
|
self.tracker_protected_list.append(torrent)
|
|
|
|
elif self.tracker_whitelist["iptorrents-bgp"] in torrent['tracker']:
|
2022-07-20 11:06:11 -05:00
|
|
|
if self.use_log:
|
|
|
|
self.tl.debug(f'Protected torrent: {torrent["tracker"]}hash: {torrent["hash"]}')
|
2022-07-14 19:03:06 -05:00
|
|
|
self.protected_count += 1
|
|
|
|
self.qbt_client.torrents_add_tags(self.tracker_protected_tag,torrent['hash'])
|
|
|
|
self.tracker_protected_list.append(torrent)
|
|
|
|
else:
|
2022-07-20 11:06:11 -05:00
|
|
|
if self.use_log:
|
|
|
|
self.tl.debug(f'Non-protected torrent: {torrent["tracker"]}hash: {torrent["hash"]}')
|
2022-07-14 19:03:06 -05:00
|
|
|
self.nonprotected_count += 1
|
|
|
|
self.qbt_client.torrents_add_tags(self.tracker_non_protected_tag,torrent['hash'])
|
|
|
|
self.tracker_nonprotected_list.append(torrent)
|
|
|
|
|
|
|
|
def writetor(self, filepath='./torrentinfo.txt'):
|
2022-07-20 11:34:13 -05:00
|
|
|
"""Write all torrent data to a file.
|
|
|
|
Useful for development of new features.
|
|
|
|
"""
|
2022-07-14 19:03:06 -05:00
|
|
|
with open(filepath, 'w') as fp:
|
|
|
|
fp.write(str(self.torrentlist))
|
|
|
|
|
|
|
|
def listfirsttor(self, index=0):
|
2022-07-14 21:37:45 -05:00
|
|
|
"""Only lists the first torrent"""
|
|
|
|
self.tl.debug('First torrent in the list:')
|
2022-07-14 19:03:06 -05:00
|
|
|
torrent = self.torrentlist[index]
|
|
|
|
for k,v in torrent.items():
|
|
|
|
self.tl.debug(f'{k}: {v}')
|
2022-07-14 21:37:45 -05:00
|
|
|
self.tl.debug('\n')
|
2022-07-14 19:03:06 -05:00
|
|
|
|
|
|
|
def listqbitapiinfo(self):
|
2022-07-14 21:37:45 -05:00
|
|
|
"""Writes torrent info to log file"""
|
2022-07-19 00:05:48 -05:00
|
|
|
self.tl.debug(f'qBittorrent: {self.qbt_client.app.version}')
|
|
|
|
self.tl.debug(f'qBittorrent Web API: {self.qbt_client.app.web_api_version}')
|
2022-07-14 19:03:06 -05:00
|
|
|
|
|
|
|
def torrentcount(self):
|
2022-07-20 11:34:13 -05:00
|
|
|
"""write torrent counts to log file"""
|
2022-07-14 19:03:06 -05:00
|
|
|
self.tl.debug(f'torrents that are protected {self.protected_count}')
|
|
|
|
self.tl.debug(f"torrents that aren't protected {self.nonprotected_count}")
|