如何解决Spotify:有人知道 Windows 10 Spotify 桌面应用程序的任何命令提示符命令吗?
我正在编写一个 python 脚本来通过命令提示符控制 Spotify,但我知道的唯一命令是:
spotify --uri=[xxxx:xxxxxxxxxxxxxxxxxxxx]
打开 Spotify 到曲目、专辑或艺术家。我尝试了许多其他随机命令,试图找到一些有用的命令,但没有运气。
解决方法
我不知道你是否可以通过 cli 来完成,但你可以模拟按键并找到进程和窗口标题。
import win32api,win32con,win32gui,win32process,psutil,time
class Helper():
play_pause = 0xB3
next_track = 0xB0
previous_track = 0xB1
def __init__(self):
self.hwnd = 0
def winEnumHandler(self,hwnd,ctx ):
process_name = psutil.Process(win32process.GetWindowThreadProcessId(hwnd)[-1]).name()
window_name = win32gui.GetWindowText(hwnd)
if win32gui.IsWindowVisible(hwnd) and process_name == "Spotify.exe" and window_name != "":
self.hwnd = hwnd
def sendKey(self,key):
win32api.keybd_event(key,0)
win32api.keybd_event(key,win32con.KEYEVENTF_KEYUP,0)
def getInfo(self):
win32gui.EnumWindows(self.winEnumHandler,None)
return win32gui.GetWindowText(self.hwnd)
hp = Helper()
print(hp.getInfo())
hp.sendKey(Helper.next_track)
time.sleep(1)
print(hp.getInfo())
hp.sendKey(Helper.play_pause)
time.sleep(1)
print(hp.getInfo())
您可以通过标题(包含-
或Spotify
)判断播放状态,您应该检查进程是否还活着/hwnd != 0。
我找到了键码 here
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。