Skip to content

Commit

Permalink
Merge pull request #1566 from sundxfansky/main
Browse files Browse the repository at this point in the history
  • Loading branch information
jxxghp committed Feb 28, 2024
2 parents c9ebe76 + 31ca418 commit 2e661f8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/modules/transmission/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,20 +121,25 @@ def __get_torrent_info() -> Tuple[str, int]:
return torrent_hash, "获取种子文件失败,下载任务可能在暂停状态"
# 需要的文件信息
file_ids = []
unwanted_file_ids = []
for torrent_file in torrent_files:
file_id = torrent_file.id
file_name = torrent_file.name
meta_info = MetaInfo(file_name)
if not meta_info.episode_list:
unwanted_file_ids.append(file_id)
continue
selected = set(meta_info.episode_list).issubset(set(episodes))
if not selected:
unwanted_file_ids.append(file_id)
continue
file_ids.append(file_id)
# 选择文件
self.transmission.set_files(torrent_hash, file_ids)
self.transmission.set_unwanted_files(torrent_hash, unwanted_file_ids)
# 开始任务
self.transmission.start_torrents(torrent_hash)
return torrent_hash, "添加下载任务成功"
else:
return torrent_hash, "添加下载任务成功"

Expand Down
14 changes: 14 additions & 0 deletions app/modules/transmission/transmission.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,19 @@ def set_files(self, tid: str, file_ids: list) -> bool:
logger.error(f"设置下载文件状态出错:{str(err)}")
return False

def set_unwanted_files(self, tid: str, file_ids: list) -> bool:
"""
设置下载文件的状态
"""
if not self.trc:
return False
try:
self.trc.change_torrent(ids=tid, files_unwanted=file_ids)
return True
except Exception as err:
logger.error(f"设置下载文件状态出错:{str(err)}")
return False

def transfer_info(self) -> Optional[SessionStats]:
"""
获取传输信息
Expand Down Expand Up @@ -359,3 +372,4 @@ def update_tracker(self, hash_string: str, tracker_list: list = None) -> bool:
except Exception as err:
logger.error(f"修改tracker出错:{str(err)}")
return False

0 comments on commit 2e661f8

Please sign in to comment.