Trying to run streamlink with arguments through PySimpleGUI, getting permission denied

662 Views Asked by At

As the title states, I'm trying to create a basic streamlink GUI with PySimpleGUI.

I've got [gui.Text('Stream link:'), gui.InputText()], and a bunch of other code (as of yet unimplemented options) which takes a stream link as an input, and runCommand('streamlink ' + values[0] + ' best -o output.ts') to use streamlink to download the stream to output.ts in the best quality.

runCommand is:

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()

(Which I found here)

And this works as such:

[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...

As you can see, when I run streamlink through runCommand, it gets a permission denied error. I'm trying to get the output file in the same directory as the .py script is ran in, but I think runCommand might be specifying a directory I don't have permission to write to.

I don't know how I would go about specifying a directory for this command, can anyone help?

1

There are 1 best solutions below

1
On

I got an output.ts under same directory as my scripy file. Link address patsted into Input, then 'go' click.

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...

if file aready exist ther,

[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...

Here, runCommand take long time to work, so GUI maybe no response. Multithread suggested for it.