diff --git a/app/chain/site.py b/app/chain/site.py index 992ca2dd..3fe4cd34 100644 --- a/app/chain/site.py +++ b/app/chain/site.py @@ -73,7 +73,7 @@ class SiteChain(ChainBase): ua=user_agent, cookies=site.cookie, proxies=settings.PROXY if site.proxy else None, - timeout=15 + timeout=site.timeout or 15 ).get_res(url=site.url) if res and res.status_code == 200: csrf_token = re.search(r'', res.text) @@ -90,7 +90,7 @@ class SiteChain(ChainBase): }, cookies=site.cookie, proxies=settings.PROXY if site.proxy else None, - timeout=15 + timeout=site.timeout or 15 ).get_res(url=f"{site.url}api/user/getInfo") if user_res and user_res.status_code == 200: user_info = user_res.json() @@ -114,14 +114,14 @@ class SiteChain(ChainBase): res = RequestUtils( headers=headers, proxies=settings.PROXY if site.proxy else None, - timeout=15 + timeout=site.timeout or 15 ).post_res(url=url) if res and res.status_code == 200: user_info = res.json() if user_info and user_info.get("data"): # 更新最后访问时间 res = RequestUtils(headers=headers, - timeout=60, + timeout=site.timeout or 15, proxies=settings.PROXY if site.proxy else None, referer=f"{site.url}index" ).post_res(url=urljoin(url, "api/member/updateLastBrowse")) @@ -148,7 +148,7 @@ class SiteChain(ChainBase): :return: """ favicon_url = urljoin(url, "favicon.ico") - res = RequestUtils(cookies=cookie, timeout=60, ua=ua).get_res(url=url) + res = RequestUtils(cookies=cookie, timeout=30, ua=ua).get_res(url=url) if res: html_text = res.text else: @@ -160,7 +160,7 @@ class SiteChain(ChainBase): if fav_link: favicon_url = urljoin(url, fav_link[0]) - res = RequestUtils(cookies=cookie, timeout=20, ua=ua).get_res(url=favicon_url) + res = RequestUtils(cookies=cookie, timeout=15, ua=ua).get_res(url=favicon_url) if res: return favicon_url, base64.b64encode(res.content).decode() else: diff --git a/app/db/models/site.py b/app/db/models/site.py index 3f21e10e..7016eb93 100644 --- a/app/db/models/site.py +++ b/app/db/models/site.py @@ -45,6 +45,8 @@ class Site(Base): limit_count = Column(Integer, default=0) # 流控间隔 limit_seconds = Column(Integer, default=0) + # 超时时间 + timeout = Column(Integer, default=0) # 是否启用 is_active = Column(Boolean(), default=True) # 创建时间 diff --git a/app/modules/indexer/mtorrent.py b/app/modules/indexer/mtorrent.py index 1f1194e3..150a38d0 100644 --- a/app/modules/indexer/mtorrent.py +++ b/app/modules/indexer/mtorrent.py @@ -27,6 +27,7 @@ class MTorrentSpider: _searchurl = "%sapi/torrent/search" _downloadurl = "%sapi/torrent/genDlToken" _pageurl = "%sdetail/%s" + _timeout = 15 # 电影分类 _movie_category = ['401', '419', '420', '421', '439', '405', '404'] @@ -62,6 +63,7 @@ class MTorrentSpider: self._ua = indexer.get('ua') self._apikey = indexer.get('apikey') self._token = indexer.get('token') + self._timeout = indexer.get('timeout') or 15 def search(self, keyword: str, mtype: MediaType = None, page: int = 0) -> Tuple[bool, List[dict]]: """ @@ -92,7 +94,7 @@ class MTorrentSpider: }, proxies=self._proxy, referer=f"{self._domain}browse", - timeout=15 + timeout=self._timeout ).post_res(url=self._searchurl, json=params) torrents = [] if res and res.status_code == 200: diff --git a/app/modules/indexer/spider.py b/app/modules/indexer/spider.py index 265f0dde..19ecbb0f 100644 --- a/app/modules/indexer/spider.py +++ b/app/modules/indexer/spider.py @@ -63,8 +63,8 @@ class TorrentSpider: torrents_info: dict = {} # 种子列表 torrents_info_array: list = [] - # 搜索超时, 默认: 30秒 - _timeout = 30 + # 搜索超时, 默认: 15秒 + _timeout = 15 def __init__(self, indexer: CommentedMap, diff --git a/app/modules/indexer/tnode.py b/app/modules/indexer/tnode.py index 28d76e1c..a7356b4c 100644 --- a/app/modules/indexer/tnode.py +++ b/app/modules/indexer/tnode.py @@ -18,6 +18,7 @@ class TNodeSpider: _ua = None _token = None _size = 100 + _timeout = 15 _searchurl = "%sapi/torrent/advancedSearch" _downloadurl = "%sapi/torrent/download/%s" _pageurl = "%storrent/info/%s" @@ -32,6 +33,7 @@ class TNodeSpider: self._proxy = settings.PROXY self._cookie = indexer.get('cookie') self._ua = indexer.get('ua') + self._timeout = indexer.get('timeout') or 15 self.init_config() def init_config(self): @@ -43,7 +45,7 @@ class TNodeSpider: res = RequestUtils(ua=self._ua, cookies=self._cookie, proxies=self._proxy, - timeout=15).get_res(url=self._domain) + timeout=self._timeout).get_res(url=self._domain) if res and res.status_code == 200: csrf_token = re.search(r'', res.text) if csrf_token: @@ -77,7 +79,7 @@ class TNodeSpider: }, cookies=self._cookie, proxies=self._proxy, - timeout=15 + timeout=self._timeout ).post_res(url=self._searchurl, json=params) torrents = [] if res and res.status_code == 200: diff --git a/app/modules/indexer/torrentleech.py b/app/modules/indexer/torrentleech.py index 741b24d0..b18f03bb 100644 --- a/app/modules/indexer/torrentleech.py +++ b/app/modules/indexer/torrentleech.py @@ -17,11 +17,13 @@ class TorrentLeech: _browseurl = "%storrents/browse/list/page/2%s" _downloadurl = "%sdownload/%s/%s" _pageurl = "%storrent/%s" + _timeout = 15 def __init__(self, indexer: CommentedMap): self._indexer = indexer if indexer.get('proxy'): self._proxy = settings.PROXY + self._timeout = indexer.get('timeout') or 15 def search(self, keyword: str, page: int = 0) -> Tuple[bool, List[dict]]: @@ -40,7 +42,7 @@ class TorrentLeech: }, cookies=self._indexer.get('cookie'), proxies=self._proxy, - timeout=15 + timeout=self._timeout ).get_res(url) torrents = [] if res and res.status_code == 200: diff --git a/app/schemas/site.py b/app/schemas/site.py index 50885cc0..2a320151 100644 --- a/app/schemas/site.py +++ b/app/schemas/site.py @@ -34,6 +34,8 @@ class Site(BaseModel): public: Optional[int] = 0 # 备注 note: Optional[str] = None + # 超时时间 + timeout: Optional[int] = 0 # 流控单位周期 limit_interval: Optional[int] = None # 流控次数