feat: 增加Docker容器环境
Browse files- .dockerignore +8 -0
- Dockerfile +56 -0
- README.md +22 -1
- conf.example.py +1 -0
- myUtils/login.py +5 -5
- sau_backend.py +2 -2
- uploader/baijiahao_uploader/main.py +6 -5
- uploader/douyin_uploader/main.py +6 -5
- uploader/ks_uploader/main.py +6 -5
- uploader/tencent_uploader/main.py +5 -4
- uploader/tk_uploader/main.py +5 -3
- uploader/tk_uploader/main_chrome.py +5 -4
- uploader/xhs_uploader/main.py +2 -2
- uploader/xiaohongshu_uploader/main.py +6 -5
.dockerignore
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.venv
|
| 2 |
+
.git
|
| 3 |
+
.idea
|
| 4 |
+
cookies
|
| 5 |
+
conf.py
|
| 6 |
+
sau_frontend/dist
|
| 7 |
+
sau_frontend/node_modules
|
| 8 |
+
sau_frontend/package-lock.json
|
Dockerfile
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM node:22.21.1 as builder
|
| 2 |
+
|
| 3 |
+
WORKDIR /app
|
| 4 |
+
|
| 5 |
+
RUN npm config set registry https://registry.npmmirror.com
|
| 6 |
+
|
| 7 |
+
COPY sau_frontend .
|
| 8 |
+
|
| 9 |
+
RUN npm install
|
| 10 |
+
|
| 11 |
+
ENV NODE_ENV=production
|
| 12 |
+
ENV PATH=/app/node_modules/.bin:$PATH
|
| 13 |
+
|
| 14 |
+
RUN npm run build
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
FROM python:3.10.19
|
| 18 |
+
|
| 19 |
+
WORKDIR /app
|
| 20 |
+
|
| 21 |
+
ENV PLAYWRIGHT_BROWSERS_PATH=/opt/playwright
|
| 22 |
+
|
| 23 |
+
COPY --from=builder /app/dist/index.html /app
|
| 24 |
+
COPY --from=builder /app/dist/assets /app/assets
|
| 25 |
+
COPY --from=builder /app/dist/vite.svg /app
|
| 26 |
+
|
| 27 |
+
RUN apt-get update && apt-get install -y --no-install-recommends libnss3 \
|
| 28 |
+
libnspr4 \
|
| 29 |
+
libdbus-1-3 \
|
| 30 |
+
libatk1.0-0 \
|
| 31 |
+
libatk-bridge2.0-0 \
|
| 32 |
+
libatspi2.0-0 \
|
| 33 |
+
libxcomposite1 \
|
| 34 |
+
libxdamage1 \
|
| 35 |
+
libxfixes3 \
|
| 36 |
+
libxrandr2 \
|
| 37 |
+
libgbm1 \
|
| 38 |
+
libxkbcommon0 \
|
| 39 |
+
libasound2 && rm -rf /var/lib/apt/lists/*
|
| 40 |
+
|
| 41 |
+
RUN pip config set global.index-url https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple
|
| 42 |
+
|
| 43 |
+
COPY requirements.txt requirements.txt
|
| 44 |
+
|
| 45 |
+
RUN pip install -r requirements.txt
|
| 46 |
+
|
| 47 |
+
RUN playwright install chromium-headless-shell
|
| 48 |
+
|
| 49 |
+
COPY . .
|
| 50 |
+
|
| 51 |
+
RUN cp conf.example.py conf.py
|
| 52 |
+
|
| 53 |
+
EXPOSE 80
|
| 54 |
+
EXPOSE 5409
|
| 55 |
+
|
| 56 |
+
CMD ["python", "sau_backend.py"]
|
README.md
CHANGED
|
@@ -46,7 +46,7 @@
|
|
| 46 |
- **功能增强**:
|
| 47 |
- [x] 更易用的版本 (GUI / CLI 交互优化)
|
| 48 |
- [x] API 封装
|
| 49 |
-
- [
|
| 50 |
- [ ] 自动化上传 (更智能的调度策略)
|
| 51 |
- [ ] 多线程/异步上传优化
|
| 52 |
- [ ] Slack/消息推送通知
|
|
@@ -164,6 +164,27 @@
|
|
| 164 |
python examples/upload_video_to_douyin.py
|
| 165 |
```
|
| 166 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 167 |
## 🐇项目背景
|
| 168 |
|
| 169 |
该项目最初是我个人用于自动化管理社交媒体视频发布的工具。我的主要发布策略是提前一天设置定时发布,因此项目中很多定时发布相关的逻辑是基于“第二天”的时间进行计算的。
|
|
|
|
| 46 |
- **功能增强**:
|
| 47 |
- [x] 更易用的版本 (GUI / CLI 交互优化)
|
| 48 |
- [x] API 封装
|
| 49 |
+
- [x] Docker 部署
|
| 50 |
- [ ] 自动化上传 (更智能的调度策略)
|
| 51 |
- [ ] 多线程/异步上传优化
|
| 52 |
- [ ] Slack/消息推送通知
|
|
|
|
| 164 |
python examples/upload_video_to_douyin.py
|
| 165 |
```
|
| 166 |
|
| 167 |
+
## Docker 环境
|
| 168 |
+
### 自己构建镜像
|
| 169 |
+
1. **构建Docker镜像**:
|
| 170 |
+
```
|
| 171 |
+
docker build -t social-auto-upload:latest .
|
| 172 |
+
```
|
| 173 |
+
2. **运行Docker容器**:
|
| 174 |
+
```
|
| 175 |
+
docker run -d -it -p 5409:5409 social-auto-upload:latest
|
| 176 |
+
```
|
| 177 |
+
### 使用预构建镜像
|
| 178 |
+
1. **拉取镜像**:
|
| 179 |
+
```
|
| 180 |
+
docker pull gzxy/social-auto-upload:latest
|
| 181 |
+
```
|
| 182 |
+
2. **运行Docker容器**:
|
| 183 |
+
```
|
| 184 |
+
docker run -d -it -p 5409:5409 gzxy/social-auto-upload:latest
|
| 185 |
+
```
|
| 186 |
+
启动容器后访问:[http://localhost:5409](http://localhost:5409)
|
| 187 |
+
|
| 188 |
## 🐇项目背景
|
| 189 |
|
| 190 |
该项目最初是我个人用于自动化管理社交媒体视频发布的工具。我的主要发布策略是提前一天设置定时发布,因此项目中很多定时发布相关的逻辑是基于“第二天”的时间进行计算的。
|
conf.example.py
CHANGED
|
@@ -3,3 +3,4 @@ from pathlib import Path
|
|
| 3 |
BASE_DIR = Path(__file__).parent.resolve()
|
| 4 |
XHS_SERVER = "http://127.0.0.1:11901"
|
| 5 |
LOCAL_CHROME_PATH = "" # change me necessary! for example C:/Program Files/Google/Chrome/Application/chrome.exe
|
|
|
|
|
|
| 3 |
BASE_DIR = Path(__file__).parent.resolve()
|
| 4 |
XHS_SERVER = "http://127.0.0.1:11901"
|
| 5 |
LOCAL_CHROME_PATH = "" # change me necessary! for example C:/Program Files/Google/Chrome/Application/chrome.exe
|
| 6 |
+
LOCAL_CHROME_HEADLESS = True
|
myUtils/login.py
CHANGED
|
@@ -7,7 +7,7 @@ from myUtils.auth import check_cookie
|
|
| 7 |
from utils.base_social_media import set_init_script
|
| 8 |
import uuid
|
| 9 |
from pathlib import Path
|
| 10 |
-
from conf import BASE_DIR
|
| 11 |
|
| 12 |
# 抖音登录
|
| 13 |
async def douyin_cookie_gen(id,status_queue):
|
|
@@ -18,7 +18,7 @@ async def douyin_cookie_gen(id,status_queue):
|
|
| 18 |
url_changed_event.set()
|
| 19 |
async with async_playwright() as playwright:
|
| 20 |
options = {
|
| 21 |
-
'headless':
|
| 22 |
}
|
| 23 |
# Make sure to run headed.
|
| 24 |
browser = await playwright.chromium.launch(**options)
|
|
@@ -88,7 +88,7 @@ async def get_tencent_cookie(id,status_queue):
|
|
| 88 |
'args': [
|
| 89 |
'--lang en-GB'
|
| 90 |
],
|
| 91 |
-
'headless':
|
| 92 |
}
|
| 93 |
# Make sure to run headed.
|
| 94 |
browser = await playwright.chromium.launch(**options)
|
|
@@ -165,7 +165,7 @@ async def get_ks_cookie(id,status_queue):
|
|
| 165 |
'args': [
|
| 166 |
'--lang en-GB'
|
| 167 |
],
|
| 168 |
-
'headless':
|
| 169 |
}
|
| 170 |
# Make sure to run headed.
|
| 171 |
browser = await playwright.chromium.launch(**options)
|
|
@@ -241,7 +241,7 @@ async def xiaohongshu_cookie_gen(id,status_queue):
|
|
| 241 |
'args': [
|
| 242 |
'--lang en-GB'
|
| 243 |
],
|
| 244 |
-
'headless':
|
| 245 |
}
|
| 246 |
# Make sure to run headed.
|
| 247 |
browser = await playwright.chromium.launch(**options)
|
|
|
|
| 7 |
from utils.base_social_media import set_init_script
|
| 8 |
import uuid
|
| 9 |
from pathlib import Path
|
| 10 |
+
from conf import BASE_DIR, LOCAL_CHROME_HEADLESS
|
| 11 |
|
| 12 |
# 抖音登录
|
| 13 |
async def douyin_cookie_gen(id,status_queue):
|
|
|
|
| 18 |
url_changed_event.set()
|
| 19 |
async with async_playwright() as playwright:
|
| 20 |
options = {
|
| 21 |
+
'headless': LOCAL_CHROME_HEADLESS
|
| 22 |
}
|
| 23 |
# Make sure to run headed.
|
| 24 |
browser = await playwright.chromium.launch(**options)
|
|
|
|
| 88 |
'args': [
|
| 89 |
'--lang en-GB'
|
| 90 |
],
|
| 91 |
+
'headless': LOCAL_CHROME_HEADLESS, # Set headless option here
|
| 92 |
}
|
| 93 |
# Make sure to run headed.
|
| 94 |
browser = await playwright.chromium.launch(**options)
|
|
|
|
| 165 |
'args': [
|
| 166 |
'--lang en-GB'
|
| 167 |
],
|
| 168 |
+
'headless': LOCAL_CHROME_HEADLESS, # Set headless option here
|
| 169 |
}
|
| 170 |
# Make sure to run headed.
|
| 171 |
browser = await playwright.chromium.launch(**options)
|
|
|
|
| 241 |
'args': [
|
| 242 |
'--lang en-GB'
|
| 243 |
],
|
| 244 |
+
'headless': LOCAL_CHROME_HEADLESS, # Set headless option here
|
| 245 |
}
|
| 246 |
# Make sure to run headed.
|
| 247 |
browser = await playwright.chromium.launch(**options)
|
sau_backend.py
CHANGED
|
@@ -37,8 +37,8 @@ def favicon(filename):
|
|
| 37 |
|
| 38 |
# (未来打包用)
|
| 39 |
@app.route('/')
|
| 40 |
-
def
|
| 41 |
-
return
|
| 42 |
|
| 43 |
@app.route('/upload', methods=['POST'])
|
| 44 |
def upload_file():
|
|
|
|
| 37 |
|
| 38 |
# (未来打包用)
|
| 39 |
@app.route('/')
|
| 40 |
+
def index(): # put application's code here
|
| 41 |
+
return send_from_directory(current_dir, 'index.html')
|
| 42 |
|
| 43 |
@app.route('/upload', methods=['POST'])
|
| 44 |
def upload_file():
|
uploader/baijiahao_uploader/main.py
CHANGED
|
@@ -7,7 +7,7 @@ import os
|
|
| 7 |
import time
|
| 8 |
import asyncio
|
| 9 |
|
| 10 |
-
from conf import LOCAL_CHROME_PATH
|
| 11 |
from utils.base_social_media import set_init_script
|
| 12 |
from utils.log import baijiahao_logger
|
| 13 |
from utils.network import async_retry
|
|
@@ -19,7 +19,7 @@ async def baijiahao_cookie_gen(account_file):
|
|
| 19 |
'args': [
|
| 20 |
'--lang en-GB'
|
| 21 |
],
|
| 22 |
-
'headless':
|
| 23 |
}
|
| 24 |
# Make sure to run headed.
|
| 25 |
browser = await playwright.chromium.launch(**options)
|
|
@@ -37,7 +37,7 @@ async def baijiahao_cookie_gen(account_file):
|
|
| 37 |
|
| 38 |
async def cookie_auth(account_file):
|
| 39 |
async with async_playwright() as playwright:
|
| 40 |
-
browser = await playwright.chromium.launch(headless=
|
| 41 |
context = await browser.new_context(storage_state=account_file)
|
| 42 |
context = await set_init_script(context)
|
| 43 |
# 创建一个新的页面
|
|
@@ -71,6 +71,7 @@ class BaiJiaHaoVideo(object):
|
|
| 71 |
self.account_file = account_file
|
| 72 |
self.date_format = '%Y年%m月%d日 %H:%M'
|
| 73 |
self.local_executable_path = LOCAL_CHROME_PATH
|
|
|
|
| 74 |
self.proxy_setting = proxy_setting
|
| 75 |
|
| 76 |
async def set_schedule_time(self, page, publish_date):
|
|
@@ -119,7 +120,7 @@ class BaiJiaHaoVideo(object):
|
|
| 119 |
|
| 120 |
async def upload(self, playwright: Playwright) -> None:
|
| 121 |
# 使用 Chromium 浏览器启动一个浏览器实例
|
| 122 |
-
browser = await playwright.chromium.launch(headless=
|
| 123 |
# 创建一个浏览器上下文,使用指定的 cookie 文件
|
| 124 |
context = await browser.new_context(storage_state=f"{self.account_file}", user_agent='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.4324.150 Safari/537.36')
|
| 125 |
# context = await set_init_script(context)
|
|
@@ -252,7 +253,7 @@ class BaiJiaHaoVideo(object):
|
|
| 252 |
# 使用 AI成片 功能
|
| 253 |
async def ai2video(self, playwright: Playwright) -> None:
|
| 254 |
# 使用 Chromium 浏览器启动一个浏览器实例
|
| 255 |
-
browser = await playwright.chromium.launch(headless=
|
| 256 |
# 创建一个浏览器上下文,使用指定的 cookie 文件
|
| 257 |
context = await browser.new_context(
|
| 258 |
viewport={"width": 1600, "height": 900},
|
|
|
|
| 7 |
import time
|
| 8 |
import asyncio
|
| 9 |
|
| 10 |
+
from conf import LOCAL_CHROME_PATH, LOCAL_CHROME_HEADLESS
|
| 11 |
from utils.base_social_media import set_init_script
|
| 12 |
from utils.log import baijiahao_logger
|
| 13 |
from utils.network import async_retry
|
|
|
|
| 19 |
'args': [
|
| 20 |
'--lang en-GB'
|
| 21 |
],
|
| 22 |
+
'headless': LOCAL_CHROME_HEADLESS, # Set headless option here
|
| 23 |
}
|
| 24 |
# Make sure to run headed.
|
| 25 |
browser = await playwright.chromium.launch(**options)
|
|
|
|
| 37 |
|
| 38 |
async def cookie_auth(account_file):
|
| 39 |
async with async_playwright() as playwright:
|
| 40 |
+
browser = await playwright.chromium.launch(headless=LOCAL_CHROME_HEADLESS)
|
| 41 |
context = await browser.new_context(storage_state=account_file)
|
| 42 |
context = await set_init_script(context)
|
| 43 |
# 创建一个新的页面
|
|
|
|
| 71 |
self.account_file = account_file
|
| 72 |
self.date_format = '%Y年%m月%d日 %H:%M'
|
| 73 |
self.local_executable_path = LOCAL_CHROME_PATH
|
| 74 |
+
self.headless = LOCAL_CHROME_HEADLESS
|
| 75 |
self.proxy_setting = proxy_setting
|
| 76 |
|
| 77 |
async def set_schedule_time(self, page, publish_date):
|
|
|
|
| 120 |
|
| 121 |
async def upload(self, playwright: Playwright) -> None:
|
| 122 |
# 使用 Chromium 浏览器启动一个浏览器实例
|
| 123 |
+
browser = await playwright.chromium.launch(headless=self.headless, executable_path=self.local_executable_path, proxy=self.proxy_setting)
|
| 124 |
# 创建一个浏览器上下文,使用指定的 cookie 文件
|
| 125 |
context = await browser.new_context(storage_state=f"{self.account_file}", user_agent='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.4324.150 Safari/537.36')
|
| 126 |
# context = await set_init_script(context)
|
|
|
|
| 253 |
# 使用 AI成片 功能
|
| 254 |
async def ai2video(self, playwright: Playwright) -> None:
|
| 255 |
# 使用 Chromium 浏览器启动一个浏览器实例
|
| 256 |
+
browser = await playwright.chromium.launch(headless=self.headless, executable_path=self.local_executable_path, proxy=self.proxy_setting)
|
| 257 |
# 创建一个浏览器上下文,使用指定的 cookie 文件
|
| 258 |
context = await browser.new_context(
|
| 259 |
viewport={"width": 1600, "height": 900},
|
uploader/douyin_uploader/main.py
CHANGED
|
@@ -5,14 +5,14 @@ from playwright.async_api import Playwright, async_playwright, Page
|
|
| 5 |
import os
|
| 6 |
import asyncio
|
| 7 |
|
| 8 |
-
from conf import LOCAL_CHROME_PATH
|
| 9 |
from utils.base_social_media import set_init_script
|
| 10 |
from utils.log import douyin_logger
|
| 11 |
|
| 12 |
|
| 13 |
async def cookie_auth(account_file):
|
| 14 |
async with async_playwright() as playwright:
|
| 15 |
-
browser = await playwright.chromium.launch(headless=
|
| 16 |
context = await browser.new_context(storage_state=account_file)
|
| 17 |
context = await set_init_script(context)
|
| 18 |
# 创建一个新的页面
|
|
@@ -48,7 +48,7 @@ async def douyin_setup(account_file, handle=False):
|
|
| 48 |
async def douyin_cookie_gen(account_file):
|
| 49 |
async with async_playwright() as playwright:
|
| 50 |
options = {
|
| 51 |
-
'headless':
|
| 52 |
}
|
| 53 |
# Make sure to run headed.
|
| 54 |
browser = await playwright.chromium.launch(**options)
|
|
@@ -72,6 +72,7 @@ class DouYinVideo(object):
|
|
| 72 |
self.account_file = account_file
|
| 73 |
self.date_format = '%Y年%m月%d日 %H:%M'
|
| 74 |
self.local_executable_path = LOCAL_CHROME_PATH
|
|
|
|
| 75 |
self.thumbnail_path = thumbnail_path
|
| 76 |
self.productLink = productLink
|
| 77 |
self.productTitle = productTitle
|
|
@@ -99,9 +100,9 @@ class DouYinVideo(object):
|
|
| 99 |
async def upload(self, playwright: Playwright) -> None:
|
| 100 |
# 使用 Chromium 浏览器启动一个浏览器实例
|
| 101 |
if self.local_executable_path:
|
| 102 |
-
browser = await playwright.chromium.launch(headless=
|
| 103 |
else:
|
| 104 |
-
browser = await playwright.chromium.launch(headless=
|
| 105 |
# 创建一个浏览器上下文,使用指定的 cookie 文件
|
| 106 |
context = await browser.new_context(storage_state=f"{self.account_file}")
|
| 107 |
context = await set_init_script(context)
|
|
|
|
| 5 |
import os
|
| 6 |
import asyncio
|
| 7 |
|
| 8 |
+
from conf import LOCAL_CHROME_PATH, LOCAL_CHROME_HEADLESS
|
| 9 |
from utils.base_social_media import set_init_script
|
| 10 |
from utils.log import douyin_logger
|
| 11 |
|
| 12 |
|
| 13 |
async def cookie_auth(account_file):
|
| 14 |
async with async_playwright() as playwright:
|
| 15 |
+
browser = await playwright.chromium.launch(headless=LOCAL_CHROME_HEADLESS)
|
| 16 |
context = await browser.new_context(storage_state=account_file)
|
| 17 |
context = await set_init_script(context)
|
| 18 |
# 创建一个新的页面
|
|
|
|
| 48 |
async def douyin_cookie_gen(account_file):
|
| 49 |
async with async_playwright() as playwright:
|
| 50 |
options = {
|
| 51 |
+
'headless': LOCAL_CHROME_HEADLESS
|
| 52 |
}
|
| 53 |
# Make sure to run headed.
|
| 54 |
browser = await playwright.chromium.launch(**options)
|
|
|
|
| 72 |
self.account_file = account_file
|
| 73 |
self.date_format = '%Y年%m月%d日 %H:%M'
|
| 74 |
self.local_executable_path = LOCAL_CHROME_PATH
|
| 75 |
+
self.headless = LOCAL_CHROME_HEADLESS
|
| 76 |
self.thumbnail_path = thumbnail_path
|
| 77 |
self.productLink = productLink
|
| 78 |
self.productTitle = productTitle
|
|
|
|
| 100 |
async def upload(self, playwright: Playwright) -> None:
|
| 101 |
# 使用 Chromium 浏览器启动一个浏览器实例
|
| 102 |
if self.local_executable_path:
|
| 103 |
+
browser = await playwright.chromium.launch(headless=self.headless, executable_path=self.local_executable_path)
|
| 104 |
else:
|
| 105 |
+
browser = await playwright.chromium.launch(headless=self.headless)
|
| 106 |
# 创建一个浏览器上下文,使用指定的 cookie 文件
|
| 107 |
context = await browser.new_context(storage_state=f"{self.account_file}")
|
| 108 |
context = await set_init_script(context)
|
uploader/ks_uploader/main.py
CHANGED
|
@@ -5,7 +5,7 @@ from playwright.async_api import Playwright, async_playwright
|
|
| 5 |
import os
|
| 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 |
from utils.log import kuaishou_logger
|
|
@@ -13,7 +13,7 @@ from utils.log import kuaishou_logger
|
|
| 13 |
|
| 14 |
async def cookie_auth(account_file):
|
| 15 |
async with async_playwright() as playwright:
|
| 16 |
-
browser = await playwright.chromium.launch(headless=
|
| 17 |
context = await browser.new_context(storage_state=account_file)
|
| 18 |
context = await set_init_script(context)
|
| 19 |
# 创建一个新的页面
|
|
@@ -46,7 +46,7 @@ async def get_ks_cookie(account_file):
|
|
| 46 |
'args': [
|
| 47 |
'--lang en-GB'
|
| 48 |
],
|
| 49 |
-
'headless':
|
| 50 |
}
|
| 51 |
# Make sure to run headed.
|
| 52 |
browser = await playwright.chromium.launch(**options)
|
|
@@ -70,6 +70,7 @@ class KSVideo(object):
|
|
| 70 |
self.account_file = account_file
|
| 71 |
self.date_format = '%Y-%m-%d %H:%M'
|
| 72 |
self.local_executable_path = LOCAL_CHROME_PATH
|
|
|
|
| 73 |
|
| 74 |
async def handle_upload_error(self, page):
|
| 75 |
kuaishou_logger.error("视频出错了,重新上传中")
|
|
@@ -80,12 +81,12 @@ class KSVideo(object):
|
|
| 80 |
print(self.local_executable_path)
|
| 81 |
if self.local_executable_path:
|
| 82 |
browser = await playwright.chromium.launch(
|
| 83 |
-
headless=
|
| 84 |
executable_path=self.local_executable_path,
|
| 85 |
)
|
| 86 |
else:
|
| 87 |
browser = await playwright.chromium.launch(
|
| 88 |
-
headless=
|
| 89 |
) # 创建一个浏览器上下文,使用指定的 cookie 文件
|
| 90 |
context = await browser.new_context(storage_state=f"{self.account_file}")
|
| 91 |
context = await set_init_script(context)
|
|
|
|
| 5 |
import os
|
| 6 |
import asyncio
|
| 7 |
|
| 8 |
+
from conf import LOCAL_CHROME_PATH, LOCAL_CHROME_HEADLESS
|
| 9 |
from utils.base_social_media import set_init_script
|
| 10 |
from utils.files_times import get_absolute_path
|
| 11 |
from utils.log import kuaishou_logger
|
|
|
|
| 13 |
|
| 14 |
async def cookie_auth(account_file):
|
| 15 |
async with async_playwright() as playwright:
|
| 16 |
+
browser = await playwright.chromium.launch(headless=LOCAL_CHROME_HEADLESS)
|
| 17 |
context = await browser.new_context(storage_state=account_file)
|
| 18 |
context = await set_init_script(context)
|
| 19 |
# 创建一个新的页面
|
|
|
|
| 46 |
'args': [
|
| 47 |
'--lang en-GB'
|
| 48 |
],
|
| 49 |
+
'headless': LOCAL_CHROME_HEADLESS, # Set headless option here
|
| 50 |
}
|
| 51 |
# Make sure to run headed.
|
| 52 |
browser = await playwright.chromium.launch(**options)
|
|
|
|
| 70 |
self.account_file = account_file
|
| 71 |
self.date_format = '%Y-%m-%d %H:%M'
|
| 72 |
self.local_executable_path = LOCAL_CHROME_PATH
|
| 73 |
+
self.headless = LOCAL_CHROME_HEADLESS
|
| 74 |
|
| 75 |
async def handle_upload_error(self, page):
|
| 76 |
kuaishou_logger.error("视频出错了,重新上传中")
|
|
|
|
| 81 |
print(self.local_executable_path)
|
| 82 |
if self.local_executable_path:
|
| 83 |
browser = await playwright.chromium.launch(
|
| 84 |
+
headless=self.headless,
|
| 85 |
executable_path=self.local_executable_path,
|
| 86 |
)
|
| 87 |
else:
|
| 88 |
browser = await playwright.chromium.launch(
|
| 89 |
+
headless=self.headless
|
| 90 |
) # 创建一个浏览器上下文,使用指定的 cookie 文件
|
| 91 |
context = await browser.new_context(storage_state=f"{self.account_file}")
|
| 92 |
context = await set_init_script(context)
|
uploader/tencent_uploader/main.py
CHANGED
|
@@ -5,7 +5,7 @@ from playwright.async_api import Playwright, async_playwright
|
|
| 5 |
import os
|
| 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 |
from utils.log import tencent_logger
|
|
@@ -33,7 +33,7 @@ def format_str_for_short_title(origin_title: str) -> str:
|
|
| 33 |
|
| 34 |
async def cookie_auth(account_file):
|
| 35 |
async with async_playwright() as playwright:
|
| 36 |
-
browser = await playwright.chromium.launch(headless=
|
| 37 |
context = await browser.new_context(storage_state=account_file)
|
| 38 |
context = await set_init_script(context)
|
| 39 |
# 创建一个新的页面
|
|
@@ -55,7 +55,7 @@ async def get_tencent_cookie(account_file):
|
|
| 55 |
'args': [
|
| 56 |
'--lang en-GB'
|
| 57 |
],
|
| 58 |
-
'headless':
|
| 59 |
}
|
| 60 |
# Make sure to run headed.
|
| 61 |
browser = await playwright.chromium.launch(**options)
|
|
@@ -90,6 +90,7 @@ class TencentVideo(object):
|
|
| 90 |
self.account_file = account_file
|
| 91 |
self.category = category
|
| 92 |
self.local_executable_path = LOCAL_CHROME_PATH
|
|
|
|
| 93 |
|
| 94 |
async def set_schedule_time_tencent(self, page, publish_date):
|
| 95 |
label_element = page.locator("label").filter(has_text="定时").nth(1)
|
|
@@ -135,7 +136,7 @@ class TencentVideo(object):
|
|
| 135 |
|
| 136 |
async def upload(self, playwright: Playwright) -> None:
|
| 137 |
# 使用 Chromium (这里使用系统内浏览器,用chromium 会造成h264错误
|
| 138 |
-
browser = await playwright.chromium.launch(headless=
|
| 139 |
# 创建一个浏览器上下文,使用指定的 cookie 文件
|
| 140 |
context = await browser.new_context(storage_state=f"{self.account_file}")
|
| 141 |
context = await set_init_script(context)
|
|
|
|
| 5 |
import os
|
| 6 |
import asyncio
|
| 7 |
|
| 8 |
+
from conf import LOCAL_CHROME_PATH, LOCAL_CHROME_HEADLESS
|
| 9 |
from utils.base_social_media import set_init_script
|
| 10 |
from utils.files_times import get_absolute_path
|
| 11 |
from utils.log import tencent_logger
|
|
|
|
| 33 |
|
| 34 |
async def cookie_auth(account_file):
|
| 35 |
async with async_playwright() as playwright:
|
| 36 |
+
browser = await playwright.chromium.launch(headless=LOCAL_CHROME_HEADLESS)
|
| 37 |
context = await browser.new_context(storage_state=account_file)
|
| 38 |
context = await set_init_script(context)
|
| 39 |
# 创建一个新的页面
|
|
|
|
| 55 |
'args': [
|
| 56 |
'--lang en-GB'
|
| 57 |
],
|
| 58 |
+
'headless': LOCAL_CHROME_HEADLESS, # Set headless option here
|
| 59 |
}
|
| 60 |
# Make sure to run headed.
|
| 61 |
browser = await playwright.chromium.launch(**options)
|
|
|
|
| 90 |
self.account_file = account_file
|
| 91 |
self.category = category
|
| 92 |
self.local_executable_path = LOCAL_CHROME_PATH
|
| 93 |
+
self.headless = LOCAL_CHROME_HEADLESS
|
| 94 |
|
| 95 |
async def set_schedule_time_tencent(self, page, publish_date):
|
| 96 |
label_element = page.locator("label").filter(has_text="定时").nth(1)
|
|
|
|
| 136 |
|
| 137 |
async def upload(self, playwright: Playwright) -> None:
|
| 138 |
# 使用 Chromium (这里使用系统内浏览器,用chromium 会造成h264错误
|
| 139 |
+
browser = await playwright.chromium.launch(headless=self.headless, 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)
|
uploader/tk_uploader/main.py
CHANGED
|
@@ -9,11 +9,12 @@ from uploader.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 |
from utils.log import tiktok_logger
|
|
|
|
| 12 |
|
| 13 |
|
| 14 |
async def cookie_auth(account_file):
|
| 15 |
async with async_playwright() as playwright:
|
| 16 |
-
browser = await playwright.firefox.launch(headless=
|
| 17 |
context = await browser.new_context(storage_state=account_file)
|
| 18 |
context = await set_init_script(context)
|
| 19 |
# 创建一个新的页面
|
|
@@ -53,7 +54,7 @@ async def get_tiktok_cookie(account_file):
|
|
| 53 |
'args': [
|
| 54 |
'--lang en-GB',
|
| 55 |
],
|
| 56 |
-
'headless':
|
| 57 |
}
|
| 58 |
# Make sure to run headed.
|
| 59 |
browser = await playwright.firefox.launch(**options)
|
|
@@ -75,6 +76,7 @@ class TiktokVideo(object):
|
|
| 75 |
self.tags = tags
|
| 76 |
self.publish_date = publish_date
|
| 77 |
self.account_file = account_file
|
|
|
|
| 78 |
self.locator_base = None
|
| 79 |
|
| 80 |
|
|
@@ -140,7 +142,7 @@ class TiktokVideo(object):
|
|
| 140 |
await file_chooser.set_files(self.file_path)
|
| 141 |
|
| 142 |
async def upload(self, playwright: Playwright) -> None:
|
| 143 |
-
browser = await playwright.firefox.launch(headless=
|
| 144 |
context = await browser.new_context(storage_state=f"{self.account_file}")
|
| 145 |
context = await set_init_script(context)
|
| 146 |
page = await context.new_page()
|
|
|
|
| 9 |
from utils.base_social_media import set_init_script
|
| 10 |
from utils.files_times import get_absolute_path
|
| 11 |
from utils.log import tiktok_logger
|
| 12 |
+
from conf import LOCAL_CHROME_HEADLESS
|
| 13 |
|
| 14 |
|
| 15 |
async def cookie_auth(account_file):
|
| 16 |
async with async_playwright() as playwright:
|
| 17 |
+
browser = await playwright.firefox.launch(headless=LOCAL_CHROME_HEADLESS)
|
| 18 |
context = await browser.new_context(storage_state=account_file)
|
| 19 |
context = await set_init_script(context)
|
| 20 |
# 创建一个新的页面
|
|
|
|
| 54 |
'args': [
|
| 55 |
'--lang en-GB',
|
| 56 |
],
|
| 57 |
+
'headless': LOCAL_CHROME_HEADLESS, # Set headless option here
|
| 58 |
}
|
| 59 |
# Make sure to run headed.
|
| 60 |
browser = await playwright.firefox.launch(**options)
|
|
|
|
| 76 |
self.tags = tags
|
| 77 |
self.publish_date = publish_date
|
| 78 |
self.account_file = account_file
|
| 79 |
+
self.headless = LOCAL_CHROME_HEADLESS
|
| 80 |
self.locator_base = None
|
| 81 |
|
| 82 |
|
|
|
|
| 142 |
await file_chooser.set_files(self.file_path)
|
| 143 |
|
| 144 |
async def upload(self, playwright: Playwright) -> None:
|
| 145 |
+
browser = await playwright.firefox.launch(headless=self.headless)
|
| 146 |
context = await browser.new_context(storage_state=f"{self.account_file}")
|
| 147 |
context = await set_init_script(context)
|
| 148 |
page = await context.new_page()
|
uploader/tk_uploader/main_chrome.py
CHANGED
|
@@ -6,7 +6,7 @@ from playwright.async_api import Playwright, async_playwright
|
|
| 6 |
import os
|
| 7 |
import asyncio
|
| 8 |
|
| 9 |
-
from conf import LOCAL_CHROME_PATH
|
| 10 |
from uploader.tk_uploader.tk_config import Tk_Locator
|
| 11 |
from utils.base_social_media import set_init_script
|
| 12 |
from utils.files_times import get_absolute_path
|
|
@@ -15,7 +15,7 @@ from utils.log import tiktok_logger
|
|
| 15 |
|
| 16 |
async def cookie_auth(account_file):
|
| 17 |
async with async_playwright() as playwright:
|
| 18 |
-
browser = await playwright.chromium.launch(headless=
|
| 19 |
context = await browser.new_context(storage_state=account_file)
|
| 20 |
context = await set_init_script(context)
|
| 21 |
# 创建一个新的页面
|
|
@@ -55,7 +55,7 @@ async def get_tiktok_cookie(account_file):
|
|
| 55 |
'args': [
|
| 56 |
'--lang en-GB',
|
| 57 |
],
|
| 58 |
-
'headless':
|
| 59 |
}
|
| 60 |
# Make sure to run headed.
|
| 61 |
browser = await playwright.chromium.launch(**options)
|
|
@@ -79,6 +79,7 @@ class TiktokVideo(object):
|
|
| 79 |
self.thumbnail_path = thumbnail_path
|
| 80 |
self.account_file = account_file
|
| 81 |
self.local_executable_path = LOCAL_CHROME_PATH
|
|
|
|
| 82 |
self.locator_base = None
|
| 83 |
|
| 84 |
async def set_schedule_time(self, page, publish_date):
|
|
@@ -146,7 +147,7 @@ class TiktokVideo(object):
|
|
| 146 |
await file_chooser.set_files(self.file_path)
|
| 147 |
|
| 148 |
async def upload(self, playwright: Playwright) -> None:
|
| 149 |
-
browser = await playwright.chromium.launch(headless=
|
| 150 |
context = await browser.new_context(storage_state=f"{self.account_file}")
|
| 151 |
# context = await set_init_script(context)
|
| 152 |
page = await context.new_page()
|
|
|
|
| 6 |
import os
|
| 7 |
import asyncio
|
| 8 |
|
| 9 |
+
from conf import LOCAL_CHROME_PATH, LOCAL_CHROME_HEADLESS
|
| 10 |
from uploader.tk_uploader.tk_config import Tk_Locator
|
| 11 |
from utils.base_social_media import set_init_script
|
| 12 |
from utils.files_times import get_absolute_path
|
|
|
|
| 15 |
|
| 16 |
async def cookie_auth(account_file):
|
| 17 |
async with async_playwright() as playwright:
|
| 18 |
+
browser = await playwright.chromium.launch(headless=LOCAL_CHROME_HEADLESS)
|
| 19 |
context = await browser.new_context(storage_state=account_file)
|
| 20 |
context = await set_init_script(context)
|
| 21 |
# 创建一个新的页面
|
|
|
|
| 55 |
'args': [
|
| 56 |
'--lang en-GB',
|
| 57 |
],
|
| 58 |
+
'headless': LOCAL_CHROME_HEADLESS, # Set headless option here
|
| 59 |
}
|
| 60 |
# Make sure to run headed.
|
| 61 |
browser = await playwright.chromium.launch(**options)
|
|
|
|
| 79 |
self.thumbnail_path = thumbnail_path
|
| 80 |
self.account_file = account_file
|
| 81 |
self.local_executable_path = LOCAL_CHROME_PATH
|
| 82 |
+
self.headless = LOCAL_CHROME_HEADLESS
|
| 83 |
self.locator_base = None
|
| 84 |
|
| 85 |
async def set_schedule_time(self, page, publish_date):
|
|
|
|
| 147 |
await file_chooser.set_files(self.file_path)
|
| 148 |
|
| 149 |
async def upload(self, playwright: Playwright) -> None:
|
| 150 |
+
browser = await playwright.chromium.launch(headless=self.headless, executable_path=self.local_executable_path)
|
| 151 |
context = await browser.new_context(storage_state=f"{self.account_file}")
|
| 152 |
# context = await set_init_script(context)
|
| 153 |
page = await context.new_page()
|
uploader/xhs_uploader/main.py
CHANGED
|
@@ -6,7 +6,7 @@ from time import sleep
|
|
| 6 |
import requests
|
| 7 |
from playwright.sync_api import sync_playwright
|
| 8 |
|
| 9 |
-
from conf import BASE_DIR, XHS_SERVER
|
| 10 |
|
| 11 |
config = configparser.RawConfigParser()
|
| 12 |
config.read('accounts.ini')
|
|
@@ -20,7 +20,7 @@ def sign_local(uri, data=None, a1="", web_session=""):
|
|
| 20 |
chromium = playwright.chromium
|
| 21 |
|
| 22 |
# 如果一直失败可尝试设置成 False 让其打开浏览器,适当添加 sleep 可查看浏览器状态
|
| 23 |
-
browser = chromium.launch(headless=
|
| 24 |
|
| 25 |
browser_context = browser.new_context()
|
| 26 |
browser_context.add_init_script(path=stealth_js_path)
|
|
|
|
| 6 |
import requests
|
| 7 |
from playwright.sync_api import sync_playwright
|
| 8 |
|
| 9 |
+
from conf import BASE_DIR, XHS_SERVER, LOCAL_CHROME_HEADLESS
|
| 10 |
|
| 11 |
config = configparser.RawConfigParser()
|
| 12 |
config.read('accounts.ini')
|
|
|
|
| 20 |
chromium = playwright.chromium
|
| 21 |
|
| 22 |
# 如果一直失败可尝试设置成 False 让其打开浏览器,适当添加 sleep 可查看浏览器状态
|
| 23 |
+
browser = chromium.launch(headless=LOCAL_CHROME_HEADLESS)
|
| 24 |
|
| 25 |
browser_context = browser.new_context()
|
| 26 |
browser_context.add_init_script(path=stealth_js_path)
|
uploader/xiaohongshu_uploader/main.py
CHANGED
|
@@ -5,14 +5,14 @@ from playwright.async_api import Playwright, async_playwright, Page
|
|
| 5 |
import os
|
| 6 |
import asyncio
|
| 7 |
|
| 8 |
-
from conf import LOCAL_CHROME_PATH
|
| 9 |
from utils.base_social_media import set_init_script
|
| 10 |
from utils.log import xiaohongshu_logger
|
| 11 |
|
| 12 |
|
| 13 |
async def cookie_auth(account_file):
|
| 14 |
async with async_playwright() as playwright:
|
| 15 |
-
browser = await playwright.chromium.launch(headless=
|
| 16 |
context = await browser.new_context(storage_state=account_file)
|
| 17 |
context = await set_init_script(context)
|
| 18 |
# 创建一个新的页面
|
|
@@ -48,7 +48,7 @@ async def xiaohongshu_setup(account_file, handle=False):
|
|
| 48 |
async def xiaohongshu_cookie_gen(account_file):
|
| 49 |
async with async_playwright() as playwright:
|
| 50 |
options = {
|
| 51 |
-
'headless':
|
| 52 |
}
|
| 53 |
# Make sure to run headed.
|
| 54 |
browser = await playwright.chromium.launch(**options)
|
|
@@ -72,6 +72,7 @@ class XiaoHongShuVideo(object):
|
|
| 72 |
self.account_file = account_file
|
| 73 |
self.date_format = '%Y年%m月%d日 %H:%M'
|
| 74 |
self.local_executable_path = LOCAL_CHROME_PATH
|
|
|
|
| 75 |
self.thumbnail_path = thumbnail_path
|
| 76 |
|
| 77 |
async def set_schedule_time_xiaohongshu(self, page, publish_date):
|
|
@@ -108,9 +109,9 @@ class XiaoHongShuVideo(object):
|
|
| 108 |
async def upload(self, playwright: Playwright) -> None:
|
| 109 |
# 使用 Chromium 浏览器启动一个浏览器实例
|
| 110 |
if self.local_executable_path:
|
| 111 |
-
browser = await playwright.chromium.launch(headless=
|
| 112 |
else:
|
| 113 |
-
browser = await playwright.chromium.launch(headless=
|
| 114 |
# 创建一个浏览器上下文,使用指定的 cookie 文件
|
| 115 |
context = await browser.new_context(
|
| 116 |
viewport={"width": 1600, "height": 900},
|
|
|
|
| 5 |
import os
|
| 6 |
import asyncio
|
| 7 |
|
| 8 |
+
from conf import LOCAL_CHROME_PATH, LOCAL_CHROME_HEADLESS
|
| 9 |
from utils.base_social_media import set_init_script
|
| 10 |
from utils.log import xiaohongshu_logger
|
| 11 |
|
| 12 |
|
| 13 |
async def cookie_auth(account_file):
|
| 14 |
async with async_playwright() as playwright:
|
| 15 |
+
browser = await playwright.chromium.launch(headless=LOCAL_CHROME_HEADLESS)
|
| 16 |
context = await browser.new_context(storage_state=account_file)
|
| 17 |
context = await set_init_script(context)
|
| 18 |
# 创建一个新的页面
|
|
|
|
| 48 |
async def xiaohongshu_cookie_gen(account_file):
|
| 49 |
async with async_playwright() as playwright:
|
| 50 |
options = {
|
| 51 |
+
'headless': LOCAL_CHROME_HEADLESS
|
| 52 |
}
|
| 53 |
# Make sure to run headed.
|
| 54 |
browser = await playwright.chromium.launch(**options)
|
|
|
|
| 72 |
self.account_file = account_file
|
| 73 |
self.date_format = '%Y年%m月%d日 %H:%M'
|
| 74 |
self.local_executable_path = LOCAL_CHROME_PATH
|
| 75 |
+
self.headless = LOCAL_CHROME_HEADLESS
|
| 76 |
self.thumbnail_path = thumbnail_path
|
| 77 |
|
| 78 |
async def set_schedule_time_xiaohongshu(self, page, publish_date):
|
|
|
|
| 109 |
async def upload(self, playwright: Playwright) -> None:
|
| 110 |
# 使用 Chromium 浏览器启动一个浏览器实例
|
| 111 |
if self.local_executable_path:
|
| 112 |
+
browser = await playwright.chromium.launch(headless=self.headless, executable_path=self.local_executable_path)
|
| 113 |
else:
|
| 114 |
+
browser = await playwright.chromium.launch(headless=self.headless)
|
| 115 |
# 创建一个浏览器上下文,使用指定的 cookie 文件
|
| 116 |
context = await browser.new_context(
|
| 117 |
viewport={"width": 1600, "height": 900},
|