zhangyong 11 mesi fa
parent
commit
7d3ab96973
3 ha cambiato i file con 42 aggiunte e 35 eliminazioni
  1. 2 0
      common/piaoquan_utils.py
  2. 14 14
      video_job.py
  3. 26 21
      video_rewriting/video_prep.py

+ 2 - 0
common/piaoquan_utils.py

@@ -98,7 +98,9 @@ class PQ:
                     all_data = {"video_id": video_id, "title": new_title, "cover": cover, "video_url": video_url}
                     list.append(all_data)
                     if len(list) == int(number):
+                        Common.logger("log").warning(f"获取视频总数:{len(list)}\n")
                         return list
+            Common.logger("log").warning(f"获取视频总数:{len(list)}\n")
             return list
         except Exception as e:
             Common.logger("log").warning(f"获取音频视频链接失败:{e}\n")

+ 14 - 14
video_job.py

@@ -71,19 +71,19 @@ def usernames_today():
     print("today 已清空")
 
 
-# video_start()
-
-
-# 定时任务设置
-schedule.every().day.at("01:00").do(usernames_today)
-
-
-schedule.every(12).hours.do(video_start)
-
-
-
-while True:
-    schedule.run_pending()
-    time.sleep(1)
+video_start()
+
+#
+# # 定时任务设置
+# schedule.every().day.at("01:00").do(usernames_today)
+#
+#
+# schedule.every(12).hours.do(video_start)
+#
+#
+#
+# while True:
+#     schedule.run_pending()
+#     time.sleep(1)
 
 

+ 26 - 21
video_rewriting/video_prep.py

@@ -43,7 +43,19 @@ class getVideo:
         return oss_id
 
 
-
+    """
+    删除文件
+    """
+    @classmethod
+    def remove_files(cls, video_path_url):
+        if os.path.exists(video_path_url) and os.path.isdir(video_path_url):
+            for root, dirs, files in os.walk(video_path_url):
+                for file in files:
+                    file_path = os.path.join(root, file)
+                    os.remove(file_path)
+                for dir in dirs:
+                    dir_path = os.path.join(root, dir)
+                    os.rmdir(dir_path)
 
     """
     飞书数据处理
@@ -71,9 +83,8 @@ class getVideo:
             title = task["title"]
             video_share = task["video_share"]
             video_ending = task["video_ending"]
-
+            video_path_url = cls.create_folders(mark, str(task_mark))  # 创建目录
             try:
-                video_path_url = cls.create_folders(mark, str(task_mark))  # 创建目录
                 if ',' in new_id:
                     n_id = new_id.split(',')
                 else:
@@ -84,25 +95,29 @@ class getVideo:
                     task_id = video_id.split(',')
                 count = 0  # 初始化计数器
                 for id in task_id:
+                    Common.logger("log").info(f"{task_mark}下的ID{id} 开始获取视频")
                     time.sleep(1)
                     if old_id and old_id != 'None':
                         data_list = PQ.get_user_url(task_mark, id, number, title, mark)
                     else:
                         data_list = PQ.get_audio_url(task_mark, id, title, mark)
 
-                    if not data_list:
+                    if len(data_list) == 0:
                         Common.logger("log").info(f"{task_mark}下的视频ID{id} 已经改造过了")
-                        Feishu.bot(mark, '机器自动改造消息通知', f'{task_mark}任务下的视频ID{id},已经改造过,请关注', name)
+                        Feishu.bot(mark, '机器自动改造消息通知', f'{task_mark}任务下的视频ID{id},没有已经改造的视频了', name)
+                        cls.remove_files(video_path_url)
                         continue
-
+                    Common.logger("log").info(f"{task_mark}下的ID{id} 获取视频完成,共{len(data_list)}条")
                     for video in data_list:
                         v_id = video["video_id"]
                         new_title = video["title"]
                         cover = video["cover"]
                         video_url = video["video_url"]
+                        time.sleep(1)
                         new_video_path = PQ.download_video(video_url, video_path_url, v_id)  # 下载视频地址
-                        if not new_video_path:
+                        if new_video_path == '':
                             Common.logger("log").info(f"{task_mark}下的视频ID{id},{new_video_path}视频下载失败")
+                            cls.remove_files(video_path_url)
                             continue
                         pw_list, zm_list = Material.get_pwsrt_data(feishu_id, pw_sheet)  # 获取srt
                         pws = random.choice(pw_list)  # 随机选择 片尾srt+音频
@@ -131,7 +146,6 @@ class getVideo:
                         oss_id = cls.random_id()
                         oss_object_key = Oss.stitching_sync_upload_oss(new_video_path, oss_id)  # 视频发送OSS
                         status = oss_object_key.get("status")
-
                         if status == 200:
                             oss_object_key = oss_object_key.get("oss_object_key")
                             time.sleep(1)
@@ -146,22 +160,13 @@ class getVideo:
                                 Feishu.insert_columns("ILb4sa0LahddRktnRipcu2vQnLb", "a74fc4", "ROWS", 1, 2)
                                 time.sleep(0.5)
                                 Feishu.update_values("ILb4sa0LahddRktnRipcu2vQnLb", "a74fc4", "A2:Z2", values)
-
-                            if os.path.exists(video_path_url) and os.path.isdir(video_path_url):
-                                for root, dirs, files in os.walk(video_path_url):
-                                    for file in files:
-                                        file_path = os.path.join(root, file)
-                                        os.remove(file_path)
-                                    for dir in dirs:
-                                        dir_path = os.path.join(root, dir)
-                                        os.rmdir(dir_path)
+                            cls.remove_files(video_path_url)
                         else:
+                            cls.remove_files(video_path_url)
                             Common.logger("log").info(f"{task_mark}下的视频ID{id} 视频发送OSS失败 ")
                     count += 1  # 每次迭代计数器加1
-                    if old_id and old_id != 'None':
-                        Feishu.bot(mark, '机器自动改造消息通知', f'{task_mark}任务改造完成,请关注', name)
-                if video_id and video_id != 'None':
-                    Feishu.bot(mark, '机器自动改造消息通知', f'{task_mark}任务改造完成,请关注', name)
+                Feishu.bot(mark, '机器自动改造消息通知', f'{task_mark}任务改造完成,请关注', name)
             except Exception as e:
+                cls.remove_files(video_path_url)
                 Common.logger("warning").warning(f"{name}的{task_mark}任务处理失败:{e}\n")
         return mark