add douyin cover upload

This commit is contained in:
forrestsocool
2024-08-22 16:22:44 +08:00
parent f402717363
commit 7c9f5d2ec4
+17 -1
View File
@@ -57,7 +57,7 @@ async def douyin_cookie_gen(account_file):
class DouYinVideo(object): class DouYinVideo(object):
def __init__(self, title, file_path, tags, publish_date: datetime, account_file): def __init__(self, title, file_path, tags, publish_date: datetime, account_file, cover_path=None):
self.title = title # 视频标题 self.title = title # 视频标题
self.file_path = file_path self.file_path = file_path
self.tags = tags self.tags = tags
@@ -65,6 +65,7 @@ class DouYinVideo(object):
self.account_file = account_file self.account_file = account_file
self.date_format = '%Y年%m月%d日 %H:%M' self.date_format = '%Y年%m月%d日 %H:%M'
self.local_executable_path = LOCAL_CHROME_PATH self.local_executable_path = LOCAL_CHROME_PATH
self.cover_path = cover_path
async def set_schedule_time_douyin(self, page, publish_date): async def set_schedule_time_douyin(self, page, publish_date):
# 选择包含特定文本内容的 label 元素 # 选择包含特定文本内容的 label 元素
@@ -159,6 +160,9 @@ class DouYinVideo(object):
douyin_logger.info(" [-] 正在上传视频中...") douyin_logger.info(" [-] 正在上传视频中...")
await asyncio.sleep(2) await asyncio.sleep(2)
#上传视频封面
await self.set_cover(page, self.cover_path)
# 更换可见元素 # 更换可见元素
await self.set_location(page, "杭州市") await self.set_location(page, "杭州市")
@@ -196,6 +200,18 @@ class DouYinVideo(object):
await context.close() await context.close()
await browser.close() await browser.close()
async def set_cover(self, page: Page, cover_path: str):
if cover_path:
await page.click('text="选择封面"')
await page.click('text="上传封面"')
# 定位到上传区域并点击
await page.locator("div[class^='semi-upload upload'] >> input.semi-upload-hidden-input").set_input_files('/mnt/NAS/MassStorage/NewsVideo/231/img_cover_v.jpg')
await page.wait_for_timeout(2000) # 等待2秒
#await page.locator('button:not([disabled]):has-text("完成")').first.click()
#await page.wait_for_selector('button:has-text("完成")')
#await page.locator('button:has-text("完成"):not([disabled])').click()
await page.locator('button:has-text("完成")').nth(1).click()
async def set_location(self, page: Page, location: str = "杭州市"): async def set_location(self, page: Page, location: str = "杭州市"):
await page.locator('div.semi-select span:has-text("输入地理位置")').click() await page.locator('div.semi-select span:has-text("输入地理位置")').click()
await page.keyboard.press("Backspace") await page.keyboard.press("Backspace")