xiaohongshu_note_uploader/example_video.py

79 lines
2.5 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""
视频笔记发布示例
这个示例展示如何发布一篇视频笔记到小红书
"""
import asyncio
from pathlib import Path
from publisher import XiaoHongShuVideoNote
async def main():
"""发布视频笔记示例"""
print("=" * 70)
print("🎬 小红书视频笔记发布示例")
print("=" * 70)
# 配置笔记信息
title = "分享日常 vlog ✨"
content = "今天的生活记录~\n记录美好瞬间🎥"
tags = ["#vlog", "#日常", "#生活记录"]
# 视频路径
# 请替换为你自己的视频路径
video_path = "../videos/demo.mp4" # 示例视频
# Cookie文件路径
cookie_file = "cookies/account.json"
# 检查视频文件是否存在
if not Path(video_path).exists():
print(f"❌ 视频文件不存在: {video_path}")
print("💡 请将你的视频文件放到正确的位置或修改video_path路径")
return
# 创建视频笔记上传器
print(f"\n📝 标题: {title}")
print(f"🎬 视频: {video_path}")
print(f"🏷️ 标签: {', '.join(tags)}")
print(f"\n正在创建上传器...")
note = XiaoHongShuVideoNote(
title=title,
content=content,
tags=tags,
video_path=video_path,
publish_date=0, # 0表示立即发布
account_file=cookie_file,
# location="北京", # 可选:添加地理位置
headless=False # 使用有头模式,可以看到操作过程
)
print("✅ 上传器创建成功")
print("\n💡 提示:")
print(" - 如果是首次使用,会自动打开浏览器让你扫码登录")
print(" - 视频上传可能需要较长时间,请耐心等待")
print(" - 浏览器会自动完成所有操作,请勿手动干预")
print(" - 整个过程大约需要2-10分钟取决于视频大小\n")
# 执行发布
try:
await note.main()
print("\n" + "=" * 70)
print("🎉 发布成功你可以打开小红书App查看你的视频了")
print("=" * 70)
except Exception as e:
print(f"\n❌ 发布失败: {e}")
print("\n💡 故障排除:")
print(" 1. 检查网络连接")
print(" 2. 确认视频文件存在且格式正确推荐mp4")
print(" 3. 确认视频文件大小不超过平台限制")
print(" 4. 查看错误截图(如果有)")
if __name__ == "__main__":
# 运行示例
asyncio.run(main())