|
|
@@ -125,9 +125,22 @@ async def make_video_slide(request: Request, response: Response, Authorize: Auth
|
|
|
|
|
|
@app.get('/user_profile', response_class=HTMLResponse)
|
|
|
def protected(request: Request, Authorize: AuthJWT = Depends()):
|
|
|
+ db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/AI_anchor?charset=utf8mb4')
|
|
|
Authorize.jwt_required()
|
|
|
current_user = Authorize.get_jwt_subject()
|
|
|
- return current_user
|
|
|
+ user_obj = first(db.query('SELECT * FROM users where username ="'+str(current_user)+'"'))
|
|
|
+ email = user_obj.email
|
|
|
+ video_num = first(db.query('SELECT COUNT(*) FROM history_input WHERE user_id ='+user_obj.id))
|
|
|
+ total_sec = first(db.query('SELECT SUM(duration) FROM history_input where user_id='+user_obj.id;
|
|
|
+ left_sec = user_obj.left_time
|
|
|
+
|
|
|
+ video_info_list = []
|
|
|
+ statement = 'SELECT * FROM history_input WHERE user_id='+user_obj.id;
|
|
|
+ for row in db.query(statement):
|
|
|
+ video_info_list.append({'id':row['id'],'title':row['name'],'duration':row['duration'],'url':row['url']})
|
|
|
+
|
|
|
+ return {'user_info':{'userName':current_user,'email':email,'video_num':video_num,'total_sec':total_sec,'left_sec':left_sec}
|
|
|
+ ,'video_info':video_info_list}
|
|
|
|
|
|
|
|
|
# login & register page
|
|
|
@@ -180,15 +193,12 @@ async def access_token(form_data: OAuth2PasswordRequestForm = Depends(), Authori
|
|
|
@app.post("/register")
|
|
|
async def register(request: Request):
|
|
|
user = models.User(**await request.form())
|
|
|
- user_register(user)
|
|
|
- return templates.TemplateResponse("login.html", {'request': request,"success": True}, status_code=status.HTTP_302_FOUND)
|
|
|
-
|
|
|
-@app.get('/user_profile', response_class=HTMLResponse)
|
|
|
-def protected(request: Request, Authorize: AuthJWT = Depends()):
|
|
|
- Authorize.jwt_required()
|
|
|
- current_user = Authorize.get_jwt_subject()
|
|
|
- return current_user
|
|
|
-
|
|
|
+ user_obj = first(db.query('SELECT * FROM users where username ="'+str(user.username)+'"'))
|
|
|
+ if user_obj != None:
|
|
|
+ user_register(user)
|
|
|
+ return templates.TemplateResponse("login.html", {'request': request,"success": True}, status_code=status.HTTP_302_FOUND)
|
|
|
+ else:
|
|
|
+ return {'msg':user.username+'重複,請更改'}
|
|
|
|
|
|
|
|
|
@app.get('/logout')
|
|
|
@@ -265,8 +275,8 @@ async def make_anchor_video_gSlide(req:models.gSlide_req,token: str = Depends(oa
|
|
|
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))
|
|
|
+ video_id = 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,video_id,user_id))
|
|
|
x.start()
|
|
|
return {"msg":"製作影片需要時間,請您耐心等候,成果會傳送至LINE群組中"}
|
|
|
|
|
|
@@ -293,8 +303,8 @@ async def make_anchor_video_long(req:models.request,token: str = Depends(oauth2_
|
|
|
except:
|
|
|
return {'msg':"無法辨別圖片網址"+imgu}
|
|
|
user_id = get_user_id(token)
|
|
|
- save_history(req,name_hash,user_id)
|
|
|
- x = threading.Thread(target=gen_video_long_queue, args=(name_hash,req.name, req.text_content, req.image_urls,int(req.avatar),req.multiLang,user_id))
|
|
|
+ video_id = save_history(req,name_hash,user_id)
|
|
|
+ x = threading.Thread(target=gen_video_long_queue, args=(name_hash,req.name, req.text_content, req.image_urls,int(req.avatar),req.multiLang,video_id,user_id))
|
|
|
x.start()
|
|
|
return {"msg":"ok"}
|
|
|
|
|
|
@@ -321,8 +331,8 @@ async def make_anchor_video(req:models.request,token: str = Depends(oauth2_schem
|
|
|
except:
|
|
|
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),req.multiLang,user_id))
|
|
|
+ video_id = 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),req.multiLang,video_id,user_id))
|
|
|
x.start()
|
|
|
return {'msg':'ok'}
|
|
|
|
|
|
@@ -344,8 +354,8 @@ async def make_anchor_video_eng(req:models.request_eng):
|
|
|
except:
|
|
|
return {'msg':"無法辨別圖片網址"+imgu}
|
|
|
|
|
|
- save_history(req,name_hash)
|
|
|
- x = threading.Thread(target=gen_video_queue_eng, args=(name_hash,req.name, req.text_content, req.image_urls,req.sub_titles,int(req.avatar)))
|
|
|
+ video_id = save_history(req,name_hash)
|
|
|
+ x = threading.Thread(target=gen_video_queue_eng, args=(name_hash,req.name, req.text_content, req.image_urls,req.sub_titles,int(req.avatar),video_id))
|
|
|
x.start()
|
|
|
return {"msg":"ok"}
|
|
|
|
|
|
@@ -457,6 +467,7 @@ def save_history(req,name_hash,user_id):
|
|
|
time_stamp = time_stamp.strftime("%Y-%m-%d %H:%M:%S")
|
|
|
pk = log_table.insert({'name':req.name,'text_content':txt_content_seperate_by_dot,'image_urls':img_urls_seperate_by_dot
|
|
|
,'user_id':user_id,'link':'www.choozmo.com:8168/'+video_sub_folder+name_hash+'.mp4','timestamp':time_stamp})
|
|
|
+ return pk
|
|
|
|
|
|
def get_url_type(url):
|
|
|
req = urllib.request.Request(url, method='HEAD', headers={'User-Agent': 'Mozilla/5.0'})
|
|
|
@@ -482,23 +493,8 @@ def notify_group(msg):
|
|
|
params = {"message": msg}
|
|
|
r = requests.post("https://notify-api.line.me/api/notify",headers=headers, params=params)
|
|
|
|
|
|
-def gen_video(name_hash,name,text_content, image_urls,avatar):
|
|
|
- c = rpyc.connect("localhost", 8858)
|
|
|
- c._config['sync_request_timeout'] = None
|
|
|
- remote_svc = c.root
|
|
|
- my_answer = remote_svc.call_video(name_hash,name,text_content, image_urls,avatar) # method call
|
|
|
- shutil.copy(tmp_video_dir+name_hash+'.mp4',video_dest+name_hash+'.mp4')
|
|
|
- os.remove(tmp_video_dir+name_hash+'.mp4')
|
|
|
-
|
|
|
-def gen_video_eng(name_hash,name,text_content, image_urls,sub_titles,avatar):
|
|
|
- c = rpyc.connect("localhost", 8858)
|
|
|
- c._config['sync_request_timeout'] = None
|
|
|
- remote_svc = c.root
|
|
|
- my_answer = remote_svc.call_video_eng(name_hash,name,text_content, image_urls,sub_titles,avatar) # method call
|
|
|
- shutil.copy(tmp_video_dir+name_hash+'.mp4',video_dest+name_hash+'.mp4')
|
|
|
- os.remove(tmp_video_dir+name_hash+'.mp4')
|
|
|
-
|
|
|
-def gen_video_long_queue(name_hash,name,text_content, image_urls,avatar,multiLang,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')
|
|
|
time_stamp = datetime.fromtimestamp(time.time()).strftime("%Y-%m-%d %H:%M:%S")
|
|
|
txt_content_seperate_by_dot = ''
|
|
|
@@ -535,6 +531,7 @@ def gen_video_long_queue(name_hash,name,text_content, image_urls,avatar,multiLan
|
|
|
left_time = user_obj['left_time']
|
|
|
email = user_obj['email']
|
|
|
print('left_time is '+str(left_time))
|
|
|
+ db.query('UPDATE history_input SET duration ='+str(vid_duration)+' WHERE id='+str(video_id)+';')
|
|
|
if left_time is None:
|
|
|
left_time = 5*60
|
|
|
if left_time < vid_duration:
|
|
|
@@ -556,7 +553,7 @@ def gen_video_long_queue(name_hash,name,text_content, image_urls,avatar,multiLan
|
|
|
db['video_queue'].delete(id=top1['id'])
|
|
|
db.query('UPDATE video_queue_status SET status = 0')
|
|
|
|
|
|
-def gen_video_queue(name_hash,name,text_content, image_urls,avatar,multiLang,user_id):
|
|
|
+def gen_video_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')
|
|
|
time_stamp = datetime.fromtimestamp(time.time()).strftime("%Y-%m-%d %H:%M:%S")
|
|
|
txt_content_seperate_by_dot = ''
|
|
|
@@ -593,6 +590,7 @@ def gen_video_queue(name_hash,name,text_content, image_urls,avatar,multiLang,use
|
|
|
left_time = user_obj['left_time']
|
|
|
email = user_obj['email']
|
|
|
print('left_time is '+str(left_time))
|
|
|
+ db.query('UPDATE history_input SET duration ='+str(vid_duration)+' WHERE id='+str(video_id)+';')
|
|
|
if left_time is None:
|
|
|
left_time = 5*60
|
|
|
if left_time < vid_duration:
|
|
|
@@ -613,7 +611,7 @@ def gen_video_queue(name_hash,name,text_content, image_urls,avatar,multiLang,use
|
|
|
db['video_queue'].delete(id=top1['id'])
|
|
|
db.query('UPDATE video_queue_status SET status = 0')
|
|
|
|
|
|
-def gen_video_queue_eng(name_hash,name,text_content, image_urls,sub_titles,avatar):
|
|
|
+def gen_video_queue_eng(name_hash,name,text_content, image_urls,sub_titles,avatar,video_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 = ''
|