agc_video.py 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531
  1. import configparser
  2. import os
  3. import random
  4. import subprocess
  5. import sys
  6. import time
  7. import shutil
  8. from datetime import datetime
  9. from common.sql_help import sqlHelp
  10. sys.path.append(os.getcwd())
  11. from common.material import Material
  12. from common import Common, Oss, Feishu, PQ
  13. from common.srt import SRT
  14. config = configparser.ConfigParser()
  15. config.read('./config.ini') # 替换为您的配置文件路径
  16. class AGC():
  17. """清除文件下所有mp4文件"""
  18. @classmethod
  19. def clear_mp4_files(cls, mark):
  20. video_path_url = config['PATHS']['VIDEO_PATH'] + mark + "/"
  21. # 获取文件夹中所有扩展名为 '.mp4' 的文件路径列表
  22. if os.path.exists(video_path_url):
  23. # 列出目录中的所有文件和文件夹
  24. for filename in os.listdir(video_path_url):
  25. file_path = os.path.join(video_path_url, filename)
  26. try:
  27. # 如果是文件,则删除
  28. if os.path.isfile(file_path) or os.path.islink(file_path):
  29. os.unlink(file_path)
  30. # 如果是文件夹,则删除文件夹及其内容
  31. elif os.path.isdir(file_path):
  32. shutil.rmtree(file_path)
  33. except Exception as e:
  34. print(f"Failed to delete {file_path}. Reason: {e}")
  35. print(f"{mark}的文件已清空。")
  36. """
  37. 站外视频拼接
  38. """
  39. @classmethod
  40. def zw_concatenate_videos(cls, videos, audio_duration, audio_video, platform, s_path, v_path, mark, v_oss_path):
  41. video_files = cls.concat_videos_with_subtitles(videos, audio_duration, platform, mark)
  42. Common.logger("video").info(f"{mark}的{platform}视频文件:{video_files}")
  43. if video_files == "":
  44. return ""
  45. print(f"{mark}的{platform}:开始拼接视频喽~~~")
  46. Common.logger("video").info(f"{mark}的{platform}:开始拼接视频喽~~~")
  47. if os.path.exists(s_path):
  48. # subtitle_cmd = f"subtitles={s_path}:force_style='Fontsize=11,Fontname=Hiragino Sans GB,Outline=0,PrimaryColour=&H000000,SecondaryColour=&H000000'"
  49. subtitle_cmd = f"subtitles={s_path}:force_style='Fontsize=12,Fontname=wqy-zenhei,Bold=1,Outline=0,PrimaryColour=&H000000,SecondaryColour=&H000000'"
  50. else:
  51. start_time = cls.seconds_to_srt_time(0)
  52. end_time = cls.seconds_to_srt_time(audio_duration)
  53. with open(s_path, 'w') as f:
  54. f.write(f"1\n{start_time} --> {end_time}\n分享、转发给群友\n")
  55. # subtitle_cmd = "drawtext=text='分享、转发给群友':fontsize=28:fontcolor=black:x=(w-text_w)/2:y=h-text_h-15"
  56. subtitle_cmd = f"subtitles={s_path}:force_style='Fontsize=12,Fontname=wqy-zenhei,Bold=1,Outline=0,PrimaryColour=&H000000,SecondaryColour=&H000000'"
  57. # 背景色参数
  58. background_cmd = "drawbox=y=ih-65:color=yellow@1.0:width=iw:height=0:t=fill"
  59. VIDEO_COUNTER = 0
  60. FF_INPUT = ""
  61. FF_SCALE = ""
  62. FF_FILTER = ""
  63. ffmpeg_cmd = ["ffmpeg"]
  64. for videos in video_files:
  65. Common.logger("video").info(f"{mark}的{platform}视频:{videos[3]}")
  66. # 添加输入文件
  67. FF_INPUT += f" -i {videos[3]}"
  68. # 为每个视频文件统一长宽,并设置SAR(采样宽高比)
  69. FF_SCALE += f"[{VIDEO_COUNTER}:v]scale=320x480,setsar=1[v{VIDEO_COUNTER}];"
  70. # 为每个视频文件创建一个输入流,并添加到-filter_complex参数中
  71. FF_FILTER += f"[v{VIDEO_COUNTER}][{VIDEO_COUNTER}:a]"
  72. # 增加视频计数器
  73. VIDEO_COUNTER += 1
  74. # 构建最终的FFmpeg命令
  75. ffmpeg_cmd.extend(FF_INPUT.split())
  76. ffmpeg_cmd.extend(["-filter_complex", f"{FF_SCALE}{FF_FILTER}concat=n={VIDEO_COUNTER}:v=1:a=1[v][a]",
  77. "-map", "[v]", "-map", "[a]", v_path])
  78. # 多线程数
  79. num_threads = 4
  80. # 构建 FFmpeg 命令,生成视频
  81. ffmpeg_cmd_oss = [
  82. "ffmpeg",
  83. "-i", v_path, # 视频文件列表
  84. "-i", audio_video, # 音频文件
  85. "-c:v", "libx264", # 复制视频流
  86. "-c:a", "aac", # 编码音频流为AAC
  87. "-threads", str(num_threads),
  88. "-vf", f"{background_cmd},{subtitle_cmd}", # 添加背景色和字幕
  89. "-t", str(int(audio_duration)), # 保持与音频时长一致
  90. "-map", "0:v:0", # 映射第一个输入的视频流
  91. "-map", "1:a:0", # 映射第二个输入的音频流
  92. "-y", # 覆盖输出文件
  93. v_oss_path
  94. ]
  95. try:
  96. timeout_seconds = 25 * 60
  97. subprocess.run(ffmpeg_cmd, timeout=timeout_seconds)
  98. if os.path.isfile(v_path):
  99. subprocess.run(ffmpeg_cmd_oss, timeout=timeout_seconds)
  100. print("视频处理完成!")
  101. except subprocess.TimeoutExpired:
  102. print("视频处理超时,处理失败!")
  103. return ""
  104. except subprocess.CalledProcessError as e:
  105. print(f"视频处理失败:{e}")
  106. return ""
  107. print(f"{mark}的{platform}:视频拼接成功啦~~~")
  108. Common.logger("video").info(f"{mark}的{platform}:视频拼接成功啦~~~")
  109. return video_files
  110. """视频秒数转换"""
  111. @classmethod
  112. def seconds_to_srt_time(cls, seconds):
  113. hours = int(seconds // 3600)
  114. minutes = int((seconds % 3600) // 60)
  115. seconds = seconds % 60
  116. milliseconds = int((seconds - int(seconds)) * 1000)
  117. return f"{hours:02d}:{minutes:02d}:{int(seconds):02d},{milliseconds:03d}"
  118. """
  119. 获取视频文件的时长(秒)
  120. """
  121. @classmethod
  122. def get_video_duration(cls, video_file):
  123. result = subprocess.run(
  124. ["ffprobe", "-v", "error", "-show_entries", "format=duration",
  125. "-of", "default=noprint_wrappers=1:nokey=1", video_file],
  126. capture_output=True, text=True)
  127. return float(result.stdout)
  128. """计算需要拼接的视频"""
  129. @classmethod
  130. def concat_videos_with_subtitles(cls, videos, audio_duration, platform, mark):
  131. # 计算视频文件列表总时长
  132. if platform == "爆款" or platform == "跟随":
  133. total_video_duration = sum(cls.get_video_duration(video_file) for video_file in videos)
  134. else:
  135. total_video_duration = sum(cls.get_video_duration(video_file[3]) for video_file in videos)
  136. Common.logger("video").info(f"{mark}的{platform}渠道总时长{total_video_duration}")
  137. if platform == "爆款" or platform == "跟随":
  138. # 视频时长大于音频时长
  139. if total_video_duration > audio_duration:
  140. return videos
  141. # 计算音频秒数与视频秒数的比率,然后加一得到需要的视频数量
  142. video_audio_ratio = audio_duration / total_video_duration
  143. videos_needed = int(video_audio_ratio) + 2
  144. trimmed_video_list = videos * videos_needed
  145. return trimmed_video_list
  146. else:
  147. # 如果视频总时长小于音频时长,则不做拼接
  148. if total_video_duration < audio_duration:
  149. Common.logger("video").info(f"{mark}的{platform}渠道时长小于等于目标时长,不做视频拼接")
  150. return ""
  151. # 如果视频总时长大于音频时长,则截断视频
  152. trimmed_video_list = []
  153. remaining_duration = audio_duration
  154. for video_file in videos:
  155. video_duration = cls.get_video_duration(video_file[3])
  156. if video_duration <= remaining_duration:
  157. # 如果视频时长小于或等于剩余时长,则将整个视频添加到列表中
  158. trimmed_video_list.append(video_file)
  159. remaining_duration -= video_duration
  160. else:
  161. trimmed_video_list.append(video_file)
  162. break
  163. return trimmed_video_list
  164. """
  165. text文件没有则创建目录
  166. """
  167. @classmethod
  168. def bk_text_folders(cls, mark):
  169. oss_id = cls.random_id()
  170. v_text_url = config['PATHS']['VIDEO_PATH'] + mark + "/text/"
  171. if not os.path.exists(v_text_url):
  172. os.makedirs(v_text_url)
  173. # srt 文件地址
  174. text_path = v_text_url + mark + f"{str(oss_id)}.text"
  175. return text_path
  176. """
  177. 站内视频拼接
  178. """
  179. @classmethod
  180. def zn_concatenate_videos(cls, videos, audio_duration, audio_video, platform, s_path, mark, v_oss_path):
  181. text_ptah = cls.bk_text_folders(mark)
  182. video_files = cls.concat_videos_with_subtitles(videos, audio_duration, platform, mark)
  183. if video_files == "":
  184. return ""
  185. with open(text_ptah, 'w') as f:
  186. for file in video_files:
  187. f.write(f"file '{file}'\n")
  188. Common.logger("video").info(f"{mark}的{platform}视频文件:{video_files}")
  189. print(f"{mark}的{platform}:开始拼接视频喽~~~")
  190. Common.logger("video").info(f"{mark}的{platform}:开始拼接视频喽~~~")
  191. if os.path.exists(s_path):
  192. # subtitle_cmd = f"subtitles={s_path}:force_style='Fontsize=11,Fontname=Hiragino Sans GB,Outline=0,PrimaryColour=&H000000,SecondaryColour=&H000000'"
  193. subtitle_cmd = f"subtitles={s_path}:force_style='Fontsize=12,Fontname=wqy-zenhei,Bold=1,Outline=0,PrimaryColour=&H000000,SecondaryColour=&H000000'"
  194. else:
  195. start_time = cls.seconds_to_srt_time(0)
  196. end_time = cls.seconds_to_srt_time(audio_duration)
  197. with open(s_path, 'w') as f:
  198. f.write(f"1\n{start_time} --> {end_time}\n分享、转发给群友\n")
  199. # subtitle_cmd = "drawtext=text='分享、转发给群友':fontsize=28:fontcolor=black:x=(w-text_w)/2:y=h-text_h-15"
  200. subtitle_cmd = f"subtitles={s_path}:force_style='Fontsize=12,Fontname=wqy-zenhei,Bold=1,Outline=0,PrimaryColour=&H000000,SecondaryColour=&H000000'"
  201. # 背景色参数
  202. background_cmd = "drawbox=y=ih-65:color=yellow@1.0:width=iw:height=0:t=fill"
  203. # 多线程数
  204. num_threads = 4
  205. # 构建 FFmpeg 命令,生成视频
  206. ffmpeg_cmd_oss = [
  207. "ffmpeg",
  208. "-f", "concat",
  209. "-safe", "0",
  210. "-i", f"{text_ptah}", # 视频文件列表
  211. "-i", audio_video, # 音频文件
  212. "-c:v", "libx264",
  213. "-c:a", "aac",
  214. "-threads", str(num_threads),
  215. "-vf", f"scale=320x480,{background_cmd},{subtitle_cmd}", # 添加背景色和字幕
  216. "-t", str(int(audio_duration)), # 保持与音频时长一致
  217. "-map", "0:v:0", # 映射第一个输入的视频流
  218. "-map", "1:a:0", # 映射第二个输入的音频流
  219. "-y", # 覆盖输出文件
  220. v_oss_path
  221. ]
  222. try:
  223. subprocess.run(ffmpeg_cmd_oss)
  224. print("视频处理完成!")
  225. if os.path.isfile(text_ptah):
  226. os.remove(text_ptah)
  227. except subprocess.CalledProcessError as e:
  228. print(f"视频处理失败:{e}")
  229. print(f"{mark}:视频拼接成功啦~~~")
  230. Common.logger("video").info(f"{mark}:视频拼接成功啦~~~")
  231. return v_oss_path
  232. """
  233. 获取视频时长
  234. """
  235. @classmethod
  236. def get_audio_duration(cls, video_url):
  237. ffprobe_cmd = [
  238. "ffprobe",
  239. "-i", video_url,
  240. "-show_entries", "format=duration",
  241. "-v", "quiet",
  242. "-of", "csv=p=0"
  243. ]
  244. output = subprocess.check_output(ffprobe_cmd).decode("utf-8").strip()
  245. return float(output)
  246. """
  247. 创建临时字幕
  248. """
  249. @classmethod
  250. def create_subtitle_file(cls, srt, s_path):
  251. with open(s_path, 'w') as f:
  252. f.write(srt)
  253. """
  254. 随机生成id
  255. """
  256. @classmethod
  257. def random_id(cls):
  258. now = datetime.now()
  259. rand_num = random.randint(10000, 99999)
  260. oss_id = "{}{}".format(now.strftime("%Y%m%d%H%M%S"), rand_num)
  261. return oss_id
  262. """
  263. 文件没有则创建目录
  264. """
  265. @classmethod
  266. def create_folders(cls, mark):
  267. oss_id = cls.random_id()
  268. video_path_url = config['PATHS']['VIDEO_PATH'] + mark + "/"
  269. # srt 目录
  270. s_path_url = config['PATHS']['VIDEO_PATH'] + mark + "/srt/"
  271. # oss 目录
  272. v_path_url = config['PATHS']['VIDEO_PATH'] + mark + "/oss/"
  273. if not os.path.exists(video_path_url):
  274. os.makedirs(video_path_url)
  275. if not os.path.exists(s_path_url):
  276. os.makedirs(s_path_url)
  277. if not os.path.exists(v_path_url):
  278. os.makedirs(v_path_url)
  279. # srt 文件地址
  280. s_path = s_path_url + mark + f"{str(oss_id)}.srt"
  281. # 最终生成视频地址
  282. v_path = v_path_url + mark + f"{str(oss_id)}.mp4"
  283. v_oss_path = v_path_url + mark + f"{str(oss_id)}oss.mp4"
  284. return s_path, v_path, video_path_url, v_oss_path
  285. """
  286. 获取未使用的数据
  287. """
  288. @classmethod
  289. def get_unique_uid_data(cls, data, count):
  290. unique_data_dict = {item['uid']: item for item in data}
  291. unique_data = list(unique_data_dict.values())
  292. if count >= len(unique_data):
  293. return unique_data
  294. else:
  295. selected_items = []
  296. selected_uids = set()
  297. while len(selected_items) < count:
  298. # 随机选择一个元素
  299. item = random.choice(unique_data)
  300. uid = item['uid']
  301. if uid not in selected_uids:
  302. # 如果该uid还未被选择过,则将该元素添加到选中项列表中,并记录已选择的uid
  303. selected_items.append(item)
  304. selected_uids.add(uid)
  305. return selected_items
  306. """
  307. 任务处理
  308. """
  309. @classmethod
  310. def video(cls, data, platform):
  311. mark_name = data['mark_name'] # 负责人
  312. mark = data["mark"] # 标示
  313. if "-" in mark:
  314. name = mark.split("-")[0]
  315. else:
  316. name = mark
  317. if platform == "爆款":
  318. pq_ids = data["pq_id"]
  319. pq_ids_list = pq_ids.split(',') # 账号ID
  320. feishu_id = data["feishu_id"] # 飞书文档ID
  321. video_call = data["video_call"] # 脚本sheet
  322. list_data = Material.get_allbk_data(feishu_id, video_call)
  323. if len(list_data) == 0:
  324. Feishu.bot('recommend', 'AGC完成通知', f'{platform}任务数为0,不做拼接', name, mark_name)
  325. return
  326. elif platform == "常规":
  327. pq_ids = data["pq_id"]# 账号ID
  328. pq_ids_list = pq_ids.split(',')
  329. feishu_id = data["feishu_id"] # 飞书文档ID
  330. video_call = data["video_call"] # 脚本sheet
  331. video_count = data["video_count"]
  332. if int(video_count) == 0:
  333. Feishu.bot('recommend', 'AGC完成通知', f'{platform}任务数为{video_count},不做拼接', name, mark_name)
  334. return mark
  335. data_list, videos_mark = Material.get_all_data(feishu_id, video_call, mark)
  336. list_data = cls.get_unique_uid_data(data_list, int(video_count))
  337. elif platform == "跟随":
  338. pq_ids = data["pq_id"]
  339. pq_ids_list = pq_ids.split(',') # 账号ID
  340. feishu_id = data["feishu_id"] # 飞书文档ID
  341. video_call = data["video_call"]
  342. video_count = data["video_count"]
  343. if int(video_count) == 0:
  344. Feishu.bot('recommend', 'AGC完成通知', f'{platform}任务数为{video_count},不做拼接', name, mark_name)
  345. return mark
  346. data_list, videos = Material.get_all_data(feishu_id, video_call, mark)
  347. list_data = cls.get_unique_uid_data(data_list, int(video_count))
  348. count = 0
  349. pj_count = 0
  350. error_count = 0
  351. total_count = 0
  352. while True:
  353. # 清空所有文件
  354. cls.clear_mp4_files(mark)
  355. s_path, v_path, video_path_url, v_oss_path = cls.create_folders(mark)
  356. if pj_count == 10:
  357. Feishu.bot('recommend', 'AGC拼接画面不足通知', f'{platform}任务视频画面不足,请及时补充!!', name, mark_name)
  358. return
  359. if count == len(list_data):
  360. break
  361. try:
  362. d_list = list_data[count]
  363. uid = d_list['uid'] # 音频id
  364. srt = d_list['text'] # srt
  365. cover = d_list['cover']
  366. audio_title = d_list['title']
  367. # if srt and len(srt.strip()) >= 3:
  368. # # 创建临时字幕文件
  369. # cls.create_subtitle_file(srt, s_path)
  370. # Common.logger("bk_video").info(f"S{mark} 文件目录创建成功")
  371. # else:
  372. srt_new = SRT.getSrt(int(uid))
  373. Common.logger("video").info(f"S{mark}的{platform}渠道音频ID{uid}")
  374. if error_count == 5:
  375. Feishu.bot('recommend', 'AGC异常通知', f'{platform}渠道音频id为{uid},任务处理异常5次,该任务跳过,请检查格式!', name, mark_name)
  376. count += 1
  377. continue
  378. if srt_new:
  379. # 创建临时字幕文件
  380. cls.create_subtitle_file(srt_new, s_path)
  381. Common.logger("video").info(f"S{mark}的{platform}渠道SRT 文件目录创建成功")
  382. try:
  383. # 获取音频
  384. audio_video = PQ.get_audio_url(uid)
  385. Common.logger("video").info(f"{mark}的{platform}渠道获音频成功{audio_video}")
  386. audio_duration = cls.get_audio_duration(audio_video)
  387. Common.logger("video").info(f"{mark}的{platform}渠道获取需要拼接的音频秒数为:{audio_duration}")
  388. except Exception as e:
  389. count += 1
  390. # 清空所有mp4数据
  391. cls.clear_mp4_files(mark)
  392. Feishu.bot('recommend', 'AGC异常通知', f'{platform}任务下,{uid}音频格式填写错误该任务跳过,请关注', name, mark_name)
  393. continue
  394. if platform != "常规":
  395. if platform == "爆款":
  396. videos = str(d_list['video'])
  397. if ',' in videos:
  398. videos = str(videos).split(',')
  399. else:
  400. videos = [str(videos)]
  401. video_id = random.choice(videos)
  402. video_url = PQ.get_audio_url(video_id)
  403. Common.logger("video").info(f"{mark}的{platform}渠道获取视频链接成功")
  404. download_video = Oss.download_url(video_url, video_path_url, str(video_id))
  405. if download_video:
  406. video_files = cls.zn_concatenate_videos(download_video, audio_duration, audio_video, platform,
  407. s_path, mark, v_oss_path)
  408. if os.path.isfile(v_oss_path):
  409. Common.logger("video").info(f"{mark}的{platform}渠道新视频生成成功")
  410. else:
  411. Common.logger("video").info(f"{mark}的{platform}渠道新视频生成失败")
  412. continue
  413. else:
  414. # chnnel_count = int(len(list_data)/2)
  415. channels = ["douyin", "kuaishou"]
  416. channel = random.choice(channels)
  417. user_id = sqlHelp.get_user_id(channel, mark)
  418. url_list, user = sqlHelp.get_url_list(user_id, mark, "50")
  419. videos = [list(item) for item in url_list]
  420. videos = Oss.get_oss_url(videos, video_path_url)
  421. Common.logger("video").info(f"{mark}的{platform}渠道获取视频链接成功")
  422. video_files = cls.zw_concatenate_videos(videos, audio_duration, audio_video, platform, s_path, v_path,
  423. mark, v_oss_path)
  424. if video_files == "":
  425. pj_count += 1
  426. Common.logger("video").info(f"{mark}的{platform}渠道使用拼接视频为空")
  427. continue
  428. if os.path.isfile(v_oss_path):
  429. Common.logger("video").info(f"{mark}的{platform}渠道新视频生成成功")
  430. else:
  431. Common.logger("video").info(f"{mark}的{platform}渠道新视频生成失败")
  432. continue
  433. pj_count = 0
  434. error_count = 0
  435. # 随机生成视频oss_id
  436. oss_id = cls.random_id()
  437. Common.logger("video").info(f"{mark}的{platform}渠道上传到 OSS 生成视频id为:{oss_id}")
  438. oss_object_key = Oss.stitching_sync_upload_oss(v_oss_path, oss_id)
  439. status = oss_object_key.get("status")
  440. if status == 200:
  441. # 获取 oss 视频地址
  442. oss_object_key = oss_object_key.get("oss_object_key")
  443. Common.logger("video").info(f"{mark}的{platform}渠道拼接视频发送成功,OSS 地址:{oss_object_key}")
  444. time.sleep(10)
  445. if platform == "常规":
  446. # 已使用视频存入数据库
  447. Common.logger("video").info(f"{mark}的{platform}渠道开始已使用视频存入数据库")
  448. sqlHelp.insert_videoAudio(video_files, uid, platform, mark)
  449. Common.logger("video").info(f"{mark}的{platform}渠道完成已使用视频存入数据库")
  450. Common.logger("video").info(f"{mark}的{platform}渠道开始视频添加到对应用户")
  451. new_video_id, title = PQ.insert_piaoquantv(oss_object_key, audio_title, pq_ids_list, cover, uid)
  452. if new_video_id:
  453. Common.logger("video").info(f"{mark}的{platform}渠道视频添加到对应用户成功")
  454. count += 1
  455. total_count += 1
  456. if mark_name == "穆新艺":
  457. sheet = '50b8a1'
  458. elif mark_name == "信欣":
  459. sheet = 'UyVK7y'
  460. elif mark_name == "范军":
  461. sheet = 'uP3zbf'
  462. elif mark_name == "鲁涛":
  463. sheet = 'iDTHt4'
  464. elif mark_name == "余海涛":
  465. sheet = 'R1jIeT'
  466. elif mark_name == "罗情":
  467. sheet = 'iuxfAt'
  468. current_time = datetime.now()
  469. formatted_time = current_time.strftime("%Y-%m-%d %H:%M:%S")
  470. if platform == "常规":
  471. third_chars = [j[2] for j in video_files]
  472. data = ",".join(third_chars)
  473. user_id = user
  474. else:
  475. user_id = video_id
  476. data = ''
  477. values = [[mark, str(uid), str(user_id), data, title, new_video_id, formatted_time]]
  478. Feishu.insert_columns("LAn9so7E0hxRYht2UMEcK5wpnMj", sheet, "ROWS", 1, 2)
  479. random_wait_time = random.uniform(0.5, 2.5)
  480. time.sleep(random_wait_time)
  481. Feishu.update_values("LAn9so7E0hxRYht2UMEcK5wpnMj", sheet, "A2:Z2", values)
  482. if srt_new:
  483. current_time = datetime.now()
  484. formatted_time = current_time.strftime("%Y-%m-%d %H:%M:%S")
  485. values = [[mark, str(uid), srt_new, formatted_time]]
  486. random_wait_time = random.uniform(0.5, 2.5)
  487. time.sleep(random_wait_time)
  488. Feishu.insert_columns("IbVVsKCpbhxhSJtwYOUc8S1jnWb", "jd9qD9", "ROWS", 1, 2)
  489. time.sleep(random_wait_time)
  490. Feishu.update_values("IbVVsKCpbhxhSJtwYOUc8S1jnWb", "jd9qD9", "A2:Z2", values)
  491. except Exception as e:
  492. error_count += 1
  493. Common.logger("video").warning(f"{mark}的视频拼接失败:{e}\n")
  494. # 清空所有mp4数据
  495. cls.clear_mp4_files(mark)
  496. continue
  497. Feishu.bot('recommend', 'AGC完成通知', f'今日{platform}任务拼接任务完成,共{total_count}条', name, mark_name)