重新支持抖音封面设置
This commit is contained in:
@@ -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,
|
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 = ''):
|
productLink = '', productTitle = ''):
|
||||||
# 生成文件的完整路径
|
# 生成文件的完整路径
|
||||||
account_file = [Path(BASE_DIR / "cookiesFile" / file) for file in account_file]
|
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"视频文件名:{file}")
|
||||||
print(f"标题:{title}")
|
print(f"标题:{title}")
|
||||||
print(f"Hashtag:{tags}")
|
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)
|
asyncio.run(app.main(), debug=False)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -337,6 +337,7 @@ def postVideo():
|
|||||||
category = None
|
category = None
|
||||||
productLink = data.get('productLink', '')
|
productLink = data.get('productLink', '')
|
||||||
productTitle = data.get('productTitle', '')
|
productTitle = data.get('productTitle', '')
|
||||||
|
thumbnail_path = data.get('thumbnail', '')
|
||||||
|
|
||||||
videos_per_day = data.get('videosPerDay')
|
videos_per_day = data.get('videosPerDay')
|
||||||
daily_times = data.get('dailyTimes')
|
daily_times = data.get('dailyTimes')
|
||||||
@@ -353,7 +354,7 @@ def postVideo():
|
|||||||
start_days)
|
start_days)
|
||||||
case 3:
|
case 3:
|
||||||
post_video_DouYin(title, file_list, tags, account_list, category, enableTimer, videos_per_day, daily_times,
|
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:
|
case 4:
|
||||||
post_video_ks(title, file_list, tags, account_list, category, enableTimer, videos_per_day, daily_times,
|
post_video_ks(title, file_list, tags, account_list, category, enableTimer, videos_per_day, daily_times,
|
||||||
start_days)
|
start_days)
|
||||||
|
|||||||
@@ -158,13 +158,6 @@ class DouYinVideo(object):
|
|||||||
await page.type(css_selector, "#" + tag)
|
await page.type(css_selector, "#" + tag)
|
||||||
await page.press(css_selector, "Space")
|
await page.press(css_selector, "Space")
|
||||||
douyin_logger.info(f'总共添加{len(self.tags)}个话题')
|
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:
|
while True:
|
||||||
# 判断重新上传按钮是否存在,如果不存在,代表视频正在上传,则等待
|
# 判断重新上传按钮是否存在,如果不存在,代表视频正在上传,则等待
|
||||||
try:
|
try:
|
||||||
@@ -183,6 +176,11 @@ class DouYinVideo(object):
|
|||||||
except:
|
except:
|
||||||
douyin_logger.info(" [-] 正在上传视频中...")
|
douyin_logger.info(" [-] 正在上传视频中...")
|
||||||
await asyncio.sleep(2)
|
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)
|
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):
|
async def set_thumbnail(self, page: Page, thumbnail_path: str):
|
||||||
if thumbnail_path:
|
if thumbnail_path:
|
||||||
|
douyin_logger.info(' [-] 正在设置视频封面...')
|
||||||
await page.click('text="选择封面"')
|
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.click('text="设置竖封面"')
|
||||||
await page.wait_for_timeout(2000) # 等待2秒
|
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.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.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('完成')")
|
# finish_confirm_element = page.locator("div[class^='confirmBtn'] >> div:has-text('完成')")
|
||||||
# if await finish_confirm_element.count():
|
# if await finish_confirm_element.count():
|
||||||
# await finish_confirm_element.click()
|
# await finish_confirm_element.click()
|
||||||
# await page.locator("div[class^='footer'] button:has-text('完成')").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 = ""):
|
async def set_location(self, page: Page, location: str = ""):
|
||||||
if not location:
|
if not location:
|
||||||
@@ -291,6 +293,7 @@ class DouYinVideo(object):
|
|||||||
|
|
||||||
async def set_product_link(self, page: Page, product_link: str, product_title: str):
|
async def set_product_link(self, page: Page, product_link: str, product_title: str):
|
||||||
"""设置商品链接功能"""
|
"""设置商品链接功能"""
|
||||||
|
await page.wait_for_timeout(2000) # 等待2秒
|
||||||
try:
|
try:
|
||||||
# 定位"添加标签"文本,然后向上导航到容器,再找到下拉框
|
# 定位"添加标签"文本,然后向上导航到容器,再找到下拉框
|
||||||
await page.wait_for_selector('text=添加标签', timeout=10000)
|
await page.wait_for_selector('text=添加标签', timeout=10000)
|
||||||
|
|||||||
Reference in New Issue
Block a user