Commit ·
243beca
1
Parent(s): 0c47692
add douyin cover upload
Browse files
uploader/douyin_uploader/main.py
CHANGED
|
@@ -57,7 +57,7 @@ async def douyin_cookie_gen(account_file):
|
|
| 57 |
|
| 58 |
|
| 59 |
class DouYinVideo(object):
|
| 60 |
-
def __init__(self, title, file_path, tags, publish_date: datetime, account_file):
|
| 61 |
self.title = title # 视频标题
|
| 62 |
self.file_path = file_path
|
| 63 |
self.tags = tags
|
|
@@ -65,6 +65,7 @@ class DouYinVideo(object):
|
|
| 65 |
self.account_file = account_file
|
| 66 |
self.date_format = '%Y年%m月%d日 %H:%M'
|
| 67 |
self.local_executable_path = LOCAL_CHROME_PATH
|
|
|
|
| 68 |
|
| 69 |
async def set_schedule_time_douyin(self, page, publish_date):
|
| 70 |
# 选择包含特定文本内容的 label 元素
|
|
@@ -158,6 +159,9 @@ class DouYinVideo(object):
|
|
| 158 |
except:
|
| 159 |
douyin_logger.info(" [-] 正在上传视频中...")
|
| 160 |
await asyncio.sleep(2)
|
|
|
|
|
|
|
|
|
|
| 161 |
|
| 162 |
# 更换可见元素
|
| 163 |
await self.set_location(page, "杭州市")
|
|
@@ -195,6 +199,18 @@ class DouYinVideo(object):
|
|
| 195 |
# 关闭浏览器上下文和浏览器实例
|
| 196 |
await context.close()
|
| 197 |
await browser.close()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 198 |
|
| 199 |
async def set_location(self, page: Page, location: str = "杭州市"):
|
| 200 |
await page.locator('div.semi-select span:has-text("输入地理位置")').click()
|
|
|
|
| 57 |
|
| 58 |
|
| 59 |
class DouYinVideo(object):
|
| 60 |
+
def __init__(self, title, file_path, tags, publish_date: datetime, account_file, cover_path=None):
|
| 61 |
self.title = title # 视频标题
|
| 62 |
self.file_path = file_path
|
| 63 |
self.tags = tags
|
|
|
|
| 65 |
self.account_file = account_file
|
| 66 |
self.date_format = '%Y年%m月%d日 %H:%M'
|
| 67 |
self.local_executable_path = LOCAL_CHROME_PATH
|
| 68 |
+
self.cover_path = cover_path
|
| 69 |
|
| 70 |
async def set_schedule_time_douyin(self, page, publish_date):
|
| 71 |
# 选择包含特定文本内容的 label 元素
|
|
|
|
| 159 |
except:
|
| 160 |
douyin_logger.info(" [-] 正在上传视频中...")
|
| 161 |
await asyncio.sleep(2)
|
| 162 |
+
|
| 163 |
+
#上传视频封面
|
| 164 |
+
await self.set_cover(page, self.cover_path)
|
| 165 |
|
| 166 |
# 更换可见元素
|
| 167 |
await self.set_location(page, "杭州市")
|
|
|
|
| 199 |
# 关闭浏览器上下文和浏览器实例
|
| 200 |
await context.close()
|
| 201 |
await browser.close()
|
| 202 |
+
|
| 203 |
+
async def set_cover(self, page: Page, cover_path: str):
|
| 204 |
+
if cover_path:
|
| 205 |
+
await page.click('text="选择封面"')
|
| 206 |
+
await page.click('text="上传封面"')
|
| 207 |
+
# 定位到上传区域并点击
|
| 208 |
+
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')
|
| 209 |
+
await page.wait_for_timeout(2000) # 等待2秒
|
| 210 |
+
#await page.locator('button:not([disabled]):has-text("完成")').first.click()
|
| 211 |
+
#await page.wait_for_selector('button:has-text("完成")')
|
| 212 |
+
#await page.locator('button:has-text("完成"):not([disabled])').click()
|
| 213 |
+
await page.locator('button:has-text("完成")').nth(1).click()
|
| 214 |
|
| 215 |
async def set_location(self, page: Page, location: str = "杭州市"):
|
| 216 |
await page.locator('div.semi-select span:has-text("输入地理位置")').click()
|