重新支持抖音封面设置

This commit is contained in:
Leo Song
2025-11-03 15:17:50 +08:00
parent 2f95a5512c
commit 0235e89b9e
3 changed files with 16 additions and 11 deletions
+2 -1
View File
@@ -30,6 +30,7 @@ def post_video_tencent(title,files,tags,account_file,category=TencentZoneTypes.L
def post_video_DouYin(title,files,tags,account_file,category=TencentZoneTypes.LIFESTYLE.value,enableTimer=False,videos_per_day = 1, daily_times=None,start_days = 0,
thumbnail_path = '',
productLink = '', productTitle = ''):
# 生成文件的完整路径
account_file = [Path(BASE_DIR / "cookiesFile" / file) for file in account_file]
@@ -45,7 +46,7 @@ def post_video_DouYin(title,files,tags,account_file,category=TencentZoneTypes.LI
print(f"视频文件名:{file}")
print(f"标题:{title}")
print(f"Hashtag{tags}")
app = DouYinVideo(title, str(file), tags, publish_datetimes[index], cookie, category, productLink, productTitle)
app = DouYinVideo(title, str(file), tags, publish_datetimes[index], cookie, thumbnail_path, productLink, productTitle)
asyncio.run(app.main(), debug=False)
+2 -1
View File
@@ -337,6 +337,7 @@ def postVideo():
category = None
productLink = data.get('productLink', '')
productTitle = data.get('productTitle', '')
thumbnail_path = data.get('thumbnail', '')
videos_per_day = data.get('videosPerDay')
daily_times = data.get('dailyTimes')
@@ -353,7 +354,7 @@ def postVideo():
start_days)
case 3:
post_video_DouYin(title, file_list, tags, account_list, category, enableTimer, videos_per_day, daily_times,
start_days, productLink, productTitle)
start_days, thumbnail_path, productLink, productTitle)
case 4:
post_video_ks(title, file_list, tags, account_list, category, enableTimer, videos_per_day, daily_times,
start_days)
+12 -9
View File
@@ -158,13 +158,6 @@ class DouYinVideo(object):
await page.type(css_selector, "#" + tag)
await page.press(css_selector, "Space")
douyin_logger.info(f'总共添加{len(self.tags)}个话题')
if self.productLink and self.productTitle:
douyin_logger.info(f' [-] 正在设置商品链接...')
await asyncio.sleep(1)
await self.set_product_link(page, self.productLink, self.productTitle)
douyin_logger.info(f' [+] 完成设置商品链接...')
while True:
# 判断重新上传按钮是否存在,如果不存在,代表视频正在上传,则等待
try:
@@ -183,6 +176,11 @@ class DouYinVideo(object):
except:
douyin_logger.info(" [-] 正在上传视频中...")
await asyncio.sleep(2)
if self.productLink and self.productTitle:
douyin_logger.info(f' [-] 正在设置商品链接...')
await self.set_product_link(page, self.productLink, self.productTitle)
douyin_logger.info(f' [+] 完成设置商品链接...')
#上传视频封面
await self.set_thumbnail(page, self.thumbnail_path)
@@ -227,18 +225,22 @@ class DouYinVideo(object):
async def set_thumbnail(self, page: Page, thumbnail_path: str):
if thumbnail_path:
douyin_logger.info(' [-] 正在设置视频封面...')
await page.click('text="选择封面"')
await page.wait_for_selector("div.semi-modal-content:visible")
await page.wait_for_selector("div.dy-creator-content-modal")
await page.click('text="设置竖封面"')
await page.wait_for_timeout(2000) # 等待2秒
# 定位到上传区域并点击
await page.locator("div[class^='semi-upload upload'] >> input.semi-upload-hidden-input").set_input_files(thumbnail_path)
await page.wait_for_timeout(2000) # 等待2秒
await page.locator("div[class^='extractFooter'] button:visible:has-text('完成')").click()
await page.locator("div#tooltip-container button:visible:has-text('完成')").click()
# finish_confirm_element = page.locator("div[class^='confirmBtn'] >> div:has-text('完成')")
# if await finish_confirm_element.count():
# await finish_confirm_element.click()
# await page.locator("div[class^='footer'] button:has-text('完成')").click()
douyin_logger.info(' [+] 视频封面设置完成!')
await page.wait_for_selector("div.extractFooter", state='detached')
async def set_location(self, page: Page, location: str = ""):
if not location:
@@ -291,6 +293,7 @@ class DouYinVideo(object):
async def set_product_link(self, page: Page, product_link: str, product_title: str):
"""设置商品链接功能"""
await page.wait_for_timeout(2000) # 等待2秒
try:
# 定位"添加标签"文本,然后向上导航到容器,再找到下拉框
await page.wait_for_selector('text=添加标签', timeout=10000)