更新了下载进度条

import time
import pywinauto
from pytube import YouTube
import win32gui
import win32con
import win32api
from googletrans import Translator
from pytube.cli import on_progress

link = input("pls input link: ")
yt = YouTube(link, on_progress_callback=on_progress)
stream = yt.streams.get_highest_resolution()

# add global statement for filesize
global filesize
filesize = stream.filesize

translator = Translator()
text = stream.title
print("video original name is "+text)
result = translator.translate(text, dest='zh-CN').text

chars_to_replace = ["#", " ", "?", "|", "*","🎧","@","$","%","^","~","`"]
for char in chars_to_replace:
    result = result.replace(char, "")
print("video chinese name is "+result)

# define progress_function with chunk, file_handle and bytes_remaining parameters
def progress_function (chunk, file_handle, bytes_remaining):
    # use chunk.filesize instead of stream.filesize
    current = ( (filesize - bytes_remaining)/filesize)
    percent = (' {0:.1f}').format (current*100)
    progress = int (50*current)
    status = '█' * progress + '-' * (50 - progress)
    # use print instead of sys.stdout.write and sys.stdout.flush
    print (' ↳ | {bar}| {percent}%'.format (bar=status, percent=percent))

# register progress_function as on_progress_callback
yt.register_on_progress_callback(progress_function)

stream.download(filename=f"{result}.mp4")

def click_button(hwnd,_x,_y):
    win32gui.SetForegroundWindow(hwnd)
    win32gui.SetActiveWindow(hwnd)
    left, top, right, bottom = win32gui.GetWindowRect(hwnd)
    #print(left, top, right, bottom)
    x = left + _x
    y = top + _y
    win32api.SetCursorPos((x, y))
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)  # 按下左键
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)  # 松开左键
    time.sleep(2)

def scan_game_board(hwnd,x,y):
    try:
        win32gui.SetForegroundWindow(hwnd)
        win32gui.SetActiveWindow(hwnd)
    except win32gui.error as e:
        print("Haven't open the B-cut", e)
    rect = win32gui.GetClientRect(hwnd)
    print(f"Rect={rect}")
    l_param = win32api.MAKELONG(x, y)
    win32api.SendMessage(hwnd, win32con.WM_LBUTTONDOWN, win32con.MK_LBUTTON, l_param)
    win32api.SendMessage(hwnd, win32con.WM_LBUTTONUP, 0, l_param)
    time.sleep(1)
#
#
hd=win32gui.FindWindow(None, "必剪")  # 点击必剪上传
click_button(hd,529,472)

hd1=win32gui.FindWindow(None, "打开") #在打开窗口点击视频
app = pywinauto.Application().connect(title="打开") # change the title as needed
textbox = app.window(title="打开").window(class_name="Edit") # change the class name as needed
textbox.set_text(f"{result}.mp4")
pywinauto.keyboard.send_keys("{ENTER}")

time.sleep(5) #等待窗口弹出来,不然找不到句柄
#hd2=win32gui.FindWindow(None, "必剪")
windows = pywinauto.findwindows.find_elements(title="必剪", backend="win32")
app = pywinauto.Application().connect(handle=windows[1].handle)
window = app.window(handle=windows[1].handle)
click_button(windows[1].handle,418,757)
time.sleep(2)
click_button(windows[1].handle,662,351)
time.sleep(2)
click_button(windows[1].handle,527,592)
time.sleep(2)
click_button(windows[1].handle,815,478)
time.sleep(2)
click_button(windows[1].handle,997,753)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值