|
@@ -117,7 +117,7 @@ async def make_anchor_video_v2(req:request):
|
|
|
for txt in req.text_content:
|
|
|
if re.search('[a-zA-Z]', txt) !=None:
|
|
|
return {'msg':'輸入字串不能包含英文字!'}
|
|
|
-
|
|
|
+ name_hash =
|
|
|
for imgu in req.image_urls:
|
|
|
try:
|
|
|
if get_url_type(imgu) =='video/mp4':
|
|
@@ -128,22 +128,9 @@ async def make_anchor_video_v2(req:request):
|
|
|
im= im.convert("RGB")
|
|
|
except:
|
|
|
return {'msg':"無法辨別圖片網址"+imgu}
|
|
|
-
|
|
|
-
|
|
|
- db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/AI_anchor?charset=utf8mb4')
|
|
|
- log_table = db['history_input']
|
|
|
- txt_content_seperate_by_dot = ''
|
|
|
- for txt in req.text_content:
|
|
|
- txt_content_seperate_by_dot += txt+","
|
|
|
- txt_content_seperate_by_dot = txt_content_seperate_by_dot[:-1]
|
|
|
- img_urls_seperate_by_dot = ''
|
|
|
- for iurl in req.image_urls:
|
|
|
- img_urls_seperate_by_dot += iurl+","
|
|
|
- img_urls_seperate_by_dot = img_urls_seperate_by_dot[:-1]
|
|
|
- time_stamp = datetime.fromtimestamp(time.time())
|
|
|
- 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,'link':'www.choozmo.com:8168/'+name_hash+'.mp4','timestamp':time_stamp})
|
|
|
- x = threading.Thread(target=anchor_video_v2, args=(req.name, req.text_content, req.image_urls,int(req.avatar),req.client_id))
|
|
|
+ name_hash = str(time.time()).replace('.','')
|
|
|
+ save_history(req,name_hash)
|
|
|
+ x = threading.Thread(target=anchor_video_v2, args=(name_hash,req.name, req.text_content, req.image_urls,int(req.avatar),req.client_id))
|
|
|
x.start()
|
|
|
return {"msg":"製作影片需要時間,請您耐心等候 稍後可以在www.choozmo.com:8168/"+name_hash+".mp4 中觀看"}
|
|
|
|
|
@@ -185,7 +172,21 @@ def notify_group(msg):
|
|
|
r = requests.post("https://notify-api.line.me/api/notify",headers=headers, params=params)
|
|
|
#print(r)
|
|
|
|
|
|
-
|
|
|
+def save_history(req,name_hash):
|
|
|
+ db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/AI_anchor?charset=utf8mb4')
|
|
|
+ log_table = db['history_input']
|
|
|
+ txt_content_seperate_by_dot = ''
|
|
|
+ for txt in req.text_content:
|
|
|
+ txt_content_seperate_by_dot += txt+","
|
|
|
+ txt_content_seperate_by_dot = txt_content_seperate_by_dot[:-1]
|
|
|
+ img_urls_seperate_by_dot = ''
|
|
|
+ for iurl in req.image_urls:
|
|
|
+ img_urls_seperate_by_dot += iurl+","
|
|
|
+ img_urls_seperate_by_dot = img_urls_seperate_by_dot[:-1]
|
|
|
+ time_stamp = datetime.fromtimestamp(time.time())
|
|
|
+ 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,'link':'www.choozmo.com:8168/'+name_hash+'.mp4','timestamp':time_stamp})
|
|
|
+
|
|
|
|
|
|
def cKey(r,g,b,fuzz):
|
|
|
col=openshot.Color()
|
|
@@ -353,7 +354,7 @@ def txt2image_title(content, save_target):
|
|
|
draw.text((5,5), text, (17, 41, 167), font)
|
|
|
canvas.save(save_target, "PNG")
|
|
|
'''
|
|
|
-def call_achor_video_v2(fileName,avatar):
|
|
|
+def call_anchor(fileName,avatar):
|
|
|
conn = rpyc.classic.connect("192.168.1.105",18812)
|
|
|
ros = conn.modules.os
|
|
|
rsys = conn.modules.sys
|
|
@@ -394,50 +395,6 @@ def call_achor_video_v2(fileName,avatar):
|
|
|
fr.close()
|
|
|
fw.close()
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-def call_achor_video(name):
|
|
|
- conn = rpyc.classic.connect("192.168.1.105",18812)
|
|
|
- ros = conn.modules.os
|
|
|
- rsys = conn.modules.sys
|
|
|
- fr=open(dir_sound+name+".mp3",'rb')# voice
|
|
|
- #warning!!! file my be replaced by other process
|
|
|
- fw=conn.builtins.open('/tmp/output.mp3','wb')
|
|
|
-
|
|
|
- while True:
|
|
|
- b=fr.read(1024)
|
|
|
- if b:
|
|
|
- fw.write(b)
|
|
|
- else:
|
|
|
- break
|
|
|
-
|
|
|
- fr.close()
|
|
|
- fw.close()
|
|
|
-
|
|
|
- val=random.randint(1000000,9999999)
|
|
|
- ros.chdir('/home/jared/to_video')
|
|
|
- ros.system('./p6.sh '+str(val)+' &')
|
|
|
-
|
|
|
- while True:
|
|
|
- print('waiting...')
|
|
|
- if ros.path.exists('/tmp/results/'+str(val)):
|
|
|
- break
|
|
|
- time.sleep(15)
|
|
|
- print('waiting...')
|
|
|
-
|
|
|
- fr=conn.builtins.open('/tmp/results/'+str(val)+'.mp4','rb')
|
|
|
- fw=open(dir_anchor+name+'.mp4','wb')#peggy1_1
|
|
|
- while True:
|
|
|
- b=fr.read(1024)
|
|
|
- if b:
|
|
|
- fw.write(b)
|
|
|
- else:
|
|
|
- break
|
|
|
-
|
|
|
- fr.close()
|
|
|
- fw.close()
|
|
|
-
|
|
|
- print('called..............................................')
|
|
|
|
|
|
|
|
|
def trim_punctuation(s):
|
|
@@ -471,11 +428,11 @@ async def sendProgress(progress,client_id):
|
|
|
ws.send(str(progress))
|
|
|
ws.close()
|
|
|
|
|
|
-def anchor_video_v2(name,text_content, image_urls,avatar,client_id):
|
|
|
+def anchor_video_v2(name_hash,name,text_content, image_urls,avatar,client_id):
|
|
|
|
|
|
progress = 0
|
|
|
asyncio.run(sendProgress(progress,client_id))
|
|
|
- name_hash = str(time.time()).replace('.','')
|
|
|
+
|
|
|
|
|
|
print('sub image made')
|
|
|
file_prepare_v2(name, name_hash, text_content,image_urls)
|
|
@@ -487,7 +444,7 @@ def anchor_video_v2(name,text_content, image_urls,avatar,client_id):
|
|
|
|
|
|
progress_per_video = int(40/len(text_content))
|
|
|
for fname in range(len(text_content)):
|
|
|
- call_achor_video_v2(name_hash+"/"+str(fname),avatar)
|
|
|
+ call_anchor(name_hash+"/"+str(fname),avatar)
|
|
|
progress += progress_per_video
|
|
|
print('step finish')
|
|
|
asyncio.run(sendProgress(progress,client_id))
|