From 210749fa0f6aab84e3b98f26b39e1cad1f746533 Mon Sep 17 00:00:00 2001 From: John Smith Date: Tue, 17 Nov 2020 21:56:01 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E5=85=BC=E5=AE=B9=E8=85=BE=E8=AE=AF?= =?UTF-8?q?=E7=BF=BB=E8=AF=91=E5=8D=87=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/chat.py | 2 +- models/avatar.py | 2 +- models/translate.py | 36 +++++++++++++++++------------------- 3 files changed, 19 insertions(+), 21 deletions(-) diff --git a/api/chat.py b/api/chat.py index 4f327ec8..9a282f42 100644 --- a/api/chat.py +++ b/api/chat.py @@ -406,7 +406,7 @@ def on_message(self, message): self._close_on_timeout_future = None else: logger.warning('Unknown cmd, client: %s, cmd: %d, body: %s', self.request.remote_ip, cmd, body) - except: + except Exception: logger.exception('on_message error, client: %s, message: %s', self.request.remote_ip, message) def on_close(self): diff --git a/models/avatar.py b/models/avatar.py index 0ef7b6ac..bdff4257 100644 --- a/models/avatar.py +++ b/models/avatar.py @@ -125,7 +125,7 @@ async def _get_avatar_url_from_web_consumer(): # 限制频率,防止被B站ban await asyncio.sleep(0.2) - except: + except Exception: logger.exception('_get_avatar_url_from_web_consumer error:') diff --git a/models/translate.py b/models/translate.py index 19d340b2..a2e0264c 100644 --- a/models/translate.py +++ b/models/translate.py @@ -98,7 +98,7 @@ def _on_translate_done(key, future): # 缓存 try: res = future.result() - except: + except Exception: return if res is None: return @@ -135,25 +135,23 @@ async def init(self): async def _do_init(self): try: - async with _http_session.get('https://fanyi.qq.com/') as r: + async with _http_session.post('https://fanyi.qq.com/api/reaauth') as r: if r.status != 200: logger.warning('TencentTranslate init request failed: status=%d %s', r.status, r.reason) return False - html = await r.text() + data = await r.json() except (aiohttp.ClientConnectionError, asyncio.TimeoutError): logger.exception('TencentTranslate init error:') return False - m = re.search(r"""\bqtv\s*=\s*['"](.+?)['"]""", html) - if m is None: - logger.exception('TencentTranslate init failed: qtv not found') + qtv = data.get('qtv', None) + if qtv is None: + logger.warning('TencentTranslate init failed: qtv not found') return False - qtv = m[1] - m = re.search(r"""\bqtk\s*=\s*['"](.+?)['"]""", html) - if m is None: - logger.exception('TencentTranslate init failed: qtk not found') + qtk = data.get('qtk', None) + if qtk is None: + logger.warning('TencentTranslate init failed: qtk not found') return False - qtk = m[1] self._qtv = qtv self._qtk = qtk @@ -168,7 +166,7 @@ async def _reinit_coroutine(self): try: if await self._do_init(): break - except: + except Exception: logger.exception('TencentTranslate init error:') await asyncio.sleep(3 * 60) except asyncio.CancelledError: @@ -232,7 +230,7 @@ def _on_fail(self): self._cool_down_future = asyncio.ensure_future(self._cool_down()) async def _cool_down(self): - logger.warning('TencentTranslate is cooling down') + logger.info('TencentTranslate is cooling down') self._qtv = self._qtk = '' try: while True: @@ -242,10 +240,10 @@ async def _cool_down(self): if await self._do_init(): self._fail_count = 0 break - except: + except Exception: logger.exception('TencentTranslate init error:') finally: - logger.warning('TencentTranslate finished cooling down') + logger.info('TencentTranslate finished cooling down') self._cool_down_future = None @@ -341,20 +339,20 @@ def _generate_salt(text): } async def _cool_down(self): - logger.warning('YoudaoTranslate is cooling down') + logger.info('YoudaoTranslate is cooling down') self._has_init = False try: while True: await asyncio.sleep(3 * 60) try: is_success = await self.init() - except: + except Exception: logger.exception('YoudaoTranslate init error:') continue if is_success: break finally: - logger.warning('YoudaoTranslate finished cooling down') + logger.info('YoudaoTranslate finished cooling down') self._cool_down_future = None @@ -385,7 +383,7 @@ async def _translate_consumer(self): asyncio.ensure_future(self._translate_coroutine(text, future)) # 频率限制一分钟20次 await asyncio.sleep(3.1) - except: + except Exception: logger.exception('BilibiliTranslate error:') async def _translate_coroutine(self, text, future): From 8c7fc2780d5d59b6f75a4f01afb0f32793aaa742 Mon Sep 17 00:00:00 2001 From: John Smith Date: Tue, 24 Nov 2020 23:17:30 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E5=85=BC=E5=AE=B9=E8=85=BE=E8=AE=AF?= =?UTF-8?q?=E7=BF=BB=E8=AF=91=E5=8D=87=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/translate.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/models/translate.py b/models/translate.py index a2e0264c..a59ffb4a 100644 --- a/models/translate.py +++ b/models/translate.py @@ -135,7 +135,19 @@ async def init(self): async def _do_init(self): try: - async with _http_session.post('https://fanyi.qq.com/api/reaauth') as r: + async with _http_session.get('https://fanyi.qq.com/') as r: + if r.status != 200: + logger.warning('TencentTranslate init request failed: status=%d %s', r.status, r.reason) + return False + html = await r.text() + + m = re.search(r"""\breauthuri\s*=\s*['"](.+?)['"]""", html) + if m is None: + logger.exception('TencentTranslate init failed: reauthuri not found') + return False + reauthuri = m[1] + + async with _http_session.post('https://fanyi.qq.com/api/' + reauthuri) as r: if r.status != 200: logger.warning('TencentTranslate init request failed: status=%d %s', r.status, r.reason) return False @@ -160,9 +172,9 @@ async def _do_init(self): async def _reinit_coroutine(self): try: while True: - await asyncio.sleep(55 * 60) + await asyncio.sleep(30) while True: - logger.info('TencentTranslate reinit') + logger.debug('TencentTranslate reinit') try: if await self._do_init(): break From 4f0964c0b3233464270576a207bdc7dbfa654632 Mon Sep 17 00:00:00 2001 From: John Smith Date: Sat, 28 Nov 2020 21:53:49 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=A0=87=E6=B3=A8?= =?UTF-8?q?=E6=89=93=E8=B5=8F=E7=94=A8=E6=88=B7=E5=90=8D=E8=AF=BB=E9=9F=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/api/chat/ChatClientDirect.js | 4 +- frontend/src/api/chatConfig.js | 3 +- .../src/components/ChatRenderer/ImgShadow.vue | 6 +- .../src/components/ChatRenderer/Ticker.vue | 5 +- .../src/components/ChatRenderer/constants.js | 11 +- .../src/components/ChatRenderer/index.vue | 7 +- frontend/src/lang/en.js | 4 + frontend/src/lang/ja.js | 4 + frontend/src/lang/zh.js | 4 + frontend/src/layout/index.vue | 2 +- frontend/src/main.js | 5 +- frontend/src/{utils.js => utils/index.js} | 0 frontend/src/utils/pronunciation/dictKana.js | 20902 ++++++++++++++++ .../src/utils/pronunciation/dictPinyin.js | 20902 ++++++++++++++++ frontend/src/utils/pronunciation/index.js | 54 + frontend/src/views/Home.vue | 7 + frontend/src/views/Room.vue | 23 +- update.py | 2 + 18 files changed, 41927 insertions(+), 18 deletions(-) rename frontend/src/{utils.js => utils/index.js} (100%) create mode 100644 frontend/src/utils/pronunciation/dictKana.js create mode 100644 frontend/src/utils/pronunciation/dictPinyin.js create mode 100644 frontend/src/utils/pronunciation/index.js diff --git a/frontend/src/api/chat/ChatClientDirect.js b/frontend/src/api/chat/ChatClientDirect.js index d3930af2..f83174f4 100644 --- a/frontend/src/api/chat/ChatClientDirect.js +++ b/frontend/src/api/chat/ChatClientDirect.js @@ -1,5 +1,5 @@ import axios from 'axios' -import {inflate} from 'pako' +import * as pako from 'pako' import {getUuid4Hex} from '@/utils' import * as avatar from './avatar' @@ -172,7 +172,7 @@ export default class ChatClientDirect { case OP_SEND_MSG_REPLY: { let body = new Uint8Array(data.buffer, offset + HEADER_SIZE, packLen - HEADER_SIZE) if (ver == WS_BODY_PROTOCOL_VERSION_DEFLATE) { - body = inflate(body) + body = pako.inflate(body) this.handlerMessage(body) } else { try { diff --git a/frontend/src/api/chatConfig.js b/frontend/src/api/chatConfig.js index 05ad65aa..5afaeae7 100644 --- a/frontend/src/api/chatConfig.js +++ b/frontend/src/api/chatConfig.js @@ -18,7 +18,8 @@ export const DEFAULT_CONFIG = { blockMedalLevel: 0, relayMessagesByServer: false, - autoTranslate: false + autoTranslate: false, + giftUsernamePronunciation: '' } export function setLocalConfig (config) { diff --git a/frontend/src/components/ChatRenderer/ImgShadow.vue b/frontend/src/components/ChatRenderer/ImgShadow.vue index f5c1368a..22ec0601 100644 --- a/frontend/src/components/ChatRenderer/ImgShadow.vue +++ b/frontend/src/components/ChatRenderer/ImgShadow.vue @@ -5,7 +5,7 @@