zoujie

支持 快手,腾讯视频号headless发布

...@@ -83,13 +83,13 @@ class KSVideo(object): ...@@ -83,13 +83,13 @@ class KSVideo(object):
83 async def upload(self, playwright: Playwright) -> None: 83 async def upload(self, playwright: Playwright) -> None:
84 # 使用 Chromium 浏览器启动一个浏览器实例 84 # 使用 Chromium 浏览器启动一个浏览器实例
85 print(self.local_executable_path) 85 print(self.local_executable_path)
86 - if self.local_executable_path: 86 + # if self.local_executable_path:
87 - browser = await playwright.chromium.launch( 87 + # browser = await playwright.chromium.launch(
88 - headless=True, 88 + # headless=True,
89 - executable_path=self.local_executable_path, 89 + # executable_path=self.local_executable_path,
90 - ) 90 + # )
91 - else: 91 + # else:
92 - browser = await playwright.chromium.launch( 92 + browser = await playwright.firefox.launch(
93 headless=True 93 headless=True
94 ) # 创建一个浏览器上下文,使用指定的 cookie 文件 94 ) # 创建一个浏览器上下文,使用指定的 cookie 文件
95 context = await browser.new_context(storage_state=f"{self.account_file}") 95 context = await browser.new_context(storage_state=f"{self.account_file}")
...@@ -114,6 +114,23 @@ class KSVideo(object): ...@@ -114,6 +114,23 @@ class KSVideo(object):
114 # await file_chooser.set_files(self.file_path) 114 # await file_chooser.set_files(self.file_path)
115 115
116 await page.locator("div[class^='_publish-container'] input").set_input_files(self.file_path) 116 await page.locator("div[class^='_publish-container'] input").set_input_files(self.file_path)
117 + await asyncio.sleep(5)
118 +
119 + # 判断视频是否上传成功,去除引导页
120 + while True:
121 + # 判断视频是否上传成功,去除引导页
122 + try:
123 + skip_button = page.get_by_role('button', name="Skip", exact=True)
124 + if await skip_button.count():
125 + await skip_button.click()
126 + await asyncio.sleep(1)
127 + else:
128 + await asyncio.sleep(1)
129 + break
130 + except:
131 + kuaishou_logger.info(" [-] 视频正在发布中...")
132 + await asyncio.sleep(0.5)
133 + break
117 134
118 if not await page.get_by_text("封面设置").count(): 135 if not await page.get_by_text("封面设置").count():
119 raise Exception("似乎没有跳转到到编辑页面") 136 raise Exception("似乎没有跳转到到编辑页面")
......
...@@ -137,7 +137,9 @@ class TencentVideo(object): ...@@ -137,7 +137,9 @@ class TencentVideo(object):
137 137
138 async def upload(self, playwright: Playwright) -> None: 138 async def upload(self, playwright: Playwright) -> None:
139 # 使用 Chromium (这里使用系统内浏览器,用chromium 会造成h264错误 139 # 使用 Chromium (这里使用系统内浏览器,用chromium 会造成h264错误
140 - browser = await playwright.chromium.launch(headless=False, executable_path=self.local_executable_path) 140 + # browser = await playwright.chromium.launch(headless=True, executable_path=self.local_executable_path)
141 + browser = await playwright.firefox.launch(headless=True )
142 +
141 # 创建一个浏览器上下文,使用指定的 cookie 文件 143 # 创建一个浏览器上下文,使用指定的 cookie 文件
142 context = await browser.new_context(storage_state=f"{self.account_file}") 144 context = await browser.new_context(storage_state=f"{self.account_file}")
143 context = await set_init_script(context) 145 context = await set_init_script(context)
...@@ -150,8 +152,9 @@ class TencentVideo(object): ...@@ -150,8 +152,9 @@ class TencentVideo(object):
150 # 等待页面跳转到指定的 URL,没进入,则自动等待到超时 152 # 等待页面跳转到指定的 URL,没进入,则自动等待到超时
151 await page.wait_for_url("https://channels.weixin.qq.com/platform/post/create") 153 await page.wait_for_url("https://channels.weixin.qq.com/platform/post/create")
152 # await page.wait_for_selector('input[type="file"]', timeout=10000) 154 # await page.wait_for_selector('input[type="file"]', timeout=10000)
153 - file_input = page.locator('input[type="file"]') 155 + file_input = await page.locator('input[type="file"]').set_input_files(self.file_path)
154 - await file_input.set_input_files(self.file_path) 156 + await page.wait_for_selector(".cover-img-horizontal",state="attached")
157 + # await file_input.set_input_files(self.file_path)
155 # 填充标题和话题 158 # 填充标题和话题
156 await self.add_title_tags(page) 159 await self.add_title_tags(page)
157 # 添加商品 160 # 添加商品
......