zoujie
......@@ -167,4 +167,7 @@ youtube_uploader/*.json
douyin_uploader/*.json
bilibili_uploader/*.json
tk_uploader/*.json
cookies
\ No newline at end of file
cookies
bin
get-pip.py
pyvenv.cfg
\ No newline at end of file
......
......@@ -11,10 +11,11 @@ from uploader.tencent_uploader.main import weixin_setup, TencentVideo
from uploader.tk_uploader.main_chrome import tiktok_setup, TiktokVideo
from uploader.xhs_uploader.main import xhs_setup, XHSVideo
from uploader.wyh_uploader.main import wyh_setup
from uploader.sohu_uploader.main import sohu_setup, SOHUVideo
from uploader.toutiao_uploader.main import toutiao_setup
from utils.base_social_media import get_supported_social_media, get_cli_action, SOCIAL_MEDIA_DOUYIN, \
SOCIAL_MEDIA_TENCENT, SOCIAL_MEDIA_TIKTOK, SOCIAL_MEDIA_KUAISHOU, SOCIAL_MEDIA_WANGYIHAO, \
SOCIAL_MEDIA_XHS, SOCIAL_MEDIA_TOUTIAO, SOCIAL_MEDIA_BAIJIAHAO
SOCIAL_MEDIA_XHS, SOCIAL_MEDIA_TOUTIAO, SOCIAL_MEDIA_BAIJIAHAO, SOCIAL_MEDIA_SOHU
from utils.constant import TencentZoneTypes
from utils.files_times import get_title_and_hashtags
......@@ -73,13 +74,40 @@ async def main():
elif args.platform == SOCIAL_MEDIA_KUAISHOU:
await ks_setup(str(account_file), handle=True)
elif args.platform == SOCIAL_MEDIA_WANGYIHAO:
await wyh_setup(str(account_file), handle=True, auto=False)
# elif args.platform == SOCIAL_MEDIA_XHS:
# await xhs_setup(str(account_file), handle=True)
await wyh_setup(str(account_file), handle=True)
elif args.platform == SOCIAL_MEDIA_XHS:
await xhs_setup(str(account_file), handle=True)
elif args.platform == SOCIAL_MEDIA_TOUTIAO:
await toutiao_setup(str(account_file), handle=True)
await toutiao_setup(str(account_file), handle=True, auto=False)
elif args.platform == SOCIAL_MEDIA_BAIJIAHAO:
await toutiao_setup(str(account_file), handle=True, auto=False)
elif args.platform == SOCIAL_MEDIA_SOHU:
await sohu_setup(str(account_file), handle=True)
elif args.action == 'auto_login':
print(f"auto Logging in with account {args.account_name} on platform {args.platform}")
if args.platform == SOCIAL_MEDIA_DOUYIN:
await douyin_setup(str(account_file), handle=True)
elif args.platform == SOCIAL_MEDIA_TIKTOK:
await tiktok_setup(str(account_file), handle=True)
elif args.platform == SOCIAL_MEDIA_TENCENT:
await weixin_setup(str(account_file), handle=True)
elif args.platform == SOCIAL_MEDIA_KUAISHOU:
await ks_setup(str(account_file), handle=True)
elif args.platform == SOCIAL_MEDIA_WANGYIHAO:
await wyh_setup(str(account_file), handle=True, auto=True)
# elif args.platform == SOCIAL_MEDIA_XHS:
# await xhs_setup(str(account_file), handle=True)
elif args.platform == SOCIAL_MEDIA_TOUTIAO:
await toutiao_setup(str(account_file), handle=True, auto=True)
elif args.platform == SOCIAL_MEDIA_BAIJIAHAO:
await toutiao_setup(str(account_file), handle=True, auto=True)
await toutiao_setup(str(account_file), handle=True)
elif args.platform == SOCIAL_MEDIA_SOHU:
await sohu_setup(str(account_file), handle=True)
elif args.action == 'upload':
title, tags = get_title_and_hashtags(args.video_file)
......@@ -108,6 +136,9 @@ async def main():
elif args.platform == SOCIAL_MEDIA_XHS:
await xhs_setup(account_file, handle=True)
app = XHSVideo(title, video_file, tags, publish_date, account_file)
elif args.platform == SOCIAL_MEDIA_SOHU:
await sohu_setup(account_file, handle=True)
app = SOHUVideo(title, video_file, tags, None, account_file)
else:
print("Wrong platform, please check your input")
exit()
......
......@@ -6,20 +6,20 @@ from utils.log import kuaishou_logger
from playwright.async_api import Playwright, async_playwright
async def wyh_setup(account_file, handle=False):
async def bjh_setup(account_file, handle=False):
print(account_file)
account_file = get_absolute_path(account_file, "wyh_uploader")
if not os.path.exists(account_file):
if not handle:
return False
kuaishou_logger.info('[+] cookie文件不存在或已失效,即将自动打开浏览器,请扫码登录,登陆后会自动生成cookie文件')
await get_wyh_cookie(account_file)
await get_bjh_cookie(account_file)
else:
await open_wyh_main_page(account_file)
await open_bjh_main_page(account_file)
return True
async def open_wyh_main_page(account_file):
async def open_bjh_main_page(account_file):
async with async_playwright() as playwright:
options = {
'args': [
......@@ -55,7 +55,7 @@ async def open_wyh_main_page(account_file):
browser.close()
async def get_wyh_cookie(account_file):
async def get_bjh_cookie(account_file):
print("get_wyh_cookie")
async with async_playwright() as playwright:
options = {
......@@ -77,6 +77,12 @@ async def get_wyh_cookie(account_file):
# await context.storage_state(path=account_file)
# 自动登陆
await page.wait_for_timeout(20000)
await page.wait_for_timeout(2000)
await page.get_by_text('注册/登录百家号').click()
await page.pause()
await page.wait_for_timeout(2000)
await page.locator("//*[@class='pass-text-input pass-text-input-userName']").fill("idiotbc")
await page.wait_for_timeout(2000)
await page.locator("//*[@class='pass-text-input pass-text-input-password']").fill("Liuyihong1023@")
await page.wait_for_timeout(2000)
await page.locator("//*[@class='pass-checkbox-input pass-checkbox-isAgree']").click()
await page.wait_for_timeout(2000)
......
# -*- coding: utf-8 -*-
from datetime import datetime
from playwright.async_api import Playwright, async_playwright
import os
import asyncio
import json
from conf import LOCAL_CHROME_PATH
from utils.base_social_media import set_init_script
from utils.files_times import get_absolute_path
from utils.log import sohu_logger
async def cookie_auth(account_file):
async with async_playwright() as playwright:
browser = await playwright.chromium.launch(headless=True)
context = await browser.new_context(storage_state=account_file)
await set_init_script(context)
# context = await browser.new_context()
page = await context.new_page()
# saved_cookies = await read_cookies_from_file(account_file)
# await context.add_cookies(saved_cookies)
try:
await page.goto("https://tv.sohu.com/", timeout=5000)
except:
pass
try:
await page.wait_for_selector("div.user-ico", timeout=5000) # 等待5秒
sohu_logger.success("[+] cookie 有效")
return True
except:
sohu_logger.info("[+] 等待5秒 cookie 失效")
return False
async def sohu_setup(account_file, handle=False):
account_file = get_absolute_path(account_file, "sohu_uploader")
if not os.path.exists(account_file) or not await cookie_auth(account_file):
if not handle:
return False
sohu_logger.info('[+] cookie文件不存在或已失效,即将自动打开浏览器,请扫码登录,登陆后会自动生成cookie文件')
await get_sohu_cookie(account_file)
return True
async def get_sohu_cookie(account_file):
async with async_playwright() as playwright:
options = {
'args': [
'--lang en-GB'
],
'headless': True, # 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()
try:
await page.goto("https://tv.sohu.com/", timeout=5000)
except:
pass
await asyncio.sleep(1)
await page.wait_for_selector("div.user-ico", timeout=50000)
sohu_logger.info("搜狐视频登录成功")
await asyncio.sleep(3)
# await page.pause()
# 点击调试器的继续,保存cookie
# cookies = await context.cookies()
# await write_cookies_to_file(cookies, account_file)
await context.storage_state(path=account_file)
class SOHUVideo(object):
def __init__(self, title, file_path, tags, publish_date: datetime, account_file):
self.title = title # 视频标题
self.file_path = file_path
self.tags = tags
self.publish_date = publish_date
self.account_file = account_file
self.date_format = '%Y-%m-%d %H:%M'
self.local_executable_path = LOCAL_CHROME_PATH
async def handle_upload_error(self, page):
pass
# sohu_logger.error("视频出错了,重新上传中")
# await page.locator('div.progress-div [class^="upload-btn-input"]').set_input_files(self.file_path)
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,
)
else:
browser = await playwright.chromium.launch(
headless=True
) # 创建一个浏览器上下文,使用指定的 cookie 文件
context = await browser.new_context(storage_state=self.account_file)
page = await context.new_page()
# saved_cookies = await read_cookies_from_file(self.account_file)
# await context.add_cookies(saved_cookies)
# context = await set_init_script(context)
# context.on("close", lambda: )
# 创建一个新的页面
# 访问指定的 URL
try:
await page.goto("https://tv.sohu.com/s/center/index.html#/", timeout=5000)
except:
pass
sohu_logger.info('正在上传-------{}.mp4'.format(self.title))
# 等待页面跳转到指定的 URL,没进入,则自动等待到超时
# 点击 "上传视频" 按钮
# await page.locator("dev.release-top").set_input_files(
# self.file_path)
await page.locator("input[type='file']").set_input_files(
self.file_path)
upload_button = page.locator('div.form-button span:has-text("发布")')
await upload_button.wait_for(state='visible') # 确保按钮可见
await asyncio.sleep(1)
sohu_logger.info("正在填充标题...")
await page.locator("input.input-topic").nth(0).fill(self.title[:99]) # 搜狐最多100
await asyncio.sleep(1)
sohu_logger.info("正在填充话题...")
inputTag = page.locator("input.input-topic").nth(1)
await inputTag.click()
for index, tag in enumerate(self.tags[:2], start=1):
await page.keyboard.type(f"#{tag}")
await page.keyboard.press("Enter")
sohu_logger.info("已写完tag")
await asyncio.sleep(1)
sohu_logger.info(self.publish_date)
# 定时任务 搜狐没有定时发布
# if self.publish_date != 0:
# await self.set_schedule_time(page, self.publish_date)
# upload_button = page.locator('button div span:has-text("定时发布")')
sohu_logger.info("提交")
await upload_button.click()
await page.wait_for_selector('h3:has-text("视频管理")')
await context.storage_state(path=self.account_file)
sohu_logger.info('cookie更新完毕!')
await asyncio.sleep(4) # 这里延迟是为了方便眼睛直观的观看
# 关闭浏览器上下文和浏览器实例
await context.close()
await browser.close()
async def main(self):
async with async_playwright() as playwright:
await self.upload(playwright)
......@@ -6,25 +6,25 @@ from utils.log import kuaishou_logger
from playwright.async_api import Playwright, async_playwright
async def toutiao_setup(account_file, handle=False):
async def toutiao_setup(account_file, handle=False, auto=False):
print(account_file)
account_file = get_absolute_path(account_file, "wyh_uploader")
if not os.path.exists(account_file):
if not handle:
return False
kuaishou_logger.info('[+] cookie文件不存在或已失效,即将自动打开浏览器,请扫码登录,登陆后会自动生成cookie文件')
await get_wyh_cookie(account_file)
if not auto:
await get_toutiao_cookie(account_file)
else:
await get_toutiao_cookie_auto(account_file)
else:
await open_wyh_main_page(account_file)
await open_toutiao_main_page(account_file)
return True
async def open_wyh_main_page(account_file):
async def open_toutiao_main_page(account_file):
async with async_playwright() as playwright:
options = {
'args': [
'--lang en-GB'
],
'headless': False, # Set headless option here
}
# Make sure to run headed.
......@@ -39,8 +39,8 @@ async def open_wyh_main_page(account_file):
browser.close()
async def get_wyh_cookie(account_file):
print("get_wyh_cookie")
async def get_toutiao_cookie_auto(account_file):
print("get_toutiao_cookie")
async with async_playwright() as playwright:
options = {
'args': [
......@@ -57,24 +57,41 @@ async def get_wyh_cookie(account_file):
page = await context.new_page()
await page.goto("https://mp.toutiao.com")
# 手动授权登录
# await page.pause()
# 点击调试器的继续,保存cookie
# await context.storage_state(path=account_file)
# 自动登陆
await page.wait_for_timeout(5000)
await page.wait_for_timeout(2000)
await page.get_by_text('密码登录').click()
await page.wait_for_timeout(5000)
await page.wait_for_timeout(2000)
await page.get_by_placeholder("手机号/邮箱").fill('18610534668')
print("输入账号成功")
await page.wait_for_timeout(1000)
await page.get_by_placeholder('密码').fill("Liuyihong1023@")
await page.wait_for_timeout(1000)
await page.wait_for_timeout(2000)
await page.locator("//*[@class='web-login-confirm-info__checkbox']").click()
await page.wait_for_timeout(1000)
await page.wait_for_timeout(2000)
await page.locator("//*[@class='web-login-button']").click()
await page.wait_for_timeout(10000)
await page.wait_for_timeout(2000)
# 点击调试器的继续,保存cookie
await context.storage_state(path=account_file)
async def get_toutiao_cookie(account_file):
print("get_toutiao_cookie")
async with async_playwright() as playwright:
options = {
'headless': False, # 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://mp.toutiao.com", {waitUntil: "commit"})
# 手动授权登录
await page.pause()
# 点击调试器的继续,保存cookie
await context.storage_state(path=account_file)
......
......@@ -6,20 +6,26 @@ from utils.log import kuaishou_logger
from playwright.async_api import Playwright, async_playwright
async def wyh_setup(account_file, handle=False):
async def wyh_setup(account_file, handle=False, auto=False):
print(account_file)
account_file = get_absolute_path(account_file, "wyh_uploader")
if not os.path.exists(account_file):
if not handle:
return False
kuaishou_logger.info('[+] cookie文件不存在或已失效,即将自动打开浏览器,请扫码登录,登陆后会自动生成cookie文件')
await get_wyh_cookie(account_file)
if not auto:
await get_wyh_cookie(account_file)
else:
await get_wyh_cookie_auto(account_file)
else:
await open_wyh_main_page(account_file)
return True
async def open_wyh_main_page(account_file):
'''
'''
async def get_wyh_cookie_auto(account_file):
print("get_wyh_cookie")
async with async_playwright() as playwright:
options = {
'args': [
......@@ -30,33 +36,29 @@ async def open_wyh_main_page(account_file):
# Make sure to run headed.
browser = await playwright.chromium.launch(**options)
# Setup context however you like.
context = await browser.new_context(storage_state=account_file) # Pass any options
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://mp.163.com")
# await page.pause()
# 点击调试器的继续,保存cookie
# await context.storage_state(path=account_file)
board = page.locator("//*[@class='homeV4__board__card__data__value']")
# html_content = await board.inner_html()
# print(html_content)
content = await board.nth(0).inner_text() #总粉丝数
print(content)
content = await board.nth(1).inner_text() #总阅读数
print(content)
content = await board.nth(2).inner_text() #总收益
print(content)
await page.get_by_text("粉丝数据").click()
await page.wait_for_timeout(5000)
await page.get_by_text("内容数据").click()
# 自动登陆
await page.wait_for_timeout(5000)
await page.get_by_text("收益数据").click()
frame = page.frame_locator('//iframe[contains(@id, "x-URS-iframe")]')
await frame.locator('[name="email"]').fill('liufuhua007@163.com')
await frame.locator('[name="password"]').fill("Liuyihong1023@")
await frame.locator('#dologin').click()
# await page.pause()
await page.wait_for_timeout(5000)
browser.close()
# 点击调试器的继续,保存cookie
await context.storage_state(path=account_file)
async def get_wyh_cookie(account_file):
print("get_wyh_cookie")
async with async_playwright() as playwright:
options = {
'args': [
......@@ -67,23 +69,47 @@ async def get_wyh_cookie(account_file):
# 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 browser.new_context(storage_state=account_file) # 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://mp.163.com")
# await page.pause()
# 点击调试器的继续,保存cookie
# await context.storage_state(path=account_file)
await page.pause()
async def open_wyh_main_page(account_file):
async with async_playwright() as playwright:
options = {
'args': [
'--lang en-GB'
],
'headless': False, # 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(storage_state=account_file) # 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://mp.163.com")
board = page.locator("//*[@class='homeV4__board__card__data__value']")
# html_content = await board.inner_html()
# print(html_content)
content = await board.nth(0).inner_text() #总粉丝数
print(content)
content = await board.nth(1).inner_text() #总阅读数
print(content)
content = await board.nth(2).inner_text() #总收益
print(content)
await page.get_by_text("粉丝数据").click()
await page.wait_for_timeout(5000)
await page.get_by_text("内容数据").click()
await page.wait_for_timeout(5000)
await page.get_by_text("收益数据").click()
await page.wait_for_timeout(5000)
browser.close()
# 自动登陆
await page.wait_for_timeout(20000)
frame = page.frame_locator('//iframe[contains(@id, "x-URS-iframe")]')
await frame.locator('[name="email"]').fill('liufuhua007@163.com')
await frame.locator('[name="password"]').fill("Liuyihong1023@")
await frame.locator('#dologin').click()
# await page.pause()
await page.wait_for_timeout(15000)
# 点击调试器的继续,保存cookie
await context.storage_state(path=account_file)
......
......@@ -25,7 +25,6 @@ async def read_cookies_from_file(file_path):
return []
async def cookie_auth(account_file):
print(account_file)
async with async_playwright() as playwright:
browser = await playwright.chromium.launch(headless=True)
# context = await browser.new_context(storage_state=account_file)
......@@ -35,7 +34,6 @@ async def cookie_auth(account_file):
await context.add_cookies(saved_cookies)
await page.goto("https://www.xiaohongshu.com")
try:
print(await page.title())
await page.wait_for_selector("div.link-wrapper a.link-wrapper span.channel", timeout=5000) # 等待5秒
xhs_logger.success("[+] cookie 有效")
return True
......@@ -72,12 +70,11 @@ async def get_xhs_cookie(account_file):
await page.goto("https://www.xiaohongshu.com")
await asyncio.sleep(1)
await page.wait_for_selector("div.link-wrapper a.link-wrapper span.channel", timeout=50000)
print("小红书登录成功")
xhs_logger.info("小红书登录成功")
await asyncio.sleep(3)
# await page.pause()
# 点击调试器的继续,保存cookie
await asyncio.sleep(3)
cookies = await context.cookies()
await write_cookies_to_file(cookies, account_file)
......@@ -93,8 +90,7 @@ class XHSVideo(object):
self.local_executable_path = LOCAL_CHROME_PATH
async def handle_upload_error(self, page):
xhs_logger.error("视频出错了,重新上传中")
await page.locator('div.progress-div [class^="upload-btn-input"]').set_input_files(self.file_path)
pass
async def upload(self, playwright: Playwright) -> None:
# 使用 Chromium 浏览器启动一个浏览器实例
......@@ -129,22 +125,25 @@ class XHSVideo(object):
xhs_logger.info("正在填充标题和话题...")
await page.locator("div.titleInput div div input").fill("花花")
await page.locator("div.titleInput div div input").fill(self.title[:19]) # 小红书最长20
inputTag = page.locator('id=quillEditor').locator('div p')
await inputTag.click()
for index, tag in enumerate(self.tags, start=1):
await page.keyboard.type(f"#{tag} ")
await asyncio.sleep(2)
await page.keyboard.type(f"#{tag}")
await page.wait_for_selector("ul.ql-mention-list")
await page.keyboard.press("Enter")
xhs_logger.info("已写完tag")
await asyncio.sleep(1)
xhs_logger.info(self.publish_date)
# 定时任务
if self.publish_date != 0:
await self.set_schedule_time(page, self.publish_date)
upload_button = page.locator('button div span:has-text("定时发布")')
xhs_logger.info("提交")
await upload_button.click()
await page.wait_for_selector('p:has-text("发布成功")')
await write_cookies_to_file(await context.cookies(), self.account_file)
......
......@@ -9,18 +9,20 @@ SOCIAL_MEDIA_TIKTOK = "tiktok"
SOCIAL_MEDIA_BILIBILI = "bilibili"
SOCIAL_MEDIA_KUAISHOU = "kuaishou"
SOCIAL_MEDIA_WANGYIHAO = 'wangyihao'
SOCIAL_MEDIA_XHS = 'xiaohongshu'
SOCIAL_MEDIA_XHS = 'xiaohongshu' # 小红书最长标题是20
SOCIAL_MEDIA_TOUTIAO = 'toutiao'
SOCIAL_MEDIA_BAIJIAHAO = 'baijiahao'
SOCIAL_MEDIA_SOHU = 'sohu' # 搜狐视频话题最多2个 标题最多100 标题不支持‍🩹
def get_supported_social_media() -> List[str]:
return [SOCIAL_MEDIA_DOUYIN, SOCIAL_MEDIA_TENCENT, SOCIAL_MEDIA_TIKTOK, SOCIAL_MEDIA_KUAISHOU,
SOCIAL_MEDIA_WANGYIHAO, SOCIAL_MEDIA_TOUTIAO, SOCIAL_MEDIA_BAIJIAHAO, SOCIAL_MEDIA_XHS]
SOCIAL_MEDIA_WANGYIHAO, SOCIAL_MEDIA_TOUTIAO, SOCIAL_MEDIA_BAIJIAHAO, SOCIAL_MEDIA_XHS,
SOCIAL_MEDIA_SOHU]
def get_cli_action() -> List[str]:
return ["upload", "login", "watch"]
return ["upload", "login", "watch", "auto_login"]
async def set_init_script(context):
......
......@@ -46,6 +46,7 @@ logger.add(stdout, colorize=True, format=log_formatter)
douyin_logger = create_logger('douyin', 'logs/douyin.log')
tencent_logger = create_logger('tencent', 'logs/tencent.log')
xhs_logger = create_logger('xhs', 'logs/xhs.log')
sohu_logger = create_logger('sohu', 'logs/sohu.log')
tiktok_logger = create_logger('tiktok', 'logs/tiktok.log')
bilibili_logger = create_logger('bilibili', 'logs/bilibili.log')
kuaishou_logger = create_logger('kuaishou', 'logs/kuaishou.log')
......