试图通过PySimpleGUI使用参数运行streamlink,但获得的权限被拒绝



正如标题所述,我正试图用PySimpleGUI创建一个基本的streamlink GUI。

我有[gui.Text('Stream link:'), gui.InputText()],和一堆以流链接为输入的其他代码(截至尚未实现的选项(,以及runCommand('streamlink ' + values[0] + ' best -o output.ts')使用streamlink将流下载到最佳质量的output.ts。

runCommand是:

def runCommand(cmd, timeout=None, window=None):
os.path.dirname(os.path.realpath(__file__)) 
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
output = ''
for line in p.stdout:
line = line.decode(errors='replace' if (sys.version_info) < (3, 5) else 'backslashreplace').rstrip()
output += line
print(line)
window.Refresh() if window else None
retval = p.wait(timeout)
return (retval, output)
if __name__ == '__main__':
main()

(我在这里找到的(

这是这样的:

[cli][info] Found matching plugin youtube for URL
[cli][info] Available streams: audio_mp4a, audio_opus, 144p (worst), 240p, 360p, 480p, 720p, 720p60, 1080p60 (best)
[cli][info] Opening stream: 1080p60 (muxed-stream)
error: Failed to open output: output.ts ([Errno 13] Permission denied: 'output.ts')
[cli][info] Closing currently open stream...

正如您所看到的,当我通过runCommand运行streamlink时,它会得到一个拒绝权限的错误。我试图将输出文件放在与.py脚本运行的目录相同的目录中,但我认为runCommand可能指定了一个我无权写入的目录。

我不知道该如何为这个命令指定一个目录,有人能帮忙吗?

我在和我的scropy文件相同的目录下得到了一个output.ts。将地址patsted链接到Input,然后单击"go"。

https://www.youtube.com/watch?v=yHURXBLNs_8
import os
import sys
import subprocess
import PySimpleGUI as sg
def runCommand(cmd, timeout=None, window=None):
os.path.dirname(os.path.realpath(__file__))
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
output = ''
for line in p.stdout:
line = line.decode(errors='replace' if (sys.version_info) < (3, 5) else 'backslashreplace').rstrip()
output += line
print(line)
window.Refresh() if window else None
retval = p.wait(timeout)
return (retval, output)
layout = [[sg.Text('Stream link:'), sg.InputText(key='-INPUT-'), sg.Button('Go')]]
window = sg.Window('Title', layout)
while True:
event, values = window.read()
if event == sg.WINDOW_CLOSED:
break
elif event == 'Go':
runCommand('streamlink ' + values['-INPUT-'] + ' best -o output.ts')
window.close()
[cli][info] Found matching plugin youtube for URL https://www.youtube.com/watch?v=yHURXBLNs_8
[cli][info] Available streams: audio_mp4a, audio_opus, 144p (worst), 240p, 360p, 480p, 720p (best)
[cli][info] Opening stream: 720p (http)
[cli][info] Stream ended
[cli][info] Closing currently open stream...

如果文件区域确实存在,

[cli][info] Found matching plugin youtube for URL https://www.youtube.com/watch?v=yHURXBLNs_8
[cli][info] Available streams: audio_mp4a, audio_opus, 144p (worst), 240p, 360p, 480p, 720p (best)
[cli][info] Opening stream: 720p (http)
[cli][error] File output.ts already exists, use --force to overwrite it.
[cli][info] Closing currently open stream...

这里,runCommand需要很长时间才能工作,所以GUI可能没有响应。建议使用多线程。