main
黄海 1 year ago
parent 8525de1c6c
commit 1068e49fa7

@ -24,3 +24,6 @@ web_url = http://127.0.0.1:9000
; 处理机编号 ; 处理机编号
machine_id = 4090D_Dsideal machine_id = 4090D_Dsideal
[monitor]
; 将剪映运行在第几个显示器上面
working_id = 2

@ -4,23 +4,27 @@ import subprocess
import time import time
import uuid import uuid
import pyautogui import pyautogui
from Util import ConfigUtil
from Util.Win32Util import * from Util.Win32Util import *
import pyperclip import pyperclip
# pip install pyautogui # pip install pyautogui
# pip install pywin32 # pip install pywin32
# pip install pyperclip # pip install pyperclip
# PyAutoGUI fail-safe triggered from mouse moving to a corner of the screen # PyAutoGUI fail-safe triggered from mouse moving to a corner of the screen
# pip install screeninfo
from screeninfo import get_monitors
def open_jian_ying(): def open_jian_ying():
# 关闭剪映 # 关闭剪映
subprocess.Popen(['taskkill', '/F', '/IM', 'JianyingPro.exe'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, subprocess.Popen(['taskkill', '/F', '/IM', 'JianyingPro.exe'], stdout=subprocess.PIPE, stderr=subprocess.PIPE,
text=True) text=True)
# 清剪映的草稿区 # 清剪映的草稿区
remove_dir_contents(JianYingCaoGao) remove_dir_contents(JianYingCaoGao)
time.sleep(1)
# 打开剪眏 # 打开剪眏
subprocess.Popen([jianYingExePath]) subprocess.Popen([jianYingExePath])
# 检查是不是已经正确打开了 # 检查是不是已经正确打开了
@ -34,17 +38,22 @@ def open_jian_ying():
if found: if found:
break break
else: else:
printf('waiting...') printf('Loading...')
time.sleep(1) time.sleep(1)
# 激活剪映为当前操作窗口 # 激活剪映为当前操作窗口
time.sleep(3) time.sleep(2)
hwnd = x[0] hwnd = x[0]
# 显示为当前窗口
win32gui.SetForegroundWindow(hwnd) win32gui.SetForegroundWindow(hwnd)
# 破解剪映 # 移动窗口到指定的显示器左上角上去
crack_jian_ying() win32gui.SetWindowPos(hwnd, win32con.HWND_TOP, wm.x, wm.y, 0, 0, win32con.SWP_NOSIZE)
# 最大化 # 最大化
win32gui.ShowWindow(hwnd, win32con.SW_SHOWMAXIMIZED) win32gui.ShowWindow(hwnd, win32con.SW_SHOWMAXIMIZED)
exit(0)
# 破解剪映
crack_jian_ying()
return hwnd return hwnd
@ -68,7 +77,9 @@ def crack_jian_ying():
is_running = True is_running = True
if is_running: if is_running:
# wm.x
win32gui.SetForegroundWindow(hwnd) win32gui.SetForegroundWindow(hwnd)
pyautogui.press('enter') pyautogui.press('enter')
time.sleep(1) time.sleep(1)
pyautogui.press('enter') pyautogui.press('enter')
@ -349,14 +360,31 @@ def run_switch(hwnd, source_img, cartoon_img):
if __name__ == '__main__': if __name__ == '__main__':
# 配置文件
config = ConfigUtil.getConfig()
# 剪映运行的显示器编号
working_id = int(config['monitor']['working_id'])
# 显示器个数检查
monitors = get_monitors()
if len(monitors) < working_id:
printf('显示器数量小于配置的显示器编号')
exit(0)
# 坐标测试的屏幕分辨率1680*1050
wm = monitors[working_id - 1]
# print(wm.width, wm.height, wm.x, wm.y)
# 显示器的分辨率和开始的位置
# for i, monitor in enumerate(monitors):
# print("显示器", i + 1, "分辨率:", monitor.width, "x", monitor.height)
# print("显示器", i + 1, "位置:", monitor.x, ",", monitor.y)
# 获取当前脚本文件的绝对路径 # 获取当前脚本文件的绝对路径
script_path = os.path.abspath(__file__) script_path = os.path.abspath(__file__)
# 获取脚本文件所在的磁盘分区 # 获取脚本文件所在的磁盘分区
# 这将返回脚本文件所在的完整路径,包括磁盘分区 # 这将返回脚本文件所在的完整路径,包括磁盘分区
disk_partition = os.path.splitdrive(script_path)[0] disk_partition = os.path.splitdrive(script_path)[0]
print("当前脚本所在的磁盘分区是:", disk_partition)
# 清时剪映的草稿区 # 清时剪映的草稿区
JianYingCaoGao = r'C:\Users\Administrator\AppData\Local\JianyingPro\User Data\Projects\com.lveditor.draft' JianYingCaoGao = r'C:\Users\Administrator\AppData\Local\JianyingPro\User Data\Projects\com.lveditor.draft'
# 打开剪眏 # 打开剪眏
@ -376,19 +404,19 @@ if __name__ == '__main__':
# 操作类型1生成MV2生成图片切换 # 操作类型1生成MV2生成图片切换
type_id = 1 type_id = 1
#
# 生成MV # # 生成MV
if type_id == 1: # if type_id == 1:
# 用户上传了多少张图片 # # 用户上传了多少张图片
imgCount = count_files(imgPath) - 1 # 因为有一个是MP3 # imgCount = count_files(imgPath) - 1 # 因为有一个是MP3
# 拷贝MP3文件到imgPath目录 # # 拷贝MP3文件到imgPath目录
shutil.copy(mp3, imgPath) # shutil.copy(mp3, imgPath)
videoName = run_once(hwnd, imgPath, imgCount) + '.mp4' # videoName = run_once(hwnd, imgPath, imgCount) + '.mp4'
print(os.path.join(JiangYingOutPath, videoName)) # print(os.path.join(JiangYingOutPath, videoName))
#
# 生成图片切换 # # 生成图片切换
if type_id == 2: # if type_id == 2:
sourceImg = disk_partition + r'\KeCheng\BaiHu\TestImage\Wife\wife.jpg' # sourceImg = disk_partition + r'\KeCheng\BaiHu\TestImage\Wife\wife.jpg'
CartoonImg = disk_partition + r'\KeCheng\BaiHu\TestImage\Wife\3.png' # CartoonImg = disk_partition + r'\KeCheng\BaiHu\TestImage\Wife\3.png'
videoName = run_switch(hwnd, sourceImg, CartoonImg) + '.mp4' # videoName = run_switch(hwnd, sourceImg, CartoonImg) + '.mp4'
print(os.path.join(JiangYingOutPath, videoName)) # print(os.path.join(JiangYingOutPath, videoName))

Loading…
Cancel
Save