Skip to content

Commit

Permalink
fix #2192
Browse files Browse the repository at this point in the history
  • Loading branch information
jxxghp committed May 27, 2024
1 parent 8d82d0f commit 1425b15
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 12 deletions.
2 changes: 1 addition & 1 deletion app/chain/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ def transfer(self, path: Path, meta: MetaBase, mediainfo: MediaInfo,
transfer_type=transfer_type, target=target, episodes_info=episodes_info,
scrape=scrape)

def transfer_completed(self, hashs: Union[str, list], path: Path = None,
def transfer_completed(self, hashs: str, path: Path = None,
downloader: str = settings.DEFAULT_DOWNLOADER) -> None:
"""
转移完成后的处理
Expand Down
2 changes: 1 addition & 1 deletion app/modules/qbittorrent/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def list_torrents(self, status: TorrentStatus = None,
return None
return ret_torrents

def transfer_completed(self, hashs: Union[str, list], path: Path = None,
def transfer_completed(self, hashs: str, path: Path = None,
downloader: str = settings.DEFAULT_DOWNLOADER) -> None:
"""
转移完成后的处理
Expand Down
11 changes: 9 additions & 2 deletions app/modules/transmission/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def list_torrents(self, status: TorrentStatus = None,
return None
return ret_torrents

def transfer_completed(self, hashs: Union[str, list], path: Path = None,
def transfer_completed(self, hashs: str, path: Path = None,
downloader: str = settings.DEFAULT_DOWNLOADER) -> None:
"""
转移完成后的处理
Expand All @@ -241,7 +241,14 @@ def transfer_completed(self, hashs: Union[str, list], path: Path = None,
"""
if downloader != "transmission":
return None
self.transmission.set_torrent_tag(ids=hashs, tags=['已整理'])
# 获取原标签
org_tags = self.transmission.get_torrent_tags(ids=hashs)
# 种子打上已整理标签
if org_tags:
tags = org_tags + ['已整理']
else:
tags = ['已整理']
self.transmission.set_torrent_tag(ids=hashs, tags=tags)
# 移动模式删除种子
if settings.TRANSFER_TYPE == "move":
if self.remove_torrents(hashs):
Expand Down
33 changes: 25 additions & 8 deletions app/modules/transmission/transmission.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import transmission_rpc
from transmission_rpc import Client, Torrent, File
from transmission_rpc.session import SessionStats
from transmission_rpc.session import SessionStats, Session

from app.core.config import settings
from app.log import logger
Expand Down Expand Up @@ -130,21 +130,38 @@ def get_downloading_torrents(self, ids: Union[str, list] = None,
logger.error(f"获取正在下载的种子列表出错:{str(err)}")
return None

def set_torrent_tag(self, ids: str, tags: list) -> bool:
def set_torrent_tag(self, ids: str, tags: list, org_tags: list = None) -> bool:
"""
设置种子标签
设置种子标签,注意TR默认会覆盖原有标签,如需追加需传入原有标签
"""
if not self.trc:
return False
if not ids or not tags:
return False
try:
self.trc.change_torrent(labels=tags, ids=ids)
self.trc.change_torrent(labels=list(set((org_tags or []) + tags)), ids=ids)
return True
except Exception as err:
logger.error(f"设置种子标签出错:{str(err)}")
return False

def get_torrent_tags(self, ids: str) -> List[str]:
"""
获取所有种子标签
"""
if not self.trc:
return []
try:
torrent = self.trc.get_torrents(ids=ids, arguments=self._trarg)
if torrent:
labels = [str(tag).strip()
for tag in torrent.labels] if hasattr(torrent, "labels") else []
return labels
except Exception as err:
logger.error(f"获取种子标签出错:{str(err)}")
return []
return []

def add_torrent(self, content: Union[str, bytes],
is_paused: bool = False,
download_dir: str = None,
Expand Down Expand Up @@ -397,15 +414,15 @@ def update_tracker(self, hash_string: str, tracker_list: list = None) -> bool:
logger.error(f"修改tracker出错:{str(err)}")
return False

def get_session(self) -> Dict[str, Union[int, bool, str]]:
def get_session(self) -> Optional[Session]:
"""
获取Transmission当前的会话信息和配置设置
:return dict or False
:return dict
"""
if not self.trc:
return False
return None
try:
return self.trc.get_session()
except Exception as err:
logger.error(f"获取session出错:{str(err)}")
return False
return None

0 comments on commit 1425b15

Please sign in to comment.