腾讯重构一版
This commit is contained in:
@@ -2,9 +2,10 @@ import asyncio
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from conf import BASE_DIR
|
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 = Path(BASE_DIR / "cookies" / "tencent_uploader" / "account.json")
|
||||||
account_file.parent.mkdir(exist_ok=True)
|
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))
|
||||||
|
|||||||
@@ -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
|
import asyncio
|
||||||
|
from datetime import datetime, timedelta
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from conf import BASE_DIR
|
from conf import BASE_DIR
|
||||||
from uploader.tencent_uploader.main import weixin_setup, TencentVideo
|
from uploader.tencent_uploader.main import TENCENT_PUBLISH_STRATEGY_IMMEDIATE
|
||||||
from utils.constant import TencentZoneTypes
|
from uploader.tencent_uploader.main import TENCENT_PUBLISH_STRATEGY_SCHEDULED
|
||||||
from utils.files_times import generate_schedule_time_next_day, get_title_and_hashtags
|
from uploader.tencent_uploader.main import TencentNote
|
||||||
|
from uploader.tencent_uploader.main import TencentVideo
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
ACCOUNT_FILE = Path(BASE_DIR / "cookies" / "tencent_uploader" / "account.json")
|
||||||
filepath = Path(BASE_DIR) / "videos"
|
|
||||||
account_file = Path(BASE_DIR / "cookies" / "tencent_uploader" / "account.json")
|
|
||||||
# 获取视频目录
|
def upload_video_to_tencent():
|
||||||
folder_path = Path(filepath)
|
video_file = Path(BASE_DIR) / "videos" / "demo.mp4"
|
||||||
# 获取文件夹中的所有文件
|
thumbnail_path = video_file.with_suffix(".png")
|
||||||
files = list(folder_path.glob("*.mp4"))
|
app = TencentVideo(
|
||||||
file_num = len(files)
|
title="视频号视频示例",
|
||||||
publish_datetimes = generate_schedule_time_next_day(file_num, 1, daily_times=[16])
|
file_path=str(video_file),
|
||||||
cookie_setup = asyncio.run(weixin_setup(account_file, handle=True))
|
tags=["视频号", "自动上传", "调试入口"],
|
||||||
category = TencentZoneTypes.LIFESTYLE.value # 标记原创需要否则不需要传
|
publish_strategy=TENCENT_PUBLISH_STRATEGY_IMMEDIATE,
|
||||||
for index, file in enumerate(files):
|
publish_date=0,
|
||||||
title, tags = get_title_and_hashtags(str(file))
|
account_file=str(ACCOUNT_FILE),
|
||||||
# 打印视频文件名、标题和 hashtag
|
desc="这里是你后面准备填写的视频简介示例",
|
||||||
print(f"视频文件名:{file}")
|
thumbnail_path=str(thumbnail_path) if thumbnail_path.exists() else None,
|
||||||
print(f"标题:{title}")
|
short_title="视频号示例",
|
||||||
print(f"Hashtag:{tags}")
|
category=None,
|
||||||
app = TencentVideo(title, file, tags, publish_datetimes[index], account_file, category)
|
is_draft=False,
|
||||||
asyncio.run(app.main(), debug=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()
|
||||||
|
|||||||
@@ -2,4 +2,30 @@ from pathlib import Path
|
|||||||
|
|
||||||
from conf import BASE_DIR
|
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",
|
||||||
|
]
|
||||||
|
|||||||
+809
-218
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user