|
@@ -1,4 +1,5 @@
|
|
|
import configparser
|
|
|
+import glob
|
|
|
import os
|
|
|
import random
|
|
|
import subprocess
|
|
@@ -16,10 +17,6 @@ from common import Common, Oss, Feishu
|
|
|
|
|
|
config = configparser.ConfigParser()
|
|
|
config.read('./config.ini') # 替换为您的配置文件路径
|
|
|
-video_path = config['PATHS']['VIDEO_PATH']
|
|
|
-srt_path = config['PATHS']['SRT_PATH']
|
|
|
-oss_path = config['PATHS']['OSS_PATH']
|
|
|
-txt_path = config['PATHS']['TXT_PATH']
|
|
|
|
|
|
|
|
|
class AgcVidoe():
|
|
@@ -176,6 +173,18 @@ class AgcVidoe():
|
|
|
capture_output=True, text=True)
|
|
|
return float(result.stdout)
|
|
|
|
|
|
+ @classmethod
|
|
|
+ def clear_mp4_files(cls, folder_path):
|
|
|
+ # 获取文件夹中所有扩展名为 '.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"已删除文件: {mp4_file}")
|
|
|
+
|
|
|
+ print(f"文件夹 '{folder_path}' 中的所有 .mp4 文件已清空。")
|
|
|
|
|
|
# 计算需要拼接的视频
|
|
|
@classmethod
|
|
@@ -224,6 +233,42 @@ class AgcVidoe():
|
|
|
machine="",
|
|
|
)
|
|
|
|
|
|
+ #文件没有则创建目录
|
|
|
+ @classmethod
|
|
|
+ def create_folders(cls, mark):
|
|
|
+ video_path_url = config['PATHS']['VIDEO_PATH'] + mark + "/"
|
|
|
+ # srt 目录
|
|
|
+ s_path_url = config['PATHS']['VIDEO_PATH'] + mark + "/srt/"
|
|
|
+ # txt 目录
|
|
|
+ t_path_url = config['PATHS']['VIDEO_PATH'] + mark + "/txt/"
|
|
|
+ # oss 目录
|
|
|
+ v_path_url = config['PATHS']['VIDEO_PATH'] + mark + "/oss/"
|
|
|
+ if not os.path.exists(video_path_url):
|
|
|
+ os.makedirs(video_path_url)
|
|
|
+ if not os.path.exists(s_path_url):
|
|
|
+ os.makedirs(s_path_url)
|
|
|
+ if not os.path.exists(t_path_url):
|
|
|
+ os.makedirs(t_path_url)
|
|
|
+ if not os.path.exists(v_path_url):
|
|
|
+ os.makedirs(v_path_url)
|
|
|
+ # srt 文件地址
|
|
|
+ s_path = s_path_url + mark + ".srt"
|
|
|
+ # txt 文件地址
|
|
|
+ t_path = t_path_url + mark + ".txt"
|
|
|
+ # 最终生成视频地址
|
|
|
+ v_path = v_path_url + mark + ".mp4"
|
|
|
+ if os.path.isfile(v_path):
|
|
|
+ os.remove(v_path)
|
|
|
+ if os.path.isfile(t_path):
|
|
|
+ os.remove(t_path)
|
|
|
+ if os.path.isfile(s_path):
|
|
|
+ os.remove(s_path)
|
|
|
+ # 清空所有mp4数据
|
|
|
+ cls.clear_mp4_files(video_path_url)
|
|
|
+ return s_path, t_path, v_path, video_path_url
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
# 视频拼接
|
|
|
@classmethod
|
|
|
def concatenate_videos(cls, videos, audio_duration, audio_video, platform, s_path, v_path, mark, t_path):
|
|
@@ -310,7 +355,11 @@ class AgcVidoe():
|
|
|
yhmw_count = 0
|
|
|
else:
|
|
|
yhmw_count = int(int(yhmw_all_count)/2)
|
|
|
- # kb_link = result[1][0]
|
|
|
+
|
|
|
+
|
|
|
+ # 如果没有该文件目录则创建,有文件目录的话 则删除文件
|
|
|
+ s_path, t_path, v_path, video_path_url = cls.create_folders(mark)
|
|
|
+
|
|
|
kb_count = int(result[1][1])
|
|
|
channel = ['douyin', 'kuaishou', 'koubo']
|
|
|
try:
|
|
@@ -344,14 +393,10 @@ class AgcVidoe():
|
|
|
Common.logger("video").info(f"未使用视频链接为空:{url_list}")
|
|
|
return ''
|
|
|
videos = [list(item) for item in url_list]
|
|
|
+
|
|
|
# 下载视频
|
|
|
- videos = Oss.get_oss_url(videos, video_path)
|
|
|
- # srt 文件地址
|
|
|
- s_path = srt_path + mark + ".srt"
|
|
|
- # ass 文件地址
|
|
|
- t_path = txt_path + mark + ".txt"
|
|
|
- # 最终生成视频地址
|
|
|
- v_path = oss_path + mark + ".mp4"
|
|
|
+ videos = Oss.get_oss_url(videos, video_path_url)
|
|
|
+
|
|
|
if srt:
|
|
|
# 创建临时字幕文件
|
|
|
cls.create_subtitle_file(srt, s_path)
|
|
@@ -390,19 +435,6 @@ class AgcVidoe():
|
|
|
piaoquantv = cls.insert_piaoquantv(oss_object_key, title_list, pq_ids_list)
|
|
|
if piaoquantv:
|
|
|
Common.logger("video").info(f"{mark}的{platform}渠道视频添加到对应用户成功")
|
|
|
- if os.path.isfile(s_path):
|
|
|
- os.remove(s_path)
|
|
|
- os.remove(t_path)
|
|
|
- else:
|
|
|
- Common.logger("video").info(f"{mark}的{platform}渠道文件不存在{s_path}")
|
|
|
- if os.path.isfile(v_path):
|
|
|
- os.remove(v_path)
|
|
|
- else:
|
|
|
- Common.logger("video").info(f"{mark}的{platform}渠道文件不存在{v_path}")
|
|
|
- for video in videos:
|
|
|
- filename = video[2].split("/")[-1]
|
|
|
- os.remove(f'{video_path}{filename}.mp4')
|
|
|
- Common.logger("video").info(f"{mark}的临时文件删除成功")
|
|
|
return ''
|
|
|
except Exception as e:
|
|
|
Common.logger("video").warning(f"{mark}的视频拼接失败:{e}\n")
|