Browse Source

add value 60sec(done) multiLang problem(not done)

ming 3 years ago
parent
commit
81248d039b
3 changed files with 31 additions and 10 deletions
  1. 18 9
      OpenshotService/openshot_video_generator.py
  2. 7 1
      api/main.py
  3. 6 0
      api/util/models.py

+ 18 - 9
OpenshotService/openshot_video_generator.py

@@ -125,7 +125,19 @@ def make_dir(name_hash):
     except FileExistsError:
         print("~~~~~~Warning~~~~~~~~~Directory " , dir_subtitle+name_hash ,  " already exists")
 
-def file_prepare(name, name_hash,text_content,image_urls,multiLang,lang='zh'):
+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)
     make_dir(name_hash)
     img_num = 1
     for imgu in image_urls:
@@ -152,13 +164,9 @@ def file_prepare(name, name_hash,text_content,image_urls,multiLang,lang='zh'):
     #make mp3
     txt_idx = 0
     for txt in text_content:
-        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")
+        if multiLang==1:
+            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"]})
@@ -171,7 +179,7 @@ def file_prepare(name, name_hash,text_content,image_urls,multiLang,lang='zh'):
         txt_idx+=1
     print("mp3 file made")
     #make title as image
-    txt2image_title(name, dir_title+name_hash+".png",lang)
+    txt2image_title(name, dir_title+name_hash+".png")
 
 
 def file_prepare_long(name, name_hash,text_content,image_urls,multiLang,lang='zh'):
@@ -220,6 +228,7 @@ 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':

+ 7 - 1
api/main.py

@@ -280,7 +280,13 @@ async def register(request: util.models.register_req):
     user_obj = first(db.query('SELECT * FROM users where username ="'+str(request.username)+'"'))
     
     if user_obj == None:
-        id = user_register(request)
+        reg_model = util.models.register_addition()
+        reg_model.username = request.username
+        reg_model.email = request.email
+        reg_model.password =request.password
+        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:

+ 6 - 0
api/util/models.py

@@ -65,6 +65,12 @@ class register_req(BaseModel):
     email: str
     password: str
 
+class register_addition(BaseModel):
+    username: str
+    email: str
+    password: str
+    left_time: int
+
 class register_invite_req(BaseModel):
     username: str
     email: str