Skip to content

Commit

Permalink
移除B站翻译白嫖版
Browse files Browse the repository at this point in the history
  • Loading branch information
xfgryujk committed Jun 18, 2022
1 parent 2c0dd6e commit 582508b
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 45 deletions.
12 changes: 1 addition & 11 deletions data/config.example.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Expand Down
34 changes: 0 additions & 34 deletions services/translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 582508b

Please sign in to comment.