| 1 | import subprocess |
| 2 | import sys |
| 3 | from pathlib import Path |
| 4 | |
| 5 | from conf import BASE_DIR |
| 6 | from utils.constant import VideoZoneTypes |
| 7 | from utils.files_times import generate_schedule_time_next_day, get_title_and_hashtags |
| 8 | |
| 9 | if __name__ == '__main__': |
| 10 | filepath = Path(BASE_DIR) / "videos" |
| 11 | folder_path = Path(filepath) |
| 12 | files = list(folder_path.glob("*.mp4")) |
| 13 | file_num = len(files) |
| 14 | publish_datetimes = generate_schedule_time_next_day(file_num, 1, daily_times=[16]) |
| 15 | cli_path = Path(BASE_DIR) / "sau_cli.py" |
| 16 | |
| 17 | for index, file in enumerate(files): |
| 18 | title, tags = get_title_and_hashtags(str(file)) |
| 19 | print(f"视频文件名:{file}") |
| 20 | print(f"标题:{title}") |
| 21 | print(f"Hashtag:{tags}") |
| 22 | desc = title |
| 23 | schedule_text = publish_datetimes[index].strftime("%Y-%m-%d %H:%M") |
| 24 | command = [ |
| 25 | sys.executable, |
| 26 | str(cli_path), |
| 27 | "bilibili", |
| 28 | "upload-video", |
| 29 | "--account", |
| 30 | "creator", |
| 31 | "--file", |
| 32 | str(file), |
| 33 | "--title", |
| 34 | title, |
| 35 | "--desc", |
| 36 | desc, |
| 37 | "--tid", |
| 38 | str(VideoZoneTypes.SPORTS_FOOTBALL.value), |
| 39 | "--tags", |
| 40 | ",".join(tags), |
| 41 | "--schedule", |
| 42 | schedule_text, |
| 43 | ] |
| 44 | subprocess.run(command, check=True) |
| 45 |