Track bundled vendor runtime sources
Some checks failed
CI / main (push) Has been cancelled
CI / release-e2e (push) Has been cancelled

This commit is contained in:
2026-07-07 10:05:50 +08:00
parent fbe179ab53
commit 52636c91ae
2111 changed files with 1850012 additions and 14 deletions

View File

View File

@@ -0,0 +1,123 @@
import asyncio
import configparser
import os
from playwright.async_api import async_playwright
from xhs import XhsClient
from conf import BASE_DIR, LOCAL_CHROME_HEADLESS
from utils.base_social_media import set_init_script
from utils.log import tencent_logger, kuaishou_logger, douyin_logger
from pathlib import Path
from uploader.xhs_uploader.main import sign_local
async def cookie_auth_douyin(account_file):
async with async_playwright() as playwright:
browser = await playwright.chromium.launch(headless=LOCAL_CHROME_HEADLESS)
context = await browser.new_context(storage_state=account_file)
context = await set_init_script(context)
# 创建一个新的页面
page = await context.new_page()
# 访问指定的 URL
await page.goto("https://creator.douyin.com/creator-micro/content/upload")
try:
await page.wait_for_url("https://creator.douyin.com/creator-micro/content/upload", timeout=5000)
# 2024.06.17 抖音创作者中心改版
# 判断
# 等待“扫码登录”元素出现,超时 5 秒(如果 5 秒没出现,说明 cookie 有效)
try:
await page.get_by_text("扫码登录").wait_for(timeout=5000)
douyin_logger.error("[+] cookie 失效,需要扫码登录")
return False
except:
douyin_logger.success("[+] cookie 有效")
return True
except:
douyin_logger.error("[+] 等待5秒 cookie 失效")
await context.close()
await browser.close()
return False
async def cookie_auth_tencent(account_file):
async with async_playwright() as playwright:
browser = await playwright.chromium.launch(headless=LOCAL_CHROME_HEADLESS)
context = await browser.new_context(storage_state=account_file)
context = await set_init_script(context)
# 创建一个新的页面
page = await context.new_page()
# 访问指定的 URL
await page.goto("https://channels.weixin.qq.com/platform/post/create")
try:
await page.wait_for_selector('div.title-name:has-text("微信小店")', timeout=5000) # 等待5秒
tencent_logger.error("[+] 等待5秒 cookie 失效")
return False
except:
tencent_logger.success("[+] cookie 有效")
return True
async def cookie_auth_ks(account_file):
async with async_playwright() as playwright:
browser = await playwright.chromium.launch(headless=LOCAL_CHROME_HEADLESS)
context = await browser.new_context(storage_state=account_file)
context = await set_init_script(context)
# 创建一个新的页面
page = await context.new_page()
# 访问指定的 URL
await page.goto("https://cp.kuaishou.com/article/publish/video")
try:
await page.wait_for_selector("div.names div.container div.name:text('机构服务')", timeout=5000) # 等待5秒
kuaishou_logger.info("[+] 等待5秒 cookie 失效")
return False
except:
kuaishou_logger.success("[+] cookie 有效")
return True
async def cookie_auth_xhs(account_file):
async with async_playwright() as playwright:
browser = await playwright.chromium.launch(headless=LOCAL_CHROME_HEADLESS)
context = await browser.new_context(storage_state=account_file)
context = await set_init_script(context)
# 创建一个新的页面
page = await context.new_page()
# 访问指定的 URL
await page.goto("https://creator.xiaohongshu.com/creator-micro/content/upload")
try:
await page.wait_for_url("https://creator.xiaohongshu.com/creator-micro/content/upload", timeout=5000)
except:
print("[+] 等待5秒 cookie 失效")
await context.close()
await browser.close()
return False
# 2024.06.17 抖音创作者中心改版
if await page.get_by_text('手机号登录').count() or await page.get_by_text('扫码登录').count():
print("[+] 等待5秒 cookie 失效")
return False
else:
print("[+] cookie 有效")
return True
async def check_cookie(type, file_path):
match type:
# 小红书
case 1:
return await cookie_auth_xhs(Path(BASE_DIR / "cookiesFile" / file_path))
# 视频号
case 2:
return await cookie_auth_tencent(Path(BASE_DIR / "cookiesFile" / file_path))
# 抖音
case 3:
return await cookie_auth_douyin(Path(BASE_DIR / "cookiesFile" / file_path))
# 快手
case 4:
return await cookie_auth_ks(Path(BASE_DIR / "cookiesFile" / file_path))
case _:
return False
# a = asyncio.run(check_cookie(1,"3a6cfdc0-3d51-11f0-8507-44e51723d63c.json"))
# print(a)

View File

@@ -0,0 +1,320 @@
import asyncio
import sqlite3
from playwright.async_api import async_playwright
from myUtils.auth import check_cookie
from utils.base_social_media import set_init_script
import uuid
from pathlib import Path
from conf import BASE_DIR, LOCAL_CHROME_HEADLESS, LOCAL_CHROME_PATH
# 统一获取浏览器启动配置(防风控+引入本地浏览器)
def get_browser_options():
options = {
'headless': LOCAL_CHROME_HEADLESS,
'args': [
'--disable-blink-features=AutomationControlled', # 核心防爬屏蔽:去掉 window.navigator.webdriver 标签
'--lang=zh-CN',
'--disable-infobars',
'--start-maximized'
]
}
# 如果用户在 conf.py 里配置了本地 Chrome就用本地的这样成功率极高
if LOCAL_CHROME_PATH:
options['executable_path'] = LOCAL_CHROME_PATH
return options
# 抖音登录
async def douyin_cookie_gen(id,status_queue):
url_changed_event = asyncio.Event()
async def on_url_change():
# 检查是否是主框架的变化
if page.url != original_url:
url_changed_event.set()
async with async_playwright() as playwright:
options = get_browser_options()
# Make sure to run headed.
browser = await playwright.chromium.launch(**options)
# Setup context however you like.
context = await browser.new_context() # Pass any options
context = await set_init_script(context)
# Pause the page, and start recording manually.
page = await context.new_page()
await page.goto("https://creator.douyin.com/")
original_url = page.url
img_locator = page.get_by_role("img", name="二维码")
# 获取 src 属性值
src = await img_locator.get_attribute("src")
print("✅ 图片地址:", src)
status_queue.put(src)
# 监听页面的 'framenavigated' 事件,只关注主框架的变化
page.on('framenavigated',
lambda frame: asyncio.create_task(on_url_change()) if frame == page.main_frame else None)
try:
# 等待 URL 变化或超时
await asyncio.wait_for(url_changed_event.wait(), timeout=200) # 最多等待 200 秒
print("监听页面跳转成功")
except asyncio.TimeoutError:
print("监听页面跳转超时")
await page.close()
await context.close()
await browser.close()
status_queue.put("500")
return None
uuid_v1 = uuid.uuid1()
print(f"UUID v1: {uuid_v1}")
# 确保cookiesFile目录存在
cookies_dir = Path(BASE_DIR / "cookiesFile")
cookies_dir.mkdir(exist_ok=True)
await context.storage_state(path=cookies_dir / f"{uuid_v1}.json")
result = await check_cookie(3, f"{uuid_v1}.json")
if not result:
status_queue.put("500")
await page.close()
await context.close()
await browser.close()
return None
await page.close()
await context.close()
await browser.close()
with sqlite3.connect(Path(BASE_DIR / "db" / "database.db")) as conn:
cursor = conn.cursor()
cursor.execute('''
INSERT INTO user_info (type, filePath, userName, status)
VALUES (?, ?, ?, ?)
''', (3, f"{uuid_v1}.json", id, 1))
conn.commit()
print("✅ 用户状态已记录")
status_queue.put("200")
# 视频号登录
async def get_tencent_cookie(id,status_queue):
url_changed_event = asyncio.Event()
async def on_url_change():
# 检查是否是主框架的变化
if page.url != original_url:
url_changed_event.set()
async with async_playwright() as playwright:
options = {
'args': [
'--lang en-GB'
],
'headless': LOCAL_CHROME_HEADLESS, # Set headless option here
}
# Make sure to run headed.
browser = await playwright.chromium.launch(**options)
# Setup context however you like.
context = await browser.new_context() # Pass any options
# Pause the page, and start recording manually.
context = await set_init_script(context)
page = await context.new_page()
await page.goto("https://channels.weixin.qq.com")
original_url = page.url
# 监听页面的 'framenavigated' 事件,只关注主框架的变化
page.on('framenavigated',
lambda frame: asyncio.create_task(on_url_change()) if frame == page.main_frame else None)
# 等待 iframe 出现(最多等 60 秒)
iframe_locator = page.frame_locator("iframe").first
# 获取 iframe 中的第一个 img 元素
img_locator = iframe_locator.get_by_role("img").first
# 获取 src 属性值
src = await img_locator.get_attribute("src")
print("✅ 图片地址:", src)
status_queue.put(src)
try:
# 等待 URL 变化或超时
await asyncio.wait_for(url_changed_event.wait(), timeout=200) # 最多等待 200 秒
print("监听页面跳转成功")
except asyncio.TimeoutError:
status_queue.put("500")
print("监听页面跳转超时")
await page.close()
await context.close()
await browser.close()
return None
uuid_v1 = uuid.uuid1()
print(f"UUID v1: {uuid_v1}")
# 确保cookiesFile目录存在
cookies_dir = Path(BASE_DIR / "cookiesFile")
cookies_dir.mkdir(exist_ok=True)
await context.storage_state(path=cookies_dir / f"{uuid_v1}.json")
result = await check_cookie(2,f"{uuid_v1}.json")
if not result:
status_queue.put("500")
await page.close()
await context.close()
await browser.close()
return None
await page.close()
await context.close()
await browser.close()
with sqlite3.connect(Path(BASE_DIR / "db" / "database.db")) as conn:
cursor = conn.cursor()
cursor.execute('''
INSERT INTO user_info (type, filePath, userName, status)
VALUES (?, ?, ?, ?)
''', (2, f"{uuid_v1}.json", id, 1))
conn.commit()
print("✅ 用户状态已记录")
status_queue.put("200")
# 快手登录
async def get_ks_cookie(id,status_queue):
url_changed_event = asyncio.Event()
async def on_url_change():
# 检查是否是主框架的变化
if page.url != original_url:
url_changed_event.set()
async with async_playwright() as playwright:
options = {
'args': [
'--lang en-GB'
],
'headless': LOCAL_CHROME_HEADLESS, # Set headless option here
}
# Make sure to run headed.
browser = await playwright.chromium.launch(**options)
# Setup context however you like.
context = await browser.new_context() # Pass any options
context = await set_init_script(context)
# Pause the page, and start recording manually.
page = await context.new_page()
await page.goto("https://cp.kuaishou.com")
# 定位并点击“立即登录”按钮(类型为 link
await page.get_by_role("link", name="立即登录").click()
await page.get_by_text("扫码登录").click()
img_locator = page.get_by_role("img", name="qrcode")
# 获取 src 属性值
src = await img_locator.get_attribute("src")
original_url = page.url
print("✅ 图片地址:", src)
status_queue.put(src)
# 监听页面的 'framenavigated' 事件,只关注主框架的变化
page.on('framenavigated',
lambda frame: asyncio.create_task(on_url_change()) if frame == page.main_frame else None)
try:
# 等待 URL 变化或超时
await asyncio.wait_for(url_changed_event.wait(), timeout=200) # 最多等待 200 秒
print("监听页面跳转成功")
except asyncio.TimeoutError:
status_queue.put("500")
print("监听页面跳转超时")
await page.close()
await context.close()
await browser.close()
return None
uuid_v1 = uuid.uuid1()
print(f"UUID v1: {uuid_v1}")
# 确保cookiesFile目录存在
cookies_dir = Path(BASE_DIR / "cookiesFile")
cookies_dir.mkdir(exist_ok=True)
await context.storage_state(path=cookies_dir / f"{uuid_v1}.json")
result = await check_cookie(4, f"{uuid_v1}.json")
if not result:
status_queue.put("500")
await page.close()
await context.close()
await browser.close()
return None
await page.close()
await context.close()
await browser.close()
with sqlite3.connect(Path(BASE_DIR / "db" / "database.db")) as conn:
cursor = conn.cursor()
cursor.execute('''
INSERT INTO user_info (type, filePath, userName, status)
VALUES (?, ?, ?, ?)
''', (4, f"{uuid_v1}.json", id, 1))
conn.commit()
print("✅ 用户状态已记录")
status_queue.put("200")
# 小红书登录
async def xiaohongshu_cookie_gen(id,status_queue):
url_changed_event = asyncio.Event()
async def on_url_change():
# 检查是否是主框架的变化
if page.url != original_url:
url_changed_event.set()
async with async_playwright() as playwright:
options = {
'args': [
'--lang en-GB'
],
'headless': LOCAL_CHROME_HEADLESS, # Set headless option here
}
# Make sure to run headed.
browser = await playwright.chromium.launch(**options)
# Setup context however you like.
context = await browser.new_context() # Pass any options
context = await set_init_script(context)
# Pause the page, and start recording manually.
page = await context.new_page()
await page.goto("https://creator.xiaohongshu.com/")
await page.locator('img.css-wemwzq').click()
img_locator = page.get_by_role("img").nth(2)
# 获取 src 属性值
src = await img_locator.get_attribute("src")
original_url = page.url
print("✅ 图片地址:", src)
status_queue.put(src)
# 监听页面的 'framenavigated' 事件,只关注主框架的变化
page.on('framenavigated',
lambda frame: asyncio.create_task(on_url_change()) if frame == page.main_frame else None)
try:
# 等待 URL 变化或超时
await asyncio.wait_for(url_changed_event.wait(), timeout=200) # 最多等待 200 秒
print("监听页面跳转成功")
except asyncio.TimeoutError:
status_queue.put("500")
print("监听页面跳转超时")
await page.close()
await context.close()
await browser.close()
return None
uuid_v1 = uuid.uuid1()
print(f"UUID v1: {uuid_v1}")
# 确保cookiesFile目录存在
cookies_dir = Path(BASE_DIR / "cookiesFile")
cookies_dir.mkdir(exist_ok=True)
await context.storage_state(path=cookies_dir / f"{uuid_v1}.json")
result = await check_cookie(1, f"{uuid_v1}.json")
if not result:
status_queue.put("500")
await page.close()
await context.close()
await browser.close()
return None
await page.close()
await context.close()
await browser.close()
with sqlite3.connect(Path(BASE_DIR / "db" / "database.db")) as conn:
cursor = conn.cursor()
cursor.execute('''
INSERT INTO user_info (type, filePath, userName, status)
VALUES (?, ?, ?, ?)
''', (1, f"{uuid_v1}.json", id, 1))
conn.commit()
print("✅ 用户状态已记录")
status_queue.put("200")
# a = asyncio.run(xiaohongshu_cookie_gen(4,None))
# print(a)

View File

@@ -0,0 +1,92 @@
import asyncio
from pathlib import Path
from conf import BASE_DIR
from uploader.douyin_uploader.main import DouYinVideo
from uploader.ks_uploader.main import KSVideo
from uploader.tencent_uploader.main import TencentVideo
from uploader.xiaohongshu_uploader.main import XiaoHongShuVideo
from utils.constant import TencentZoneTypes
from utils.files_times import generate_schedule_time_next_day
def post_video_tencent(title,files,tags,account_file,category=TencentZoneTypes.LIFESTYLE.value,enableTimer=False,videos_per_day = 1, daily_times=None,start_days = 0, is_draft=False):
# 生成文件的完整路径
account_file = [Path(BASE_DIR / "cookiesFile" / file) for file in account_file]
files = [Path(BASE_DIR / "videoFile" / file) for file in files]
if enableTimer:
publish_datetimes = generate_schedule_time_next_day(len(files), videos_per_day, daily_times,start_days)
else:
publish_datetimes = [0 for i in range(len(files))]
for index, file in enumerate(files):
for cookie in account_file:
print(f"文件路径{str(file)}")
# 打印视频文件名、标题和 hashtag
print(f"视频文件名:{file}")
print(f"标题:{title}")
print(f"Hashtag{tags}")
app = TencentVideo(title, str(file), tags, publish_datetimes[index], cookie, category, is_draft)
asyncio.run(app.main(), debug=False)
def post_video_DouYin(title,files,tags,account_file,category=TencentZoneTypes.LIFESTYLE.value,enableTimer=False,videos_per_day = 1, daily_times=None,start_days = 0,
thumbnail_path = '',
productLink = '', productTitle = ''):
# 生成文件的完整路径
account_file = [Path(BASE_DIR / "cookiesFile" / file) for file in account_file]
files = [Path(BASE_DIR / "videoFile" / file) for file in files]
if enableTimer:
publish_datetimes = generate_schedule_time_next_day(len(files), videos_per_day, daily_times,start_days)
else:
publish_datetimes = [0 for i in range(len(files))]
for index, file in enumerate(files):
for cookie in account_file:
print(f"文件路径{str(file)}")
# 打印视频文件名、标题和 hashtag
print(f"视频文件名:{file}")
print(f"标题:{title}")
print(f"Hashtag{tags}")
app = DouYinVideo(title, str(file), tags, publish_datetimes[index], cookie, thumbnail_path, productLink, productTitle)
asyncio.run(app.douyin_upload_video(), debug=False)
def post_video_ks(title,files,tags,account_file,category=TencentZoneTypes.LIFESTYLE.value,enableTimer=False,videos_per_day = 1, daily_times=None,start_days = 0):
# 生成文件的完整路径
account_file = [Path(BASE_DIR / "cookiesFile" / file) for file in account_file]
files = [Path(BASE_DIR / "videoFile" / file) for file in files]
if enableTimer:
publish_datetimes = generate_schedule_time_next_day(len(files), videos_per_day, daily_times,start_days)
else:
publish_datetimes = [0 for i in range(len(files))]
for index, file in enumerate(files):
for cookie in account_file:
print(f"文件路径{str(file)}")
# 打印视频文件名、标题和 hashtag
print(f"视频文件名:{file}")
print(f"标题:{title}")
print(f"Hashtag{tags}")
app = KSVideo(title, str(file), tags, publish_datetimes[index], cookie)
asyncio.run(app.main(), debug=False)
def post_video_xhs(title,files,tags,account_file,category=TencentZoneTypes.LIFESTYLE.value,enableTimer=False,videos_per_day = 1, daily_times=None,start_days = 0):
# 生成文件的完整路径
account_file = [Path(BASE_DIR / "cookiesFile" / file) for file in account_file]
files = [Path(BASE_DIR / "videoFile" / file) for file in files]
file_num = len(files)
if enableTimer:
publish_datetimes = generate_schedule_time_next_day(file_num, videos_per_day, daily_times,start_days)
else:
publish_datetimes = 0
for index, file in enumerate(files):
for cookie in account_file:
# 打印视频文件名、标题和 hashtag
print(f"视频文件名:{file}")
print(f"标题:{title}")
print(f"Hashtag{tags}")
app = XiaoHongShuVideo(title, file, tags, publish_datetimes, cookie)
asyncio.run(app.main(), debug=False)
# post_video("333",["demo.mp4"],"d","d")
# post_video_DouYin("333",["demo.mp4"],"d","d")