Skip to main content
 首页 » 编程设计

启动 MPV 的 Python 脚本

2025年05月04日10cloudgamer

我写了一个 python 脚本来使 mpv 的使用更容易(cim 是标题)。

这是脚本:

from sh import mpv 
cim=input("Cím: ") 
a=int(input("with start(1) | without start (2) ")) 
b=int(input("with sub (1) | without sub(2) ")) 
if a == 1: 
    #w/ start 
    c=input("xx:yy:zz : ") 
    if b == 1: 
        #w/ sub 
        sh.mpv(cim,"--sub-file=",d,"start=",c) 
 
 
    elif b == 2: 
        #w/ sub 
        sh.mpv(cim,"start=",c) 
 
elif a == 2: 
    #nincs start 
    if b == 1: 
        #w/ sub 
        d=input("sub: ") 
        sh.mpv(cim,"--sub-file=",d) 
 
    if b == 2: 
        sh.mpv(cim) 

当我尝试运行它时:

RAN:  
'/usr/bin/mpv Red Museum.avi --sub-file= eng.srt' 
 
STDOUT: 
Error parsing option sub-file (option requires parameter) 
Setting commandline option --sub-file= failed. 

请您参考如下方法:

问题似乎是 --sub-file= 和 eng.srt 之间的额外空间。您可以通过删除 = 来修复它,以便 mpv 期望它们由空格分隔。即替换行

sh.mpv(cim,"--sub-file=",d) 

与

sh.mpv(cim,"--sub-file", d) 

如果这不起作用,您可以通过使用字符串连接来去除多余的空间:

sh.mpv(cim,"--sub-file=" + d)