Skip to content

Commit 456d520

Browse files
authored
增加中文标题,简介翻译
1 parent e0ef3f3 commit 456d520

File tree

1 file changed

+38
-10
lines changed

1 file changed

+38
-10
lines changed

main.py

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from flask import Flask, request
1515
from flask import render_template
1616
from flask import send_file
17+
from googletrans import Translator
1718

1819

1920
if sys.version.find('2', 0, 1) == 0:
@@ -69,8 +70,8 @@ def addUser(adminToken, username):
6970
return json.dumps({'issuccess': 'false', 'token': '', 'ex': '未授权访问'})
7071

7172

72-
@app.route('/<requestType>/<dirTagLine>/<q>/<token>/<FQDN>/<port>')
73-
def getMediaInfos(requestType, dirTagLine, q, token, FQDN, port):
73+
@app.route('/<requestType>/<dirTagLine>/<q>/<token>/<FQDN>/<port>/<transum>/<trantitle>')
74+
def getMediaInfos(requestType, dirTagLine, q, token, FQDN, port, transum,trantitle):
7475
"""
7576
根据搜刮网站列表进行数据搜刮
7677
:param cacheFlag: 使用缓存标识
@@ -148,30 +149,32 @@ def getMediaInfos(requestType, dirTagLine, q, token, FQDN, port):
148149
cacheFlag = False
149150
q = q.replace(config.CacheTag, '')
150151
if dirTagLine != "" or not spider_config.SOURCE_LIST[dirTagLine]:
151-
#初始化绕过正则判断变量
152+
# 初始化绕过正则判断变量
152153
nore = False
153154
for template in spider_config.SOURCE_LIST[dirTagLine]:
154155
# 循环模板列表
155156
codeList = []
156157
if q.find(config.NotUseRe) > -1:
157158
#q = q.replace(config.NotUseRe, '')
158-
#设置绕过正则变量
159+
# 设置绕过正则变量
159160
nore = True
160-
re_list = re.finditer(r'.+', q.replace(config.NotUseRe, ''), re.IGNORECASE)
161+
re_list = re.finditer(
162+
r'.+', q.replace(config.NotUseRe, ''), re.IGNORECASE)
161163
else:
162-
re_list = re.finditer(template['pattern'], q.replace(config.NotUseRe, ''), re.IGNORECASE)
164+
re_list = re.finditer(template['pattern'], q.replace(
165+
config.NotUseRe, ''), re.IGNORECASE)
163166

164167
for item in re_list:
165168
codeList.append(item.group())
166-
169+
167170
while '' in re_list:
168171
re_list.remove('')
169172

170173
if len(codeList) == 0:
171174
continue
172175
# 对正则匹配结果进行搜索
173176
for code in codeList:
174-
#判断绕过正则
177+
# 判断绕过正则
175178
if nore:
176179
items = search(template['webList'],
177180
code, autoFlag, cacheFlag)
@@ -182,6 +185,29 @@ def getMediaInfos(requestType, dirTagLine, q, token, FQDN, port):
182185
cacheFlag)
183186

184187
if items.get("issuccess") == "true":
188+
logging.info("翻译简介")
189+
if transum == 'y':
190+
translator = Translator()
191+
if dirTagLine == 'censored' or dirTagLine == 'uncensored' or dirTagLine == 'animation':
192+
items.get('json_data')[0].get('Arzon').update({'m_summary': translator.translate(
193+
items.get('json_data')[0].get('Arzon').get('m_summary'), src='ja', dest='zh-cn').text})
194+
195+
if dirTagLine == 'europe':
196+
items.get('json_data')[0].get('Arzon').update({'m_summary': translator.translate(
197+
items.get('json_data')[0].get('Arzon').get('m_summary'), src='en', dest='zh-cn').text})
198+
199+
logging.info("翻译标题")
200+
if trantitle == 'y':
201+
if dirTagLine == 'censored' or dirTagLine == 'uncensored' or dirTagLine == 'animation':
202+
items.get('json_data')[0].get('Arzon').update({'m_title': translator.translate(
203+
items.get('json_data')[0].get('Arzon').get('m_title'), src='ja', dest='zh-cn').text})
204+
205+
if dirTagLine == 'europe':
206+
items.get('json_data')[0].get('Arzon').update({'m_title': translator.translate(
207+
items.get('json_data')[0].get('Arzon').get('m_title'), src='en', dest='zh-cn').text})
208+
209+
translator = None
210+
185211
logging.info("匹配数据结果:success")
186212
logging.info(u'======结束请求======')
187213
logging.info(u'======返回json======')
@@ -236,11 +262,13 @@ def checkState(token, FQDN, port):
236262
mongoTools.getCollection('meta_cache')
237263
resultDate.append(setCheckState('2.3', '数据库用户权限设置正确'))
238264
except Exception:
239-
resultDate.append(setCheckState('2.1', '数据库用户权限设置不正确,请检查用户权限'))
265+
resultDate.append(setCheckState(
266+
'2.1', '数据库用户权限设置不正确,请检查用户权限'))
240267
except Exception:
241268
resultDate.append(setCheckState('2.2', '数据库登陆失败,请检测用户名密码'))
242269
except Exception:
243-
resultDate.append(setCheckState('2.3', '数据库链接创建失败,请检查服务器是否启动及地址是否正确'))
270+
resultDate.append(setCheckState(
271+
'2.3', '数据库链接创建失败,请检查服务器是否启动及地址是否正确'))
244272

245273
# 用户检测
246274
if config.THIN_MODE is True or config.USER_CHECK is True:

0 commit comments

Comments
 (0)