|
@@ -415,10 +415,10 @@ async def create_upload_file(file: UploadFile = File(...)):
|
|
@app.post("/upload_pttx/")
|
|
@app.post("/upload_pttx/")
|
|
async def upload_pttx(file: UploadFile = File(...)):
|
|
async def upload_pttx(file: UploadFile = File(...)):
|
|
try:
|
|
try:
|
|
- if "_" in file.filename:
|
|
|
|
- return {'msg':{'eng':'symbol"_" is not allowed in file name','zh':'檔案無法使用檔名不能含有"_"符號'}}
|
|
|
|
|
|
+ if "#" in file.filename:
|
|
|
|
+ return {'msg':{'eng':'symbol"#" is not allowed in file name','zh':'檔案無法使用檔名不能含有"#"符號'}}
|
|
else:
|
|
else:
|
|
- pttx_name = str(time.time()).replace('.','')+'.pptx'
|
|
|
|
|
|
+ pttx_name = file.filename.replace('.pptx','#')+str(time.time()).replace('.','')+'.pptx'
|
|
with open(pttx_dest+pttx_name, "wb+") as file_object:
|
|
with open(pttx_dest+pttx_name, "wb+") as file_object:
|
|
file_object.write(file.file.read())
|
|
file_object.write(file.file.read())
|
|
return {"msg": resource_server+pttx_sub_folder+pttx_name}
|
|
return {"msg": resource_server+pttx_sub_folder+pttx_name}
|
|
@@ -436,27 +436,20 @@ async def make_anchor_video_gSlide(req:util.models.gSlide_req,token: str = Depen
|
|
|
|
|
|
if len(image_urls) != len(text_content):
|
|
if len(image_urls) != len(text_content):
|
|
return {'msg':{'eng':'number of subtitles and images(videos) should be the same','zh':'副標題數量、圖片(影片)數量以及台詞數量必須一致'}}
|
|
return {'msg':{'eng':'number of subtitles and images(videos) should be the same','zh':'副標題數量、圖片(影片)數量以及台詞數量必須一致'}}
|
|
|
|
+
|
|
for idx in range(len(image_urls)):
|
|
for idx in range(len(image_urls)):
|
|
if 'http' not in image_urls[idx]:
|
|
if 'http' not in image_urls[idx]:
|
|
image_urls[idx] = 'http://'+image_urls[idx]
|
|
image_urls[idx] = 'http://'+image_urls[idx]
|
|
- if req.multiLang==0:
|
|
|
|
- for txt in text_content:
|
|
|
|
- if re.search('[a-zA-Z]', txt) !=None:
|
|
|
|
- print('語言錯誤')
|
|
|
|
- return {'msg':{'eng':'English is not allowed in subtitles','zh':'輸入字串不能包含英文字!'}}
|
|
|
|
- if re.search(',', txt) !=None:
|
|
|
|
- print('包含非法符號')
|
|
|
|
- return {'msg':{'eng':'symbol "," is not allowede','zh':'輸入不能含有","符號'}}
|
|
|
|
|
|
+
|
|
|
|
+ mulitLang, hasError = Check_text_content(text_content)
|
|
|
|
+ if hasError is not False :
|
|
|
|
+ return hasError
|
|
|
|
+
|
|
|
|
+ imgError = Check_image_url(image_urls)
|
|
|
|
+ if imgError is not False :
|
|
|
|
+ return imgError
|
|
|
|
+
|
|
name_hash = str(time.time()).replace('.','')
|
|
name_hash = str(time.time()).replace('.','')
|
|
- for imgu in image_urls:
|
|
|
|
- try:
|
|
|
|
- if get_url_type(imgu) =='video/mp4':
|
|
|
|
- r=requests.get(imgu)
|
|
|
|
- else:
|
|
|
|
- im = Image.open(requests.get(imgu, stream=True).raw)
|
|
|
|
- im= im.convert("RGB")
|
|
|
|
- except:
|
|
|
|
- return {'msg':{'eng':req.imgurl+'cant be proccessed','zh':"無法辨別圖片網址"+req.imgurl}}
|
|
|
|
user_id = get_user_id(token)
|
|
user_id = get_user_id(token)
|
|
proto_req = util.models.request_normal()
|
|
proto_req = util.models.request_normal()
|
|
proto_req.text_content = text_content
|
|
proto_req.text_content = text_content
|
|
@@ -799,6 +792,37 @@ def notify_group(msg):
|
|
headers = {"Authorization": "Bearer " + gid,"Content-Type": "application/x-www-form-urlencoded"}
|
|
headers = {"Authorization": "Bearer " + gid,"Content-Type": "application/x-www-form-urlencoded"}
|
|
r = requests.post("https://notify-api.line.me/api/notify",headers=headers, params={"message": msg})
|
|
r = requests.post("https://notify-api.line.me/api/notify",headers=headers, params={"message": msg})
|
|
|
|
|
|
|
|
+def notify_choozmo(msg):
|
|
|
|
+ #'WekCRfnAirSiSxALiD6gcm0B56EejsoK89zFbIaiZQD' is ChoozmoTeam
|
|
|
|
+ glist = ['WekCRfnAirSiSxALiD6gcm0B56EejsoK89zFbIaiZQD']
|
|
|
|
+ for gid in glist:
|
|
|
|
+ headers = {"Authorization": "Bearer " + gid,"Content-Type": "application/x-www-form-urlencoded"}
|
|
|
|
+ r = requests.post("https://notify-api.line.me/api/notify",headers=headers, params={"message": msg})
|
|
|
|
+
|
|
|
|
+def Check_text_content(text_content):
|
|
|
|
+ mulitLang = 0
|
|
|
|
+ status = False
|
|
|
|
+ for txt in text_content:
|
|
|
|
+ if re.search('[a-zA-Z]', txt) !=None:
|
|
|
|
+ mulitLang = 1
|
|
|
|
+ if re.search(',', txt) !=None:
|
|
|
|
+ print('包含非法符號')
|
|
|
|
+ status = {'msg':{'eng':'symbol "," is not allowede','zh':'輸入不能含有","符號'}}
|
|
|
|
+ return mulitLang, status
|
|
|
|
+
|
|
|
|
+def Check_image_url(image_urls):
|
|
|
|
+ status =False
|
|
|
|
+ for imgu in image_urls:
|
|
|
|
+ try:
|
|
|
|
+ if get_url_type(imgu) =='video/mp4':
|
|
|
|
+ r=requests.get(imgu)
|
|
|
|
+ else:
|
|
|
|
+ im = Image.open(requests.get(imgu, stream=True).raw)
|
|
|
|
+ im= im.convert("RGB")
|
|
|
|
+ except:
|
|
|
|
+ status = {'msg':{'eng':req.imgurl+'cant be proccessed','zh':"無法辨別圖片網址"+req.imgurl}}
|
|
|
|
+ return status
|
|
|
|
+
|
|
|
|
|
|
def gen_video_long_queue(name_hash,name,text_content, image_urls,avatar,multiLang,video_id,user_id):
|
|
def gen_video_long_queue(name_hash,name,text_content, image_urls,avatar,multiLang,video_id,user_id):
|
|
db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/AI_anchor?charset=utf8mb4')
|
|
db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/AI_anchor?charset=utf8mb4')
|
|
@@ -1068,7 +1092,7 @@ def call_speech(text,speaker):
|
|
fw.close()
|
|
fw.close()
|
|
shutil.copy(text+'.wav',speech_dest+text+'.wav')
|
|
shutil.copy(text+'.wav',speech_dest+text+'.wav')
|
|
os.remove(text+'.wav')
|
|
os.remove(text+'.wav')
|
|
- notify_group("speech at www.choozmo.com:8168/speech/"+text+".wav")
|
|
|
|
|
|
+ notify_choozmo("speech at www.choozmo.com:8168/speech/"+text+".wav")
|
|
|
|
|
|
|
|
|
|
def verify_jwt_token(token):
|
|
def verify_jwt_token(token):
|