Pārlūkot izejas kodu

Merge branch 'master' of http://git.choozmo.com:3000/choozmo/AI_Anchor_2

huai-sian 3 gadi atpakaļ
vecāks
revīzija
153fc77094
1 mainītis faili ar 39 papildinājumiem un 12 dzēšanām
  1. 39 12
      api/main.py

+ 39 - 12
api/main.py

@@ -1148,7 +1148,7 @@ def gen_video_queue_eng(name_hash,name,text_content, image_urls,sub_titles,avata
             return 
         db.query('UPDATE video_queue_status SET status = 0;')
         print('start clear eng video')
-    else: 
+    else:        
         time_stamp = datetime.fromtimestamp(time.time()).strftime("%Y-%m-%d %H:%M:%S")
         txt_content_seperate_by_dot = ''
         for txt in text_content:
@@ -1162,18 +1162,24 @@ def gen_video_queue_eng(name_hash,name,text_content, image_urls,sub_titles,avata
         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,'video_type':'eng','avatar':avatar,'timestamp':time_stamp,'freeTrial':freeTrial})
+
+        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,'multiLang':multiLang,'video_type':'eng','avatar':avatar,'timestamp':time_stamp,'freeTrial':freeTrial})
     while True:
         db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/AI_anchor?charset=utf8mb4')
         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')
+            print('another process running, leave loop')#1 means already running
             break
         if first(db.query('SELECT COUNT(1) FROM video_queue where video_type="eng"'))['COUNT(1)'] == 0:
             print('all finish, leave loop')
             break
-        top1 = first(db.query('SELECT * FROM video_queue where video_type="eng"'))
         try:
+            db.close()
+            db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/AI_anchor?charset=utf8mb4')
+            top1 = first(db.query('SELECT * FROM video_queue where video_type="eng"'))
+            print(top1)
+            print(top1['name_hash'])
+        # if True:
             db.query('UPDATE video_queue_status SET status = 1;')
             c = rpyc.connect("localhost", 8858)
             c._config['sync_request_timeout'] = None
@@ -1181,11 +1187,38 @@ def gen_video_queue_eng(name_hash,name,text_content, image_urls,sub_titles,avata
             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'],top1['freeTrial']) # 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')
-            notify_group(top1['name']+"(ENG)的影片已經產生完成囉! www.choozmo.com:8168/"+video_sub_folder+['name_hash']+".mp4")
+            vid_duration = VideoFileClip(video_dest+top1['name_hash']+'.mp4').duration
+            line_token=''
+            left_time=10000
+            email=''
+            if user_id!=-1:
+                user_obj = first(db.query('SELECT * FROM users where id ="'+str(user_id)+'"'))
+                line_token = user_obj['line_token']         # aa
+                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 and freeTrial!=1:
+                msg = '您本月額度剩下'+str(left_time)+'秒,此部影片有'+str(vid_duration)+'秒, 若要繼續產生影片請至 192.168.1.107:8887/confirm_add_value?name_hash='+name_hash+' 加值'
+                print(msg)
+                msg =msg.encode(encoding='utf-8')
+                mailer.send_left_not_enough(msg, email)
+                notify_group(msg)
+                #notify_line_user(msg, line_token)
+            else:
+                left_time = left_time - vid_duration
+                if user_id != -1:
+                    db.query('UPDATE users SET left_time ='+str(left_time)+' WHERE id='+str(user_id)+';')
+                notify_group(top1['name']+"的影片(ENG)已經產生完成囉! www.choozmo.com:8168/"+video_sub_folder+top1['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())
             print('video generation error')
             notify_group('影片錯誤')
+        
         db['video_queue'].delete(id=top1['id'])
         db.query('UPDATE video_queue_status SET status = 0')
         db.close()
@@ -1230,9 +1263,6 @@ def gen_avatar(name_hash, imgurl):
         statement = 'UPDATE avatar_service_status SET status = 0 WHERE id=1;'  #only one row in this table, which id 1 one
         db.query(statement)
 def call_voice(text):
-    print(text)
-    print(len(text))
-    print(type(text))
     c = rpyc.connect("localhost", 8858)
     c._config['sync_request_timeout'] = None
     remote_svc = c.root
@@ -1283,9 +1313,6 @@ def call_speech(text,speaker):
 
 
 def verify_jwt_token(token):
-    for row in db.query('SELECT * FROM jwt_black_list'):
-        print(row)
-    print(first(db.query('SELECT COUNT(*) FROM jwt_black_list where token="'+token+'"'))['COUNT(*)'])
     if first(db.query('SELECT COUNT(*) FROM jwt_black_list where token="'+token+'"'))['COUNT(*)'] == 0:
         return  'ok'
     else: