1. 统一命名thumbnail

2. 更换完成定位
This commit is contained in:
pookz@stme
2024-08-23 15:14:37 +08:00
parent 57eda1b7fd
commit cd1a82fbb9
2 changed files with 12 additions and 8 deletions
+5 -1
View File
@@ -18,9 +18,13 @@ if __name__ == '__main__':
cookie_setup = asyncio.run(douyin_setup(account_file, handle=False)) cookie_setup = asyncio.run(douyin_setup(account_file, handle=False))
for index, file in enumerate(files): for index, file in enumerate(files):
title, tags = get_title_and_hashtags(str(file)) title, tags = get_title_and_hashtags(str(file))
thumbnail_path = file.with_suffix('.png')
# 打印视频文件名、标题和 hashtag # 打印视频文件名、标题和 hashtag
print(f"视频文件名:{file}") print(f"视频文件名:{file}")
print(f"标题:{title}") print(f"标题:{title}")
print(f"Hashtag:{tags}") print(f"Hashtag:{tags}")
app = DouYinVideo(title, file, tags, publish_datetimes[index], account_file) if thumbnail_path.exists():
app = DouYinVideo(title, file, tags, publish_datetimes[index], account_file, thumbnail_path=thumbnail_path)
else:
app = DouYinVideo(title, file, tags, publish_datetimes[index], account_file)
asyncio.run(app.main(), debug=False) asyncio.run(app.main(), debug=False)
+7 -7
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, cover_path=None): def __init__(self, title, file_path, tags, publish_date: datetime, account_file, thumbnail_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,7 +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 self.thumbnail_path = thumbnail_path
async def set_schedule_time_douyin(self, page, publish_date): async def set_schedule_time_douyin(self, page, publish_date):
# 选择包含特定文本内容的 label 元素 # 选择包含特定文本内容的 label 元素
@@ -161,7 +161,7 @@ class DouYinVideo(object):
await asyncio.sleep(2) await asyncio.sleep(2)
#上传视频封面 #上传视频封面
await self.set_cover(page, self.cover_path) await self.set_thumbnail(page, self.thumbnail_path)
# 更换可见元素 # 更换可见元素
await self.set_location(page, "杭州市") await self.set_location(page, "杭州市")
@@ -200,14 +200,14 @@ 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): async def set_thumbnail(self, page: Page, thumbnail_path: str):
if cover_path: if thumbnail_path:
await page.click('text="选择封面"') await page.click('text="选择封面"')
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.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('button:has-text("完成")').nth(1).click() await page.locator("div[class^='uploadCrop'] button:has-text('完成')").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()