From 582508bd3f1b82033005ada3de6e471736e70354 Mon Sep 17 00:00:00 2001 From: John Smith Date: Sat, 18 Jun 2022 21:42:03 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4B=E7=AB=99=E7=BF=BB=E8=AF=91?= =?UTF-8?q?=E7=99=BD=E5=AB=96=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data/config.example.ini | 12 +----------- services/translate.py | 34 ---------------------------------- 2 files changed, 1 insertion(+), 45 deletions(-) diff --git a/data/config.example.ini b/data/config.example.ini index c0eef9b5..ce6bedf8 100644 --- a/data/config.example.ini +++ b/data/config.example.ini @@ -55,7 +55,7 @@ translation_cache_size = 50000 # 翻译器配置,索引到下面的配置节。可以以逗号分隔配置多个翻译器,翻译时会自动负载均衡 # 配置多个翻译器可以增加额度、增加QPS、容灾 # 不同配置可以使用同一个类型,但要使用不同的账号,否则还是会遇到额度、调用频率限制 -translator_configs = tencent_translate_free,bilibili_translate_free +translator_configs = tencent_translate_free [tencent_translate_free] @@ -75,16 +75,6 @@ source_language = zh target_language = jp -[bilibili_translate_free] -# 类型:B站翻译白嫖版。使用了B站直播网页的接口,**将来可能失效**。目前B站翻译后端是百度翻译 -type = BilibiliTranslateFree - -# 请求间隔时间(秒),等于 1 / QPS。目前此接口频率限制是3秒一次 -query_interval = 3.1 -# 最大队列长度,注意最长等待时间等于 最大队列长度 * 请求间隔时间 -max_queue_size = 3 - - [tencent_translate] # 文档:https://cloud.tencent.com/product/tmt # 定价:https://cloud.tencent.com/document/product/551/35017 diff --git a/services/translate.py b/services/translate.py index b97b1970..6debfe8c 100644 --- a/services/translate.py +++ b/services/translate.py @@ -57,8 +57,6 @@ def create_translate_provider(cfg): cfg['query_interval'], cfg['max_queue_size'], cfg['source_language'], cfg['target_language'] ) - elif type_ == 'BilibiliTranslateFree': - return BilibiliTranslateFree(cfg['query_interval'], cfg['max_queue_size']) elif type_ == 'TencentTranslate': return TencentTranslate( cfg['query_interval'], cfg['max_queue_size'], cfg['source_language'], @@ -416,38 +414,6 @@ def _cool_down(self): self._fail_count = 0 -class BilibiliTranslateFree(FlowControlTranslateProvider): - def __init__(self, query_interval, max_queue_size): - super().__init__(query_interval, max_queue_size) - - async def _do_translate(self, text): - try: - async with utils.request.http_session.get( - 'https://api.live.bilibili.com/av/v1/SuperChat/messageTranslate', - headers={ - 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)' - ' Chrome/102.0.0.0 Safari/537.36' - }, - params={ - 'room_id': '21396545', - 'ruid': '407106379', - 'parent_area_id': '9', - 'area_id': '371', - 'msg': text - } - ) as r: - if r.status != 200: - logger.warning('BilibiliTranslateFree request failed: status=%d %s', r.status, r.reason) - return None - data = await r.json() - except (aiohttp.ClientConnectionError, asyncio.TimeoutError): - return None - if data['code'] != 0: - logger.warning('BilibiliTranslateFree failed: %d %s', data['code'], data['msg']) - return None - return data['data']['message_trans'] - - class TencentTranslate(FlowControlTranslateProvider): def __init__(self, query_interval, max_queue_size, source_language, target_language, secret_id, secret_key, region):