|
@@ -179,7 +179,7 @@ class AgcVidoe():
|
|
|
|
|
|
# 计算需要拼接的视频
|
|
|
@classmethod
|
|
|
- def concat_videos_with_subtitles(cls, videos, audio_duration, platform):
|
|
|
+ def concat_videos_with_subtitles(cls, videos, audio_duration, platform, mark):
|
|
|
# 计算视频文件列表总时长
|
|
|
total_video_duration = sum(cls.get_video_duration(video_file[3]) for video_file in videos)
|
|
|
if platform == "koubo":
|
|
@@ -194,7 +194,7 @@ class AgcVidoe():
|
|
|
else:
|
|
|
# 如果视频总时长小于音频时长,则不做拼接
|
|
|
if total_video_duration < audio_duration:
|
|
|
- Common.logger("video").info(f"时长小于等于目标时长,不做视频拼接")
|
|
|
+ Common.logger("video").info(f"{mark}的{platform}渠道时长小于等于目标时长,不做视频拼接")
|
|
|
return ""
|
|
|
# 如果视频总时长大于音频时长,则截断视频
|
|
|
trimmed_video_list = []
|
|
@@ -227,7 +227,7 @@ class AgcVidoe():
|
|
|
# 视频拼接
|
|
|
@classmethod
|
|
|
def concatenate_videos(cls, videos, audio_duration, audio_video, platform, s_path, v_path, mark, t_path):
|
|
|
- video_files = cls.concat_videos_with_subtitles(videos, audio_duration, platform)
|
|
|
+ video_files = cls.concat_videos_with_subtitles(videos, audio_duration, platform, mark)
|
|
|
if video_files == "":
|
|
|
return ""
|
|
|
print(f"{mark}的{platform}:开始拼接视频喽~~~")
|
|
@@ -288,116 +288,113 @@ class AgcVidoe():
|
|
|
|
|
|
@classmethod
|
|
|
def video_stitching(cls, ex_list):
|
|
|
- try:
|
|
|
- pq_ids = ex_list["pq_id"]
|
|
|
- pq_ids_list = pq_ids.split(',')
|
|
|
- mark_name = ex_list['mark_name']
|
|
|
-
|
|
|
- mark = ex_list["mark"]
|
|
|
- feishu_id = ex_list["feishu_id"]
|
|
|
- video_call = ex_list["video_call"]
|
|
|
- parts = video_call.split(',')
|
|
|
- result = []
|
|
|
- for part in parts:
|
|
|
- sub_parts = part.split('--')
|
|
|
- result.append(sub_parts)
|
|
|
- link = result[0][0]
|
|
|
- yhmw_all_count = result[0][1]
|
|
|
- if int(yhmw_all_count) == 0:
|
|
|
- yhmw_count = 0
|
|
|
- else:
|
|
|
- yhmw_count = int(int(yhmw_all_count)/2)
|
|
|
- # 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)
|
|
|
- user = random.choice(user_id)
|
|
|
- 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"SRT 文件目录创建成功")
|
|
|
- # 获取音频
|
|
|
- audio_video = cls.get_audio_url(uid, mark, mark_name)
|
|
|
- Common.logger("video").info(f"获取需要拼接的音频成功")
|
|
|
- # 获取音频秒数
|
|
|
- audio_duration = cls.get_audio_duration(audio_video)
|
|
|
- Common.logger("video").info(f"获取需要拼接的音频秒数为:{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"使用拼接视频为空")
|
|
|
- return ""
|
|
|
- if os.path.isfile(v_path):
|
|
|
- Common.logger("video").info(f"新视频生成成功")
|
|
|
- else:
|
|
|
- Common.logger("video").info(f"新视频生成失败")
|
|
|
- return ""
|
|
|
- # 随机生成视频oss_id
|
|
|
- oss_id = cls.random_id()
|
|
|
- Common.logger("video").info(f"上传到 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"拼接视频发送成功,OSS 地址:{oss_object_key}")
|
|
|
- time.sleep(10)
|
|
|
- # 已使用视频存入数据库
|
|
|
- Common.logger("video").info(f"开始已使用视频存入数据库")
|
|
|
- cls.insert_videoAudio(video_files, uid, platform, mark)
|
|
|
- Common.logger("video").info(f"完成已使用视频存入数据库")
|
|
|
- Common.logger("video").info(f"开始视频添加到对应用户")
|
|
|
- piaoquantv = cls.insert_piaoquantv(oss_object_key, title_list, pq_ids_list)
|
|
|
- if piaoquantv:
|
|
|
- Common.logger("video").info(f"视频添加到对应用户成功")
|
|
|
- if os.path.isfile(s_path):
|
|
|
- os.remove(s_path)
|
|
|
- os.remove(t_path)
|
|
|
- else:
|
|
|
- Common.logger("video").info(f"文件不存在{s_path}")
|
|
|
- if os.path.isfile(v_path):
|
|
|
- os.remove(v_path)
|
|
|
- else:
|
|
|
- Common.logger("video").info(f"文件不存在{v_path}")
|
|
|
- for video in videos:
|
|
|
- filename = video[2].split("/")[-1]
|
|
|
- os.remove(f'{video_path}{filename}.mp4')
|
|
|
- Common.logger("video").info(f"{mark}的临时文件删除成功")
|
|
|
+
|
|
|
+ pq_ids = ex_list["pq_id"]
|
|
|
+ pq_ids_list = pq_ids.split(',')
|
|
|
+ mark_name = ex_list['mark_name']
|
|
|
+
|
|
|
+ mark = ex_list["mark"]
|
|
|
+ feishu_id = ex_list["feishu_id"]
|
|
|
+ video_call = ex_list["video_call"]
|
|
|
+ parts = video_call.split(',')
|
|
|
+ result = []
|
|
|
+ for part in parts:
|
|
|
+ sub_parts = part.split('--')
|
|
|
+ result.append(sub_parts)
|
|
|
+ link = result[0][0]
|
|
|
+ yhmw_all_count = result[0][1]
|
|
|
+ if int(yhmw_all_count) == 0:
|
|
|
+ yhmw_count = 0
|
|
|
+ else:
|
|
|
+ yhmw_count = int(int(yhmw_all_count)/2)
|
|
|
+ # 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)
|
|
|
+ user = random.choice(user_id)
|
|
|
+ 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 ''
|
|
|
- except Exception as e:
|
|
|
- Common.logger("video").warning(f"拼接视频失败了:{e}\n")
|
|
|
+ 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 ''
|
|
|
|
|
|
|