pookz@stme commited on
Commit ·
0ef83f2
1
Parent(s): e825bcb
1. add stealth to avoid detect
Browse files- .gitignore +2 -1
- README.MD +1 -1
- douyin_uploader/main.py +4 -1
- tencent_uploader/main.py +21 -16
- tk_uploader/main.py +4 -2
- utils/base_social_media.py +9 -0
- utils/stealth.min.js +0 -0
- xhs_uploader/main.py +1 -2
.gitignore
CHANGED
|
@@ -166,4 +166,5 @@ tencent_uploader/*.json
|
|
| 166 |
youtube_uploader/*.json
|
| 167 |
douyin_uploader/*.json
|
| 168 |
bilibili_uploader/*.json
|
| 169 |
-
tk_uploader/*.json
|
|
|
|
|
|
| 166 |
youtube_uploader/*.json
|
| 167 |
douyin_uploader/*.json
|
| 168 |
bilibili_uploader/*.json
|
| 169 |
+
tk_uploader/*.json
|
| 170 |
+
cookies
|
README.MD
CHANGED
|
@@ -196,7 +196,7 @@ xhs签名方式分为两种:
|
|
| 196 |
故如果你有多账号分发,建议采用自建签名服务(todo 上传docker配置)
|
| 197 |
```
|
| 198 |
##### 疑难杂症
|
| 199 |
-
遇到签名问题,可尝试更新
|
| 200 |
https://github.com/requireCool/stealth.min.js
|
| 201 |
|
| 202 |
24.4.10 大多数人小红书失败的原因在于你的cookie有问题,请参照你cookie是不是如我这样
|
|
|
|
| 196 |
故如果你有多账号分发,建议采用自建签名服务(todo 上传docker配置)
|
| 197 |
```
|
| 198 |
##### 疑难杂症
|
| 199 |
+
遇到签名问题,可尝试更新 "utils/stealth.min.js"文件
|
| 200 |
https://github.com/requireCool/stealth.min.js
|
| 201 |
|
| 202 |
24.4.10 大多数人小红书失败的原因在于你的cookie有问题,请参照你cookie是不是如我这样
|
douyin_uploader/main.py
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
# -*- coding: utf-8 -*-
|
| 2 |
-
import pathlib
|
| 3 |
from datetime import datetime
|
| 4 |
|
| 5 |
from playwright.async_api import Playwright, async_playwright
|
|
@@ -7,12 +6,14 @@ import os
|
|
| 7 |
import asyncio
|
| 8 |
|
| 9 |
from conf import LOCAL_CHROME_PATH
|
|
|
|
| 10 |
|
| 11 |
|
| 12 |
async def cookie_auth(account_file):
|
| 13 |
async with async_playwright() as playwright:
|
| 14 |
browser = await playwright.chromium.launch(headless=True)
|
| 15 |
context = await browser.new_context(storage_state=account_file)
|
|
|
|
| 16 |
# 创建一个新的页面
|
| 17 |
page = await context.new_page()
|
| 18 |
# 访问指定的 URL
|
|
@@ -45,6 +46,7 @@ async def douyin_cookie_gen(account_file):
|
|
| 45 |
browser = await playwright.chromium.launch(**options)
|
| 46 |
# Setup context however you like.
|
| 47 |
context = await browser.new_context() # Pass any options
|
|
|
|
| 48 |
# Pause the page, and start recording manually.
|
| 49 |
page = await context.new_page()
|
| 50 |
await page.goto("https://creator.douyin.com/")
|
|
@@ -91,6 +93,7 @@ class DouYinVideo(object):
|
|
| 91 |
browser = await playwright.chromium.launch(headless=False)
|
| 92 |
# 创建一个浏览器上下文,使用指定的 cookie 文件
|
| 93 |
context = await browser.new_context(storage_state=f"{self.account_file}")
|
|
|
|
| 94 |
|
| 95 |
# 创建一个新的页面
|
| 96 |
page = await context.new_page()
|
|
|
|
| 1 |
# -*- coding: utf-8 -*-
|
|
|
|
| 2 |
from datetime import datetime
|
| 3 |
|
| 4 |
from playwright.async_api import Playwright, async_playwright
|
|
|
|
| 6 |
import asyncio
|
| 7 |
|
| 8 |
from conf import LOCAL_CHROME_PATH
|
| 9 |
+
from utils.base_social_media import set_init_script
|
| 10 |
|
| 11 |
|
| 12 |
async def cookie_auth(account_file):
|
| 13 |
async with async_playwright() as playwright:
|
| 14 |
browser = await playwright.chromium.launch(headless=True)
|
| 15 |
context = await browser.new_context(storage_state=account_file)
|
| 16 |
+
context = await set_init_script(context)
|
| 17 |
# 创建一个新的页面
|
| 18 |
page = await context.new_page()
|
| 19 |
# 访问指定的 URL
|
|
|
|
| 46 |
browser = await playwright.chromium.launch(**options)
|
| 47 |
# Setup context however you like.
|
| 48 |
context = await browser.new_context() # Pass any options
|
| 49 |
+
context = await set_init_script(context)
|
| 50 |
# Pause the page, and start recording manually.
|
| 51 |
page = await context.new_page()
|
| 52 |
await page.goto("https://creator.douyin.com/")
|
|
|
|
| 93 |
browser = await playwright.chromium.launch(headless=False)
|
| 94 |
# 创建一个浏览器上下文,使用指定的 cookie 文件
|
| 95 |
context = await browser.new_context(storage_state=f"{self.account_file}")
|
| 96 |
+
context = await set_init_script(context)
|
| 97 |
|
| 98 |
# 创建一个新的页面
|
| 99 |
page = await context.new_page()
|
tencent_uploader/main.py
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
# -*- coding: utf-8 -*-
|
| 2 |
-
import json
|
| 3 |
from datetime import datetime
|
| 4 |
|
| 5 |
from playwright.async_api import Playwright, async_playwright
|
|
@@ -7,6 +6,7 @@ import os
|
|
| 7 |
import asyncio
|
| 8 |
|
| 9 |
from conf import LOCAL_CHROME_PATH
|
|
|
|
| 10 |
from utils.files_times import get_absolute_path
|
| 11 |
|
| 12 |
|
|
@@ -34,6 +34,7 @@ async def cookie_auth(account_file):
|
|
| 34 |
async with async_playwright() as playwright:
|
| 35 |
browser = await playwright.chromium.launch(headless=True)
|
| 36 |
context = await browser.new_context(storage_state=account_file)
|
|
|
|
| 37 |
# 创建一个新的页面
|
| 38 |
page = await context.new_page()
|
| 39 |
# 访问指定的 URL
|
|
@@ -47,20 +48,25 @@ async def cookie_auth(account_file):
|
|
| 47 |
return True
|
| 48 |
|
| 49 |
|
| 50 |
-
async def
|
| 51 |
-
async with async_playwright() as
|
| 52 |
-
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
page = await context.new_page()
|
| 55 |
await page.goto("https://channels.weixin.qq.com")
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
# 保存存储状态到文件
|
| 60 |
-
storage_state = await context.storage_state()
|
| 61 |
-
with open(account_file, 'w') as f:
|
| 62 |
-
f.write(json.dumps(storage_state))
|
| 63 |
-
await browser.close()
|
| 64 |
|
| 65 |
|
| 66 |
async def weixin_setup(account_file, handle=False):
|
|
@@ -70,9 +76,7 @@ async def weixin_setup(account_file, handle=False):
|
|
| 70 |
# Todo alert message
|
| 71 |
return False
|
| 72 |
print('[+] cookie文件不存在或已失效,即将自动打开浏览器,请扫码登录,登陆后会自动生成cookie文件')
|
| 73 |
-
|
| 74 |
-
os.system('python3 -m playwright install')
|
| 75 |
-
os.system(f'playwright codegen channels.weixin.qq.com --save-storage={account_file}') # 生成cookie文件
|
| 76 |
return True
|
| 77 |
|
| 78 |
|
|
@@ -135,6 +139,7 @@ class TencentVideo(object):
|
|
| 135 |
browser = await playwright.chromium.launch(headless=False, executable_path=self.local_executable_path)
|
| 136 |
# 创建一个浏览器上下文,使用指定的 cookie 文件
|
| 137 |
context = await browser.new_context(storage_state=f"{self.account_file}")
|
|
|
|
| 138 |
|
| 139 |
# 创建一个新的页面
|
| 140 |
page = await context.new_page()
|
|
|
|
| 1 |
# -*- coding: utf-8 -*-
|
|
|
|
| 2 |
from datetime import datetime
|
| 3 |
|
| 4 |
from playwright.async_api import Playwright, async_playwright
|
|
|
|
| 6 |
import asyncio
|
| 7 |
|
| 8 |
from conf import LOCAL_CHROME_PATH
|
| 9 |
+
from utils.base_social_media import set_init_script
|
| 10 |
from utils.files_times import get_absolute_path
|
| 11 |
|
| 12 |
|
|
|
|
| 34 |
async with async_playwright() as playwright:
|
| 35 |
browser = await playwright.chromium.launch(headless=True)
|
| 36 |
context = await browser.new_context(storage_state=account_file)
|
| 37 |
+
context = await set_init_script(context)
|
| 38 |
# 创建一个新的页面
|
| 39 |
page = await context.new_page()
|
| 40 |
# 访问指定的 URL
|
|
|
|
| 48 |
return True
|
| 49 |
|
| 50 |
|
| 51 |
+
async def get_tencent_cookie(account_file):
|
| 52 |
+
async with async_playwright() as playwright:
|
| 53 |
+
options = {
|
| 54 |
+
'args': [
|
| 55 |
+
'--lang en-GB'
|
| 56 |
+
],
|
| 57 |
+
'headless': False, # Set headless option here
|
| 58 |
+
}
|
| 59 |
+
# Make sure to run headed.
|
| 60 |
+
browser = await playwright.chromium.launch(**options)
|
| 61 |
+
# Setup context however you like.
|
| 62 |
+
context = await browser.new_context() # Pass any options
|
| 63 |
+
# Pause the page, and start recording manually.
|
| 64 |
+
context = await set_init_script(context)
|
| 65 |
page = await context.new_page()
|
| 66 |
await page.goto("https://channels.weixin.qq.com")
|
| 67 |
+
await page.pause()
|
| 68 |
+
# 点击调试器的继续,保存cookie
|
| 69 |
+
await context.storage_state(path=account_file)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
|
| 71 |
|
| 72 |
async def weixin_setup(account_file, handle=False):
|
|
|
|
| 76 |
# Todo alert message
|
| 77 |
return False
|
| 78 |
print('[+] cookie文件不存在或已失效,即将自动打开浏览器,请扫码登录,登陆后会自动生成cookie文件')
|
| 79 |
+
await get_tencent_cookie(account_file)
|
|
|
|
|
|
|
| 80 |
return True
|
| 81 |
|
| 82 |
|
|
|
|
| 139 |
browser = await playwright.chromium.launch(headless=False, executable_path=self.local_executable_path)
|
| 140 |
# 创建一个浏览器上下文,使用指定的 cookie 文件
|
| 141 |
context = await browser.new_context(storage_state=f"{self.account_file}")
|
| 142 |
+
context = await set_init_script(context)
|
| 143 |
|
| 144 |
# 创建一个新的页面
|
| 145 |
page = await context.new_page()
|
tk_uploader/main.py
CHANGED
|
@@ -3,10 +3,10 @@ import re
|
|
| 3 |
from datetime import datetime
|
| 4 |
|
| 5 |
from playwright.async_api import Playwright, async_playwright
|
| 6 |
-
import time
|
| 7 |
import os
|
| 8 |
import asyncio
|
| 9 |
from tk_uploader.tk_config import Tk_Locator
|
|
|
|
| 10 |
from utils.files_times import get_absolute_path
|
| 11 |
|
| 12 |
|
|
@@ -14,6 +14,7 @@ async def cookie_auth(account_file):
|
|
| 14 |
async with async_playwright() as playwright:
|
| 15 |
browser = await playwright.firefox.launch(headless=True)
|
| 16 |
context = await browser.new_context(storage_state=account_file)
|
|
|
|
| 17 |
# 创建一个新的页面
|
| 18 |
page = await context.new_page()
|
| 19 |
# 访问指定的 URL
|
|
@@ -57,6 +58,7 @@ async def get_tiktok_cookie(account_file):
|
|
| 57 |
browser = await playwright.firefox.launch(**options)
|
| 58 |
# Setup context however you like.
|
| 59 |
context = await browser.new_context() # Pass any options
|
|
|
|
| 60 |
# Pause the page, and start recording manually.
|
| 61 |
page = await context.new_page()
|
| 62 |
await page.goto("https://www.tiktok.com/creator-center/content")
|
|
@@ -138,7 +140,7 @@ class TiktokVideo(object):
|
|
| 138 |
async def upload(self, playwright: Playwright) -> None:
|
| 139 |
browser = await playwright.firefox.launch(headless=False)
|
| 140 |
context = await browser.new_context(storage_state=f"{self.account_file}")
|
| 141 |
-
|
| 142 |
page = await context.new_page()
|
| 143 |
|
| 144 |
await page.goto("https://www.tiktok.com/creator-center/upload")
|
|
|
|
| 3 |
from datetime import datetime
|
| 4 |
|
| 5 |
from playwright.async_api import Playwright, async_playwright
|
|
|
|
| 6 |
import os
|
| 7 |
import asyncio
|
| 8 |
from tk_uploader.tk_config import Tk_Locator
|
| 9 |
+
from utils.base_social_media import set_init_script
|
| 10 |
from utils.files_times import get_absolute_path
|
| 11 |
|
| 12 |
|
|
|
|
| 14 |
async with async_playwright() as playwright:
|
| 15 |
browser = await playwright.firefox.launch(headless=True)
|
| 16 |
context = await browser.new_context(storage_state=account_file)
|
| 17 |
+
context = await set_init_script(context)
|
| 18 |
# 创建一个新的页面
|
| 19 |
page = await context.new_page()
|
| 20 |
# 访问指定的 URL
|
|
|
|
| 58 |
browser = await playwright.firefox.launch(**options)
|
| 59 |
# Setup context however you like.
|
| 60 |
context = await browser.new_context() # Pass any options
|
| 61 |
+
context = await set_init_script(context)
|
| 62 |
# Pause the page, and start recording manually.
|
| 63 |
page = await context.new_page()
|
| 64 |
await page.goto("https://www.tiktok.com/creator-center/content")
|
|
|
|
| 140 |
async def upload(self, playwright: Playwright) -> None:
|
| 141 |
browser = await playwright.firefox.launch(headless=False)
|
| 142 |
context = await browser.new_context(storage_state=f"{self.account_file}")
|
| 143 |
+
context = await set_init_script(context)
|
| 144 |
page = await context.new_page()
|
| 145 |
|
| 146 |
await page.goto("https://www.tiktok.com/creator-center/upload")
|
utils/base_social_media.py
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
|
|
| 1 |
from typing import List
|
| 2 |
|
|
|
|
|
|
|
| 3 |
SOCIAL_MEDIA_DOUYIN = "douyin"
|
| 4 |
SOCIAL_MEDIA_TENCENT = "tencent"
|
| 5 |
SOCIAL_MEDIA_TIKTOK = "tiktok"
|
|
@@ -12,3 +15,9 @@ def get_supported_social_media() -> List[str]:
|
|
| 12 |
|
| 13 |
def get_cli_action() -> List[str]:
|
| 14 |
return ["upload", "login", "watch"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pathlib import Path
|
| 2 |
from typing import List
|
| 3 |
|
| 4 |
+
from conf import BASE_DIR
|
| 5 |
+
|
| 6 |
SOCIAL_MEDIA_DOUYIN = "douyin"
|
| 7 |
SOCIAL_MEDIA_TENCENT = "tencent"
|
| 8 |
SOCIAL_MEDIA_TIKTOK = "tiktok"
|
|
|
|
| 15 |
|
| 16 |
def get_cli_action() -> List[str]:
|
| 17 |
return ["upload", "login", "watch"]
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
async def set_init_script(context):
|
| 21 |
+
stealth_js_path = Path(BASE_DIR / "utils/stealth.min.js")
|
| 22 |
+
await context.add_init_script(path=stealth_js_path)
|
| 23 |
+
return context
|
utils/stealth.min.js
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
xhs_uploader/main.py
CHANGED
|
@@ -16,8 +16,7 @@ def sign_local(uri, data=None, a1="", web_session=""):
|
|
| 16 |
for _ in range(10):
|
| 17 |
try:
|
| 18 |
with sync_playwright() as playwright:
|
| 19 |
-
stealth_js_path = pathlib.Path(
|
| 20 |
-
BASE_DIR) / "xhs_uploader" / "cdn.jsdelivr.net_gh_requireCool_stealth.min.js_stealth.min.js"
|
| 21 |
chromium = playwright.chromium
|
| 22 |
|
| 23 |
# 如果一直失败可尝试设置成 False 让其打开浏览器,适当添加 sleep 可查看浏览器状态
|
|
|
|
| 16 |
for _ in range(10):
|
| 17 |
try:
|
| 18 |
with sync_playwright() as playwright:
|
| 19 |
+
stealth_js_path = pathlib.Path(BASE_DIR / "utils/stealth.min.js")
|
|
|
|
| 20 |
chromium = playwright.chromium
|
| 21 |
|
| 22 |
# 如果一直失败可尝试设置成 False 让其打开浏览器,适当添加 sleep 可查看浏览器状态
|