diff --git a/package.json b/package.json index fef90d9..10b4578 100644 --- a/package.json +++ b/package.json @@ -236,11 +236,12 @@ "name": "IYUU自动辅种", "description": "基于IYUU官方Api实现自动辅种。", "labels": "做种,IYUU", - "version": "1.7", + "version": "1.8", "icon": "IYUU.png", "author": "jxxghp", "level": 2, "history": { + "v1.8": "适配新版本IYUU开发版", "v1.7": "适配馒头最新变化,需要升级至v1.8.5+版本且维护好Authorization", "v1.6": "增加不辅种小体积种子功能", "v1.5": "支持馒头新架构辅种" diff --git a/plugins/iyuuautoseed/__init__.py b/plugins/iyuuautoseed/__init__.py index 172542d..681395c 100644 --- a/plugins/iyuuautoseed/__init__.py +++ b/plugins/iyuuautoseed/__init__.py @@ -34,7 +34,7 @@ class IYUUAutoSeed(_PluginBase): # 插件图标 plugin_icon = "IYUU.png" # 插件版本 - plugin_version = "1.7" + plugin_version = "1.8" # 插件作者 plugin_author = "jxxghp" # 作者主页 diff --git a/plugins/iyuuautoseed/iyuu_helper.py b/plugins/iyuuautoseed/iyuu_helper.py index 914595a..0867181 100644 --- a/plugins/iyuuautoseed/iyuu_helper.py +++ b/plugins/iyuuautoseed/iyuu_helper.py @@ -3,14 +3,16 @@ import json import time from typing import Tuple, Optional +from app.log import logger from app.utils.http import RequestUtils class IyuuHelper(object): - _version = "2.0.0" - _api_base = "http://api.bolahg.cn/%s" + _version = "8.2.0" + _api_base = "https://dev.iyuu.cn" _sites = {} _token = None + _sid_sha1 = None def __init__(self, token: str): self._token = token @@ -24,28 +26,23 @@ class IyuuHelper(object): """ 向IYUUApi发送请求 """ - if params: - if not params.get("sign"): - params.update({"sign": self._token}) - if not params.get("version"): - params.update({"version": self._version}) - else: - params = {"sign": self._token, "version": self._version} - # 开始请求 - if method == "get": + ret = None + if method == "post": ret = RequestUtils( - accept_type="application/json" - ).get_res(f"{url}", params=params) + accept_type="application/json", + headers={'token': self._token} + ).post_res(f'{self._api_base + url}', json=params) else: ret = RequestUtils( - accept_type="application/json" - ).post_res(f"{url}", data=params) + accept_type="application/json", + headers={'token': self._token} + ).get_res(f'{self._api_base + url}', params=params) if ret: result = ret.json() - if result.get('ret') == 200: + if result.get('code') == 0: return result.get('data'), "" else: - return None, f"请求IYUU失败,状态码:{result.get('ret')},返回信息:{result.get('msg')}" + return None, f'请求IYUU失败,状态码:{result.get("code")},返回信息:{result.get("msg")}' elif ret is not None: return None, f"请求IYUU失败,状态码:{ret.status_code},错误原因:{ret.reason}" else: @@ -65,27 +62,11 @@ class IyuuHelper(object): """ 返回支持辅种的全部站点 :return: 站点列表、错误信息 - { - "ret": 200, - "data": { - "sites": [ - { - "id": 1, - "site": "keepfrds", - "nickname": "朋友", - "base_url": "pt.keepfrds.com", - "download_page": "download.php?id={}&passkey={passkey}", - "reseed_check": "passkey", - "is_https": 2 - }, - ] - } - } """ - result, msg = self.__request_iyuu(url=self._api_base % 'App.Api.Sites') + result, msg = self.__request_iyuu(url='/reseed/sites/index') if result: ret_sites = {} - sites = result.get('sites') or [] + sites = result.get('sites') for site in sites: ret_sites[site.get('id')] = site return ret_sites @@ -93,37 +74,41 @@ class IyuuHelper(object): print(msg) return {} + def __report_existing(self) -> Optional[str]: + """ + 汇报辅种的站点 + :return: + """ + if not self._sites: + self._sites = self.__get_sites() + sid_list = list(self._sites.keys()) + result, msg = self.__request_iyuu(url='/reseed/sites/reportExisting', + method='post', + params={'sid_list': sid_list}) + if result: + return result.get('sid_sha1') + return None + def get_seed_info(self, info_hashs: list) -> Tuple[Optional[dict], str]: """ 返回info_hash对应的站点id、种子id - { - "ret": 200, - "data": [ - { - "sid": 3, - "torrent_id": 377467, - "info_hash": "a444850638e7a6f6220e2efdde94099c53358159" - }, - { - "sid": 7, - "torrent_id": 35538, - "info_hash": "cf7d88fd656d10fe5130d13567aec27068b96676" - } - ], - "msg": "", - "version": "1.0.0" - } + :param info_hashs: + :return: """ + if not self._sid_sha1: + self._sid_sha1 = self.__report_existing() info_hashs.sort() json_data = json.dumps(info_hashs, separators=(',', ':'), ensure_ascii=False) sha1 = self.get_sha1(json_data) - result, msg = self.__request_iyuu(url=self._api_base % 'App.Api.Infohash', - method="post", - params={ - "timestamp": time.time(), - "hash": json_data, - "sha1": sha1 - }) + logger.info(f'{json_data}') + logger.info(f'{sha1}') + result, msg = self.__request_iyuu(url='/reseed/index/index', method='post', params={ + 'hash': json_data, + 'sha1': sha1, + 'sid_sha1': self._sid_sha1, + 'timestamp': int(time.time()), + 'version': self._version + }) return result, msg @staticmethod