zhangyong 9 months ago
parent
commit
dc781d56d7
1 changed files with 11 additions and 10 deletions
  1. 11 10
      video_rewriting/video_processor.py

+ 11 - 10
video_rewriting/video_processor.py

@@ -56,12 +56,13 @@ class VideoProcessor:
         return f"{now.strftime('%Y%m%d%H%M%S')}{rand_num}"
 
     @classmethod
-    def remove_files(cls, video_path_url):
+    def remove_files(cls, mark):
         """
         删除指定目录下的所有文件和子目录
         """
-        if os.path.exists(video_path_url) and os.path.isdir(video_path_url):
-            for root, dirs, files in os.walk(video_path_url):
+        path = config['PATHS']['VIDEO_PATH'] + mark + "/"
+        if os.path.exists(path) and os.path.isdir(path):
+            for root, dirs, files in os.walk(path):
                 for file in files:
                     file_path = os.path.join(root, file)
                     os.remove(file_path)
@@ -108,7 +109,7 @@ class VideoProcessor:
             )
             Feishu.finish_bot(text, "https://open.feishu.cn/open-apis/bot/v2/hook/e7697dc6-5254-4411-8b59-3cd0742bf703",
                               "【 机器改造通知 】")
-            cls.remove_files(video_path_url)
+            cls.remove_files(mark)
             return
         Common.logger(mark).info(f"{name}的{task_mark}下的ID{url} 获取视频完成,共{len(data_list)}条")
         for video in data_list:
@@ -153,13 +154,13 @@ class VideoProcessor:
                     Feishu.finish_bot(text,
                                       "https://open.feishu.cn/open-apis/bot/v2/hook/e7697dc6-5254-4411-8b59-3cd0742bf703",
                                       "【 机器改造通知 】")
-                    cls.remove_files(video_path_url)
+                    cls.remove_files(mark)
                     continue
                 if new_video_path:
                     if video_ending and video_ending != 'None':
                         new_video_path = cls.handle_video_ending(new_video_path, video_ending, old_title, pw_random_id, video_path_url, mark, task_mark, url, name, video_share, zm, voice)
                         if new_video_path == None:
-                            cls.remove_files(video_path_url)
+                            cls.remove_files(mark)
                             continue
                     else:
                         if video_share and video_share != 'None':
@@ -179,7 +180,7 @@ class VideoProcessor:
                         Feishu.finish_bot(text,
                                           "https://open.feishu.cn/open-apis/bot/v2/hook/e7697dc6-5254-4411-8b59-3cd0742bf703",
                                           "【 机器改造通知 】")
-                        cls.remove_files(video_path_url)
+                        cls.remove_files(mark)
                         continue
                     # 上传视频和封面,并更新数据库
                     code = cls.upload_video_and_thumbnail(new_video_path, cover, v_id, new_title, task_mark, name, piaoquan_id,
@@ -308,10 +309,10 @@ class VideoProcessor:
                         Feishu.insert_columns("ILb4sa0LahddRktnRipcu2vQnLb", sheet, "ROWS", 1, 2)
                         time.sleep(0.5)
                         Feishu.update_values("ILb4sa0LahddRktnRipcu2vQnLb", sheet, "A2:Z2", values)
-                cls.remove_files(video_path_url)
+                cls.remove_files(mark)
             except Exception as e:
                 Common.logger(mark).info(f"{name}的{task_mark}任务处理失败:{e}")
-                cls.remove_files(video_path_url)
+                cls.remove_files(mark)
                 continue
 
     @classmethod
@@ -520,7 +521,7 @@ class VideoProcessor:
 
                 return code
         except Exception as e:
-            cls.remove_files(video_path_url)
+            cls.remove_files(mark)
             Common.logger("error").warning(f"{name}的{task_mark}上传视频和封面到OSS,并更新数据库失败:{e}\n")
             return