Skip to content

Commit

Permalink
1:适配新的页面元素 2:区分标题和正文,避免标题在正文中重复
Browse files Browse the repository at this point in the history
  • Loading branch information
toolazytoname committed Feb 27, 2025
1 parent bdad326 commit e230039
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 13 deletions.
2 changes: 1 addition & 1 deletion pages/03_auto_publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def start_publish_video():
st.text_input(label=tr("Driver Debugger Address"), value="127.0.0.1:2828", key="video_publish_debugger_address")
st.text_input(label=tr("Video Content Dir"), key="video_publish_content_dir",
value=get_content_location(), on_change=set_content_location, args=('video_publish_content_dir',))
video_list = get_file_map_from_dir(st.session_state["video_publish_content_dir"], ".mp4")
video_list = get_file_map_from_dir(st.session_state["video_publish_content_dir"], ".mp4,.mov")
st.selectbox(label=tr("Video File"), key="video_publish_content_file",
options=video_list, format_func=lambda x: video_list[x])
file_list = get_file_map_from_dir(st.session_state["video_publish_content_dir"], ".txt")
Expand Down
10 changes: 7 additions & 3 deletions services/publisher/douyin_publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import time

from config.config import douyin_site
from tools.file_utils import read_head, read_file_with_extra_enter
from tools.file_utils import read_head, read_file_with_extra_enter, read_file_start_with_secondline


def douyin_publisher(driver, video_file, text_file):
Expand Down Expand Up @@ -80,7 +80,7 @@ def douyin_publisher(driver, video_file, text_file):
time.sleep(2)
cmd_ctrl = Keys.COMMAND if sys.platform == 'darwin' else Keys.CONTROL
# 将要粘贴的文本内容复制到剪贴板
content_text = read_file_with_extra_enter(text_file)
content_text = read_file_start_with_secondline(text_file)
pyperclip.copy(content_text)
action_chains = webdriver.ActionChains(driver)
# 模拟实际的粘贴操作
Expand Down Expand Up @@ -127,7 +127,11 @@ def douyin_publisher(driver, video_file, text_file):
collection_to_select.click()
time.sleep(1)

# 发布
# 设置是否允许他人保存视频
not_allow_save_label = driver.find_element(By.XPATH, '//*[@id="root"]/div/div/div[1]/div[11]/div/label[2]')
not_allow_save_label.click()
time.sleep(2)
# 发布
publish_button = driver.find_element(By.XPATH, '//button[text()="发布"]')
auto_publish = st.session_state.get('video_publish_auto_publish')
if auto_publish:
Expand Down
11 changes: 8 additions & 3 deletions services/publisher/kuaishou_publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,14 @@ def kuaishou_publisher(driver, video_file, text_file):
actions.move_to_element(domain_level_2).click().perform()
# domain_level_2.click()
time.sleep(1)

# 发布
publish_button = driver.find_element(By.XPATH, '//button[@type="button"]/span[text()="发布"]')

# 设置是否允许他人保存视频
allow_save_label = driver.find_element(By.XPATH, '//*[@id="setting-tours"]/div[2]/div/label[2]')
allow_save_label.click()
time.sleep(2)

# 发布
publish_button = driver.find_element(By.CLASS_NAME, '_button-primary_si04s_60')
auto_publish = st.session_state.get('video_publish_auto_publish')
if auto_publish:
print("auto publish")
Expand Down
4 changes: 2 additions & 2 deletions services/publisher/shipinhao_publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import time

from config.config import shipinhao_site
from tools.file_utils import read_head, read_file_with_extra_enter
from tools.file_utils import read_head, read_file_with_extra_enter, read_file_start_with_secondline


def shipinhao_publisher(driver, video_file, text_file):
Expand Down Expand Up @@ -83,7 +83,7 @@ def shipinhao_publisher(driver, video_file, text_file):
time.sleep(2)
cmd_ctrl = Keys.COMMAND if sys.platform == 'darwin' else Keys.CONTROL
# 将要粘贴的文本内容复制到剪贴板
content_text = read_file_with_extra_enter(text_file)
content_text = read_file_start_with_secondline(text_file)
pyperclip.copy(content_text)
action_chains = webdriver.ActionChains(driver)
# 模拟实际的粘贴操作
Expand Down
8 changes: 4 additions & 4 deletions services/publisher/xiaohongshu_publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import time

from config.config import xiaohongshu_site
from tools.file_utils import read_head, read_file_with_extra_enter
from tools.file_utils import read_head, read_file_with_extra_enter, read_file_start_with_secondline


def xiaohongshu_publisher(driver, video_file, text_file):
Expand All @@ -53,7 +53,7 @@ def xiaohongshu_publisher(driver, video_file, text_file):
wait.until(EC.presence_of_element_located((By.CLASS_NAME, 'c-input_inner')))

# 设置标题
title = driver.find_element(By.CLASS_NAME, 'el-input__inner')
title = driver.find_element(By.CLASS_NAME, 'd-text')
title_text = read_head(text_file)
use_common = st.session_state.get('video_publish_use_common_config')
if use_common:
Expand All @@ -68,8 +68,8 @@ def xiaohongshu_publisher(driver, video_file, text_file):
time.sleep(2)

# 设置内容
content = driver.find_element(By.ID, 'post-textarea')
content_text = read_file_with_extra_enter(text_file)
content = driver.find_element(By.XPATH, '//*[@id="quillEditor"]/div')
content_text = read_file_start_with_secondline(text_file)
content.send_keys(content_text)
time.sleep(2)

Expand Down
12 changes: 12 additions & 0 deletions tools/file_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,18 @@ def read_file_with_extra_enter(file):
cleaned_content = '\n'.join(lines)
return cleaned_content

def read_file_start_with_secondline(file):
# 使用with语句打开文件,确保文件在使用后会被正确关闭
with open(file, 'r', encoding='UTF-8') as f:
# 读取文件内容
content = f.read()
# 使用splitlines()将内容分割成行列表
lines = content.splitlines()
lines = lines[1:];
# 使用join()将行重新组合成字符串
cleaned_content = '\n'.join(lines)
return cleaned_content


def read_file(file):
# 打开文件
Expand Down

0 comments on commit e230039

Please sign in to comment.