浏览代码

add asyncio

ming 3 年之前
父节点
当前提交
6114bc339c
共有 1 个文件被更改,包括 12 次插入11 次删除
  1. 12 11
      main.py

+ 12 - 11
main.py

@@ -18,6 +18,7 @@ import time
 import math
 import hashlib
 import re
+import asyncio
 import urllib.request
 from fastapi.responses import FileResponse
 from websocket import create_connection
@@ -473,31 +474,31 @@ def generate_subtitle_image(name_hash,text_content):
             img_list[idx]+=[{"count":len(sub),"path":sv_path}]
     return img_list
 
-def sendProgress(progress,client_id):
-    ws = create_connection("ws://www.choozmo.com:8888/progress/"+client_id)
-    ws.send(str(progress))
-    ws.close()
+async def sendProgress(progress,client_id):
+    await ws = create_connection("ws://www.choozmo.com:8888/progress/"+client_id)
+    await ws.send(str(progress))
+    await ws.close()
 
 def anchor_video_v2(name,text_content, image_urls,avatar,client_id):
     
     progress = 0
-    sendProgress(progress,client_id)
+    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)
     progress = 10
-    sendProgress(progress,client_id)
+    asyncio.run(sendProgress(progress,client_id))
     sub_list=generate_subtitle_image(name_hash,text_content)
     progress = 20
-    sendProgress(progress,client_id)
+    asyncio.run(sendProgress(progress,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)
         progress += progress_per_video
         print('step finish')
-        sendProgress(progress,client_id)
+        asyncio.run(sendProgress(progress,client_id))
     print('called............................................')
 
     ck=cKey(0,254,0,270)
@@ -582,7 +583,7 @@ def anchor_video_v2(name,text_content, image_urls,avatar,client_id):
         idx+=1
 
     progress+=10
-    sendProgress(progress,client_id)
+    asyncio.run(sendProgress(progress,client_id))
     
     LOGO_ED = openshot.FFmpegReader(dir_video+"LOGO_ED.avi")
     LOGO_ED.Open()
@@ -636,14 +637,14 @@ def anchor_video_v2(name,text_content, image_urls,avatar,client_id):
         
             
     progress = 100
-    sendProgress(progress,client_id)
+    asyncio.run(sendProgress(progress,client_id))
     notify_group(name+"的影片已經產生完成囉! www.choozmo.com:8168/"+name_hash+".mp4")
     t.Close()
     w.Close()
 
 
     progress = 100
-    sendProgress(progress,client_id)
+    asyncio.run(sendProgress(progress,client_id))
     print("Raw Video done")
     print("video at : www.choozmo.com:8168/"+name_hash+".mp4")