zhangyong 8 ماه پیش
والد
کامیت
3d849109ee
3فایلهای تغییر یافته به همراه33 افزوده شده و 96 حذف شده
  1. 2 2
      common/feishu_form.py
  2. 16 50
      job_fj.py
  3. 15 44
      job_wxk.py

+ 2 - 2
common/feishu_form.py

@@ -67,7 +67,7 @@ class Material():
                     if ',' in channel_url:
                         channel_url = channel_url.split(',')
                     else:
-                        channel_url = channel_url
+                        channel_url = [channel_url]
                     for user in channel_url:
                         number_dict = {
                             "task_mark": task_mark,
@@ -103,7 +103,7 @@ class Material():
                                 "crop_total": crop_tool,
                                 "gg_duration_total": gg_duration,
                             }
-                            processed_list.append(number_dict)
+                            processed_list.append(json.dumps(number_dict, ensure_ascii=False))
 
                 else:
                     return processed_list

+ 16 - 50
job_fj.py

@@ -1,64 +1,30 @@
 import os
 import concurrent.futures
-import re
-
-import schedule
 import time
 import threading
 from common import Material
 from video_rewriting.video_processor import VideoProcessor
 
+# 控制读写速度的参数
 MAX_BPS = 120 * 1024 * 1024  # 120MB/s
 MAX_WORKERS = os.cpu_count() * 2  # 线程池最大工作线程数量
 READ_WRITE_CHUNK_SIZE = 1024 * 1024  # 每次读写的块大小 (1MB)
 SLEEP_INTERVAL = READ_WRITE_CHUNK_SIZE / MAX_BPS  # 控制每次读写的延迟时间
+
 # 全局锁,用于同步读写操作
 lock = threading.Lock()
 
-
-
-def video_task_start(data):
-    mark = VideoProcessor.main(data)
-    print(f"返回用户名{mark}")
-
-
-# data = Material.feishu_list()
-# video_task_start(data[0])
-
-
-def controlled_io_operation(data):
-    with lock:
-        start_time = time.time()
-        time.sleep(SLEEP_INTERVAL)
-        end_time = time.time()
-        elapsed_time = end_time - start_time
-        if elapsed_time < SLEEP_INTERVAL:
-            time.sleep(SLEEP_INTERVAL - elapsed_time)
-    video_task_start(data)
-
-
-
-
-def video_start():
-    print("开始执行生成视频脚本.")
-
-    data = Material.feishu_list()
-    data = data[1]
-    with concurrent.futures.ThreadPoolExecutor(max_workers=MAX_WORKERS) as executor:
-        futures = {executor.submit(controlled_io_operation, data)}
-        for future in concurrent.futures.as_completed(futures):
-            try:
-                future.result()
-                print("处理结果: 成功")
-            except concurrent.futures.TimeoutError:
-                print("任务超时,已取消.")
-            except Exception as e:
-                print("处理任务时出现异常:", e)
-    print("执行生成视频脚本结束.")
-video_start()
-schedule.every(6).hours.do(video_start)
-while True:
-    schedule.run_pending()
-    time.sleep(1)
-
-
+def video_task_start():
+    data = Material.feishu_list()[1]
+    """处理视频任务,返回用户名并根据结果决定延迟时间"""
+    while True:
+        try:
+            mark = VideoProcessor.main(data)
+            print(f"返回用户名: {mark}")
+            time.sleep(10 if mark else 120)  # 根据 mark 是否为空设置延迟
+        except Exception as e:
+            print("处理任务时出现异常:", e)
+            time.sleep(10)
+            continue
+if __name__ == '__main__':
+    video_task_start()

+ 15 - 44
job_wxk.py

@@ -1,49 +1,20 @@
-import os
-import concurrent.futures
+
 import time
-import threading
 from common import Material
-from video_rewriting.video_processor import VideoProcessor
-
-# 控制读写速度的参数
-MAX_BPS = 120 * 1024 * 1024  # 120MB/s
-MAX_WORKERS = os.cpu_count() * 2  # 线程池最大工作线程数量
-READ_WRITE_CHUNK_SIZE = 1024 * 1024  # 每次读写的块大小 (1MB)
-SLEEP_INTERVAL = READ_WRITE_CHUNK_SIZE / MAX_BPS  # 控制每次读写的延迟时间
-
-# 全局锁,用于同步读写操作
-lock = threading.Lock()
 
-def video_task_start(data):
+from video_rewriting.video_processor import VideoProcessor
+def video_task_start():
     """处理视频任务,返回用户名并根据结果决定延迟时间"""
-    try:
-        mark = VideoProcessor.main(data)
-        print(f"返回用户名: {mark}")
-        time.sleep(10 if mark else 120)  # 根据 mark 是否为空设置延迟
-        return mark
-    except Exception as e:
-        print("处理任务时出现异常:", e)
-        return None
-
-def controlled_io_operation(data):
-    """同步控制IO操作并执行视频任务"""
-    with lock:
-        time.sleep(SLEEP_INTERVAL)
-    return video_task_start(data)
-
-def video_start():
-    """启动视频生成任务"""
-    print("开始执行生成视频脚本.")
     data = Material.feishu_list()[0]
-    with concurrent.futures.ThreadPoolExecutor(max_workers=MAX_WORKERS) as executor:
-        futures = [executor.submit(controlled_io_operation, data) for _ in range(MAX_WORKERS)]
-        for future in concurrent.futures.as_completed(futures):
-            try:
-                result = future.result()
-                print(f"处理结果: 成功, 用户名: {result}")
-            except Exception as e:
-                print("处理任务时出现异常:", e)
-    print("执行生成视频脚本结束.")
-
-while True:
-    video_start()
+    while True:
+        try:
+            print("开始执行任务")
+            mark = VideoProcessor.main(data)
+            print(f"返回用户名: {mark}")
+            time.sleep(10 if mark else 120)  # 根据 mark 是否为空设置延迟
+        except Exception as e:
+            print("处理任务时出现异常:", e)
+            time.sleep(10)
+            continue
+if __name__ == '__main__':
+    video_task_start()