소스 검색

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

huai-sian 3 년 전
부모
커밋
a2a37d5537
2개의 변경된 파일19개의 추가작업 그리고 20개의 파일을 삭제
  1. 9 18
      OpenshotService/openshot_video_generator.py
  2. 10 2
      api/main.py

+ 9 - 18
OpenshotService/openshot_video_generator.py

@@ -125,19 +125,7 @@ def make_dir(name_hash):
     except FileExistsError:
         print("~~~~~~Warning~~~~~~~~~Directory " , dir_subtitle+name_hash ,  " already exists")
 
-def Check_text_content(text_content):
-    mulitLang = 0
-    status = False
-    for txt in text_content:
-        if re.search('[a-zA-Z]', txt) !=None:
-            mulitLang = 1
-        if re.search(',', txt) !=None:
-            print('包含非法符號')
-            status = {'msg':{'eng':'symbol "," is not allowede','zh':'輸入不能含有","符號'}}
-    return mulitLang, status
-
-def file_prepare(name, name_hash,text_content,image_urls):
-    mulitLang, status = Check_text_content(text_content)
+def file_prepare(name, name_hash,text_content,image_urls,multiLang,lang='zh'):
     make_dir(name_hash)
     img_num = 1
     for imgu in image_urls:
@@ -164,9 +152,13 @@ def file_prepare(name, name_hash,text_content,image_urls):
     #make mp3
     txt_idx = 0
     for txt in text_content:
-        if multiLang==1:
-            tts = gTTS(txt,lang='zh-tw')
-            tts.save(dir_sound+name_hash+"/"+str(txt_idx)+"raw.mp3")
+        if lang!='zh' or multiLang==1:
+            if lang!='zh':
+                tts = gTTS(txt)
+                tts.save(dir_sound+name_hash+"/"+str(txt_idx)+"raw.mp3")
+            else:
+                tts = gTTS(txt,lang='zh-tw')
+                tts.save(dir_sound+name_hash+"/"+str(txt_idx)+"raw.mp3")
             #speed up 
             ff = ffmpy.FFmpeg(inputs={dir_sound+name_hash+"/"+str(txt_idx)+"raw.mp3": None}
                             , outputs={dir_sound+name_hash+"/"+str(txt_idx)+".mp3": ["-filter:a", "atempo=1.2"]})
@@ -179,7 +171,7 @@ def file_prepare(name, name_hash,text_content,image_urls):
         txt_idx+=1
     print("mp3 file made")
     #make title as image
-    txt2image_title(name, dir_title+name_hash+".png")
+    txt2image_title(name, dir_title+name_hash+".png",lang)
 
 
 def file_prepare_long(name, name_hash,text_content,image_urls,multiLang,lang='zh'):
@@ -228,7 +220,6 @@ def file_prepare_long(name, name_hash,text_content,image_urls,multiLang,lang='zh
     txt2image_title(name, dir_title+name_hash+".png",lang)
 
 def txt2image(content, save_target,lang='zh'):
-    mulitLang, status = Check_text_content(text_content)
     unicode_text = trim_punctuation(content)
     font = ''
     if lang=='zh':

+ 10 - 2
api/main.py

@@ -44,6 +44,8 @@ import gSlide
 import aiofiles
 import json
 import util.user
+#https://www.choozmo.com:8887/verify_email?code=16370312713065429 => 
+#https://video.choozmo.com/verify_email.html?code=16370312713065429
 pymysql.install_as_MySQLdb()
 
 app = FastAPI()
@@ -55,7 +57,7 @@ app.add_middleware(
     allow_origins=["*"],
     allow_credentials=True,
     allow_methods=["*"],
-    allow_headers=["*"],
+    allow_headers=['Accept','Content-Type','X-Requested-With','x-api-key'],
 )
 SECRET_KEY = "df2f77bd544240801a048bd4293afd8eeb7fff3cb7050e42c791db4b83ebadcd"
 ALGORITHM = "HS256"
@@ -287,6 +289,7 @@ async def register(request: util.models.register_req):
         reg_model.left_time = 60
 
         id = user_register(reg_model)
+
         result = util.user.add_to_basic_role(id)
         print(result)
         if type(id) is int:
@@ -1075,7 +1078,7 @@ def gen_video_queue(name_hash,name,text_content, image_urls,avatar,multiLang,vid
         db['video_queue'].insert({'name_hash':name_hash,'name':name,'text_content':txt_content_seperate_by_dot
         ,'image_urls':img_urls_seperate_by_dot,'multiLang':multiLang,'video_type':'short','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')#1 means already running
             break
@@ -1123,8 +1126,10 @@ def gen_video_queue(name_hash,name,text_content, image_urls,avatar,multiLang,vid
             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()
     db.close()
 
 def gen_video_queue_eng(name_hash,name,text_content, image_urls,sub_titles,avatar,video_id,freeTrial):
@@ -1151,6 +1156,7 @@ def gen_video_queue_eng(name_hash,name,text_content, image_urls,sub_titles,avata
         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})
     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')
             break
@@ -1172,12 +1178,14 @@ def gen_video_queue_eng(name_hash,name,text_content, image_urls,sub_titles,avata
             notify_group('影片錯誤')
         db['video_queue'].delete(id=top1['id'])
         db.query('UPDATE video_queue_status SET status = 0')
+        db.close()
     db.close()
 
 def gen_avatar(name_hash, imgurl):
     db_check()
     db['avatar_queue'].insert({'name_hash':name_hash,'imgurl':imgurl})
     while True:
+        
         statement = 'SELECT * FROM avatar_service_status'#only one row in this table, which is the id 1 one
         status = -1
         for row in db.query(statement):