Browse Source

gen video queue

ming 3 years ago
parent
commit
9d8d415afb
1 changed files with 40 additions and 5 deletions
  1. 40 5
      api/main.py

+ 40 - 5
api/main.py

@@ -243,8 +243,7 @@ def gen_video_queue(name_hash,name,text_content, image_urls,avatar):
             print('all finish, leave loop')
             break
         top1 = first(db.query('SELECT * FROM video_queue'))
-        #try:
-        if True:
+        try:
             db.query('UPDATE video_queue_status SET status = 1;')
             c = rpyc.connect("localhost", 8878)
             c._config['sync_request_timeout'] = None
@@ -252,13 +251,49 @@ def gen_video_queue(name_hash,name,text_content, image_urls,avatar):
             my_answer = remote_svc.call_video(top1['name_hash'],top1['name'],top1['text_content'].split(','), top1['image_urls'].split(','),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')
-        if True:
+        except:
             print('video generation error')
-            #notify_group('影片錯誤')
+            notify_group('影片錯誤')
         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):
+    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 = ''
+    for txt in 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 image_urls:
+        img_urls_seperate_by_dot += iurl+","
+    img_urls_seperate_by_dot = img_urls_seperate_by_dot[:-1]
+    subtitles_seperate_by_dot = ''
+    for sub in sub_titles:
+        subtitles_seperate_by_dot += sub+","
+    subtitles_seperate_by_dot = subtitles_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,'subtitles':subtitles_seperate_by_dot,'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
+            print('another process running, leave loop')
+            break
+        if first(db.query('SELECT COUNT(1) FROM video_queue'))['COUNT(1)'] == 0:
+            print('all finish, leave loop')
+            break
+        top1 = first(db.query('SELECT * FROM video_queue'))
+        try:
+            db.query('UPDATE video_queue_status SET status = 1;')
+            c = rpyc.connect("localhost", 8878)
+            c._config['sync_request_timeout'] = None
+            remote_svc = c.root
+            my_answer = remote_svc.call_video_eng(top1['name_hash'],top1['name'],top1['text_content'].split(','), top1['image_urls'].split(','),top1['subtitles'].split(','),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')
+        except:
+            print('video generation error')
+            notify_group('影片錯誤')
+        db['video_queue'].delete(id=top1['id'])
+        db.query('UPDATE video_queue_status SET status = 0')
 
 def gen_avatar(name_hash, imgurl):
     db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/AI_anchor?charset=utf8mb4')