|
@@ -128,166 +128,167 @@ class getVideo:
|
|
|
continue
|
|
|
Common.logger("log").info(f"{task_mark}下的ID{url} 获取视频完成,共{len(data_list)}条")
|
|
|
|
|
|
- # try:
|
|
|
- for video in data_list:
|
|
|
- new_title = video['old_title'].strip().replace("\n", "") \
|
|
|
- .replace("/", "").replace("\\", "").replace("\r", "") \
|
|
|
- .replace(":", "").replace("*", "").replace("?", "") \
|
|
|
- .replace("?", "").replace('"', "").replace("<", "") \
|
|
|
- .replace(">", "").replace("|", "").replace(" ", "") \
|
|
|
- .replace("&NBSP", "").replace(".", "。").replace(" ", "") \
|
|
|
- .replace("'", "").replace("#", "").replace("Merge", "")
|
|
|
- if title == "原标题":
|
|
|
- if new_title == "" or len(new_title) == 0 or new_title == None:
|
|
|
- new_title = '🔴好漂亮的视频,给你最美的祝福❗'
|
|
|
- elif title == "AI标题":
|
|
|
- if new_title == "" or len(new_title) == 0 or new_title == None:
|
|
|
- new_title = '🔴好漂亮的视频,给你最美的祝福❗'
|
|
|
- else:
|
|
|
- new_title = GPT4o.get_ai_title(new_title)
|
|
|
- else:
|
|
|
- if '/' in title:
|
|
|
- titles = title.split('/')
|
|
|
+ try:
|
|
|
+ for video in data_list:
|
|
|
+ new_title = video['old_title'].strip().replace("\n", "") \
|
|
|
+ .replace("/", "").replace("\\", "").replace("\r", "") \
|
|
|
+ .replace(":", "").replace("*", "").replace("?", "") \
|
|
|
+ .replace("?", "").replace('"', "").replace("<", "") \
|
|
|
+ .replace(">", "").replace("|", "").replace(" ", "") \
|
|
|
+ .replace("&NBSP", "").replace(".", "。").replace(" ", "") \
|
|
|
+ .replace("'", "").replace("#", "").replace("Merge", "")
|
|
|
+ if title == "原标题":
|
|
|
+ if new_title == "" or len(new_title) == 0 or new_title == None:
|
|
|
+ new_title = '🔴好漂亮的视频,给你最美的祝福❗'
|
|
|
+ elif title == "AI标题":
|
|
|
+ if new_title == "" or len(new_title) == 0 or new_title == None:
|
|
|
+ new_title = '🔴好漂亮的视频,给你最美的祝福❗'
|
|
|
+ else:
|
|
|
+ new_title = GPT4o.get_ai_title(new_title)
|
|
|
else:
|
|
|
- titles = [title]
|
|
|
- new_title = random.choice(titles)
|
|
|
- v_id = video["video_id"]
|
|
|
- cover = video["cover"]
|
|
|
- video_url = video["video_url"]
|
|
|
- rule = video['rule']
|
|
|
- old_title = video['old_title']
|
|
|
+ if '/' in title:
|
|
|
+ titles = title.split('/')
|
|
|
+ else:
|
|
|
+ titles = [title]
|
|
|
+ new_title = random.choice(titles)
|
|
|
+ v_id = video["video_id"]
|
|
|
+ cover = video["cover"]
|
|
|
+ video_url = video["video_url"]
|
|
|
+ rule = video['rule']
|
|
|
+ old_title = video['old_title']
|
|
|
|
|
|
- time.sleep(1)
|
|
|
- pw_random_id = cls.random_id()
|
|
|
- if channel_id == "票圈":
|
|
|
- new_video_path = PQ.download_video(video_url, video_path_url, v_id) # 下载视频地址
|
|
|
- else:
|
|
|
- new_video_path = Oss.download_video_oss(video_url, video_path_url, v_id) # 下载视频地址
|
|
|
+ time.sleep(1)
|
|
|
+ pw_random_id = cls.random_id()
|
|
|
+ if channel_id == "票圈":
|
|
|
+ new_video_path = PQ.download_video(video_url, video_path_url, v_id) # 下载视频地址
|
|
|
+ else:
|
|
|
+ new_video_path = Oss.download_video_oss(video_url, video_path_url, v_id) # 下载视频地址
|
|
|
+ Common.logger("log").info(f"{task_mark}下的视频{url},{new_video_path}视频下载成功")
|
|
|
+ if not os.path.isfile(new_video_path):
|
|
|
+ Common.logger("log").info(f"{task_mark}下的视频{url},{new_video_path}视频下载失败")
|
|
|
+ cls.remove_files(video_path_url)
|
|
|
+ continue
|
|
|
Common.logger("log").info(f"{task_mark}下的视频{url},{new_video_path}视频下载成功")
|
|
|
- if not os.path.isfile(new_video_path):
|
|
|
- Common.logger("log").info(f"{task_mark}下的视频{url},{new_video_path}视频下载失败")
|
|
|
- cls.remove_files(video_path_url)
|
|
|
- continue
|
|
|
- Common.logger("log").info(f"{task_mark}下的视频{url},{new_video_path}视频下载成功")
|
|
|
- if crop_total and crop_total != 'None': # 判断是否需要裁剪
|
|
|
- new_video_path = FFmpeg.video_crop(new_video_path, video_path_url, pw_random_id)
|
|
|
- if gg_duration_total and gg_duration_total != 'None': # 判断是否需要指定视频时长
|
|
|
- new_video_path = FFmpeg.video_ggduration(new_video_path, video_path_url, pw_random_id, gg_duration_total)
|
|
|
- if video_ending and video_ending != 'None':
|
|
|
- if video_ending == "AI片尾引导":
|
|
|
- pw_srt_text = GPT4o.get_ai_pw(new_title)
|
|
|
- if pw_srt_text:
|
|
|
- pw_url = TTS.get_pw_zm(pw_srt_text)
|
|
|
- if pw_url:
|
|
|
- pw_url_sec = FFmpeg.get_videos_duration(pw_url) # 获取片尾秒数
|
|
|
- pw_srt = TTS.get_srt_format(pw_srt_text, pw_url_sec)
|
|
|
+ if crop_total and crop_total != 'None': # 判断是否需要裁剪
|
|
|
+ new_video_path = FFmpeg.video_crop(new_video_path, video_path_url, pw_random_id)
|
|
|
+ if gg_duration_total and gg_duration_total != 'None': # 判断是否需要指定视频时长
|
|
|
+ new_video_path = FFmpeg.video_ggduration(new_video_path, video_path_url, pw_random_id, gg_duration_total)
|
|
|
+ if video_ending and video_ending != 'None':
|
|
|
+ if video_ending == "AI片尾引导":
|
|
|
+ pw_srt_text = GPT4o.get_ai_pw(new_title)
|
|
|
+ if pw_srt_text:
|
|
|
+ pw_url = TTS.get_pw_zm(pw_srt_text)
|
|
|
+ Common.logger("log").info(f"{task_mark}下的视频{url},获取AI片尾音频成功")
|
|
|
+ if pw_url:
|
|
|
+ pw_url_sec = FFmpeg.get_videos_duration(pw_url) # 获取片尾秒数
|
|
|
+ pw_srt = TTS.get_srt_format(pw_srt_text, pw_url_sec)
|
|
|
+ else:
|
|
|
+ continue
|
|
|
else:
|
|
|
continue
|
|
|
else:
|
|
|
+ if ',' in video_ending:
|
|
|
+ video_ending_list = video_ending.split(',')
|
|
|
+ else:
|
|
|
+ video_ending_list = [video_ending]
|
|
|
+ ending = random.choice(video_ending_list)
|
|
|
+ pw_list = Material.get_pwsrt_data("summary", pw_sheet, ending) # 获取srt
|
|
|
+ if pw_list:
|
|
|
+ pw_id = pw_list["pw_id"]
|
|
|
+ pw_srt = pw_list["pw_srt"]
|
|
|
+ pw_url = PQ.get_pw_url(pw_id)
|
|
|
+ else:
|
|
|
+ Feishu.bot(mark, '机器自动改造消息通知', f'{task_mark}任务下片尾标示错误,请关注!!!!', name)
|
|
|
+ for attempt in range(3):
|
|
|
+ jpg_path = FFmpeg.video_png(new_video_path, video_path_url, pw_random_id) # 生成视频最后一帧jpg
|
|
|
+ if os.path.isfile(jpg_path):
|
|
|
+ Common.logger("log").info(f"{task_mark}下的视频{url},生成视频最后一帧成功")
|
|
|
+ break
|
|
|
+ time.sleep(1)
|
|
|
+ if not os.path.isfile(jpg_path):
|
|
|
+ Feishu.bot(mark, '机器自动改造消息通知', f'{task_mark}任务用户{url}下的视频{v_id},获取视频最后一帧失败,请关注', name)
|
|
|
+ cls.remove_files(video_path_url)
|
|
|
continue
|
|
|
- else:
|
|
|
- if ',' in video_ending:
|
|
|
- video_ending_list = video_ending.split(',')
|
|
|
- else:
|
|
|
- video_ending_list = [video_ending]
|
|
|
- ending = random.choice(video_ending_list)
|
|
|
- pw_list = Material.get_pwsrt_data("summary", pw_sheet, ending) # 获取srt
|
|
|
- if pw_list:
|
|
|
- pw_id = pw_list["pw_id"]
|
|
|
- pw_srt = pw_list["pw_srt"]
|
|
|
- pw_url = PQ.get_pw_url(pw_id)
|
|
|
- else:
|
|
|
- Feishu.bot(mark, '机器自动改造消息通知', f'{task_mark}任务下片尾标示错误,请关注!!!!', name)
|
|
|
- for attempt in range(3):
|
|
|
- jpg_path = FFmpeg.video_png(new_video_path, video_path_url, pw_random_id) # 生成视频最后一帧jpg
|
|
|
- if os.path.isfile(jpg_path):
|
|
|
- Common.logger("log").info(f"{task_mark}下的视频{url},生成视频最后一帧成功")
|
|
|
- break
|
|
|
- time.sleep(1)
|
|
|
- if not os.path.isfile(jpg_path):
|
|
|
- Feishu.bot(mark, '机器自动改造消息通知', f'{task_mark}任务用户{url}下的视频{v_id},获取视频最后一帧失败,请关注', name)
|
|
|
- cls.remove_files(video_path_url)
|
|
|
- continue
|
|
|
- for attempt in range(3):
|
|
|
- pw_mp3_path = FFmpeg.get_video_mp3(pw_url, video_path_url, pw_random_id)
|
|
|
- Common.logger("log").info(f"{task_mark}下的视频{url},获取mp3成功")
|
|
|
- pw_path = FFmpeg.pw_video(jpg_path, video_path_url, pw_url, pw_srt, pw_random_id, pw_mp3_path) # 生成片尾视频
|
|
|
- if os.path.isfile(pw_path):
|
|
|
- Common.logger("log").info(f"{task_mark}下的视频{url},生成片尾视频成功")
|
|
|
- break
|
|
|
+ for attempt in range(3):
|
|
|
+ pw_mp3_path = FFmpeg.get_video_mp3(pw_url, video_path_url, pw_random_id)
|
|
|
+ Common.logger("log").info(f"{task_mark}下的视频{url},获取mp3成功")
|
|
|
+ pw_path = FFmpeg.pw_video(jpg_path, video_path_url, pw_url, pw_srt, pw_random_id, pw_mp3_path) # 生成片尾视频
|
|
|
+ if os.path.isfile(pw_path):
|
|
|
+ Common.logger("log").info(f"{task_mark}下的视频{url},生成片尾视频成功")
|
|
|
+ break
|
|
|
+ time.sleep(1)
|
|
|
+ if not os.path.isfile(pw_path):
|
|
|
+ Feishu.bot(mark, '机器自动改造消息通知', f'{task_mark}任务用户{url}下的视频{v_id},生成片尾视频失败,请关注',
|
|
|
+ name)
|
|
|
+ cls.remove_files(video_path_url)
|
|
|
+ continue
|
|
|
+ pw_video_list = [new_video_path, pw_path]
|
|
|
+ Common.logger("log").info(f"{task_mark}下的视频{url},视频与片尾开始拼接")
|
|
|
+ video_path = FFmpeg.concatenate_videos(pw_video_list, video_path_url) # 视频与片尾拼接到一起
|
|
|
+ Common.logger("log").info(f"{task_mark}下的视频{url},视频与片尾拼接成功")
|
|
|
time.sleep(1)
|
|
|
- if not os.path.isfile(pw_path):
|
|
|
- Feishu.bot(mark, '机器自动改造消息通知', f'{task_mark}任务用户{url}下的视频{v_id},生成片尾视频失败,请关注',
|
|
|
- name)
|
|
|
- cls.remove_files(video_path_url)
|
|
|
- continue
|
|
|
- pw_video_list = [new_video_path, pw_path]
|
|
|
- Common.logger("log").info(f"{task_mark}下的视频{url},视频与片尾开始拼接")
|
|
|
- video_path = FFmpeg.concatenate_videos(pw_video_list, video_path_url) # 视频与片尾拼接到一起
|
|
|
- Common.logger("log").info(f"{task_mark}下的视频{url},视频与片尾拼接成功")
|
|
|
- time.sleep(1)
|
|
|
- if video_share and video_share != 'None':
|
|
|
- new_video_path = FFmpeg.single_video(video_path, video_share_mark, video_path_url, zm)
|
|
|
+ if video_share and video_share != 'None':
|
|
|
+ new_video_path = FFmpeg.single_video(video_path, video_share_mark, video_path_url, zm)
|
|
|
+ else:
|
|
|
+ new_video_path = video_path
|
|
|
else:
|
|
|
- new_video_path = video_path
|
|
|
- else:
|
|
|
- if video_share and video_share != 'None':
|
|
|
- new_video_path = FFmpeg.single_video(new_video_path, video_share_mark, video_path_url, zm)
|
|
|
- time.sleep(1)
|
|
|
- oss_id = cls.random_id()
|
|
|
- Common.logger("log").info(f"{task_mark}下的视频{url},开始发送oss")
|
|
|
- oss_object_key = Oss.stitching_sync_upload_oss(new_video_path, oss_id) # 视频发送OSS
|
|
|
- status = oss_object_key.get("status")
|
|
|
- if status == 200:
|
|
|
- oss_object_key = oss_object_key.get("oss_object_key")
|
|
|
+ if video_share and video_share != 'None':
|
|
|
+ new_video_path = FFmpeg.single_video(new_video_path, video_share_mark, video_path_url, zm)
|
|
|
time.sleep(1)
|
|
|
+ oss_id = cls.random_id()
|
|
|
+ Common.logger("log").info(f"{task_mark}下的视频{url},开始发送oss")
|
|
|
+ oss_object_key = Oss.stitching_sync_upload_oss(new_video_path, oss_id) # 视频发送OSS
|
|
|
+ status = oss_object_key.get("status")
|
|
|
+ if status == 200:
|
|
|
+ oss_object_key = oss_object_key.get("oss_object_key")
|
|
|
+ time.sleep(1)
|
|
|
|
|
|
- code = PQ.insert_piaoquantv(oss_object_key, new_title, cover, piaoquan_id)
|
|
|
- if code:
|
|
|
- Common.logger("log").info(f"{task_mark}下的视频ID{v_id}发送成功")
|
|
|
- sqlCollect.insert_task(task_mark, v_id, mark, channel_id) # 插入数据库
|
|
|
- current_time = datetime.now()
|
|
|
- formatted_time = current_time.strftime("%Y-%m-%d %H:%M:%S")
|
|
|
- sqlCollect.insert_machine_making_data(name, task_mark, channel_id, url, v_id, piaoquan_id, new_title, code, formatted_time, old_title)
|
|
|
- if title == "原标题" or title == "AI标题":
|
|
|
- values = [[name, task_mark, channel_id, url, str(v_id), piaoquan_id, old_title, title,new_title, str(code), formatted_time, str(rule)]]
|
|
|
- else:
|
|
|
- values = [[name, task_mark, channel_id, url, str(v_id), piaoquan_id, old_title, "",new_title, str(code), formatted_time, str(rule)]]
|
|
|
- # 使用锁保护表格插入操作
|
|
|
- with lock:
|
|
|
- if name == "王雪珂":
|
|
|
- sheet = "vfhHwj"
|
|
|
- elif name == "王雪珂-1":
|
|
|
- sheet = "61kvW7"
|
|
|
- elif name == "鲁涛":
|
|
|
- sheet = "FhewlS"
|
|
|
- elif name == "范军":
|
|
|
- sheet = "B6dCfS"
|
|
|
- elif name == "余海涛":
|
|
|
- sheet = "mfBrNT"
|
|
|
- elif name == "罗情":
|
|
|
- sheet = "2J3PwN"
|
|
|
- elif name == "王玉婷":
|
|
|
- sheet = "bBHFwC"
|
|
|
- elif name == "刘诗雨":
|
|
|
- sheet = "fBdxIQ"
|
|
|
- elif name == "信欣":
|
|
|
- sheet = "lPe1eT"
|
|
|
- elif name == "快手创作者版品类推荐流":
|
|
|
- sheet = "k7l7nQ"
|
|
|
- elif name == "抖音品类账号":
|
|
|
- sheet = "Bsg5UR"
|
|
|
- Feishu.insert_columns("ILb4sa0LahddRktnRipcu2vQnLb", sheet, "ROWS", 1, 2)
|
|
|
- time.sleep(0.5)
|
|
|
- Feishu.update_values("ILb4sa0LahddRktnRipcu2vQnLb", sheet, "A2:Z2", values)
|
|
|
- cls.remove_files(video_path_url)
|
|
|
- else:
|
|
|
- cls.remove_files(video_path_url)
|
|
|
- Common.logger("log").info(f"{task_mark}下的{url}视频{v_id} 视频发送OSS失败 ")
|
|
|
- Feishu.bot(mark, '机器自动改造消息通知', f'{task_mark}任务改造完成,请关注', name)
|
|
|
- # except Exception as e:
|
|
|
- # cls.remove_files(video_path_url)
|
|
|
- # Common.logger("warning").warning(f"{name}的{task_mark}任务处理失败:{e}\n")
|
|
|
+ code = PQ.insert_piaoquantv(oss_object_key, new_title, cover, piaoquan_id)
|
|
|
+ if code:
|
|
|
+ Common.logger("log").info(f"{task_mark}下的视频ID{v_id}发送成功")
|
|
|
+ sqlCollect.insert_task(task_mark, v_id, mark, channel_id) # 插入数据库
|
|
|
+ current_time = datetime.now()
|
|
|
+ formatted_time = current_time.strftime("%Y-%m-%d %H:%M:%S")
|
|
|
+ sqlCollect.insert_machine_making_data(name, task_mark, channel_id, url, v_id, piaoquan_id, new_title, code, formatted_time, old_title)
|
|
|
+ if title == "原标题" or title == "AI标题":
|
|
|
+ values = [[name, task_mark, channel_id, url, str(v_id), piaoquan_id, old_title, title,new_title, str(code), formatted_time, str(rule)]]
|
|
|
+ else:
|
|
|
+ values = [[name, task_mark, channel_id, url, str(v_id), piaoquan_id, old_title, "",new_title, str(code), formatted_time, str(rule)]]
|
|
|
+ # 使用锁保护表格插入操作
|
|
|
+ with lock:
|
|
|
+ if name == "王雪珂":
|
|
|
+ sheet = "vfhHwj"
|
|
|
+ elif name == "王雪珂-1":
|
|
|
+ sheet = "61kvW7"
|
|
|
+ elif name == "鲁涛":
|
|
|
+ sheet = "FhewlS"
|
|
|
+ elif name == "范军":
|
|
|
+ sheet = "B6dCfS"
|
|
|
+ elif name == "余海涛":
|
|
|
+ sheet = "mfBrNT"
|
|
|
+ elif name == "罗情":
|
|
|
+ sheet = "2J3PwN"
|
|
|
+ elif name == "王玉婷":
|
|
|
+ sheet = "bBHFwC"
|
|
|
+ elif name == "刘诗雨":
|
|
|
+ sheet = "fBdxIQ"
|
|
|
+ elif name == "信欣":
|
|
|
+ sheet = "lPe1eT"
|
|
|
+ elif name == "快手创作者版品类推荐流":
|
|
|
+ sheet = "k7l7nQ"
|
|
|
+ elif name == "抖音品类账号":
|
|
|
+ sheet = "Bsg5UR"
|
|
|
+ Feishu.insert_columns("ILb4sa0LahddRktnRipcu2vQnLb", sheet, "ROWS", 1, 2)
|
|
|
+ time.sleep(0.5)
|
|
|
+ Feishu.update_values("ILb4sa0LahddRktnRipcu2vQnLb", sheet, "A2:Z2", values)
|
|
|
+ cls.remove_files(video_path_url)
|
|
|
+ else:
|
|
|
+ cls.remove_files(video_path_url)
|
|
|
+ Common.logger("log").info(f"{task_mark}下的{url}视频{v_id} 视频发送OSS失败 ")
|
|
|
+ Feishu.bot(mark, '机器自动改造消息通知', f'{task_mark}任务改造完成,请关注', name)
|
|
|
+ except Exception as e:
|
|
|
+ cls.remove_files(video_path_url)
|
|
|
+ Common.logger("warning").warning(f"{name}的{task_mark}任务处理失败:{e}\n")
|
|
|
|
|
|
batch_size = 1
|
|
|
with concurrent.futures.ThreadPoolExecutor(max_workers=batch_size) as executor:
|