腾讯重构一版

This commit is contained in:
home-dev-pookz
2026-04-22 19:04:20 +08:00
parent cccfea0232
commit ff0285c7a6
4 changed files with 943 additions and 244 deletions
+4 -3
View File
@@ -2,9 +2,10 @@ import asyncio
from pathlib import Path
from conf import BASE_DIR
from uploader.tencent_uploader.main import weixin_setup
from uploader.tencent_uploader.main import tencent_setup
if __name__ == '__main__':
if __name__ == "__main__":
account_file = Path(BASE_DIR / "cookies" / "tencent_uploader" / "account.json")
account_file.parent.mkdir(exist_ok=True)
cookie_setup = asyncio.run(weixin_setup(str(account_file), handle=True))
asyncio.run(tencent_setup(str(account_file), handle=True))
+103 -22
View File
@@ -1,28 +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 weixin_setup, TencentVideo
from utils.constant import TencentZoneTypes
from utils.files_times import generate_schedule_time_next_day, get_title_and_hashtags
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
if __name__ == '__main__':
filepath = Path(BASE_DIR) / "videos"
account_file = Path(BASE_DIR / "cookies" / "tencent_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(weixin_setup(account_file, handle=True))
category = TencentZoneTypes.LIFESTYLE.value # 标记原创需要否则不需要传
for index, file in enumerate(files):
title, tags = get_title_and_hashtags(str(file))
# 打印视频文件名、标题和 hashtag
print(f"视频文件名:{file}")
print(f"标题:{title}")
print(f"Hashtag:{tags}")
app = TencentVideo(title, file, tags, publish_datetimes[index], account_file, category)
asyncio.run(app.main(), debug=False)
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()
+27 -1
View File
@@ -2,4 +2,30 @@ from pathlib import Path
from conf import BASE_DIR
Path(BASE_DIR / "cookies" / "tencent_uploader").mkdir(exist_ok=True)
Path(BASE_DIR / "cookies" / "tencent_uploader").mkdir(exist_ok=True)
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 TencentBaseUploader
from uploader.tencent_uploader.main import TencentNote
from uploader.tencent_uploader.main import TencentVideo
from uploader.tencent_uploader.main import cookie_auth
from uploader.tencent_uploader.main import format_str_for_short_title
from uploader.tencent_uploader.main import get_tencent_cookie
from uploader.tencent_uploader.main import tencent_cookie_gen
from uploader.tencent_uploader.main import tencent_setup
from uploader.tencent_uploader.main import weixin_setup
__all__ = [
"TENCENT_PUBLISH_STRATEGY_IMMEDIATE",
"TENCENT_PUBLISH_STRATEGY_SCHEDULED",
"TencentBaseUploader",
"TencentNote",
"TencentVideo",
"cookie_auth",
"format_str_for_short_title",
"get_tencent_cookie",
"tencent_cookie_gen",
"tencent_setup",
"weixin_setup",
]
File diff suppressed because it is too large Load Diff