| 1 | """ |
| 2 | 当前主线优先使用 CLI: |
| 3 | |
| 4 | sau xiaohongshu login --account <account_name> |
| 5 | sau xiaohongshu upload-video --account <account_name> --file videos/demo.mp4 --title "示例标题" --desc "示例简介" |
| 6 | sau xiaohongshu upload-note --account <account_name> --images videos/1.png videos/2.png --title "图文标题" --note "图文正文" |
| 7 | |
| 8 | 这个脚本保留为小红书 uploader 的调试入口 / 历史直连路径。 |
| 9 | """ |
| 10 | |
| 11 | import asyncio |
| 12 | from datetime import datetime, timedelta |
| 13 | from pathlib import Path |
| 14 | |
| 15 | from conf import BASE_DIR |
| 16 | from uploader.xiaohongshu_uploader.main import XIAOHONGSHU_PUBLISH_STRATEGY_IMMEDIATE |
| 17 | from uploader.xiaohongshu_uploader.main import XIAOHONGSHU_PUBLISH_STRATEGY_SCHEDULED |
| 18 | from uploader.xiaohongshu_uploader.main import XiaoHongShuNote |
| 19 | from uploader.xiaohongshu_uploader.main import XiaoHongShuVideo |
| 20 | |
| 21 | |
| 22 | ACCOUNT_FILE = Path(BASE_DIR / "cookies" / "xiaohongshu_uploader" / "account.json") |
| 23 | |
| 24 | |
| 25 | def upload_video_to_xiaohongshu(): |
| 26 | video_file = Path(BASE_DIR) / "videos" / "demo.mp4" |
| 27 | thumbnail_path = video_file.with_suffix(".png") |
| 28 | app = XiaoHongShuVideo( |
| 29 | title="小红书视频示例", |
| 30 | file_path=str(video_file), |
| 31 | desc="你好", |
| 32 | tags=["小红书", "视频示例", "调试入口"], |
| 33 | publish_strategy=XIAOHONGSHU_PUBLISH_STRATEGY_IMMEDIATE, |
| 34 | publish_date=0, |
| 35 | account_file=str(ACCOUNT_FILE), |
| 36 | thumbnail_path=str(thumbnail_path) if thumbnail_path.exists() else None, |
| 37 | ) |
| 38 | asyncio.run(app.xiaohongshu_upload_video()) |
| 39 | |
| 40 | |
| 41 | def upload_video_to_xiaohongshu_scheduled(): |
| 42 | video_file = Path(BASE_DIR) / "videos" / "demo.mp4" |
| 43 | thumbnail_path = video_file.with_suffix(".png") |
| 44 | publish_time = (datetime.now() + timedelta(hours=3)).replace(second=0, microsecond=0) |
| 45 | app = XiaoHongShuVideo( |
| 46 | title="小红书视频定时发布示例", |
| 47 | file_path=str(video_file), |
| 48 | desc="这是一条定时发布的小红书视频示例", |
| 49 | tags=["小红书", "定时发布", "调试入口"], |
| 50 | publish_strategy=XIAOHONGSHU_PUBLISH_STRATEGY_SCHEDULED, |
| 51 | publish_date=publish_time, |
| 52 | account_file=str(ACCOUNT_FILE), |
| 53 | thumbnail_path=str(thumbnail_path) if thumbnail_path.exists() else None, |
| 54 | ) |
| 55 | asyncio.run(app.xiaohongshu_upload_video()) |
| 56 | |
| 57 | |
| 58 | def upload_note_to_xiaohongshu(): |
| 59 | image_candidates = [ |
| 60 | Path(BASE_DIR) / "videos" / "demo.png", |
| 61 | Path(BASE_DIR) / "videos" / "demo1.png", |
| 62 | Path(BASE_DIR) / "videos" / "demo2.png", |
| 63 | ] |
| 64 | image_paths = [str(path) for path in image_candidates if path.exists()] |
| 65 | app = XiaoHongShuNote( |
| 66 | image_paths=image_paths, |
| 67 | note="小红书图文内容示例 #图文调试", |
| 68 | tags=["小红书图文", "自动上传", "调试入口"], |
| 69 | publish_strategy=XIAOHONGSHU_PUBLISH_STRATEGY_IMMEDIATE, |
| 70 | publish_date=0, |
| 71 | account_file=str(ACCOUNT_FILE), |
| 72 | title="小红书图文示例", |
| 73 | ) |
| 74 | asyncio.run(app.xiaohongshu_upload_note()) |
| 75 | |
| 76 | def upload_note_to_xiaohongshu_scheduled(): |
| 77 | image_candidates = [ |
| 78 | Path(BASE_DIR) / "videos" / "demo.png", |
| 79 | Path(BASE_DIR) / "videos" / "demo1.png", |
| 80 | Path(BASE_DIR) / "videos" / "demo2.png", |
| 81 | ] |
| 82 | image_paths = [str(path) for path in image_candidates if path.exists()] |
| 83 | publish_time = (datetime.now() + timedelta(hours=3)).replace(second=0, microsecond=0) |
| 84 | app = XiaoHongShuNote( |
| 85 | image_paths=image_paths, |
| 86 | note="小红书图文内容示例 #图文调试", |
| 87 | tags=["小红书图文", "自动上传", "调试入口"], |
| 88 | publish_strategy=XIAOHONGSHU_PUBLISH_STRATEGY_SCHEDULED, |
| 89 | publish_date=publish_time, |
| 90 | account_file=str(ACCOUNT_FILE), |
| 91 | title="小红书图文示例", |
| 92 | ) |
| 93 | asyncio.run(app.xiaohongshu_upload_note()) |
| 94 | |
| 95 | |
| 96 | if __name__ == '__main__': |
| 97 | # upload_video_to_xiaohongshu() |
| 98 | # upload_video_to_xiaohongshu_scheduled() |
| 99 | # upload_note_to_xiaohongshu() |
| 100 | upload_note_to_xiaohongshu_scheduled() |
| 101 |