fix tag bug

This commit is contained in:
jxxghp 2023-06-13 22:22:08 +08:00
parent 6b3bfd04a3
commit c1a22518a2
3 changed files with 12 additions and 11 deletions

View File

@ -51,7 +51,7 @@ class QbittorrentModule(_ModuleBase):
return None, f"添加种子任务失败:{torrent_path}"
else:
# 获取种子Hash
torrent_hash = self.qbittorrent.get_torrent_id_by_tag(tag=tag)
torrent_hash = self.qbittorrent.get_torrent_id_by_tag(tags=tag)
if not torrent_hash:
return None, f"获取种子Hash失败{torrent_path}"
else:
@ -149,4 +149,3 @@ class QbittorrentModule(_ModuleBase):
:return: bool
"""
return self.qbittorrent.delete_torrents(delete_file=True, ids=hashs)

View File

@ -66,7 +66,8 @@ class Qbittorrent(metaclass=Singleton):
if not isinstance(tags, list):
tags = [tags]
for torrent in torrents:
if set(tags).issubset(set(torrent.get("tags").split(','))):
torrent_tags = [str(tag).strip() for tag in torrent.get("tags").split(',')]
if set(tags).issubset(set(torrent_tags)):
results.append(torrent)
return results, False
return torrents or [], False
@ -132,14 +133,14 @@ class Qbittorrent(metaclass=Singleton):
except Exception as err:
logger.error(f"设置强制作种出错:{err}")
def __get_last_add_torrentid_by_tag(self, tag: Union[str, list],
def __get_last_add_torrentid_by_tag(self, tags: Union[str, list],
status: Union[str, list] = None) -> Optional[str]:
"""
根据种子的下载链接获取下载中或暂停的钟子的ID
:return: 种子ID
"""
try:
torrents, _ = self.get_torrents(status=status, tags=tag)
torrents, _ = self.get_torrents(status=status, tags=tags)
except Exception as err:
logger.error(f"获取种子列表出错:{err}")
return None
@ -148,21 +149,21 @@ class Qbittorrent(metaclass=Singleton):
else:
return None
def get_torrent_id_by_tag(self, tag: Union[str, list],
def get_torrent_id_by_tag(self, tags: Union[str, list],
status: Union[str, list] = None) -> Optional[str]:
"""
通过标签多次尝试获取刚添加的种子ID并移除标签
"""
torrent_id = None
# QB添加下载后需要时间重试5次每次等待5秒
for i in range(1, 6):
time.sleep(5)
torrent_id = self.__get_last_add_torrentid_by_tag(tag=tag,
for i in range(1, 10):
time.sleep(3)
torrent_id = self.__get_last_add_torrentid_by_tag(tags=tags,
status=status)
if torrent_id is None:
continue
else:
self.remove_torrents_tag(torrent_id, tag)
self.remove_torrents_tag(torrent_id, tags)
break
return torrent_id

View File

@ -71,7 +71,8 @@ class Transmission(metaclass=Singleton):
if status and torrent.status not in status:
continue
# 种子标签
labels = torrent.labels.split(',') if hasattr(torrent, "labels") else []
labels = [str(tag).strip()
for tag in torrent.labels.split(',')] if hasattr(torrent, "labels") else []
if tags and not set(tags).issubset(set(labels)):
continue
ret_torrents.append(torrent)