|
@@ -273,7 +273,6 @@ class AgcVidoe():
|
|
|
"-map", "0:v:0", # 映射第一个输入的视频流
|
|
|
"-map", "1:a:0", # 映射第二个输入的音频流
|
|
|
"-y", # 覆盖输出文件
|
|
|
- "-loglevel", "error", # 忽略警告
|
|
|
v_path
|
|
|
]
|
|
|
# 执行 FFmpeg 命令
|
|
@@ -310,95 +309,97 @@ class AgcVidoe():
|
|
|
# kb_link = result[1][0]
|
|
|
kb_count = int(result[1][1])
|
|
|
channel = ['douyin', 'kuaishou', 'koubo']
|
|
|
- for platform in channel:
|
|
|
- limit_count = 40
|
|
|
- count = cls.get_link_count(mark, platform)
|
|
|
- if platform == "douyin" and count >= yhmw_count:
|
|
|
- continue
|
|
|
- elif platform == "kuaishou" and count >= yhmw_count:
|
|
|
- continue
|
|
|
- elif platform == "koubo":
|
|
|
- link = result[1][0]
|
|
|
- limit_count = 1
|
|
|
- if count >= kb_count or kb_count == 0:
|
|
|
- Feishu.bot('recommend', 'AGC完成通知', '今日自制视频拼接任务完成啦~', mark, mark_name)
|
|
|
- return mark
|
|
|
- # 获取音频类型+字幕+标题
|
|
|
- uid, srt, title_list = Material.get_all_data(feishu_id, link, mark)
|
|
|
- # 获取已入库的用户id
|
|
|
- user_id = cls.get_user_id(platform, mark)
|
|
|
- if user_id:
|
|
|
- user = random.choice(user_id)
|
|
|
- else:
|
|
|
- Common.logger("video").info(f"{mark}的{platform} 渠道无抓取的数据")
|
|
|
- return ""
|
|
|
- user = str(user).replace('(', '').replace(')', '').replace(',', '')
|
|
|
- Common.logger("video").info(f"{mark}的{platform}渠道获取的用户ID:{user}")
|
|
|
- # 获取 未使用的视频链接
|
|
|
- url_list = cls.get_url_list(user, mark, limit_count)
|
|
|
- if url_list == None:
|
|
|
- Common.logger("video").info(f"未使用视频链接为空:{url_list}")
|
|
|
+ try:
|
|
|
+ for platform in channel:
|
|
|
+ limit_count = 40
|
|
|
+ count = cls.get_link_count(mark, platform)
|
|
|
+ if platform == "douyin" and count >= yhmw_count:
|
|
|
+ continue
|
|
|
+ elif platform == "kuaishou" and count >= yhmw_count:
|
|
|
+ continue
|
|
|
+ elif platform == "koubo":
|
|
|
+ link = result[1][0]
|
|
|
+ limit_count = 1
|
|
|
+ if count >= kb_count or kb_count == 0:
|
|
|
+ Feishu.bot('recommend', 'AGC完成通知', '今日自制视频拼接任务完成啦~', mark, mark_name)
|
|
|
+ return mark
|
|
|
+ # 获取音频类型+字幕+标题
|
|
|
+ uid, srt, title_list = Material.get_all_data(feishu_id, link, mark)
|
|
|
+ # 获取已入库的用户id
|
|
|
+ user_id = cls.get_user_id(platform, mark)
|
|
|
+ if user_id:
|
|
|
+ user = random.choice(user_id)
|
|
|
+ else:
|
|
|
+ Common.logger("video").info(f"{mark}的{platform} 渠道无抓取的数据")
|
|
|
+ return ""
|
|
|
+ user = str(user).replace('(', '').replace(')', '').replace(',', '')
|
|
|
+ Common.logger("video").info(f"{mark}的{platform}渠道获取的用户ID:{user}")
|
|
|
+ # 获取 未使用的视频链接
|
|
|
+ url_list = cls.get_url_list(user, mark, limit_count)
|
|
|
+ if url_list == None:
|
|
|
+ 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"
|
|
|
+ if srt:
|
|
|
+ # 创建临时字幕文件
|
|
|
+ cls.create_subtitle_file(srt, s_path)
|
|
|
+ Common.logger("video").info(f"S{mark}的{platform}渠道RT 文件目录创建成功")
|
|
|
+ # 获取音频
|
|
|
+ audio_video = cls.get_audio_url(uid, mark, mark_name)
|
|
|
+ Common.logger("video").info(f"{mark}的{platform}渠道获取需要拼接的音频成功")
|
|
|
+ # 获取音频秒数
|
|
|
+ audio_duration = cls.get_audio_duration(audio_video)
|
|
|
+ Common.logger("video").info(f"{mark}的{platform}渠道获取需要拼接的音频秒数为:{audio_duration}")
|
|
|
+ video_files = cls.concatenate_videos(videos, audio_duration, audio_video, platform, s_path, v_path, mark, t_path)
|
|
|
+ if video_files == "":
|
|
|
+ Common.logger("video").info(f"{mark}的{platform}渠道使用拼接视频为空")
|
|
|
+ return ""
|
|
|
+ if os.path.isfile(v_path):
|
|
|
+ Common.logger("video").info(f"{mark}的{platform}渠道新视频生成成功")
|
|
|
+ else:
|
|
|
+ Common.logger("video").info(f"{mark}的{platform}渠道新视频生成失败")
|
|
|
+ return ""
|
|
|
+ # 随机生成视频oss_id
|
|
|
+ oss_id = cls.random_id()
|
|
|
+ Common.logger("video").info(f"{mark}的{platform}渠道上传到 OSS 生成视频id为:{oss_id}")
|
|
|
+ # 上传 oss
|
|
|
+ oss_object_key = Oss.stitching_sync_upload_oss(v_path, oss_id)
|
|
|
+ status = oss_object_key.get("status")
|
|
|
+ if status == 200:
|
|
|
+ # 获取 oss 视频地址
|
|
|
+ oss_object_key = oss_object_key.get("oss_object_key")
|
|
|
+ Common.logger("video").info(f"{mark}的{platform}渠道拼接视频发送成功,OSS 地址:{oss_object_key}")
|
|
|
+ time.sleep(10)
|
|
|
+ # 已使用视频存入数据库
|
|
|
+ Common.logger("video").info(f"{mark}的{platform}渠道开始已使用视频存入数据库")
|
|
|
+ cls.insert_videoAudio(video_files, uid, platform, mark)
|
|
|
+ Common.logger("video").info(f"{mark}的{platform}渠道完成已使用视频存入数据库")
|
|
|
+ Common.logger("video").info(f"{mark}的{platform}渠道开始视频添加到对应用户")
|
|
|
+ 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 ''
|
|
|
- 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"
|
|
|
- if srt:
|
|
|
- # 创建临时字幕文件
|
|
|
- cls.create_subtitle_file(srt, s_path)
|
|
|
- Common.logger("video").info(f"S{mark}的{platform}渠道RT 文件目录创建成功")
|
|
|
- # 获取音频
|
|
|
- audio_video = cls.get_audio_url(uid, mark, mark_name)
|
|
|
- Common.logger("video").info(f"{mark}的{platform}渠道获取需要拼接的音频成功")
|
|
|
- # 获取音频秒数
|
|
|
- audio_duration = cls.get_audio_duration(audio_video)
|
|
|
- Common.logger("video").info(f"{mark}的{platform}渠道获取需要拼接的音频秒数为:{audio_duration}")
|
|
|
- video_files = cls.concatenate_videos(videos, audio_duration, audio_video, platform, s_path, v_path, mark, t_path)
|
|
|
- if video_files == "":
|
|
|
- Common.logger("video").info(f"{mark}的{platform}渠道使用拼接视频为空")
|
|
|
- return ""
|
|
|
- if os.path.isfile(v_path):
|
|
|
- Common.logger("video").info(f"{mark}的{platform}渠道新视频生成成功")
|
|
|
- else:
|
|
|
- Common.logger("video").info(f"{mark}的{platform}渠道新视频生成失败")
|
|
|
- return ""
|
|
|
- # 随机生成视频oss_id
|
|
|
- oss_id = cls.random_id()
|
|
|
- Common.logger("video").info(f"{mark}的{platform}渠道上传到 OSS 生成视频id为:{oss_id}")
|
|
|
- # 上传 oss
|
|
|
- oss_object_key = Oss.stitching_sync_upload_oss(v_path, oss_id)
|
|
|
- status = oss_object_key.get("status")
|
|
|
- if status == 200:
|
|
|
- # 获取 oss 视频地址
|
|
|
- oss_object_key = oss_object_key.get("oss_object_key")
|
|
|
- Common.logger("video").info(f"{mark}的{platform}渠道拼接视频发送成功,OSS 地址:{oss_object_key}")
|
|
|
- time.sleep(10)
|
|
|
- # 已使用视频存入数据库
|
|
|
- Common.logger("video").info(f"{mark}的{platform}渠道开始已使用视频存入数据库")
|
|
|
- cls.insert_videoAudio(video_files, uid, platform, mark)
|
|
|
- Common.logger("video").info(f"{mark}的{platform}渠道完成已使用视频存入数据库")
|
|
|
- Common.logger("video").info(f"{mark}的{platform}渠道开始视频添加到对应用户")
|
|
|
- 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")
|
|
|
+ return ''
|