43 lines
1.8 KiB
Python
43 lines
1.8 KiB
Python
|
|
# 在文件开头添加以下代码(在原导入语句之前)
|
|||
|
|
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 uploader.xiaohongshu_uploader.main import xiaohongshu_setup, XiaoHongShuVideo
|
|||
|
|
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" / "xiaohongshu_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])
|
|||
|
|
#print(publish_datetimes)
|
|||
|
|
cookie_setup = asyncio.run(xiaohongshu_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 = XiaoHongShuVideo(title, file, tags, publish_datetimes[index], account_file, thumbnail_path=thumbnail_path)
|
|||
|
|
# else:
|
|||
|
|
app = XiaoHongShuVideo(title, file, tags, publish_datetimes[index], account_file,)
|
|||
|
|
asyncio.run(app.main(), debug=False)
|