| 1 | import asyncio |
| 2 | from pathlib import Path |
| 3 | |
| 4 | from conf import BASE_DIR |
| 5 | from uploader.baijiahao_uploader.main import baijiahao_setup, BaiJiaHaoVideo |
| 6 | from utils.files_times import generate_schedule_time_next_day, get_title_and_hashtags |
| 7 | |
| 8 | |
| 9 | if __name__ == '__main__': |
| 10 | filepath = Path(BASE_DIR) / "videos" |
| 11 | account_file = Path(BASE_DIR / "cookies" / "baijiahao_uploader" / "account.json") |
| 12 | # 获取视频目录 |
| 13 | folder_path = Path(filepath) |
| 14 | # 获取文件夹中的所有文件 |
| 15 | files = list(folder_path.glob("*.mp4")) |
| 16 | file_num = len(files) |
| 17 | publish_datetimes = generate_schedule_time_next_day(file_num, 1, daily_times=[16]) |
| 18 | cookie_setup = asyncio.run(baijiahao_setup(account_file, handle=False)) |
| 19 | for index, file in enumerate(files): |
| 20 | title, tags = get_title_and_hashtags(str(file)) |
| 21 | thumbnail_path = file.with_suffix('.png') |
| 22 | # 打印视频文件名、标题和 hashtag |
| 23 | print(f"视频文件名:{file}") |
| 24 | print(f"标题:{title}") |
| 25 | print(f"Hashtag:{tags}") |
| 26 | app = BaiJiaHaoVideo(title, file, tags, publish_datetimes[index], account_file) |
| 27 | asyncio.run(app.main(), debug=False) |
| 28 |