|
@@ -1,22 +1,13 @@
|
|
|
import configparser
|
|
|
-import glob
|
|
|
import os
|
|
|
import random
|
|
|
-import re
|
|
|
import subprocess
|
|
|
import sys
|
|
|
import time
|
|
|
-import urllib.parse
|
|
|
-import json
|
|
|
-
|
|
|
-import requests
|
|
|
-from datetime import datetime, timedelta
|
|
|
-from urllib.parse import urlencode
|
|
|
-
|
|
|
+import shutil
|
|
|
+from datetime import datetime
|
|
|
from common.sql_help import sqlHelp
|
|
|
-
|
|
|
sys.path.append(os.getcwd())
|
|
|
-from common.db import MysqlHelper
|
|
|
from common.material import Material
|
|
|
from common import Common, Oss, Feishu, PQ
|
|
|
from common.srt import SRT
|
|
@@ -28,15 +19,25 @@ config.read('./config.ini') # 替换为您的配置文件路径
|
|
|
class AGC():
|
|
|
"""清除文件下所有mp4文件"""
|
|
|
@classmethod
|
|
|
- def clear_mp4_files(cls, folder_path):
|
|
|
+ def clear_mp4_files(cls, mark):
|
|
|
+ video_path_url = config['PATHS']['VIDEO_PATH'] + mark + "/"
|
|
|
# 获取文件夹中所有扩展名为 '.mp4' 的文件路径列表
|
|
|
- mp4_files = glob.glob(os.path.join(folder_path, '*.mp4'))
|
|
|
- if not mp4_files:
|
|
|
- return
|
|
|
- # 遍历并删除所有 .mp4 文件
|
|
|
- for mp4_file in mp4_files:
|
|
|
- os.remove(mp4_file)
|
|
|
- print(f"文件夹 '{folder_path}' 中的所有 .mp4 文件已清空。")
|
|
|
+ if os.path.exists(video_path_url):
|
|
|
+ # 列出目录中的所有文件和文件夹
|
|
|
+ for filename in os.listdir(video_path_url):
|
|
|
+ file_path = os.path.join(video_path_url, filename)
|
|
|
+ try:
|
|
|
+ # 如果是文件,则删除
|
|
|
+ if os.path.isfile(file_path) or os.path.islink(file_path):
|
|
|
+ os.unlink(file_path)
|
|
|
+ # 如果是文件夹,则删除文件夹及其内容
|
|
|
+ elif os.path.isdir(file_path):
|
|
|
+ shutil.rmtree(file_path)
|
|
|
+ except Exception as e:
|
|
|
+ print(f"Failed to delete {file_path}. Reason: {e}")
|
|
|
+ print(f"文件已清空。")
|
|
|
+ else:
|
|
|
+ print(f"文件已清空。")
|
|
|
"""
|
|
|
站外视频拼接
|
|
|
"""
|
|
@@ -362,9 +363,12 @@ class AGC():
|
|
|
return mark
|
|
|
data_list, videos = Material.get_all_data(feishu_id, video_call, mark)
|
|
|
list_data = cls.get_unique_uid_data(data_list, int(video_count))
|
|
|
- s_path, v_path, video_path_url, v_oss_path = cls.create_folders(mark)
|
|
|
count = 0
|
|
|
while True:
|
|
|
+ # 清空所有文件
|
|
|
+ cls.clear_mp4_files(mark)
|
|
|
+ s_path, v_path, video_path_url, v_oss_path = cls.create_folders(mark)
|
|
|
+
|
|
|
if count == len(list_data):
|
|
|
break
|
|
|
# for d_list in list_data:
|
|
@@ -454,14 +458,6 @@ class AGC():
|
|
|
new_video_id, title = PQ.insert_piaoquantv(oss_object_key, audio_title, pq_ids_list, cover, uid)
|
|
|
if new_video_id:
|
|
|
Common.logger("video").info(f"{mark}的{platform}渠道视频添加到对应用户成功")
|
|
|
- if os.path.isfile(v_oss_path):
|
|
|
- os.remove(v_oss_path)
|
|
|
- if os.path.isfile(v_path):
|
|
|
- os.remove(v_path)
|
|
|
- if os.path.isfile(s_path):
|
|
|
- os.remove(s_path)
|
|
|
- # 清空所有mp4数据
|
|
|
- cls.clear_mp4_files(video_path_url)
|
|
|
count += 1
|
|
|
if mark_name == "穆新艺":
|
|
|
sheet = '50b8a1'
|
|
@@ -491,14 +487,8 @@ class AGC():
|
|
|
Feishu.update_values("LAn9so7E0hxRYht2UMEcK5wpnMj", sheet, "A2:Z2", values)
|
|
|
except Exception as e:
|
|
|
Common.logger("bk_video").warning(f"{mark}的视频拼接失败:{e}\n")
|
|
|
- if os.path.isfile(v_oss_path):
|
|
|
- os.remove(v_oss_path)
|
|
|
- if os.path.isfile(v_path):
|
|
|
- os.remove(v_path)
|
|
|
- if os.path.isfile(s_path):
|
|
|
- os.remove(s_path)
|
|
|
# 清空所有mp4数据
|
|
|
- cls.clear_mp4_files(video_path_url)
|
|
|
+ cls.clear_mp4_files(mark)
|
|
|
continue
|
|
|
if "-" in mark:
|
|
|
name = mark.split("-")[0]
|