feat: 增加Docker容器环境

This commit is contained in:
听风
2025-11-06 14:50:19 +08:00
parent 7de1a30b92
commit de2389c9b1
14 changed files with 135 additions and 41 deletions
+6 -5
View File
@@ -7,7 +7,7 @@ import os
import time
import asyncio
from conf import LOCAL_CHROME_PATH
from conf import LOCAL_CHROME_PATH, LOCAL_CHROME_HEADLESS
from utils.base_social_media import set_init_script
from utils.log import baijiahao_logger
from utils.network import async_retry
@@ -19,7 +19,7 @@ async def baijiahao_cookie_gen(account_file):
'args': [
'--lang en-GB'
],
'headless': False, # Set headless option here
'headless': LOCAL_CHROME_HEADLESS, # Set headless option here
}
# Make sure to run headed.
browser = await playwright.chromium.launch(**options)
@@ -37,7 +37,7 @@ async def baijiahao_cookie_gen(account_file):
async def cookie_auth(account_file):
async with async_playwright() as playwright:
browser = await playwright.chromium.launch(headless=True)
browser = await playwright.chromium.launch(headless=LOCAL_CHROME_HEADLESS)
context = await browser.new_context(storage_state=account_file)
context = await set_init_script(context)
# 创建一个新的页面
@@ -71,6 +71,7 @@ class BaiJiaHaoVideo(object):
self.account_file = account_file
self.date_format = '%Y年%m月%d日 %H:%M'
self.local_executable_path = LOCAL_CHROME_PATH
self.headless = LOCAL_CHROME_HEADLESS
self.proxy_setting = proxy_setting
async def set_schedule_time(self, page, publish_date):
@@ -119,7 +120,7 @@ class BaiJiaHaoVideo(object):
async def upload(self, playwright: Playwright) -> None:
# 使用 Chromium 浏览器启动一个浏览器实例
browser = await playwright.chromium.launch(headless=False, executable_path=self.local_executable_path, proxy=self.proxy_setting)
browser = await playwright.chromium.launch(headless=self.headless, executable_path=self.local_executable_path, proxy=self.proxy_setting)
# 创建一个浏览器上下文,使用指定的 cookie 文件
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')
# context = await set_init_script(context)
@@ -252,7 +253,7 @@ class BaiJiaHaoVideo(object):
# 使用 AI成片 功能
async def ai2video(self, playwright: Playwright) -> None:
# 使用 Chromium 浏览器启动一个浏览器实例
browser = await playwright.chromium.launch(headless=False, executable_path=self.local_executable_path, proxy=self.proxy_setting)
browser = await playwright.chromium.launch(headless=self.headless, executable_path=self.local_executable_path, proxy=self.proxy_setting)
# 创建一个浏览器上下文,使用指定的 cookie 文件
context = await browser.new_context(
viewport={"width": 1600, "height": 900},
+6 -5
View File
@@ -5,14 +5,14 @@ from playwright.async_api import Playwright, async_playwright, Page
import os
import asyncio
from conf import LOCAL_CHROME_PATH
from conf import LOCAL_CHROME_PATH, LOCAL_CHROME_HEADLESS
from utils.base_social_media import set_init_script
from utils.log import douyin_logger
async def cookie_auth(account_file):
async with async_playwright() as playwright:
browser = await playwright.chromium.launch(headless=True)
browser = await playwright.chromium.launch(headless=LOCAL_CHROME_HEADLESS)
context = await browser.new_context(storage_state=account_file)
context = await set_init_script(context)
# 创建一个新的页面
@@ -48,7 +48,7 @@ async def douyin_setup(account_file, handle=False):
async def douyin_cookie_gen(account_file):
async with async_playwright() as playwright:
options = {
'headless': False
'headless': LOCAL_CHROME_HEADLESS
}
# Make sure to run headed.
browser = await playwright.chromium.launch(**options)
@@ -72,6 +72,7 @@ class DouYinVideo(object):
self.account_file = account_file
self.date_format = '%Y年%m月%d日 %H:%M'
self.local_executable_path = LOCAL_CHROME_PATH
self.headless = LOCAL_CHROME_HEADLESS
self.thumbnail_path = thumbnail_path
self.productLink = productLink
self.productTitle = productTitle
@@ -99,9 +100,9 @@ class DouYinVideo(object):
async def upload(self, playwright: Playwright) -> None:
# 使用 Chromium 浏览器启动一个浏览器实例
if self.local_executable_path:
browser = await playwright.chromium.launch(headless=False, executable_path=self.local_executable_path)
browser = await playwright.chromium.launch(headless=self.headless, executable_path=self.local_executable_path)
else:
browser = await playwright.chromium.launch(headless=False)
browser = await playwright.chromium.launch(headless=self.headless)
# 创建一个浏览器上下文,使用指定的 cookie 文件
context = await browser.new_context(storage_state=f"{self.account_file}")
context = await set_init_script(context)
+6 -5
View File
@@ -5,7 +5,7 @@ from playwright.async_api import Playwright, async_playwright
import os
import asyncio
from conf import LOCAL_CHROME_PATH
from conf import LOCAL_CHROME_PATH, LOCAL_CHROME_HEADLESS
from utils.base_social_media import set_init_script
from utils.files_times import get_absolute_path
from utils.log import kuaishou_logger
@@ -13,7 +13,7 @@ from utils.log import kuaishou_logger
async def cookie_auth(account_file):
async with async_playwright() as playwright:
browser = await playwright.chromium.launch(headless=True)
browser = await playwright.chromium.launch(headless=LOCAL_CHROME_HEADLESS)
context = await browser.new_context(storage_state=account_file)
context = await set_init_script(context)
# 创建一个新的页面
@@ -46,7 +46,7 @@ async def get_ks_cookie(account_file):
'args': [
'--lang en-GB'
],
'headless': False, # Set headless option here
'headless': LOCAL_CHROME_HEADLESS, # Set headless option here
}
# Make sure to run headed.
browser = await playwright.chromium.launch(**options)
@@ -70,6 +70,7 @@ class KSVideo(object):
self.account_file = account_file
self.date_format = '%Y-%m-%d %H:%M'
self.local_executable_path = LOCAL_CHROME_PATH
self.headless = LOCAL_CHROME_HEADLESS
async def handle_upload_error(self, page):
kuaishou_logger.error("视频出错了,重新上传中")
@@ -80,12 +81,12 @@ class KSVideo(object):
print(self.local_executable_path)
if self.local_executable_path:
browser = await playwright.chromium.launch(
headless=False,
headless=self.headless,
executable_path=self.local_executable_path,
)
else:
browser = await playwright.chromium.launch(
headless=False
headless=self.headless
) # 创建一个浏览器上下文,使用指定的 cookie 文件
context = await browser.new_context(storage_state=f"{self.account_file}")
context = await set_init_script(context)
+5 -4
View File
@@ -5,7 +5,7 @@ from playwright.async_api import Playwright, async_playwright
import os
import asyncio
from conf import LOCAL_CHROME_PATH
from conf import LOCAL_CHROME_PATH, LOCAL_CHROME_HEADLESS
from utils.base_social_media import set_init_script
from utils.files_times import get_absolute_path
from utils.log import tencent_logger
@@ -33,7 +33,7 @@ def format_str_for_short_title(origin_title: str) -> str:
async def cookie_auth(account_file):
async with async_playwright() as playwright:
browser = await playwright.chromium.launch(headless=True)
browser = await playwright.chromium.launch(headless=LOCAL_CHROME_HEADLESS)
context = await browser.new_context(storage_state=account_file)
context = await set_init_script(context)
# 创建一个新的页面
@@ -55,7 +55,7 @@ async def get_tencent_cookie(account_file):
'args': [
'--lang en-GB'
],
'headless': False, # Set headless option here
'headless': LOCAL_CHROME_HEADLESS, # Set headless option here
}
# Make sure to run headed.
browser = await playwright.chromium.launch(**options)
@@ -90,6 +90,7 @@ class TencentVideo(object):
self.account_file = account_file
self.category = category
self.local_executable_path = LOCAL_CHROME_PATH
self.headless = LOCAL_CHROME_HEADLESS
async def set_schedule_time_tencent(self, page, publish_date):
label_element = page.locator("label").filter(has_text="定时").nth(1)
@@ -135,7 +136,7 @@ class TencentVideo(object):
async def upload(self, playwright: Playwright) -> None:
# 使用 Chromium (这里使用系统内浏览器,用chromium 会造成h264错误
browser = await playwright.chromium.launch(headless=False, executable_path=self.local_executable_path)
browser = await playwright.chromium.launch(headless=self.headless, executable_path=self.local_executable_path)
# 创建一个浏览器上下文,使用指定的 cookie 文件
context = await browser.new_context(storage_state=f"{self.account_file}")
context = await set_init_script(context)
+5 -3
View File
@@ -9,11 +9,12 @@ from uploader.tk_uploader.tk_config import Tk_Locator
from utils.base_social_media import set_init_script
from utils.files_times import get_absolute_path
from utils.log import tiktok_logger
from conf import LOCAL_CHROME_HEADLESS
async def cookie_auth(account_file):
async with async_playwright() as playwright:
browser = await playwright.firefox.launch(headless=True)
browser = await playwright.firefox.launch(headless=LOCAL_CHROME_HEADLESS)
context = await browser.new_context(storage_state=account_file)
context = await set_init_script(context)
# 创建一个新的页面
@@ -53,7 +54,7 @@ async def get_tiktok_cookie(account_file):
'args': [
'--lang en-GB',
],
'headless': False, # Set headless option here
'headless': LOCAL_CHROME_HEADLESS, # Set headless option here
}
# Make sure to run headed.
browser = await playwright.firefox.launch(**options)
@@ -75,6 +76,7 @@ class TiktokVideo(object):
self.tags = tags
self.publish_date = publish_date
self.account_file = account_file
self.headless = LOCAL_CHROME_HEADLESS
self.locator_base = None
@@ -140,7 +142,7 @@ class TiktokVideo(object):
await file_chooser.set_files(self.file_path)
async def upload(self, playwright: Playwright) -> None:
browser = await playwright.firefox.launch(headless=False)
browser = await playwright.firefox.launch(headless=self.headless)
context = await browser.new_context(storage_state=f"{self.account_file}")
context = await set_init_script(context)
page = await context.new_page()
+5 -4
View File
@@ -6,7 +6,7 @@ from playwright.async_api import Playwright, async_playwright
import os
import asyncio
from conf import LOCAL_CHROME_PATH
from conf import LOCAL_CHROME_PATH, LOCAL_CHROME_HEADLESS
from uploader.tk_uploader.tk_config import Tk_Locator
from utils.base_social_media import set_init_script
from utils.files_times import get_absolute_path
@@ -15,7 +15,7 @@ from utils.log import tiktok_logger
async def cookie_auth(account_file):
async with async_playwright() as playwright:
browser = await playwright.chromium.launch(headless=True)
browser = await playwright.chromium.launch(headless=LOCAL_CHROME_HEADLESS)
context = await browser.new_context(storage_state=account_file)
context = await set_init_script(context)
# 创建一个新的页面
@@ -55,7 +55,7 @@ async def get_tiktok_cookie(account_file):
'args': [
'--lang en-GB',
],
'headless': False, # Set headless option here
'headless': LOCAL_CHROME_HEADLESS, # Set headless option here
}
# Make sure to run headed.
browser = await playwright.chromium.launch(**options)
@@ -79,6 +79,7 @@ class TiktokVideo(object):
self.thumbnail_path = thumbnail_path
self.account_file = account_file
self.local_executable_path = LOCAL_CHROME_PATH
self.headless = LOCAL_CHROME_HEADLESS
self.locator_base = None
async def set_schedule_time(self, page, publish_date):
@@ -146,7 +147,7 @@ class TiktokVideo(object):
await file_chooser.set_files(self.file_path)
async def upload(self, playwright: Playwright) -> None:
browser = await playwright.chromium.launch(headless=False, executable_path=self.local_executable_path)
browser = await playwright.chromium.launch(headless=self.headless, executable_path=self.local_executable_path)
context = await browser.new_context(storage_state=f"{self.account_file}")
# context = await set_init_script(context)
page = await context.new_page()
+2 -2
View File
@@ -6,7 +6,7 @@ from time import sleep
import requests
from playwright.sync_api import sync_playwright
from conf import BASE_DIR, XHS_SERVER
from conf import BASE_DIR, XHS_SERVER, LOCAL_CHROME_HEADLESS
config = configparser.RawConfigParser()
config.read('accounts.ini')
@@ -20,7 +20,7 @@ def sign_local(uri, data=None, a1="", web_session=""):
chromium = playwright.chromium
# 如果一直失败可尝试设置成 False 让其打开浏览器,适当添加 sleep 可查看浏览器状态
browser = chromium.launch(headless=True)
browser = chromium.launch(headless=LOCAL_CHROME_HEADLESS)
browser_context = browser.new_context()
browser_context.add_init_script(path=stealth_js_path)
+6 -5
View File
@@ -5,14 +5,14 @@ from playwright.async_api import Playwright, async_playwright, Page
import os
import asyncio
from conf import LOCAL_CHROME_PATH
from conf import LOCAL_CHROME_PATH, LOCAL_CHROME_HEADLESS
from utils.base_social_media import set_init_script
from utils.log import xiaohongshu_logger
async def cookie_auth(account_file):
async with async_playwright() as playwright:
browser = await playwright.chromium.launch(headless=True)
browser = await playwright.chromium.launch(headless=LOCAL_CHROME_HEADLESS)
context = await browser.new_context(storage_state=account_file)
context = await set_init_script(context)
# 创建一个新的页面
@@ -48,7 +48,7 @@ async def xiaohongshu_setup(account_file, handle=False):
async def xiaohongshu_cookie_gen(account_file):
async with async_playwright() as playwright:
options = {
'headless': False
'headless': LOCAL_CHROME_HEADLESS
}
# Make sure to run headed.
browser = await playwright.chromium.launch(**options)
@@ -72,6 +72,7 @@ class XiaoHongShuVideo(object):
self.account_file = account_file
self.date_format = '%Y年%m月%d日 %H:%M'
self.local_executable_path = LOCAL_CHROME_PATH
self.headless = LOCAL_CHROME_HEADLESS
self.thumbnail_path = thumbnail_path
async def set_schedule_time_xiaohongshu(self, page, publish_date):
@@ -108,9 +109,9 @@ class XiaoHongShuVideo(object):
async def upload(self, playwright: Playwright) -> None:
# 使用 Chromium 浏览器启动一个浏览器实例
if self.local_executable_path:
browser = await playwright.chromium.launch(headless=False, executable_path=self.local_executable_path)
browser = await playwright.chromium.launch(headless=self.headless, executable_path=self.local_executable_path)
else:
browser = await playwright.chromium.launch(headless=False)
browser = await playwright.chromium.launch(headless=self.headless)
# 创建一个浏览器上下文,使用指定的 cookie 文件
context = await browser.new_context(
viewport={"width": 1600, "height": 900},