重构douyin上传,增加douyin图文
修复douyin视频封面上传
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
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()
|
||||
@@ -1,31 +0,0 @@
|
||||
import asyncio
|
||||
from pathlib import Path
|
||||
|
||||
from conf import BASE_DIR
|
||||
from uploader.douyin_uploader.main import douyin_setup, DouYinVideo
|
||||
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" / "douyin_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(douyin_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}")
|
||||
# 暂时没有时间修复封面上传,故先隐藏掉该功能
|
||||
# if thumbnail_path.exists():
|
||||
# app = DouYinVideo(title, file, tags, publish_datetimes[index], account_file, thumbnail_path=thumbnail_path)
|
||||
# else:
|
||||
app = DouYinVideo(title, file, tags, publish_datetimes[index], account_file)
|
||||
asyncio.run(app.main(), debug=False)
|
||||
Reference in New Issue
Block a user