|
@@ -8,7 +8,7 @@ import time
|
|
|
import urllib.parse
|
|
|
|
|
|
import requests
|
|
|
-from datetime import datetime
|
|
|
+from datetime import datetime, timedelta
|
|
|
|
|
|
sys.path.append(os.getcwd())
|
|
|
from common.db import MysqlHelper
|
|
@@ -23,16 +23,27 @@ class AgcVidoe():
|
|
|
|
|
|
# 获取未使用的视频链接
|
|
|
@classmethod
|
|
|
- def get_url_list(cls, user, mark, limit_count):
|
|
|
- current_time = datetime.now()
|
|
|
- formatted_time = current_time.strftime("%Y-%m-%d")
|
|
|
- url_list = f"""SELECT a.video_id,a.account_id,a.oss_object_key FROM agc_video_url a WHERE NOT EXISTS (
|
|
|
- SELECT video_id
|
|
|
- FROM agc_video_deposit b
|
|
|
- WHERE a.oss_object_key = b.oss_object_key AND b.time = '{formatted_time}'
|
|
|
- ) AND a.account_id = {user} and a.`status` = 1 and a.mark = '{mark}' limit {limit_count};"""
|
|
|
- url_list = MysqlHelper.get_values(url_list, "prod")
|
|
|
- return url_list
|
|
|
+ def get_url_list(cls, user_list, mark, limit_count):
|
|
|
+ for i in range(5):
|
|
|
+ user = random.choice(user_list)
|
|
|
+ current_time = datetime.now()
|
|
|
+ three_days_ago = current_time - timedelta(days=3)
|
|
|
+ formatted_current_time = current_time.strftime("%Y-%m-%d")
|
|
|
+ formatted_three_days_ago = three_days_ago.strftime("%Y-%m-%d")
|
|
|
+ url_list = f"""SELECT a.video_id,a.account_id,a.oss_object_key FROM agc_video_url a WHERE NOT EXISTS (
|
|
|
+ SELECT video_id
|
|
|
+ FROM agc_video_deposit b
|
|
|
+ WHERE a.oss_object_key = b.oss_object_key AND b.time >= '{formatted_three_days_ago}' AND b.time <= '{formatted_current_time}'
|
|
|
+ ) AND a.account_id = {user} and a.`status` = 1 and a.mark = '{mark}' limit {limit_count};"""
|
|
|
+
|
|
|
+ url_list = MysqlHelper.get_values(url_list, "prod")
|
|
|
+ if limit_count == 1:
|
|
|
+ if url_list:
|
|
|
+ return url_list
|
|
|
+ else:
|
|
|
+ if len(url_list) >= 30:
|
|
|
+ return url_list
|
|
|
+ return None
|
|
|
|
|
|
|
|
|
# 随机生成id
|
|
@@ -62,6 +73,42 @@ class AgcVidoe():
|
|
|
count = str(count).replace('(', '').replace(')', '').replace(',', '')
|
|
|
return int(count)
|
|
|
|
|
|
+ # 获取跟随脚本已入库数量
|
|
|
+ @classmethod
|
|
|
+ def get_link_gs_count(cls, mark):
|
|
|
+ current_time = datetime.now()
|
|
|
+ formatted_time = current_time.strftime("%Y-%m-%d")
|
|
|
+ count = f"""SELECT COUNT(*) AS total_count FROM ( SELECT audio, account_id FROM agc_video_deposit WHERE time = '{formatted_time}' and mark = '{mark}' GROUP BY audio, account_id) AS subquery;"""
|
|
|
+ count = MysqlHelper.get_values(count, "prod")
|
|
|
+ if count == None:
|
|
|
+ count = 0
|
|
|
+ count = str(count).replace('(', '').replace(')', '').replace(',', '')
|
|
|
+ return int(count)
|
|
|
+
|
|
|
+ # 获取跟随脚本站外已入库数量
|
|
|
+ @classmethod
|
|
|
+ def get_link_zw_count(cls, mark, platform):
|
|
|
+ current_time = datetime.now()
|
|
|
+ formatted_time = current_time.strftime("%Y-%m-%d")
|
|
|
+ count = f"""SELECT COUNT(*) AS total_count FROM ( SELECT audio, account_id FROM agc_video_deposit WHERE time = '{formatted_time}' AND platform != '{platform}' and mark = '{mark}' GROUP BY audio, account_id) AS subquery;"""
|
|
|
+ count = MysqlHelper.get_values(count, "prod")
|
|
|
+ if count == None:
|
|
|
+ count = 0
|
|
|
+ count = str(count).replace('(', '').replace(')', '').replace(',', '')
|
|
|
+ return int(count)
|
|
|
+
|
|
|
+ # 获取跟随脚本站内已入库数量
|
|
|
+ @classmethod
|
|
|
+ def get_link_zn_count(cls, mark, platform):
|
|
|
+ current_time = datetime.now()
|
|
|
+ formatted_time = current_time.strftime("%Y-%m-%d")
|
|
|
+ count = f"""SELECT COUNT(*) AS total_count FROM ( SELECT audio, account_id FROM agc_video_deposit WHERE time = '{formatted_time}' AND platform = '{platform}' and mark = '{mark}' GROUP BY audio, account_id) AS subquery;"""
|
|
|
+ count = MysqlHelper.get_values(count, "prod")
|
|
|
+ if count == None:
|
|
|
+ count = 0
|
|
|
+ count = str(count).replace('(', '').replace(')', '').replace(',', '')
|
|
|
+ return int(count)
|
|
|
+
|
|
|
@classmethod
|
|
|
def create_subtitle_file(cls, srt, s_path):
|
|
|
# 创建临时字幕文件
|
|
@@ -75,13 +122,12 @@ class AgcVidoe():
|
|
|
|
|
|
# 新生成视频上传到对应账号下
|
|
|
@classmethod
|
|
|
- def insert_piaoquantv(cls, oss_object_key, title_list, pq_ids_list):
|
|
|
+ def insert_piaoquantv(cls, oss_object_key, audio_title, pq_ids_list):
|
|
|
for i in range(2):
|
|
|
- title_list = [item for item in title_list if item is not None]
|
|
|
- title = random.choice(title_list)
|
|
|
+
|
|
|
url = "https://vlogapi.piaoquantv.com/longvideoapi/crawler/video/send"
|
|
|
payload = dict(pageSource='vlog-pages/post/post-video-post', videoPath=oss_object_key, width='720',
|
|
|
- height='1280', fileExtensions='mp4', viewStatus='1', title=title,
|
|
|
+ height='1280', fileExtensions='mp4', viewStatus='1', title=audio_title,
|
|
|
careModelStatus='1',
|
|
|
token='f04f58d6e664cbc9902660a1e8d20ce6cd7fdb0f', loginUid=pq_ids_list[i],
|
|
|
versionCode='719',
|
|
@@ -93,7 +139,7 @@ class AgcVidoe():
|
|
|
hotSenceType='1089', id='1050', channel='pq')
|
|
|
|
|
|
payload['videoPath'] = oss_object_key
|
|
|
- payload['title'] = title
|
|
|
+ payload['title'] = audio_title
|
|
|
data = urllib.parse.urlencode(payload)
|
|
|
headers = {
|
|
|
'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 15_6_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/8.0.44(0x18002c2d) NetType/WIFI Language/zh_CN',
|
|
@@ -102,8 +148,7 @@ class AgcVidoe():
|
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
'Cookie': 'JSESSIONID=A60D96E7A300A25EA05425B069C8B459'
|
|
|
}
|
|
|
- response = requests.post(url, data=data, headers=headers)
|
|
|
- data = response.json()
|
|
|
+ requests.post(url, data=data, headers=headers)
|
|
|
return True
|
|
|
|
|
|
# 获取视频链接
|
|
@@ -140,7 +185,8 @@ class AgcVidoe():
|
|
|
Feishu.bot('recommend', '管理后台', '管理后台cookie失效,请及时更换~', mark, mark_name)
|
|
|
return ""
|
|
|
audio_url = data["content"]["transedVideoPath"]
|
|
|
- return audio_url
|
|
|
+ audio_title = data["content"]['title']
|
|
|
+ return audio_url, audio_title
|
|
|
except Exception as e:
|
|
|
Common.logger("video").warning(f"获取音频视频链接失败:{e}\n")
|
|
|
return ""
|
|
@@ -327,6 +373,9 @@ class AgcVidoe():
|
|
|
Common.logger("video").info(f"{mark}的{platform}:视频拼接成功啦~~~")
|
|
|
return video_files
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+ # 常规任务
|
|
|
@classmethod
|
|
|
def video_stitching(cls, ex_list):
|
|
|
|
|
@@ -357,7 +406,7 @@ class AgcVidoe():
|
|
|
channel = ['douyin', 'kuaishou', 'koubo']
|
|
|
try:
|
|
|
for platform in channel:
|
|
|
- limit_count = 40
|
|
|
+ limit_count = 35
|
|
|
count = cls.get_link_count(mark, platform)
|
|
|
if platform == "douyin" and count >= yhmw_count:
|
|
|
continue
|
|
@@ -367,26 +416,18 @@ class AgcVidoe():
|
|
|
link = result[1][0]
|
|
|
limit_count = 1
|
|
|
if count >= kb_count or kb_count == 0:
|
|
|
- Feishu.bot('recommend', 'AGC完成通知', '今日自制视频拼接任务完成啦~', mark, mark_name)
|
|
|
+ Feishu.bot('recommend', 'AGC完成通知', '今日常规自制视频拼接任务完成啦~', mark, mark_name)
|
|
|
return mark
|
|
|
# 获取音频类型+字幕+标题
|
|
|
- uid, srt, title_list = Material.get_all_data(feishu_id, link, mark)
|
|
|
+ uid, srt, video_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)
|
|
|
+ url_list = cls.get_url_list(user_id, 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_url)
|
|
|
|
|
@@ -395,7 +436,7 @@ class AgcVidoe():
|
|
|
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)
|
|
|
+ audio_video, audio_title = cls.get_audio_url(uid, mark, mark_name)
|
|
|
Common.logger("video").info(f"{mark}的{platform}渠道获取需要拼接的音频成功")
|
|
|
# 获取音频秒数
|
|
|
audio_duration = cls.get_audio_duration(audio_video)
|
|
@@ -431,10 +472,117 @@ class AgcVidoe():
|
|
|
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)
|
|
|
+ piaoquantv = cls.insert_piaoquantv(oss_object_key, audio_title, pq_ids_list)
|
|
|
if piaoquantv:
|
|
|
Common.logger("video").info(f"{mark}的{platform}渠道视频添加到对应用户成功")
|
|
|
return ''
|
|
|
+ except Exception as e:
|
|
|
+ Common.logger("video").warning(f"{mark}的视频拼接失败:{e}\n")
|
|
|
+ return ''
|
|
|
+
|
|
|
+ # 脚本跟随任务
|
|
|
+ @classmethod
|
|
|
+ def video_gs_stitching(cls, ex_list):
|
|
|
+
|
|
|
+ pq_ids = ex_list["pq_id"]
|
|
|
+ pq_ids_list = pq_ids.split(',') # 账号ID
|
|
|
+ mark_name = ex_list['mark_name'] # 负责人
|
|
|
+ mark = ex_list["mark"] # 标示
|
|
|
+ feishu_id = ex_list["feishu_id"] # 飞书文档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] # 脚本链接
|
|
|
+ count = result[0][1] # 生成条数
|
|
|
+ zd_count = ex_list["zd_count"] # 生成总条数
|
|
|
+
|
|
|
+ # 总条数
|
|
|
+ all_count = cls.get_link_gs_count(mark)
|
|
|
+ if all_count >= int(zd_count):
|
|
|
+ Feishu.bot('recommend', 'AGC完成通知', '今日脚本跟随视频拼接任务完成啦~', mark, mark_name)
|
|
|
+ return mark
|
|
|
+ # 获取音频类型+字幕+标题
|
|
|
+ uid, srt, video_list = Material.get_all_data(feishu_id, link, mark)
|
|
|
+ platform_list = ex_list["platform_list"] # 渠道
|
|
|
+ # 如果没有该文件目录则创建,有文件目录的话 则删除文件
|
|
|
+ s_path, v_path, video_path_url, v_oss_path = cls.create_folders(mark)
|
|
|
+ platform = ''
|
|
|
+ if platform_list:
|
|
|
+ platform_name_list = random.choice(platform_list)
|
|
|
+ platform_name = platform_name_list[1]
|
|
|
+ platform_url = platform_name_list[0]
|
|
|
+ if platform_name == "快手":
|
|
|
+ platform = 'kuaishou'
|
|
|
+ elif platform_name == "抖音":
|
|
|
+ platform = 'douyin'
|
|
|
+ zw_count = cls.get_link_zw_count(mark, "zhannei")
|
|
|
+ if zw_count >= int(count):
|
|
|
+ return
|
|
|
+ # 获取所有视频素材ID
|
|
|
+ video_list = Material.get_user_id(feishu_id, platform_url)
|
|
|
+ limit_count = 35
|
|
|
+ else:
|
|
|
+ platform = 'zhannei'
|
|
|
+ zw_count = cls.get_link_zn_count(mark, platform)
|
|
|
+ if zw_count >= int(count):
|
|
|
+ return
|
|
|
+ limit_count = 1
|
|
|
+ url_list = cls.get_url_list(video_list, mark, limit_count)
|
|
|
+ if url_list == None:
|
|
|
+ Common.logger("video").info(f"S{mark}的{platform} 渠道 视频画面不足无法拼接")
|
|
|
+ return
|
|
|
+ videos = [list(item) for item in url_list]
|
|
|
+ try:
|
|
|
+ # 下载视频
|
|
|
+ videos = Oss.get_oss_url(videos, video_path_url)
|
|
|
+ if srt:
|
|
|
+ # 创建临时字幕文件
|
|
|
+ cls.create_subtitle_file(srt, s_path)
|
|
|
+ Common.logger("video").info(f"S{mark}的{platform}渠道RT 文件目录创建成功")
|
|
|
+ # 获取音频
|
|
|
+ audio_video, audio_title = 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, v_oss_path)
|
|
|
+ if video_files == "":
|
|
|
+ Common.logger("video").info(f"{mark}的{platform}渠道使用拼接视频为空")
|
|
|
+ return ""
|
|
|
+ if os.path.isfile(v_oss_path):
|
|
|
+ Common.logger("video").info(f"{mark}的{platform}渠道新视频生成成功")
|
|
|
+ else:
|
|
|
+ Common.logger("video").info(f"{mark}的{platform}渠道新视频生成失败")
|
|
|
+ return ""
|
|
|
+ # 随机生成视频oss_id
|
|
|
+ oss_id = cls.random_id()
|
|
|
+ # 获取新生成视频时长
|
|
|
+ v_path_duration = cls.get_audio_duration(v_oss_path)
|
|
|
+ if v_path_duration > audio_duration+3 or v_path_duration < audio_duration-3:
|
|
|
+ print(f"{mark}的{platform}渠道最终生成视频秒数错误,生成了:{v_path_duration}秒,实际秒数{audio_duration}")
|
|
|
+ Common.logger("video").info(f"{mark}的{platform}渠道最终生成视频秒数错误,生成了:{v_path_duration}秒,实际秒数{audio_duration}")
|
|
|
+ return ""
|
|
|
+ # 上传 oss
|
|
|
+ Common.logger("video").info(f"{mark}的{platform}渠道上传到 OSS 生成视频id为:{oss_id}")
|
|
|
+ oss_object_key = Oss.stitching_sync_upload_oss(v_oss_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, audio_title, pq_ids_list)
|
|
|
+ if piaoquantv:
|
|
|
+ Common.logger("video").info(f"{mark}的{platform}渠道视频添加到对应用户成功")
|
|
|
+ return ''
|
|
|
except Exception as e:
|
|
|
Common.logger("video").warning(f"{mark}的视频拼接失败:{e}\n")
|
|
|
return ''
|