agc_video.py 25 KB

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