|
@@ -40,6 +40,7 @@ import mailer
|
|
|
from moviepy.editor import VideoFileClip
|
|
|
import traceback
|
|
|
import logging
|
|
|
+import gSlide
|
|
|
pymysql.install_as_MySQLdb()
|
|
|
|
|
|
app = FastAPI()
|
|
@@ -75,7 +76,6 @@ video_dest = '/var/www/html/'+video_sub_folder
|
|
|
avatar_dest = '/var/www/html/'+avatar_sub_folder
|
|
|
|
|
|
|
|
|
-
|
|
|
@app.get("/index2")
|
|
|
async def index2():
|
|
|
return FileResponse('static/index2.html')
|
|
@@ -102,6 +102,15 @@ async def get_home_page(request: Request, response: Response, Authorize: AuthJWT
|
|
|
current_user = Authorize.get_jwt_subject()
|
|
|
return templates.TemplateResponse("make_video.html", {"request": request, "response": response})
|
|
|
|
|
|
+@app.get("/make_video_slide", response_class=HTMLResponse)
|
|
|
+async def make_video_slide(request: Request, response: Response, Authorize: AuthJWT = Depends()):
|
|
|
+ try:
|
|
|
+ Authorize.jwt_required()
|
|
|
+ except Exception as e:
|
|
|
+ print(e)
|
|
|
+ return '請先登入帳號'
|
|
|
+ current_user = Authorize.get_jwt_subject()
|
|
|
+ return templates.TemplateResponse("make_video_slide.html", {"request": request, "response": response})
|
|
|
|
|
|
@app.get('/user_profile', response_class=HTMLResponse)
|
|
|
def protected(request: Request, Authorize: AuthJWT = Depends()):
|
|
@@ -209,6 +218,41 @@ async def create_upload_file(file: UploadFile = File(...)):
|
|
|
return {'msg':'檔案無法使用'}
|
|
|
return {"msg": 'www.choozmo.com:8168/'+tmp_img_sub_folder+img_name+'.jpg'}
|
|
|
|
|
|
+@app.post("/make_anchor_video_gSlide")
|
|
|
+async def make_anchor_video_gSlide(req:models.gSlide_req,token: str = Depends(oauth2_scheme)):
|
|
|
+ name, text_content, image_urls = gSlide.parse_slide_url(req.slide_url,eng=False)
|
|
|
+ if len(image_urls) != len(text_content):
|
|
|
+ return {'msg':'副標題數量、圖片(影片)數量以及台詞數量必須一致'}
|
|
|
+ for idx in range(len(image_urls)):
|
|
|
+ if 'http' not in 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':'輸入字串不能包含英文字!'}
|
|
|
+ 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':"無法辨別圖片網址"+imgu}
|
|
|
+ user_id = get_user_id(token)
|
|
|
+ proto_req = models.request_normal()
|
|
|
+ proto_req.text_content = text_content
|
|
|
+ proto_req.name = name
|
|
|
+ proto_req.image_urls = image_urls
|
|
|
+ proto_req.avatar = req.avatar
|
|
|
+ proto_req.multiLang = req.multiLang
|
|
|
+ save_history(proto_req,name_hash,user_id)
|
|
|
+ x = threading.Thread(target=gen_video_queue, args=(name_hash,name, text_content, image_urls,int(req.avatar),req.multiLang,user_id))
|
|
|
+ x.start()
|
|
|
+ return {"msg":"製作影片需要時間,請您耐心等候,成果會傳送至LINE群組中"}
|
|
|
+
|
|
|
@app.post("/make_anchor_video")
|
|
|
async def make_anchor_video(req:models.request,token: str = Depends(oauth2_scheme)):
|
|
|
if len(req.image_urls) != len(req.text_content):
|
|
@@ -216,9 +260,11 @@ async def make_anchor_video(req:models.request,token: str = Depends(oauth2_schem
|
|
|
for idx in range(len(req.image_urls)):
|
|
|
if 'http' not in req.image_urls[idx]:
|
|
|
req.image_urls[idx] = 'http://'+req.image_urls[idx]
|
|
|
- for txt in req.text_content:
|
|
|
- if re.search('[a-zA-Z]', txt) !=None:
|
|
|
- return {'msg':'輸入字串不能包含英文字!'}
|
|
|
+ if req.multiLang==0:
|
|
|
+ for txt in req.text_content:
|
|
|
+ if re.search('[a-zA-Z]', txt) !=None:
|
|
|
+ print('語言錯誤')
|
|
|
+ return {'msg':'輸入字串不能包含英文字!'}
|
|
|
name_hash = str(time.time()).replace('.','')
|
|
|
for imgu in req.image_urls:
|
|
|
try:
|
|
@@ -231,7 +277,7 @@ async def make_anchor_video(req:models.request,token: str = Depends(oauth2_schem
|
|
|
return {'msg':"無法辨別圖片網址"+imgu}
|
|
|
user_id = get_user_id(token)
|
|
|
save_history(req,name_hash,user_id)
|
|
|
- x = threading.Thread(target=gen_video_queue, args=(name_hash,req.name, req.text_content, req.image_urls,int(req.avatar),user_id))
|
|
|
+ x = threading.Thread(target=gen_video_queue, args=(name_hash,req.name, req.text_content, req.image_urls,int(req.avatar),req.multiLang,user_id))
|
|
|
x.start()
|
|
|
return {"msg":"製作影片需要時間,請您耐心等候,成果會傳送至LINE群組中"}
|
|
|
|
|
@@ -407,7 +453,7 @@ def gen_video_eng(name_hash,name,text_content, image_urls,sub_titles,avatar):
|
|
|
shutil.copy(tmp_video_dir+name_hash+'.mp4',video_dest+name_hash+'.mp4')
|
|
|
os.remove(tmp_video_dir+name_hash+'.mp4')
|
|
|
|
|
|
-def gen_video_queue(name_hash,name,text_content, image_urls,avatar,user_id):
|
|
|
+def gen_video_queue(name_hash,name,text_content, image_urls,avatar,multiLang,user_id):
|
|
|
db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/AI_anchor?charset=utf8mb4')
|
|
|
time_stamp = datetime.fromtimestamp(time.time()).strftime("%Y-%m-%d %H:%M:%S")
|
|
|
txt_content_seperate_by_dot = ''
|
|
@@ -418,7 +464,8 @@ def gen_video_queue(name_hash,name,text_content, image_urls,avatar,user_id):
|
|
|
for iurl in image_urls:
|
|
|
img_urls_seperate_by_dot += iurl+","
|
|
|
img_urls_seperate_by_dot = img_urls_seperate_by_dot[:-1]
|
|
|
- db['video_queue'].insert({'name_hash':name_hash,'name':name,'text_content':txt_content_seperate_by_dot,'image_urls':img_urls_seperate_by_dot,'avatar':avatar,'timestamp':time_stamp})
|
|
|
+
|
|
|
+ db['video_queue'].insert({'name_hash':name_hash,'name':name,'text_content':txt_content_seperate_by_dot,'image_urls':img_urls_seperate_by_dot,'multiLang':multiLang,'avatar':avatar,'timestamp':time_stamp})
|
|
|
while True:
|
|
|
|
|
|
if first(db.query('SELECT * FROM video_queue_status'))['status'] == 1:#only one row in this table, which is the id 1 one
|
|
@@ -434,7 +481,7 @@ def gen_video_queue(name_hash,name,text_content, image_urls,avatar,user_id):
|
|
|
c = rpyc.connect("localhost", 8858)
|
|
|
c._config['sync_request_timeout'] = None
|
|
|
remote_svc = c.root
|
|
|
- my_answer = remote_svc.call_video(top1['name_hash'],top1['name'],top1['text_content'].split(','), top1['image_urls'].split(','),top1['avatar']) # method call
|
|
|
+ my_answer = remote_svc.call_video(top1['name_hash'],top1['name'],top1['text_content'].split(','), top1['image_urls'].split(','),top1['multiLang'],top1['avatar']) # method call
|
|
|
shutil.copy(tmp_video_dir+top1['name_hash']+'.mp4',video_dest+top1['name_hash']+'.mp4')
|
|
|
os.remove(tmp_video_dir+top1['name_hash']+'.mp4')
|
|
|
vid_duration = VideoFileClip(video_dest+top1['name_hash']+'.mp4').duration
|
|
@@ -454,7 +501,7 @@ def gen_video_queue(name_hash,name,text_content, image_urls,avatar,user_id):
|
|
|
else:
|
|
|
left_time = left_time - vid_duration
|
|
|
db.query('UPDATE users SET left_time ='+str(left_time)+' WHERE id='+str(user_id)+';')
|
|
|
- notify_group(name+"的影片已經產生完成囉! www.choozmo.com:8168/"+video_sub_folder+name_hash+".mp4")
|
|
|
+ #notify_group(name+"的影片已經產生完成囉! www.choozmo.com:8168/"+video_sub_folder+name_hash+".mp4")
|
|
|
notify_line_user(name+"的影片已經產生完成囉! www.choozmo.com:8168/"+video_sub_folder+name_hash+".mp4", line_token)
|
|
|
except Exception as e:
|
|
|
logging.error(traceback.format_exc())
|