autoUpload/examples/upload_video_to_tiktok.py
2025-09-08 09:32:45 +08:00

42 lines
1.8 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 在文件开头添加以下代码(在原导入语句之前)
import sys
import os
# 获取当前脚本所在目录
current_dir = os.path.dirname(os.path.abspath(__file__))
# 项目根目录是当前目录的上一级因为examples目录和conf.py同级
project_root = os.path.dirname(current_dir)
# 将项目根目录添加到系统路径
sys.path.append(project_root)
import asyncio
from pathlib import Path
from conf import BASE_DIR
# from tk_uploader.main import tiktok_setup, TiktokVideo
#from uploader.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)