agc_video.py 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  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. if platform == "爆款" or platform == "跟随":
  137. # 视频时长大于音频时长
  138. if total_video_duration > audio_duration:
  139. return videos
  140. # 计算音频秒数与视频秒数的比率,然后加一得到需要的视频数量
  141. video_audio_ratio = audio_duration / total_video_duration
  142. videos_needed = int(video_audio_ratio) + 2
  143. trimmed_video_list = videos * videos_needed
  144. return trimmed_video_list
  145. else:
  146. # 如果视频总时长小于音频时长,则不做拼接
  147. if total_video_duration < audio_duration:
  148. Common.logger("video").info(f"{mark}的{platform}渠道时长小于等于目标时长,不做视频拼接")
  149. return ""
  150. # 如果视频总时长大于音频时长,则截断视频
  151. trimmed_video_list = []
  152. remaining_duration = audio_duration
  153. for video_file in videos:
  154. video_duration = cls.get_video_duration(video_file[3])
  155. if video_duration <= remaining_duration:
  156. # 如果视频时长小于或等于剩余时长,则将整个视频添加到列表中
  157. trimmed_video_list.append(video_file)
  158. remaining_duration -= video_duration
  159. else:
  160. trimmed_video_list.append(video_file)
  161. break
  162. return trimmed_video_list
  163. """
  164. text文件没有则创建目录
  165. """
  166. @classmethod
  167. def bk_text_folders(cls, mark):
  168. oss_id = cls.random_id()
  169. v_text_url = config['PATHS']['VIDEO_PATH'] + mark + "/text/"
  170. if not os.path.exists(v_text_url):
  171. os.makedirs(v_text_url)
  172. # srt 文件地址
  173. text_path = v_text_url + mark + f"{str(oss_id)}.text"
  174. return text_path
  175. """
  176. 站内视频拼接
  177. """
  178. @classmethod
  179. def zn_concatenate_videos(cls, videos, audio_duration, audio_video, platform, s_path, mark, v_oss_path):
  180. text_ptah = cls.bk_text_folders(mark)
  181. video_files = cls.concat_videos_with_subtitles(videos, audio_duration, platform, mark)
  182. if video_files == "":
  183. return ""
  184. with open(text_ptah, 'w') as f:
  185. for file in video_files:
  186. f.write(f"file '{file}'\n")
  187. Common.logger("video").info(f"{mark}的{platform}视频文件:{video_files}")
  188. print(f"{mark}的{platform}:开始拼接视频喽~~~")
  189. Common.logger("video").info(f"{mark}的{platform}:开始拼接视频喽~~~")
  190. if os.path.exists(s_path):
  191. # subtitle_cmd = f"subtitles={s_path}:force_style='Fontsize=11,Fontname=Hiragino Sans GB,Outline=0,PrimaryColour=&H000000,SecondaryColour=&H000000'"
  192. subtitle_cmd = f"subtitles={s_path}:force_style='Fontsize=12,Fontname=wqy-zenhei,Bold=1,Outline=0,PrimaryColour=&H000000,SecondaryColour=&H000000'"
  193. else:
  194. start_time = cls.seconds_to_srt_time(0)
  195. end_time = cls.seconds_to_srt_time(audio_duration)
  196. with open(s_path, 'w') as f:
  197. f.write(f"1\n{start_time} --> {end_time}\n分享、转发给群友\n")
  198. # subtitle_cmd = "drawtext=text='分享、转发给群友':fontsize=28:fontcolor=black:x=(w-text_w)/2:y=h-text_h-15"
  199. subtitle_cmd = f"subtitles={s_path}:force_style='Fontsize=12,Fontname=wqy-zenhei,Bold=1,Outline=0,PrimaryColour=&H000000,SecondaryColour=&H000000'"
  200. # 背景色参数
  201. background_cmd = "drawbox=y=ih-65:color=yellow@1.0:width=iw:height=0:t=fill"
  202. # 多线程数
  203. num_threads = 4
  204. # 构建 FFmpeg 命令,生成视频
  205. ffmpeg_cmd_oss = [
  206. "ffmpeg",
  207. "-f", "concat",
  208. "-safe", "0",
  209. "-i", f"{text_ptah}", # 视频文件列表
  210. "-i", audio_video, # 音频文件
  211. "-c:v", "libx264",
  212. "-c:a", "aac",
  213. "-threads", str(num_threads),
  214. "-vf", f"scale=320x480,{background_cmd},{subtitle_cmd}", # 添加背景色和字幕
  215. "-t", str(int(audio_duration)), # 保持与音频时长一致
  216. "-map", "0:v:0", # 映射第一个输入的视频流
  217. "-map", "1:a:0", # 映射第二个输入的音频流
  218. "-y", # 覆盖输出文件
  219. v_oss_path
  220. ]
  221. try:
  222. subprocess.run(ffmpeg_cmd_oss)
  223. print("视频处理完成!")
  224. if os.path.isfile(text_ptah):
  225. os.remove(text_ptah)
  226. except subprocess.CalledProcessError as e:
  227. print(f"视频处理失败:{e}")
  228. print(f"{mark}:视频拼接成功啦~~~")
  229. Common.logger("video").info(f"{mark}:视频拼接成功啦~~~")
  230. return v_oss_path
  231. """
  232. 获取视频时长
  233. """
  234. @classmethod
  235. def get_audio_duration(cls, video_url):
  236. ffprobe_cmd = [
  237. "ffprobe",
  238. "-i", video_url,
  239. "-show_entries", "format=duration",
  240. "-v", "quiet",
  241. "-of", "csv=p=0"
  242. ]
  243. output = subprocess.check_output(ffprobe_cmd).decode("utf-8").strip()
  244. return float(output)
  245. """
  246. 创建临时字幕
  247. """
  248. @classmethod
  249. def create_subtitle_file(cls, srt, s_path):
  250. with open(s_path, 'w') as f:
  251. f.write(srt)
  252. """
  253. 随机生成id
  254. """
  255. @classmethod
  256. def random_id(cls):
  257. now = datetime.now()
  258. rand_num = random.randint(10000, 99999)
  259. oss_id = "{}{}".format(now.strftime("%Y%m%d%H%M%S"), rand_num)
  260. return oss_id
  261. """
  262. 文件没有则创建目录
  263. """
  264. @classmethod
  265. def create_folders(cls, mark):
  266. oss_id = cls.random_id()
  267. video_path_url = config['PATHS']['VIDEO_PATH'] + mark + "/"
  268. # srt 目录
  269. s_path_url = config['PATHS']['VIDEO_PATH'] + mark + "/srt/"
  270. # oss 目录
  271. v_path_url = config['PATHS']['VIDEO_PATH'] + mark + "/oss/"
  272. if not os.path.exists(video_path_url):
  273. os.makedirs(video_path_url)
  274. if not os.path.exists(s_path_url):
  275. os.makedirs(s_path_url)
  276. if not os.path.exists(v_path_url):
  277. os.makedirs(v_path_url)
  278. # srt 文件地址
  279. s_path = s_path_url + mark + f"{str(oss_id)}.srt"
  280. # 最终生成视频地址
  281. v_path = v_path_url + mark + f"{str(oss_id)}.mp4"
  282. v_oss_path = v_path_url + mark + f"{str(oss_id)}oss.mp4"
  283. return s_path, v_path, video_path_url, v_oss_path
  284. """
  285. 获取未使用的数据
  286. """
  287. @classmethod
  288. def get_unique_uid_data(cls, data, count):
  289. unique_data_dict = {item['uid']: item for item in data}
  290. unique_data = list(unique_data_dict.values())
  291. if count >= len(unique_data):
  292. return unique_data
  293. else:
  294. selected_items = []
  295. selected_uids = set()
  296. while len(selected_items) < count:
  297. # 随机选择一个元素
  298. item = random.choice(unique_data)
  299. uid = item['uid']
  300. if uid not in selected_uids:
  301. # 如果该uid还未被选择过,则将该元素添加到选中项列表中,并记录已选择的uid
  302. selected_items.append(item)
  303. selected_uids.add(uid)
  304. return selected_items
  305. """
  306. 任务处理
  307. """
  308. @classmethod
  309. def video(cls, data, platform):
  310. mark_name = data['mark_name'] # 负责人
  311. mark = data["mark"] # 标示
  312. if "-" in mark:
  313. name = mark.split("-")[0]
  314. else:
  315. name = mark
  316. if platform == "爆款":
  317. pq_ids = data["pq_id"]
  318. pq_ids_list = pq_ids.split(',') # 账号ID
  319. feishu_id = data["feishu_id"] # 飞书文档ID
  320. video_call = data["video_call"] # 脚本sheet
  321. list_data = Material.get_allbk_data(feishu_id, video_call)
  322. if len(list_data) == 0:
  323. Feishu.bot('recommend', 'AGC完成通知', f'{platform}任务数为0,不做拼接', name, mark_name)
  324. return
  325. elif platform == "常规":
  326. pq_ids = data["pq_id"]# 账号ID
  327. pq_ids_list = pq_ids.split(',')
  328. feishu_id = data["feishu_id"] # 飞书文档ID
  329. video_call = data["video_call"] # 脚本sheet
  330. video_count = data["video_count"]
  331. if int(video_count) == 0:
  332. Feishu.bot('recommend', 'AGC完成通知', f'{platform}任务数为{video_count},不做拼接', name, mark_name)
  333. return mark
  334. data_list, videos_mark = Material.get_all_data(feishu_id, video_call, mark)
  335. list_data = cls.get_unique_uid_data(data_list, int(video_count))
  336. elif platform == "跟随":
  337. pq_ids = data["pq_id"]
  338. pq_ids_list = pq_ids.split(',') # 账号ID
  339. feishu_id = data["feishu_id"] # 飞书文档ID
  340. video_call = data["video_call"]
  341. video_count = data["video_count"]
  342. if int(video_count) == 0:
  343. Feishu.bot('recommend', 'AGC完成通知', f'{platform}任务数为{video_count},不做拼接', name, mark_name)
  344. return mark
  345. data_list, videos = Material.get_all_data(feishu_id, video_call, mark)
  346. list_data = cls.get_unique_uid_data(data_list, int(video_count))
  347. count = 0
  348. pj_count = 0
  349. error_count = 0
  350. while True:
  351. # 清空所有文件
  352. cls.clear_mp4_files(mark)
  353. s_path, v_path, video_path_url, v_oss_path = cls.create_folders(mark)
  354. if pj_count == 10:
  355. Feishu.bot('recommend', 'AGC拼接画面不足通知', f'视频画面不足,请及时补充!!', name, mark_name)
  356. return
  357. if count == len(list_data):
  358. break
  359. try:
  360. d_list = list_data[count]
  361. uid = d_list['uid'] # 音频id
  362. srt = d_list['text'] # srt
  363. cover = d_list['cover']
  364. audio_title = d_list['title']
  365. # if srt and len(srt.strip()) >= 3:
  366. # # 创建临时字幕文件
  367. # cls.create_subtitle_file(srt, s_path)
  368. # Common.logger("bk_video").info(f"S{mark} 文件目录创建成功")
  369. # else:
  370. srt_new = SRT.getSrt(int(uid))
  371. Common.logger("video").info(f"S{mark}的{platform}渠道音频ID")
  372. if error_count == 5:
  373. Feishu.bot('recommend', 'AGC异常通知', f'音频id为{uid},任务处理异常5次,该任务跳过,请检查格式!', name, mark_name)
  374. count += 1
  375. continue
  376. if srt_new:
  377. # 创建临时字幕文件
  378. cls.create_subtitle_file(srt_new, s_path)
  379. Common.logger("video").info(f"S{mark}的{platform}渠道SRT 文件目录创建成功")
  380. try:
  381. # 获取音频
  382. audio_video = PQ.get_audio_url(uid)
  383. Common.logger("video").info(f"{mark}的{platform}渠道获音频成功")
  384. audio_duration = cls.get_audio_duration(audio_video)
  385. Common.logger("video").info(f"{mark}的{platform}渠道获取需要拼接的音频秒数为:{audio_duration}")
  386. except Exception as e:
  387. count += 1
  388. # 清空所有mp4数据
  389. cls.clear_mp4_files(mark)
  390. Feishu.bot('recommend', 'AGC异常通知', f'{platform}任务下,{uid}音频格式填写该任务跳过,请关注', name, mark_name)
  391. continue
  392. if platform != "常规":
  393. if platform == "爆款":
  394. videos = str(d_list['video'])
  395. if ',' in videos:
  396. videos = str(videos).split(',')
  397. else:
  398. videos = [str(videos)]
  399. video_id = random.choice(videos)
  400. video_url = PQ.get_audio_url(video_id)
  401. download_video = Oss.download_url(video_url, video_path_url, str(video_id))
  402. if download_video:
  403. video_files = cls.zn_concatenate_videos(download_video, audio_duration, audio_video, platform,
  404. s_path, mark, v_oss_path)
  405. if os.path.isfile(v_oss_path):
  406. Common.logger("video").info(f"{mark}的{platform}渠道新视频生成成功")
  407. else:
  408. Common.logger("video").info(f"{mark}的{platform}渠道新视频生成失败")
  409. continue
  410. else:
  411. # chnnel_count = int(len(list_data)/2)
  412. channels = ["douyin", "kuaishou"]
  413. channel = random.choice(channels)
  414. user_id = sqlHelp.get_user_id(channel, mark)
  415. url_list, user = sqlHelp.get_url_list(user_id, mark, "35")
  416. videos = [list(item) for item in url_list]
  417. videos = Oss.get_oss_url(videos, video_path_url)
  418. video_files = cls.zw_concatenate_videos(videos, audio_duration, audio_video, platform, s_path, v_path,
  419. mark, v_oss_path)
  420. if video_files == "":
  421. pj_count += 1
  422. Common.logger("video").info(f"{mark}的{platform}渠道使用拼接视频为空")
  423. continue
  424. if os.path.isfile(v_oss_path):
  425. Common.logger("video").info(f"{mark}的{platform}渠道新视频生成成功")
  426. else:
  427. Common.logger("video").info(f"{mark}的{platform}渠道新视频生成失败")
  428. continue
  429. pj_count = 0
  430. error_count = 0
  431. # 随机生成视频oss_id
  432. oss_id = cls.random_id()
  433. Common.logger("video").info(f"{mark}的{platform}渠道上传到 OSS 生成视频id为:{oss_id}")
  434. oss_object_key = Oss.stitching_sync_upload_oss(v_oss_path, oss_id)
  435. status = oss_object_key.get("status")
  436. if status == 200:
  437. # 获取 oss 视频地址
  438. oss_object_key = oss_object_key.get("oss_object_key")
  439. Common.logger("video").info(f"{mark}的{platform}渠道拼接视频发送成功,OSS 地址:{oss_object_key}")
  440. time.sleep(10)
  441. if platform == "常规":
  442. # 已使用视频存入数据库
  443. Common.logger("video").info(f"{mark}的{platform}渠道开始已使用视频存入数据库")
  444. sqlHelp.insert_videoAudio(video_files, uid, platform, mark)
  445. Common.logger("video").info(f"{mark}的{platform}渠道完成已使用视频存入数据库")
  446. Common.logger("video").info(f"{mark}的{platform}渠道开始视频添加到对应用户")
  447. new_video_id, title = PQ.insert_piaoquantv(oss_object_key, audio_title, pq_ids_list, cover, uid)
  448. if new_video_id:
  449. Common.logger("video").info(f"{mark}的{platform}渠道视频添加到对应用户成功")
  450. count += 1
  451. if mark_name == "穆新艺":
  452. sheet = '50b8a1'
  453. elif mark_name == "信欣":
  454. sheet = 'UyVK7y'
  455. elif mark_name == "范军":
  456. sheet = 'uP3zbf'
  457. elif mark_name == "鲁涛":
  458. sheet = 'iDTHt4'
  459. elif mark_name == "余海涛":
  460. sheet = 'R1jIeT'
  461. elif mark_name == "罗情":
  462. sheet = 'iuxfAt'
  463. current_time = datetime.now()
  464. formatted_time = current_time.strftime("%Y-%m-%d %H:%M:%S")
  465. if platform == "常规":
  466. third_chars = [j[2] for j in video_files]
  467. data = ",".join(third_chars)
  468. user_id = user
  469. else:
  470. user_id = video_id
  471. data = ''
  472. values = [[mark, str(uid), str(user_id), data, title, new_video_id, formatted_time]]
  473. Feishu.insert_columns("LAn9so7E0hxRYht2UMEcK5wpnMj", sheet, "ROWS", 1, 2)
  474. random_wait_time = random.uniform(0.5, 2.5)
  475. time.sleep(random_wait_time)
  476. Feishu.update_values("LAn9so7E0hxRYht2UMEcK5wpnMj", sheet, "A2:Z2", values)
  477. if srt_new:
  478. current_time = datetime.now()
  479. formatted_time = current_time.strftime("%Y-%m-%d %H:%M:%S")
  480. values = [[mark, str(uid), srt_new, formatted_time]]
  481. random_wait_time = random.uniform(0.5, 2.5)
  482. time.sleep(random_wait_time)
  483. Feishu.insert_columns("IbVVsKCpbhxhSJtwYOUc8S1jnWb", "jd9qD9", "ROWS", 1, 2)
  484. time.sleep(random_wait_time)
  485. Feishu.update_values("IbVVsKCpbhxhSJtwYOUc8S1jnWb", "jd9qD9", "A2:Z2", values)
  486. except Exception as e:
  487. error_count += 1
  488. Common.logger("video").warning(f"{mark}的视频拼接失败:{e}\n")
  489. # 清空所有mp4数据
  490. cls.clear_mp4_files(mark)
  491. continue
  492. Feishu.bot('recommend', 'AGC完成通知', f'今日{platform}任务拼接任务完成,共{count}条', name, mark_name)