فهرست منبع

upload_pttx fix and noauth video post

ming 3 سال پیش
والد
کامیت
9debf3f6db
4فایلهای تغییر یافته به همراه47 افزوده شده و 7 حذف شده
  1. BIN
      api/__pycache__/mailer.cpython-39.pyc
  2. BIN
      api/__pycache__/main.cpython-39.pyc
  3. 47 7
      api/main.py
  4. BIN
      api/util/__pycache__/models.cpython-39.pyc

BIN
api/__pycache__/mailer.cpython-39.pyc


BIN
api/__pycache__/main.cpython-39.pyc


+ 47 - 7
api/main.py

@@ -418,7 +418,7 @@ async def upload_pttx(file: UploadFile = File(...)):
         if "_" in file.filename:
             return {'msg':{'eng':'symbol"_" is not allowed in file name','zh':'檔案無法使用檔名不能含有"_"符號'}}
         else:
-            pttx_name = file.filename+'_'+str(time.time()).replace('.','')
+            pttx_name = str(time.time()).replace('.','')+'.pptx'
             with open(pttx_dest+pttx_name, "wb+") as file_object:
                 file_object.write(file.file.read())
             return {"msg": resource_server+pttx_sub_folder+pttx_name}
@@ -426,7 +426,6 @@ async def upload_pttx(file: UploadFile = File(...)):
         logging.error(traceback.format_exc())
         return {'msg':{'eng':'file cant be prossessed','zh':'檔案無法使用'}}
 
-
 @app.post("/make_anchor_video_gSlide")
 async def make_anchor_video_gSlide(req:util.models.gSlide_req,token: str = Depends(oauth2_scheme)):
     if req.url_type == 0:
@@ -434,6 +433,7 @@ async def make_anchor_video_gSlide(req:util.models.gSlide_req,token: str = Depen
     else :
         filename = req.slide_url.replace(resource_server+pttx_sub_folder,resource_folder+pttx_sub_folder)
         name, text_content, image_urls = gSlide.parse_pttx_url(filename,img_upload_folder,resource_server+tmp_img_sub_folder,eng=False)
+    
     if len(image_urls) != len(text_content):
         return {'msg':{'eng':'number of subtitles and images(videos) should be the same','zh':'副標題數量、圖片(影片)數量以及台詞數量必須一致'}}
     for idx in range(len(image_urls)):
@@ -508,7 +508,6 @@ async def make_anchor_video_long(req:util.models.request,token: str = Depends(oa
         returnMsg =  {'msg':{'eng':'Processing video requires a few minutes, please wait for notification','zh':'影片處理需要數分鐘,請等待通知'}}
     return returnMsg
 
-
 @app.post("/make_anchor_video")
 async def make_anchor_video(req:util.models.request,token: str = Depends(oauth2_scheme)):
     db_check()
@@ -540,6 +539,43 @@ async def make_anchor_video(req:util.models.request,token: str = Depends(oauth2_
     x = threading.Thread(target=gen_video_queue, args=(name_hash,req.name, req.text_content, req.image_urls,int(req.avatar),req.multiLang,video_id,user_id))
     x.start()
      
+    if first(db.query('SELECT COUNT(1) FROM video_queue'))['COUNT(1)'] >= 3:
+        return {'msg':{'eng':'There are many videos have been processing, please wait.','zh':'目前有多部影片處理中,煩請耐心等候'}}
+    else:
+        return {'msg':{'eng':'Processing video requires a few minutes, please wait for notification','zh':'影片處理需要數分鐘,請等待通知'}}
+    return {'msg':'ok'}
+#not auth 
+@app.post("/make_anchor_video_noAuth")
+async def make_anchor_video_noAuth(req:util.models.request):
+    db_check()
+    if len(req.image_urls) != len(req.text_content):
+        return {'msg':{'eng':'number of subtitles and images(videos) should be the same','zh':'副標題數量、圖片(影片)數量以及台詞數量必須一致'}}
+    for idx in range(len(req.image_urls)):
+        if 'http' not in req.image_urls[idx]:
+            req.image_urls[idx] = 'http://'+req.image_urls[idx]
+    if req.multiLang==0:
+        for txt in req.text_content:
+            if re.search('[a-zA-Z]', txt) !=None:
+                print('語言錯誤')
+                return {'msg':{'eng':'English is not allowed in subtitles','zh':'輸入字串不能包含英文字!'}}
+            if re.search(',', txt) !=None:
+                print('包含非法符號')
+                return {'msg':{'eng':'symbol "," is not allowede','zh':'輸入不能含有","符號'}}
+    name_hash = str(time.time()).replace('.','')
+    for imgu in req.image_urls:
+        try:
+            if get_url_type(imgu) =='video/mp4':
+                r=requests.get(imgu)
+            else:
+                im = Image.open(requests.get(imgu, stream=True).raw)
+                im= im.convert("RGB")
+        except:
+            return {'msg':{'eng':req.imgurl+'cant be proccessed','zh':"無法辨別圖片網址"+req.imgurl}}
+    user_id = get_user_id(token)
+    video_id = save_history(req,name_hash,user_id)
+    x = threading.Thread(target=gen_video_queue, args=(name_hash,req.name, req.text_content, req.image_urls,int(req.avatar),req.multiLang,video_id,user_id))
+    x.start()
+     
     if first(db.query('SELECT COUNT(1) FROM video_queue'))['COUNT(1)'] >= 3:
         return {'msg':{'eng':'There are many videos have been processing, please wait.','zh':'目前有多部影片處理中,煩請耐心等候'}}
     else:
@@ -765,7 +801,7 @@ def notify_group(msg):
 
 
 def gen_video_long_queue(name_hash,name,text_content, image_urls,avatar,multiLang,video_id,user_id):
-    db_check()
+    db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/AI_anchor?charset=utf8mb4')
     if name_hash == 'keepRunning':
         if first(db.query('SELECT COUNT(1) FROM video_queue where video_type="longvideo"'))['COUNT(1)'] == 0:
             return 
@@ -829,9 +865,10 @@ def gen_video_long_queue(name_hash,name,text_content, image_urls,avatar,multiLan
             notify_group('長影片錯誤-測試')
         db['video_queue'].delete(id=top1['id'])
         db.query('UPDATE video_queue_status SET status = 0')
+    db.close()
 
 def gen_video_queue(name_hash,name,text_content, image_urls,avatar,multiLang,video_id,user_id):
-    db_check()
+    db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/AI_anchor?charset=utf8mb4')
     if name_hash == 'keepRunning':
         if first(db.query('SELECT COUNT(1) FROM video_queue where video_type="short"'))['COUNT(1)'] == 0:
             return 
@@ -895,9 +932,10 @@ def gen_video_queue(name_hash,name,text_content, image_urls,avatar,multiLang,vid
             notify_group('影片錯誤')
         db['video_queue'].delete(id=top1['id'])
         db.query('UPDATE video_queue_status SET status = 0')
+    db.close()
 
 def gen_video_queue_eng(name_hash,name,text_content, image_urls,sub_titles,avatar,video_id):
-    db_check()
+    db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/AI_anchor?charset=utf8mb4')
     if name_hash == 'keepRunning':
         if first(db.query('SELECT COUNT(1) FROM video_queue where video_type="eng"'))['COUNT(1)'] == 0:
             return 
@@ -941,6 +979,7 @@ 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()
 
 def gen_avatar(name_hash, imgurl):
     db_check()
@@ -1042,7 +1081,8 @@ def verify_jwt_token(token):
         return 'please login again'
 def db_check():
     global db
-    db.close()
+    if db!=None:
+        db.close()
     db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/AI_anchor?charset=utf8mb4')
 
 

BIN
api/util/__pycache__/models.cpython-39.pyc