From 8303fe76d8e2c242c85f5830f9c1111678a37176 Mon Sep 17 00:00:00 2001 From: ljmeng Date: Wed, 27 Mar 2024 19:34:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BE=9D=E8=B5=96=EF=BC=8C?= =?UTF-8?q?=E5=85=BC=E5=AE=B9=E6=86=A8=E6=86=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- plugins/crossseed/__init__.py | 5 ++-- plugins/crossseed/cross_seed_helper.py | 40 +++++++++++--------------- plugins/crossseed/requirements.txt | 1 - 4 files changed, 19 insertions(+), 29 deletions(-) delete mode 100644 plugins/crossseed/requirements.txt diff --git a/package.json b/package.json index efac413..36ed80b 100644 --- a/package.json +++ b/package.json @@ -186,7 +186,7 @@ "CrossSeed": { "name": "青蛙辅种助手", "description": "参考ReseedPuppy和IYUU辅种插件实现自动辅种,支持站点:青蛙【已验证】, AGSVPT, 麒麟, UBits, 聆音 等", - "version": "1.4", + "version": "1.5", "icon": "qingwa.png", "author": "233@qingwa", "level": 2 diff --git a/plugins/crossseed/__init__.py b/plugins/crossseed/__init__.py index 5f77021..10d96a0 100644 --- a/plugins/crossseed/__init__.py +++ b/plugins/crossseed/__init__.py @@ -36,7 +36,7 @@ class CrossSeed(_PluginBase): # 插件图标 plugin_icon = "qingwa.png" # 插件版本 - plugin_version = "1.4" + plugin_version = "1.5" # 插件作者 plugin_author = "233@qingwa" # 作者主页 @@ -559,7 +559,6 @@ class CrossSeed(_PluginBase): logger.info(f"下载器 {downloader} 没有已完成种子") continue hash_strs = [] - torrent_site_pieces_hashes = set() for torrent in torrents: if self._event.is_set(): logger.info(f"辅种服务停止") @@ -856,7 +855,7 @@ class CrossSeed(_PluginBase): return False # 添加任务前查询校验一次,避免重复添加,导致暂停的任务被重新开始 - tmp_tor_info, err_msg = TorInfo.from_file(content) + tmp_tor_info, err_msg = TorInfo.from_data(content) if tmp_tor_info and tmp_tor_info.info_hash: tors, msg = self.__get_downloader(downloader).get_torrents(ids=[tmp_tor_info.info_hash]) if tors: diff --git a/plugins/crossseed/cross_seed_helper.py b/plugins/crossseed/cross_seed_helper.py index 622e9be..82441f4 100644 --- a/plugins/crossseed/cross_seed_helper.py +++ b/plugins/crossseed/cross_seed_helper.py @@ -1,10 +1,9 @@ import hashlib -import os from pathlib import Path -from typing import List, Self +from typing import Self -import bencodepy import requests +from bencode import decode, encode class CSSiteConfig(object): @@ -18,6 +17,8 @@ class CSSiteConfig(object): self.passkey = site_passkey def get_api_url(self): + if self.name == "憨憨": + return f"{self.url}/npapi/pieces-hash" return f"{self.url}/api/pieces-hash" def get_torrent_url(self, torrent_id: str): @@ -57,18 +58,17 @@ class TorInfo: ) @staticmethod - def from_file(data: bytes) -> tuple[Self, str]: + def from_data(data: bytes) -> tuple[Self, str]: try: - torrent = bencodepy.decode(data) - info = torrent[b"info"] - pieces = info[b"pieces"] - info_hash = hashlib.sha1(bencodepy.encode(info)).hexdigest() + torrent = decode(data) + info = torrent["info"] + pieces = info["pieces"] + info_hash = hashlib.sha1(encode(info)).hexdigest() pieces_hash = hashlib.sha1(pieces).hexdigest() local_tor = TorInfo(info_hash=info_hash, pieces_hash=pieces_hash) #从种子中获取 announce, qb可能存在获取不到的情况,会存在于fastresume文件中 - if b"announce" in torrent: - announce: bytes = torrent[b"announce"] - local_tor.torrent_announce = announce.decode(encoding="utf-8") + if "announce" in torrent: + local_tor.torrent_announce = torrent["announce"] return local_tor, None except Exception as err: return None, err @@ -80,7 +80,7 @@ class TorInfo: return f"{self.site_name}:{self.pieces_hash}" class CrossSeedHelper(object): - _version = "0.1.0" + _version = "0.2.0" def get_local_torrent_info(self, torrent_path: Path | str) -> tuple[TorInfo, str]: try: @@ -90,17 +90,10 @@ class CrossSeedHelper(object): else: with open(torrent_path, "rb") as f: torrent_data = f.read() - torrent = bencodepy.decode(torrent_data) - info = torrent[b"info"] - pieces = info[b"pieces"] - - info_hash = hashlib.sha1(bencodepy.encode(info)).hexdigest() - pieces_hash = hashlib.sha1(pieces).hexdigest() - local_tor = TorInfo.local(str(torrent_path), info_hash, pieces_hash) - # 对于 transmission 可以从种子中补充 announce - if b"announce" in torrent: - announce: bytes = torrent[b"announce"] - local_tor.torrent_announce = announce.decode(encoding="utf-8") + local_tor, err = TorInfo.from_data(torrent_data) + if not local_tor: + return None, err + local_tor.torrent_path = str(torrent_path) return local_tor, "" except Exception as err: return None, err @@ -133,4 +126,3 @@ class CrossSeedHelper(object): TorInfo.remote(site.name, pieces_hash, torrent_id) ) return remote_torrent_infos, None - diff --git a/plugins/crossseed/requirements.txt b/plugins/crossseed/requirements.txt deleted file mode 100644 index cfce719..0000000 --- a/plugins/crossseed/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -bencode.py==4.0.0 \ No newline at end of file