Skip to content

Commit

Permalink
fix: 'NoneType' object has no attribute 'state' (#138)
Browse files Browse the repository at this point in the history
Bug Fixes:

- Fix the 'NoneType' object has no attribute 'state' error by ensuring the client is passed correctly to the get_download function.

Enhancements:

- Introduce a client method in the QbittorrentStatus class to access the client instance.
  • Loading branch information
Angel-noori authored Sep 14, 2024
1 parent f5774bf commit 0d011f9
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions bot/helper/mirror_leech_utils/status_utils/qbit_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,25 @@
)


def get_download(tag):
def get_download(client, tag):
try:
return xnox_client.torrents_info(tag=tag)[0]
return client.torrents_info(tag=tag)[0]
except Exception as e:
LOGGER.error(f"{e}: Qbittorrent, while getting torrent info. Tag: {tag}")
return None


class QbittorrentStatus:
def __init__(self, listener, seeding=False, queued=False):
self.__client = xnox_client
self.__listener = listener
self.__info = None
self.__info = get_download(self.__client, f'{self.__listener.uid}')
self.queued = queued
self.seeding = seeding
self.message = listener.message

def __update(self):
new_info = get_download(f"{self.__listener.uid}")
new_info = get_download(self.__client, f"{self.__listener.uid}")
if new_info is not None:
self.__info = new_info

Expand Down Expand Up @@ -92,14 +93,17 @@ def gid(self):
def hash(self):
self.__update()
return self.__info.hash

def client(self):
return self.__client

def listener(self):
return self.__listener

async def cancel_download(self):
self.__update()
await sync_to_async(
xnox_client.torrents_pause, torrent_hashes=self.__info.hash
self.__client.torrents_pause, torrent_hashes=self.__info.hash
)
if not self.seeding:
if self.queued:
Expand All @@ -110,10 +114,11 @@ async def cancel_download(self):
msg = "Download stopped by user!"
await sleep(0.3)
await sync_to_async(
xnox_client.torrents_delete,
self.__client.torrents_delete,
torrent_hashes=self.__info.hash,
delete_files=True,
)
await sync_to_async(self.__client.torrents_delete_tags, tags=self.__info.tags)
async with qb_listener_lock:
if self.__info.tags in QbTorrents:
del QbTorrents[self.__info.tags]
Expand Down

0 comments on commit 0d011f9

Please sign in to comment.