mirror of
https://github.com/dreammis/social-auto-upload.git
synced 2026-08-28 17:43:28 +08:00
feat(wechat-channel): add draft upload functionality for video channel
- Add isDraft parameter to TencentVideo class to control publishing behavior - Modify click_publish method to click "保存草稿" instead of "发表" when isDraft is true - Update post_video_tencent function to accept and pass is_draft parameter - Add is_draft parameter to /postVideo API endpoint to receive frontend data - Add "视频号上传草稿" checkbox in frontend that appears only for video channel platform - Update defaultTabInit to include isDraft property with default value false - Include isDraft in publishData sent to backend API - Implement proper URL checking for draft vs publish success confirmation The new functionality allows users to save WeChat Channel videos as drafts instead of immediately publishing them when the checkbox is selected.
This commit is contained in:
@@ -10,7 +10,7 @@ from utils.constant import TencentZoneTypes
|
||||
from utils.files_times import generate_schedule_time_next_day
|
||||
|
||||
|
||||
def post_video_tencent(title,files,tags,account_file,category=TencentZoneTypes.LIFESTYLE.value,enableTimer=False,videos_per_day = 1, daily_times=None,start_days = 0):
|
||||
def post_video_tencent(title,files,tags,account_file,category=TencentZoneTypes.LIFESTYLE.value,enableTimer=False,videos_per_day = 1, daily_times=None,start_days = 0, is_draft=False):
|
||||
# 生成文件的完整路径
|
||||
account_file = [Path(BASE_DIR / "cookiesFile" / file) for file in account_file]
|
||||
files = [Path(BASE_DIR / "videoFile" / file) for file in files]
|
||||
@@ -25,7 +25,7 @@ def post_video_tencent(title,files,tags,account_file,category=TencentZoneTypes.L
|
||||
print(f"视频文件名:{file}")
|
||||
print(f"标题:{title}")
|
||||
print(f"Hashtag:{tags}")
|
||||
app = TencentVideo(title, str(file), tags, publish_datetimes[index], cookie, category)
|
||||
app = TencentVideo(title, str(file), tags, publish_datetimes[index], cookie, category, is_draft)
|
||||
asyncio.run(app.main(), debug=False)
|
||||
|
||||
|
||||
|
||||
+2
-1
@@ -363,6 +363,7 @@ def postVideo():
|
||||
productLink = data.get('productLink', '')
|
||||
productTitle = data.get('productTitle', '')
|
||||
thumbnail_path = data.get('thumbnail', '')
|
||||
is_draft = data.get('isDraft', False) # 新增参数:是否保存为草稿
|
||||
|
||||
videos_per_day = data.get('videosPerDay')
|
||||
daily_times = data.get('dailyTimes')
|
||||
@@ -376,7 +377,7 @@ def postVideo():
|
||||
start_days)
|
||||
case 2:
|
||||
post_video_tencent(title, file_list, tags, account_list, category, enableTimer, videos_per_day, daily_times,
|
||||
start_days)
|
||||
start_days, is_draft)
|
||||
case 3:
|
||||
post_video_DouYin(title, file_list, tags, account_list, category, enableTimer, videos_per_day, daily_times,
|
||||
start_days, thumbnail_path, productLink, productTitle)
|
||||
|
||||
@@ -402,6 +402,15 @@
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- 草稿选项 (仅在视频号可见) -->
|
||||
<div v-if="tab.selectedPlatform === 2" class="draft-section">
|
||||
<el-checkbox
|
||||
v-model="tab.isDraft"
|
||||
label="视频号上传草稿"
|
||||
class="draft-checkbox"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- 定时发布 -->
|
||||
<div class="schedule-section">
|
||||
<h3>定时发布</h3>
|
||||
@@ -534,7 +543,8 @@ const defaultTabInit = {
|
||||
dailyTimes: ['10:00'], // 每天发布时间点列表
|
||||
startDays: 0, // 从今天开始计算的发布天数,0表示明天,1表示后天
|
||||
publishStatus: null, // 发布状态,包含message和type
|
||||
publishing: false // 发布状态,用于控制按钮loading效果
|
||||
publishing: false, // 发布状态,用于控制按钮loading效果
|
||||
isDraft: false // 是否保存为草稿,仅视频号平台可见
|
||||
}
|
||||
|
||||
// helper to create a fresh deep-copied tab from defaultTabInit
|
||||
@@ -791,7 +801,8 @@ const confirmPublish = async (tab) => {
|
||||
startDays: tab.scheduleEnabled ? tab.startDays || 0 : 0, // 从今天开始计算的发布天数,0表示明天,1表示后天
|
||||
category: 0, //表示非原创
|
||||
productLink: tab.productLink.trim() || '', // 商品链接
|
||||
productTitle: tab.productTitle.trim() || '' // 商品名称
|
||||
productTitle: tab.productTitle.trim() || '', // 商品名称
|
||||
isDraft: tab.isDraft // 是否保存为草稿,仅视频号平台使用
|
||||
}
|
||||
|
||||
// 调用后端发布API
|
||||
|
||||
@@ -82,13 +82,14 @@ async def weixin_setup(account_file, handle=False):
|
||||
|
||||
|
||||
class TencentVideo(object):
|
||||
def __init__(self, title, file_path, tags, publish_date: datetime, account_file, category=None):
|
||||
def __init__(self, title, file_path, tags, publish_date: datetime, account_file, category=None, is_draft=False):
|
||||
self.title = title # 视频标题
|
||||
self.file_path = file_path
|
||||
self.tags = tags
|
||||
self.publish_date = publish_date
|
||||
self.account_file = account_file
|
||||
self.category = category
|
||||
self.is_draft = is_draft # 是否保存为草稿
|
||||
self.local_executable_path = LOCAL_CHROME_PATH or None
|
||||
|
||||
async def set_schedule_time_tencent(self, page, publish_date):
|
||||
@@ -185,21 +186,37 @@ class TencentVideo(object):
|
||||
async def click_publish(self, page):
|
||||
while True:
|
||||
try:
|
||||
publish_buttion = page.locator('div.form-btns button:has-text("发表")')
|
||||
if await publish_buttion.count():
|
||||
await publish_buttion.click()
|
||||
await page.wait_for_url("https://channels.weixin.qq.com/platform/post/list", timeout=5000)
|
||||
tencent_logger.success(" [-]视频发布成功")
|
||||
if self.is_draft:
|
||||
# 点击"保存草稿"按钮
|
||||
draft_button = page.locator('div.form-btns button:has-text("保存草稿")')
|
||||
if await draft_button.count():
|
||||
await draft_button.click()
|
||||
# 等待跳转到草稿箱页面或确认保存成功
|
||||
await page.wait_for_url("**/post/list**", timeout=5000) # 使用通配符匹配包含post/list的URL
|
||||
tencent_logger.success(" [-]视频草稿保存成功")
|
||||
else:
|
||||
# 点击"发表"按钮
|
||||
publish_button = page.locator('div.form-btns button:has-text("发表")')
|
||||
if await publish_button.count():
|
||||
await publish_button.click()
|
||||
await page.wait_for_url("https://channels.weixin.qq.com/platform/post/list", timeout=5000)
|
||||
tencent_logger.success(" [-]视频发布成功")
|
||||
break
|
||||
except Exception as e:
|
||||
current_url = page.url
|
||||
if "https://channels.weixin.qq.com/platform/post/list" in current_url:
|
||||
tencent_logger.success(" [-]视频发布成功")
|
||||
break
|
||||
if self.is_draft:
|
||||
# 检查是否在草稿相关的页面
|
||||
if "post/list" in current_url or "draft" in current_url:
|
||||
tencent_logger.success(" [-]视频草稿保存成功")
|
||||
break
|
||||
else:
|
||||
tencent_logger.exception(f" [-] Exception: {e}")
|
||||
tencent_logger.info(" [-] 视频正在发布中...")
|
||||
await asyncio.sleep(0.5)
|
||||
# 检查是否在发布列表页面
|
||||
if "https://channels.weixin.qq.com/platform/post/list" in current_url:
|
||||
tencent_logger.success(" [-]视频发布成功")
|
||||
break
|
||||
tencent_logger.exception(f" [-] Exception: {e}")
|
||||
tencent_logger.info(" [-] 视频正在发布中...")
|
||||
await asyncio.sleep(0.5)
|
||||
|
||||
async def detect_upload_status(self, page):
|
||||
while True:
|
||||
|
||||
Reference in New Issue
Block a user