Track bundled vendor runtime sources
This commit is contained in:
0
vendor/social-auto-upload/examples/__init__.py
vendored
Normal file
0
vendor/social-auto-upload/examples/__init__.py
vendored
Normal file
10
vendor/social-auto-upload/examples/get_baijiahao_cookie.py
vendored
Normal file
10
vendor/social-auto-upload/examples/get_baijiahao_cookie.py
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
import asyncio
|
||||
from pathlib import Path
|
||||
|
||||
from conf import BASE_DIR
|
||||
from uploader.baijiahao_uploader.main import baijiahao_setup
|
||||
|
||||
if __name__ == '__main__':
|
||||
account_file = Path(BASE_DIR / "cookies" / "baijiahao_uploader" / "account.json")
|
||||
account_file.parent.mkdir(exist_ok=True)
|
||||
cookie_setup = asyncio.run(baijiahao_setup(str(account_file), handle=True))
|
||||
24
vendor/social-auto-upload/examples/get_bilibili_cookie.py
vendored
Normal file
24
vendor/social-auto-upload/examples/get_bilibili_cookie.py
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
from conf import BASE_DIR
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# 建议直接在本地真实终端里运行这个脚本。
|
||||
# 如果终端里的二维码显示不完整,可以打开当前目录下的 qrcode.png 扫码。
|
||||
cli_path = Path(BASE_DIR) / "sau_cli.py"
|
||||
subprocess.run(
|
||||
[
|
||||
sys.executable,
|
||||
str(cli_path),
|
||||
"bilibili",
|
||||
"login",
|
||||
"--account",
|
||||
"creator",
|
||||
],
|
||||
check=True,
|
||||
)
|
||||
10
vendor/social-auto-upload/examples/get_douyin_cookie.py
vendored
Normal file
10
vendor/social-auto-upload/examples/get_douyin_cookie.py
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
import asyncio
|
||||
from pathlib import Path
|
||||
|
||||
from conf import BASE_DIR
|
||||
from uploader.douyin_uploader.main import douyin_setup
|
||||
|
||||
if __name__ == '__main__':
|
||||
account_file = Path(BASE_DIR / "cookies" / "douyin_uploader" / "account.json")
|
||||
account_file.parent.mkdir(exist_ok=True)
|
||||
cookie_setup = asyncio.run(douyin_setup(str(account_file), handle=True))
|
||||
21
vendor/social-auto-upload/examples/get_kuaishou_cookie.py
vendored
Normal file
21
vendor/social-auto-upload/examples/get_kuaishou_cookie.py
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
"""Legacy direct login helper for Kuaishou.
|
||||
|
||||
Current mainline usage prefers:
|
||||
sau kuaishou login --account creator
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
from pathlib import Path
|
||||
|
||||
from conf import BASE_DIR
|
||||
from uploader.ks_uploader.main import ks_setup
|
||||
|
||||
|
||||
def login_to_kuaishou():
|
||||
account_file = Path(BASE_DIR / "cookies" / "kuaishou_creator.json")
|
||||
account_file.parent.mkdir(exist_ok=True)
|
||||
asyncio.run(ks_setup(str(account_file), handle=True))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
login_to_kuaishou()
|
||||
11
vendor/social-auto-upload/examples/get_tencent_cookie.py
vendored
Normal file
11
vendor/social-auto-upload/examples/get_tencent_cookie.py
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
import asyncio
|
||||
from pathlib import Path
|
||||
|
||||
from conf import BASE_DIR
|
||||
from uploader.tencent_uploader.main import tencent_setup
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
account_file = Path(BASE_DIR / "cookies" / "tencent_uploader" / "account.json")
|
||||
account_file.parent.mkdir(exist_ok=True)
|
||||
asyncio.run(tencent_setup(str(account_file), handle=True))
|
||||
10
vendor/social-auto-upload/examples/get_tk_cookie.py
vendored
Normal file
10
vendor/social-auto-upload/examples/get_tk_cookie.py
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
import asyncio
|
||||
from pathlib import Path
|
||||
|
||||
from conf import BASE_DIR
|
||||
from uploader.tk_uploader.main_chrome import tiktok_setup
|
||||
|
||||
if __name__ == '__main__':
|
||||
account_file = Path(BASE_DIR / "cookies" / "tk_uploader" / "account.json")
|
||||
account_file.parent.mkdir(exist_ok=True)
|
||||
cookie_setup = asyncio.run(tiktok_setup(str(account_file), handle=True))
|
||||
24
vendor/social-auto-upload/examples/get_xiaohongshu_cookie.py
vendored
Normal file
24
vendor/social-auto-upload/examples/get_xiaohongshu_cookie.py
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
"""
|
||||
当前主线优先使用 CLI:
|
||||
|
||||
sau xiaohongshu login --account <account_name>
|
||||
|
||||
这个脚本保留为小红书 uploader 的调试入口 / 历史直连路径。
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
from pathlib import Path
|
||||
|
||||
from conf import BASE_DIR
|
||||
from uploader.xiaohongshu_uploader.main import xiaohongshu_setup
|
||||
|
||||
if __name__ == '__main__':
|
||||
account_file = Path(BASE_DIR / "cookies" / "xiaohongshu_uploader" / "account.json")
|
||||
account_file.parent.mkdir(exist_ok=True)
|
||||
result = asyncio.run(
|
||||
xiaohongshu_setup(
|
||||
str(account_file),
|
||||
handle=True,
|
||||
return_detail=True,
|
||||
)
|
||||
)
|
||||
64
vendor/social-auto-upload/examples/upload_to_douyin.py
vendored
Normal file
64
vendor/social-auto-upload/examples/upload_to_douyin.py
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
"""Legacy direct-uploader example for Douyin.
|
||||
|
||||
Current mainline usage prefers:
|
||||
sau douyin login --account creator
|
||||
sau douyin upload-video ...
|
||||
sau douyin upload-note ...
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
|
||||
from conf import BASE_DIR
|
||||
from uploader.douyin_uploader.main import (
|
||||
DOUYIN_PUBLISH_STRATEGY_IMMEDIATE,
|
||||
DOUYIN_PUBLISH_STRATEGY_SCHEDULED,
|
||||
DouYinNote,
|
||||
DouYinVideo,
|
||||
)
|
||||
|
||||
|
||||
def upload_video_to_douyin():
|
||||
account_file = Path(BASE_DIR / "cookies" / "douyin_uploader" / "account.json")
|
||||
video_file_path = Path(BASE_DIR) / "videos/demo.mp4"
|
||||
video_meta_title = "男子为了心爱之人每天坚守❤️🩹"
|
||||
video_meta_hashtags = ["坚持不懈", "爱情执着", "奋斗使者", "短视频"]
|
||||
thumbnail_landscape_path = Path(BASE_DIR) / "videos/demo.png"
|
||||
thumbnail_portrait_path = Path(BASE_DIR) / "videos/demo.png"
|
||||
video_meta_publish_time = datetime.strptime("2026-3-25 12:13", "%Y-%m-%d %H:%M")
|
||||
|
||||
app = DouYinVideo(
|
||||
title=video_meta_title,
|
||||
file_path=video_file_path,
|
||||
tags=video_meta_hashtags,
|
||||
publish_date=video_meta_publish_time,
|
||||
thumbnail_landscape_path=thumbnail_landscape_path,
|
||||
thumbnail_portrait_path=thumbnail_portrait_path,
|
||||
account_file=account_file,
|
||||
publish_strategy=DOUYIN_PUBLISH_STRATEGY_SCHEDULED,
|
||||
)
|
||||
asyncio.run(app.douyin_upload_video())
|
||||
|
||||
|
||||
def upload_note_to_douyin():
|
||||
account_file = Path(BASE_DIR / "cookies" / "douyin_uploader" / "account.json")
|
||||
image_paths = [Path(BASE_DIR) / "videos/demo.png", Path(BASE_DIR) / "videos/demo.png", Path(BASE_DIR) / "videos/demo.png"]
|
||||
note = "图文内容示例"
|
||||
tags = ["图文", "示例", "抖音图文"]
|
||||
video_meta_publish_time = datetime.strptime("2026-3-25 12:13", "%Y-%m-%d %H:%M")
|
||||
|
||||
app = DouYinNote(
|
||||
image_paths=image_paths,
|
||||
note=note,
|
||||
tags=tags,
|
||||
publish_date=0,
|
||||
account_file=account_file,
|
||||
publish_strategy=DOUYIN_PUBLISH_STRATEGY_IMMEDIATE,
|
||||
)
|
||||
asyncio.run(app.douyin_upload_note())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# upload_video_to_douyin()
|
||||
upload_note_to_douyin()
|
||||
72
vendor/social-auto-upload/examples/upload_to_kuaishou.py
vendored
Normal file
72
vendor/social-auto-upload/examples/upload_to_kuaishou.py
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
"""Legacy direct-uploader example for Kuaishou.
|
||||
|
||||
Current mainline usage prefers:
|
||||
sau kuaishou login --account creator
|
||||
sau kuaishou upload-video ...
|
||||
sau kuaishou upload-note ...
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
|
||||
from conf import BASE_DIR
|
||||
from uploader.ks_uploader.main import (
|
||||
KUAISHOU_PUBLISH_STRATEGY_IMMEDIATE,
|
||||
KUAISHOU_PUBLISH_STRATEGY_SCHEDULED,
|
||||
KSNote,
|
||||
KSVideo,
|
||||
)
|
||||
|
||||
|
||||
def upload_video_to_kuaishou():
|
||||
account_file = Path(BASE_DIR / "cookies" / "kuaishou_creator.json")
|
||||
account_file.parent.mkdir(exist_ok=True)
|
||||
|
||||
video_file_path = Path(BASE_DIR) / "videos/demo.mp4"
|
||||
thumbnail_path = video_file_path.with_suffix(".png")
|
||||
video_meta_title = "快手视频上传示例"
|
||||
video_meta_hashtags = ["快手", "自动上传", "示例"]
|
||||
video_meta_publish_time = datetime.strptime("2026-03-27 12:13", "%Y-%m-%d %H:%M")
|
||||
publish_strategy = KUAISHOU_PUBLISH_STRATEGY_SCHEDULED
|
||||
|
||||
app = KSVideo(
|
||||
title=video_meta_title,
|
||||
file_path=video_file_path,
|
||||
tags=video_meta_hashtags,
|
||||
publish_date=video_meta_publish_time,
|
||||
account_file=account_file,
|
||||
thumbnail_path=thumbnail_path if thumbnail_path.exists() else None,
|
||||
publish_strategy=publish_strategy,
|
||||
)
|
||||
asyncio.run(app.main())
|
||||
|
||||
|
||||
def upload_note_to_kuaishou():
|
||||
account_file = Path(BASE_DIR / "cookies" / "kuaishou_creator.json")
|
||||
account_file.parent.mkdir(exist_ok=True)
|
||||
|
||||
image_paths = [
|
||||
Path(BASE_DIR) / "videos/demo.png",
|
||||
Path(BASE_DIR) / "videos/demo1.png",
|
||||
Path(BASE_DIR) / "videos/demo2.png",
|
||||
]
|
||||
note = "快手图文内容示例"
|
||||
tags = ["快手图文", "自动上传", "示例"]
|
||||
note_meta_publish_time = datetime.strptime("2026-03-27 12:13", "%Y-%m-%d %H:%M")
|
||||
publish_strategy = KUAISHOU_PUBLISH_STRATEGY_SCHEDULED
|
||||
|
||||
app = KSNote(
|
||||
image_paths=image_paths,
|
||||
note=note,
|
||||
tags=tags,
|
||||
publish_date=note_meta_publish_time,
|
||||
account_file=account_file,
|
||||
publish_strategy=publish_strategy,
|
||||
)
|
||||
asyncio.run(app.main())
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
upload_video_to_kuaishou()
|
||||
# upload_note_to_kuaishou()
|
||||
27
vendor/social-auto-upload/examples/upload_video_to_baijiahao.py
vendored
Normal file
27
vendor/social-auto-upload/examples/upload_video_to_baijiahao.py
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
import asyncio
|
||||
from pathlib import Path
|
||||
|
||||
from conf import BASE_DIR
|
||||
from uploader.baijiahao_uploader.main import baijiahao_setup, BaiJiaHaoVideo
|
||||
from utils.files_times import generate_schedule_time_next_day, get_title_and_hashtags
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
filepath = Path(BASE_DIR) / "videos"
|
||||
account_file = Path(BASE_DIR / "cookies" / "baijiahao_uploader" / "account.json")
|
||||
# 获取视频目录
|
||||
folder_path = Path(filepath)
|
||||
# 获取文件夹中的所有文件
|
||||
files = list(folder_path.glob("*.mp4"))
|
||||
file_num = len(files)
|
||||
publish_datetimes = generate_schedule_time_next_day(file_num, 1, daily_times=[16])
|
||||
cookie_setup = asyncio.run(baijiahao_setup(account_file, handle=False))
|
||||
for index, file in enumerate(files):
|
||||
title, tags = get_title_and_hashtags(str(file))
|
||||
thumbnail_path = file.with_suffix('.png')
|
||||
# 打印视频文件名、标题和 hashtag
|
||||
print(f"视频文件名:{file}")
|
||||
print(f"标题:{title}")
|
||||
print(f"Hashtag:{tags}")
|
||||
app = BaiJiaHaoVideo(title, file, tags, publish_datetimes[index], account_file)
|
||||
asyncio.run(app.main(), debug=False)
|
||||
44
vendor/social-auto-upload/examples/upload_video_to_bilibili.py
vendored
Normal file
44
vendor/social-auto-upload/examples/upload_video_to_bilibili.py
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
from conf import BASE_DIR
|
||||
from utils.constant import VideoZoneTypes
|
||||
from utils.files_times import generate_schedule_time_next_day, get_title_and_hashtags
|
||||
|
||||
if __name__ == '__main__':
|
||||
filepath = Path(BASE_DIR) / "videos"
|
||||
folder_path = Path(filepath)
|
||||
files = list(folder_path.glob("*.mp4"))
|
||||
file_num = len(files)
|
||||
publish_datetimes = generate_schedule_time_next_day(file_num, 1, daily_times=[16])
|
||||
cli_path = Path(BASE_DIR) / "sau_cli.py"
|
||||
|
||||
for index, file in enumerate(files):
|
||||
title, tags = get_title_and_hashtags(str(file))
|
||||
print(f"视频文件名:{file}")
|
||||
print(f"标题:{title}")
|
||||
print(f"Hashtag:{tags}")
|
||||
desc = title
|
||||
schedule_text = publish_datetimes[index].strftime("%Y-%m-%d %H:%M")
|
||||
command = [
|
||||
sys.executable,
|
||||
str(cli_path),
|
||||
"bilibili",
|
||||
"upload-video",
|
||||
"--account",
|
||||
"creator",
|
||||
"--file",
|
||||
str(file),
|
||||
"--title",
|
||||
title,
|
||||
"--desc",
|
||||
desc,
|
||||
"--tid",
|
||||
str(VideoZoneTypes.SPORTS_FOOTBALL.value),
|
||||
"--tags",
|
||||
",".join(tags),
|
||||
"--schedule",
|
||||
schedule_text,
|
||||
]
|
||||
subprocess.run(command, check=True)
|
||||
109
vendor/social-auto-upload/examples/upload_video_to_tencent.py
vendored
Normal file
109
vendor/social-auto-upload/examples/upload_video_to_tencent.py
vendored
Normal file
@@ -0,0 +1,109 @@
|
||||
"""
|
||||
当前文件先保留为视频号 uploader 的调试入口 / 历史直连路径。
|
||||
|
||||
注意:
|
||||
1. `uploader/tencent_uploader/main.py` 里的核心页面交互逻辑目前是骨架;
|
||||
2. 你需要自己补视频里的 `fill_title_and_tags` / `wait_for_upload_complete` / `set_thumbnail` / `submit_publish` 等方法;
|
||||
3. 你需要自己补图文里的 `switch_to_note_mode` / `upload_note_images` / `fill_note_title_and_tags` / `submit_publish` 等方法;
|
||||
3. 补完后,这个 example 就可以直接作为本地调试入口继续使用。
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
from datetime import datetime, timedelta
|
||||
from pathlib import Path
|
||||
|
||||
from conf import BASE_DIR
|
||||
from uploader.tencent_uploader.main import TENCENT_PUBLISH_STRATEGY_IMMEDIATE
|
||||
from uploader.tencent_uploader.main import TENCENT_PUBLISH_STRATEGY_SCHEDULED
|
||||
from uploader.tencent_uploader.main import TencentNote
|
||||
from uploader.tencent_uploader.main import TencentVideo
|
||||
|
||||
|
||||
ACCOUNT_FILE = Path(BASE_DIR / "cookies" / "tencent_uploader" / "account.json")
|
||||
|
||||
|
||||
def upload_video_to_tencent():
|
||||
video_file = Path(BASE_DIR) / "videos" / "demo.mp4"
|
||||
thumbnail_path = video_file.with_suffix(".png")
|
||||
app = TencentVideo(
|
||||
title="视频号视频示例",
|
||||
file_path=str(video_file),
|
||||
tags=["视频号", "自动上传", "调试入口"],
|
||||
publish_strategy=TENCENT_PUBLISH_STRATEGY_IMMEDIATE,
|
||||
publish_date=0,
|
||||
account_file=str(ACCOUNT_FILE),
|
||||
desc="这里是你后面准备填写的视频简介示例",
|
||||
thumbnail_path=str(thumbnail_path) if thumbnail_path.exists() else None,
|
||||
short_title="视频号示例",
|
||||
category=None,
|
||||
is_draft=False,
|
||||
)
|
||||
asyncio.run(app.tencent_upload_video())
|
||||
|
||||
|
||||
def upload_video_to_tencent_scheduled():
|
||||
video_file = Path(BASE_DIR) / "videos" / "demo.mp4"
|
||||
thumbnail_path = video_file.with_suffix(".png")
|
||||
publish_time = (datetime.now() + timedelta(hours=3)).replace(second=0, microsecond=0)
|
||||
app = TencentVideo(
|
||||
title="视频号定时发布示例",
|
||||
file_path=str(video_file),
|
||||
tags=["视频号", "定时发布", "调试入口"],
|
||||
publish_strategy=TENCENT_PUBLISH_STRATEGY_SCHEDULED,
|
||||
publish_date=publish_time,
|
||||
account_file=str(ACCOUNT_FILE),
|
||||
desc="这里是定时发布的视频简介示例",
|
||||
thumbnail_path=str(thumbnail_path) if thumbnail_path.exists() else None,
|
||||
short_title="定时发布示例",
|
||||
category=None,
|
||||
is_draft=False,
|
||||
)
|
||||
asyncio.run(app.tencent_upload_video())
|
||||
|
||||
|
||||
def upload_note_to_tencent():
|
||||
image_candidates = [
|
||||
Path(BASE_DIR) / "videos" / "demo.png",
|
||||
Path(BASE_DIR) / "videos" / "demo1.png",
|
||||
Path(BASE_DIR) / "videos" / "demo2.png",
|
||||
]
|
||||
image_paths = [str(path) for path in image_candidates if path.exists()]
|
||||
app = TencentNote(
|
||||
image_paths=image_paths,
|
||||
note="视频号图文内容示例 #图文调试",
|
||||
tags=["视频号图文", "自动上传", "调试入口"],
|
||||
publish_strategy=TENCENT_PUBLISH_STRATEGY_IMMEDIATE,
|
||||
publish_date=0,
|
||||
account_file=str(ACCOUNT_FILE),
|
||||
title="视频号图文示例",
|
||||
is_draft=False,
|
||||
)
|
||||
asyncio.run(app.tencent_upload_note())
|
||||
|
||||
|
||||
def upload_note_to_tencent_scheduled():
|
||||
image_candidates = [
|
||||
Path(BASE_DIR) / "videos" / "demo.png",
|
||||
Path(BASE_DIR) / "videos" / "demo1.png",
|
||||
Path(BASE_DIR) / "videos" / "demo2.png",
|
||||
]
|
||||
image_paths = [str(path) for path in image_candidates if path.exists()]
|
||||
publish_time = (datetime.now() + timedelta(hours=3)).replace(second=0, microsecond=0)
|
||||
app = TencentNote(
|
||||
image_paths=image_paths,
|
||||
note="视频号图文定时发布示例 #图文调试",
|
||||
tags=["视频号图文", "定时发布", "调试入口"],
|
||||
publish_strategy=TENCENT_PUBLISH_STRATEGY_SCHEDULED,
|
||||
publish_date=publish_time,
|
||||
account_file=str(ACCOUNT_FILE),
|
||||
title="视频号图文定时示例",
|
||||
is_draft=False,
|
||||
)
|
||||
asyncio.run(app.tencent_upload_note())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
upload_video_to_tencent()
|
||||
# upload_video_to_tencent_scheduled()
|
||||
# upload_note_to_tencent()
|
||||
# upload_note_to_tencent_scheduled()
|
||||
30
vendor/social-auto-upload/examples/upload_video_to_tiktok.py
vendored
Normal file
30
vendor/social-auto-upload/examples/upload_video_to_tiktok.py
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
import asyncio
|
||||
from pathlib import Path
|
||||
|
||||
from conf import BASE_DIR
|
||||
# from tk_uploader.main import tiktok_setup, TiktokVideo
|
||||
from uploader.tk_uploader.main_chrome import tiktok_setup, TiktokVideo
|
||||
from utils.files_times import generate_schedule_time_next_day, get_title_and_hashtags
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
filepath = Path(BASE_DIR) / "videos"
|
||||
account_file = Path(BASE_DIR / "cookies" / "tk_uploader" / "account.json")
|
||||
folder_path = Path(filepath)
|
||||
# get video files from folder
|
||||
files = list(folder_path.glob("*.mp4"))
|
||||
file_num = len(files)
|
||||
publish_datetimes = generate_schedule_time_next_day(file_num, 1, daily_times=[16])
|
||||
cookie_setup = asyncio.run(tiktok_setup(account_file, handle=True))
|
||||
for index, file in enumerate(files):
|
||||
title, tags = get_title_and_hashtags(str(file))
|
||||
thumbnail_path = file.with_suffix('.png')
|
||||
print(f"video_file_name:{file}")
|
||||
print(f"video_title:{title}")
|
||||
print(f"video_hashtag:{tags}")
|
||||
if thumbnail_path.exists():
|
||||
print(f"thumbnail_file_name:{thumbnail_path}")
|
||||
app = TiktokVideo(title, file, tags, publish_datetimes[index], account_file, thumbnail_path)
|
||||
else:
|
||||
app = TiktokVideo(title, file, tags, publish_datetimes[index], account_file)
|
||||
asyncio.run(app.main(), debug=False)
|
||||
68
vendor/social-auto-upload/examples/upload_video_to_xhs.py
vendored
Normal file
68
vendor/social-auto-upload/examples/upload_video_to_xhs.py
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
import configparser
|
||||
from pathlib import Path
|
||||
from time import sleep
|
||||
|
||||
from xhs import XhsClient
|
||||
|
||||
from conf import BASE_DIR
|
||||
from utils.files_times import generate_schedule_time_next_day, get_title_and_hashtags
|
||||
from uploader.xhs_uploader.main import sign_local, beauty_print
|
||||
|
||||
config = configparser.RawConfigParser()
|
||||
config.read(Path(BASE_DIR / "uploader" / "xhs_uploader" / "accounts.ini"))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
filepath = Path(BASE_DIR) / "videos"
|
||||
# 获取视频目录
|
||||
folder_path = Path(filepath)
|
||||
# 获取文件夹中的所有文件
|
||||
files = list(folder_path.glob("*.mp4"))
|
||||
file_num = len(files)
|
||||
|
||||
cookies = config['account1']['cookies']
|
||||
xhs_client = XhsClient(cookies, sign=sign_local, timeout=60)
|
||||
# auth cookie
|
||||
# 注意:该校验cookie方式可能并没那么准确
|
||||
try:
|
||||
xhs_client.get_video_first_frame_image_id("3214")
|
||||
except:
|
||||
print("cookie 失效")
|
||||
exit()
|
||||
|
||||
publish_datetimes = generate_schedule_time_next_day(file_num, 1, daily_times=[16])
|
||||
|
||||
for index, file in enumerate(files):
|
||||
title, tags = get_title_and_hashtags(str(file))
|
||||
# 加入到标题 补充标题(xhs 可以填1000字不写白不写)
|
||||
tags_str = ' '.join(['#' + tag for tag in tags])
|
||||
hash_tags_str = ''
|
||||
hash_tags = []
|
||||
|
||||
# 打印视频文件名、标题和 hashtag
|
||||
print(f"视频文件名:{file}")
|
||||
print(f"标题:{title}")
|
||||
print(f"Hashtag:{tags}")
|
||||
|
||||
topics = []
|
||||
# 获取hashtag
|
||||
for i in tags[:3]:
|
||||
topic_official = xhs_client.get_suggest_topic(i)
|
||||
if topic_official:
|
||||
topic_official[0]['type'] = 'topic'
|
||||
topic_one = topic_official[0]
|
||||
hash_tag_name = topic_one['name']
|
||||
hash_tags.append(hash_tag_name)
|
||||
topics.append(topic_one)
|
||||
|
||||
hash_tags_str = ' ' + ' '.join(['#' + tag + '[话题]#' for tag in hash_tags])
|
||||
|
||||
note = xhs_client.create_video_note(title=title[:20], video_path=str(file),
|
||||
desc=title + tags_str + hash_tags_str,
|
||||
topics=topics,
|
||||
is_private=False,
|
||||
post_time=publish_datetimes[index].strftime("%Y-%m-%d %H:%M:%S"))
|
||||
|
||||
beauty_print(note)
|
||||
# 强制休眠30s,避免风控(必要)
|
||||
sleep(30)
|
||||
100
vendor/social-auto-upload/examples/upload_video_to_xiaohongshu.py
vendored
Normal file
100
vendor/social-auto-upload/examples/upload_video_to_xiaohongshu.py
vendored
Normal file
@@ -0,0 +1,100 @@
|
||||
"""
|
||||
当前主线优先使用 CLI:
|
||||
|
||||
sau xiaohongshu login --account <account_name>
|
||||
sau xiaohongshu upload-video --account <account_name> --file videos/demo.mp4 --title "示例标题" --desc "示例简介"
|
||||
sau xiaohongshu upload-note --account <account_name> --images videos/1.png videos/2.png --title "图文标题" --note "图文正文"
|
||||
|
||||
这个脚本保留为小红书 uploader 的调试入口 / 历史直连路径。
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
from datetime import datetime, timedelta
|
||||
from pathlib import Path
|
||||
|
||||
from conf import BASE_DIR
|
||||
from uploader.xiaohongshu_uploader.main import XIAOHONGSHU_PUBLISH_STRATEGY_IMMEDIATE
|
||||
from uploader.xiaohongshu_uploader.main import XIAOHONGSHU_PUBLISH_STRATEGY_SCHEDULED
|
||||
from uploader.xiaohongshu_uploader.main import XiaoHongShuNote
|
||||
from uploader.xiaohongshu_uploader.main import XiaoHongShuVideo
|
||||
|
||||
|
||||
ACCOUNT_FILE = Path(BASE_DIR / "cookies" / "xiaohongshu_uploader" / "account.json")
|
||||
|
||||
|
||||
def upload_video_to_xiaohongshu():
|
||||
video_file = Path(BASE_DIR) / "videos" / "demo.mp4"
|
||||
thumbnail_path = video_file.with_suffix(".png")
|
||||
app = XiaoHongShuVideo(
|
||||
title="小红书视频示例",
|
||||
file_path=str(video_file),
|
||||
desc="你好",
|
||||
tags=["小红书", "视频示例", "调试入口"],
|
||||
publish_strategy=XIAOHONGSHU_PUBLISH_STRATEGY_IMMEDIATE,
|
||||
publish_date=0,
|
||||
account_file=str(ACCOUNT_FILE),
|
||||
thumbnail_path=str(thumbnail_path) if thumbnail_path.exists() else None,
|
||||
)
|
||||
asyncio.run(app.xiaohongshu_upload_video())
|
||||
|
||||
|
||||
def upload_video_to_xiaohongshu_scheduled():
|
||||
video_file = Path(BASE_DIR) / "videos" / "demo.mp4"
|
||||
thumbnail_path = video_file.with_suffix(".png")
|
||||
publish_time = (datetime.now() + timedelta(hours=3)).replace(second=0, microsecond=0)
|
||||
app = XiaoHongShuVideo(
|
||||
title="小红书视频定时发布示例",
|
||||
file_path=str(video_file),
|
||||
desc="这是一条定时发布的小红书视频示例",
|
||||
tags=["小红书", "定时发布", "调试入口"],
|
||||
publish_strategy=XIAOHONGSHU_PUBLISH_STRATEGY_SCHEDULED,
|
||||
publish_date=publish_time,
|
||||
account_file=str(ACCOUNT_FILE),
|
||||
thumbnail_path=str(thumbnail_path) if thumbnail_path.exists() else None,
|
||||
)
|
||||
asyncio.run(app.xiaohongshu_upload_video())
|
||||
|
||||
|
||||
def upload_note_to_xiaohongshu():
|
||||
image_candidates = [
|
||||
Path(BASE_DIR) / "videos" / "demo.png",
|
||||
Path(BASE_DIR) / "videos" / "demo1.png",
|
||||
Path(BASE_DIR) / "videos" / "demo2.png",
|
||||
]
|
||||
image_paths = [str(path) for path in image_candidates if path.exists()]
|
||||
app = XiaoHongShuNote(
|
||||
image_paths=image_paths,
|
||||
note="小红书图文内容示例 #图文调试",
|
||||
tags=["小红书图文", "自动上传", "调试入口"],
|
||||
publish_strategy=XIAOHONGSHU_PUBLISH_STRATEGY_IMMEDIATE,
|
||||
publish_date=0,
|
||||
account_file=str(ACCOUNT_FILE),
|
||||
title="小红书图文示例",
|
||||
)
|
||||
asyncio.run(app.xiaohongshu_upload_note())
|
||||
|
||||
def upload_note_to_xiaohongshu_scheduled():
|
||||
image_candidates = [
|
||||
Path(BASE_DIR) / "videos" / "demo.png",
|
||||
Path(BASE_DIR) / "videos" / "demo1.png",
|
||||
Path(BASE_DIR) / "videos" / "demo2.png",
|
||||
]
|
||||
image_paths = [str(path) for path in image_candidates if path.exists()]
|
||||
publish_time = (datetime.now() + timedelta(hours=3)).replace(second=0, microsecond=0)
|
||||
app = XiaoHongShuNote(
|
||||
image_paths=image_paths,
|
||||
note="小红书图文内容示例 #图文调试",
|
||||
tags=["小红书图文", "自动上传", "调试入口"],
|
||||
publish_strategy=XIAOHONGSHU_PUBLISH_STRATEGY_SCHEDULED,
|
||||
publish_date=publish_time,
|
||||
account_file=str(ACCOUNT_FILE),
|
||||
title="小红书图文示例",
|
||||
)
|
||||
asyncio.run(app.xiaohongshu_upload_note())
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# upload_video_to_xiaohongshu()
|
||||
# upload_video_to_xiaohongshu_scheduled()
|
||||
# upload_note_to_xiaohongshu()
|
||||
upload_note_to_xiaohongshu_scheduled()
|
||||
Reference in New Issue
Block a user