N
N
neuro4live2021-05-01 14:41:52
linux
neuro4live, 2021-05-01 14:41:52

How to run youtube-dl via subprocess in python?

Hello. I need to get the video sheet format from the link in order to find the code of the format I'm interested in. To do this, I'm trying to run youtube-dl with the --list-formats parameter to link to the video via the subprocess module. But in the terminal, instead of a list of formats, I see this text: [b'ERROR: \'--list-formats https://www.youtube.com/watch?v=e_Z6ZcCwPcU\ ' is not a valid URL. Set --default-search "ytsearch" (or run youtube-dl "ytsearch:--list-formats https://www.youtube.com/watch?v=e_Z6ZcCwPcU " ) to search YouTube\n']
But if you run just with the specified link, then the video just swings in maximum quality as it should.
Here is the code, please help me what is the problem:

import subprocess


p=subprocess.Popen(['youtube-dl', " --list-formats https://www.youtube.com/watch?v=e_Z6ZcCwPcU"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
result=p.stdout.readlines()
print(result)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2021-05-01
@neuro4live

p=subprocess.Popen(['youtube-dl', "--list-formats", "https://www.youtube.com/watch?v=e_Z6ZcCwPcU"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)

Need to share. The docs have examples
https://docs.python.org/3/library/subprocess.html#...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question