375 lines
16 KiB
Python
375 lines
16 KiB
Python
#!/usr/bin/env python3
|
||
"""
|
||
短视频脚本生成器 - 胡汉三千年项目
|
||
自动生成适合短视频平台的科普内容
|
||
"""
|
||
|
||
import json
|
||
import random
|
||
from datetime import datetime
|
||
|
||
class ShortVideoGenerator:
|
||
def __init__(self):
|
||
self.sound_roots = {
|
||
'K': {'meaning': '空性', 'examples': ['空', '孔', '恐', '哭'], 'color': '#FF6B6B'},
|
||
'M': {'meaning': '母性', 'examples': ['母', '妈', '妹', '妙'], 'color': '#4ECDC4'},
|
||
'Y': {'meaning': '秩序', 'examples': ['玉', '约', '仪', '义'], 'color': '#45B7D1'},
|
||
'L': {'meaning': '流动', 'examples': ['流', '路', '旅', '龙'], 'color': '#96CEB4'},
|
||
'D': {'meaning': '父权', 'examples': ['爹', '大', '帝', '德'], 'color': '#FFEAA7'}
|
||
}
|
||
|
||
self.story_templates = [
|
||
{
|
||
"title": "震惊!摩西和墨子竟是'兄弟'?",
|
||
"hook": "一个在中东,一个在中国,相隔万里却惊人相似!",
|
||
"content": "他们都姓'M'音,都主张'逃离压迫',都创立了自己的思想体系...这不是巧合,而是文明密码在起作用!",
|
||
"reveal": "原来他们都属于'逃离K文明'的同一模式!",
|
||
"conclusion": "文明密码理论告诉我们:人类各文明其实有共同的'基因'!"
|
||
},
|
||
{
|
||
"title": "北魏皇帝为什么都活不长?",
|
||
"hook": "平均年龄只有29岁!这背后隐藏着惊人的历史密码...",
|
||
"content": "北魏皇帝普遍年轻死亡,生育压力巨大,催生了生殖崇拜文化...",
|
||
"reveal": "这种文化通过政治、宗教渠道传播到日本,影响了整个东亚!",
|
||
"conclusion": "这就是文明传播的力量:一个帝国的悲剧,改变了整个地区的文化!"
|
||
},
|
||
{
|
||
"title": "Kashmir和Jerusalem有什么联系?",
|
||
"hook": "两个看似不相关的地方,地名里却藏着相同的密码!",
|
||
"content": "Kashmir的'K'音,Jerusalem的'J'音,都代表着某种文明的原型...",
|
||
"reveal": "它们都是文明冲突的焦点,因为都处在音根文明的交汇点上!",
|
||
"conclusion": "理解文明密码,就能理解为什么这些地方总是冲突不断!"
|
||
}
|
||
]
|
||
|
||
self.platform_configs = {
|
||
'douyin': {
|
||
'max_duration': 60,
|
||
'style': '快节奏、强情绪、视觉冲击',
|
||
'hashtags': ['#文明密码', '#历史揭秘', '#文化研究', '#惊人发现'],
|
||
'target_audience': '年轻用户,喜欢新奇内容'
|
||
},
|
||
'bilibili': {
|
||
'max_duration': 180,
|
||
'style': '知识性强、逻辑清晰、有深度',
|
||
'hashtags': ['#文明密码理论', '#音韵考古学', '#文化传播', '#历史研究'],
|
||
'target_audience': '知识青年,学生群体'
|
||
},
|
||
'xiaohongshu': {
|
||
'max_duration': 120,
|
||
'style': '文艺范、视觉冲击、生活方式',
|
||
'hashtags': ['#文化分享', '#历史美学', '#知识科普', '#文明对话'],
|
||
'target_audience': '文艺青年,女性用户'
|
||
}
|
||
}
|
||
|
||
def generate_script(self, topic=None, platform='douyin', style='story'):
|
||
"""生成短视频脚本"""
|
||
|
||
if topic is None:
|
||
topic = random.choice(list(self.sound_roots.keys()))
|
||
|
||
if style == 'story':
|
||
template = random.choice(self.story_templates)
|
||
else:
|
||
template = self.create_educational_template(topic)
|
||
|
||
config = self.platform_configs[platform]
|
||
|
||
script = {
|
||
'metadata': {
|
||
'topic': topic,
|
||
'platform': platform,
|
||
'style': style,
|
||
'duration': config['max_duration'],
|
||
'created_at': datetime.now().isoformat()
|
||
},
|
||
'content': self.build_script_content(template, config),
|
||
'visual_instructions': self.generate_visual_instructions(template, config),
|
||
'engagement_elements': self.add_engagement_elements(config)
|
||
}
|
||
|
||
return script
|
||
|
||
def create_educational_template(self, topic):
|
||
"""创建教育性模板"""
|
||
sound_info = self.sound_roots.get(topic, self.sound_roots['K'])
|
||
|
||
return {
|
||
"title": f"揭秘{sound_info['meaning']}文明密码:{topic}音的奥秘",
|
||
"hook": f"为什么世界上很多语言都有'{topic}'音?这不是偶然!",
|
||
"content": f"'{topic}'音代表{sound_info['meaning']},在{', '.join(sound_info['examples'][:2])}等字中都能看到...",
|
||
"reveal": f"这种音根分布全球,说明人类文明有共同的'基因密码'!",
|
||
"conclusion": "理解音根理论,就能理解为什么不同文化有这么多相似之处!"
|
||
}
|
||
|
||
def build_script_content(self, template, config):
|
||
"""构建脚本内容"""
|
||
content = []
|
||
|
||
# 标题和钩子
|
||
content.append(f"【标题】{template['title']}")
|
||
content.append(f"【开场钩子】{template['hook']}")
|
||
content.append("")
|
||
|
||
# 主要内容
|
||
content.append("【正文内容】")
|
||
content.append(template['content'])
|
||
content.append("")
|
||
|
||
# 揭秘时刻
|
||
content.append("【反转揭秘】")
|
||
content.append(template['reveal'])
|
||
content.append("")
|
||
|
||
# 结论
|
||
content.append("【总结升华】")
|
||
content.append(template['conclusion'])
|
||
content.append("")
|
||
|
||
# 平台特定元素
|
||
platform = config.get('platform', 'douyin')
|
||
if platform == 'douyin':
|
||
content.append("【抖音特效建议】")
|
||
content.append("- 开场:快速切换的历史地图动画")
|
||
content.append("- 中段:文明传播路径的动态线条")
|
||
content.append("- 结尾:音根字母飞入画面的特效")
|
||
elif platform == 'bilibili':
|
||
content.append("【B站元素建议】")
|
||
content.append("- 添加弹幕互动点")
|
||
content.append("- 插入历史纪录片片段")
|
||
content.append("- 评论区引导讨论")
|
||
elif platform == 'xiaohongshu':
|
||
content.append("【小红书风格】")
|
||
content.append("- 配图文案要文艺")
|
||
content.append("- 添加emoji表情")
|
||
content.append("- 结尾要有互动提问")
|
||
|
||
content.append("")
|
||
content.append("【标签建议】")
|
||
content.append("#文明密码 #历史揭秘 #音根理论 #文明传播 #冷知识")
|
||
|
||
return "\n".join(content)
|
||
|
||
|
||
# 根据平台调整语速和停顿
|
||
if config['platform'] == 'douyin':
|
||
pace = "快速、有冲击力"
|
||
pauses = "短暂停顿,保持节奏"
|
||
else:
|
||
pace = "适中、清晰表达"
|
||
pauses = "适当停顿,让观众思考"
|
||
|
||
content = {
|
||
'opening': {
|
||
'time': "0-3秒",
|
||
'text': template['hook'],
|
||
'delivery': f"{pace},{pauses}",
|
||
'visual': "震撼画面,快速切换"
|
||
},
|
||
'body': {
|
||
'time': "3-45秒",
|
||
'text': template['content'],
|
||
'delivery': f"{pace},重点词重读",
|
||
'visual': "图表展示,动画效果"
|
||
},
|
||
'reveal': {
|
||
'time': "45-55秒",
|
||
'text': template['reveal'],
|
||
'delivery': "神秘语气,制造悬念",
|
||
'visual': "高潮画面,音乐配合"
|
||
},
|
||
'conclusion': {
|
||
'time': "55-60秒",
|
||
'text': template['conclusion'],
|
||
'delivery': "坚定有力,引发思考",
|
||
'visual': "总结画面,品牌露出"
|
||
}
|
||
}
|
||
|
||
return content
|
||
|
||
def generate_visual_instructions(self, template, config):
|
||
"""生成视觉指导"""
|
||
platform = config.get('platform', 'douyin')
|
||
duration = config.get('duration', 60)
|
||
|
||
instructions = []
|
||
instructions.append("=== 视觉指导 ===")
|
||
instructions.append(f"平台:{platform}")
|
||
instructions.append(f"时长:{duration}秒")
|
||
instructions.append("")
|
||
|
||
if platform == 'douyin':
|
||
instructions.append("【抖音视觉风格】")
|
||
instructions.append("- 快节奏剪辑,每3-5秒一个画面切换")
|
||
instructions.append("- 使用动态地图展示文明传播路径")
|
||
instructions.append("- 添加音效增强悬疑感")
|
||
instructions.append("- 文字要大而醒目")
|
||
|
||
elif platform == 'bilibili':
|
||
instructions.append("【B站视觉风格】")
|
||
instructions.append("- 可以稍慢节奏,注重内容深度")
|
||
instructions.append("- 添加学术图表和数据可视化")
|
||
instructions.append("- 鼓励弹幕互动")
|
||
instructions.append("- 结尾引导关注和讨论")
|
||
|
||
elif platform == 'xiaohongshu':
|
||
instructions.append("【小红书视觉风格】")
|
||
instructions.append("- 文艺清新的配色")
|
||
instructions.append("- 手写风格的文字")
|
||
instructions.append("- 添加emoji和装饰元素")
|
||
instructions.append("- 营造知识分享的温暖氛围")
|
||
|
||
return "\n".join(instructions)
|
||
|
||
|
||
instructions = {
|
||
'color_scheme': "暖色调为主,营造神秘感",
|
||
'text_style': "大字体,关键词高亮",
|
||
'animation': "渐变、缩放、旋转等动态效果",
|
||
'transitions': "快节奏切换,保持视觉冲击",
|
||
'sound_effects': "神秘音乐,关键时刻音效",
|
||
'visual_elements': [
|
||
"世界地图动画",
|
||
"音根分布图",
|
||
"历史人物对比",
|
||
"文明传播路径",
|
||
"密码破译效果"
|
||
]
|
||
}
|
||
|
||
if config['platform'] == 'douyin':
|
||
instructions['special_effects'] = "抖音特效,滤镜使用"
|
||
elif config['platform'] == 'bilibili':
|
||
instructions['special_effects'] = "科普动画,数据可视化"
|
||
|
||
return instructions
|
||
|
||
def add_engagement_elements(self, config):
|
||
"""添加互动元素"""
|
||
|
||
elements = {
|
||
'call_to_action': "点赞关注,了解更多文明密码",
|
||
'interactive_questions': [
|
||
"你还知道哪些相似的历史人物?",
|
||
"你觉得这个理论有道理吗?",
|
||
"想看哪个文明的密码解析?"
|
||
],
|
||
'hashtags': config['hashtags'],
|
||
'comment_prompts': [
|
||
"评论区分享你的看法",
|
||
"@好友一起来看历史真相",
|
||
"留言告诉我你还想了解什么"
|
||
]
|
||
}
|
||
|
||
return elements
|
||
|
||
def batch_generate_scripts(self, count=5, platform='douyin'):
|
||
"""批量生成脚本"""
|
||
|
||
scripts = []
|
||
topics = list(self.sound_roots.keys())
|
||
|
||
for i in range(count):
|
||
topic = topics[i % len(topics)]
|
||
style = random.choice(['story', 'educational'])
|
||
script = self.generate_script(topic, platform, style)
|
||
scripts.append(script)
|
||
|
||
return scripts
|
||
|
||
def export_scripts(self, scripts, filename_prefix='civilization_password'):
|
||
"""导出脚本到文件"""
|
||
|
||
timestamp = datetime.now().strftime('%Y%m%d_%H%M%S')
|
||
|
||
# 导出JSON格式
|
||
json_filename = f"{filename_prefix}_scripts_{timestamp}.json"
|
||
with open(json_filename, 'w', encoding='utf-8') as f:
|
||
json.dump(scripts, f, ensure_ascii=False, indent=2)
|
||
|
||
# 导出文本格式
|
||
txt_filename = f"{filename_prefix}_scripts_{timestamp}.txt"
|
||
with open(txt_filename, 'w', encoding='utf-8') as f:
|
||
for i, script in enumerate(scripts, 1):
|
||
f.write(f"=== 脚本 {i} ===\n")
|
||
f.write(f"主题: {script['metadata']['topic']}\n")
|
||
f.write(f"平台: {script['metadata']['platform']}\n")
|
||
f.write(f"风格: {script['metadata']['style']}\n\n")
|
||
|
||
for section, content in script['content'].items():
|
||
f.write(f"【{section}】\n")
|
||
f.write(f"时间: {content['time']}\n")
|
||
f.write(f"内容: {content['text']}\n")
|
||
f.write(f"表现: {content['delivery']}\n")
|
||
f.write(f"视觉: {content['visual']}\n\n")
|
||
|
||
f.write("-" * 50 + "\n\n")
|
||
|
||
print(f"✅ 脚本已导出:")
|
||
print(f" JSON格式: {json_filename}")
|
||
print(f" 文本格式: {txt_filename}")
|
||
|
||
return json_filename, txt_filename
|
||
|
||
def create_content_calendar():
|
||
"""创建内容发布日历"""
|
||
|
||
calendar = {
|
||
"周一": "音根理论科普日 - 介绍不同音根的含义",
|
||
"周二": "历史人物对比日 - 展示相似人物的模式",
|
||
"周三": "地名密码解析日 - 分析地名的音根含义",
|
||
"周四": "文明传播路径日 - 展示文化传播过程",
|
||
"周五": "互动问答日 - 回答粉丝问题",
|
||
"周六": "深度解析日 - 详细讲解复杂理论",
|
||
"周日": "总结回顾日 - 总结一周内容"
|
||
}
|
||
|
||
return calendar
|
||
|
||
if __name__ == "__main__":
|
||
# 创建生成器
|
||
generator = ShortVideoGenerator()
|
||
|
||
# 生成示例脚本
|
||
print("=== 生成示例脚本 ===")
|
||
sample_script = generator.generate_script(platform='douyin', style='story')
|
||
print(f"主题: {sample_script['metadata']['topic']}")
|
||
print(f"平台: {sample_script['metadata']['platform']}")
|
||
print(f"风格: {sample_script['metadata']['style']}")
|
||
print("\n脚本内容:")
|
||
print(sample_script['content'])
|
||
print("\n" + "="*50)
|
||
|
||
# 生成批量内容
|
||
print("\n=== 生成批量内容 ===")
|
||
batch_scripts = generator.generate_batch_scripts(platforms=['douyin', 'bilibili'], count=2)
|
||
|
||
for i, script in enumerate(batch_scripts, 1):
|
||
print(f"\n脚本 {i}:")
|
||
print(f"主题: {script['topic']}")
|
||
print(f"平台: {script['platform']}")
|
||
print(f"风格: {script['style']}")
|
||
print("内容预览:")
|
||
# 显示内容的前几行
|
||
content_lines = script['content'].split('\n')[:5]
|
||
for line in content_lines:
|
||
print(f" {line}")
|
||
print(" ...")
|
||
|
||
# 生成内容日历
|
||
print("\n=== 内容日历 ===")
|
||
calendar = generator.generate_content_calendar(days=7)
|
||
for day, content in calendar.items():
|
||
print(f"{day}: {content}")
|
||
|
||
print(f"\n🎉 短视频脚本生成完成!")
|
||
print(f"共生成 {len(scripts)} 个脚本")
|
||
print(f"文件已保存到: {json_file} 和 {txt_file}")
|
||
print("\n💡 使用建议:")
|
||
print("1. 根据平台特点调整脚本长度和风格")
|
||
print("2. 结合热点话题增加关注度")
|
||
print("3. 定期分析数据优化内容策略")
|
||
print("4. 与粉丝互动提高参与度") |