Reputation: 1
I'm trying to build a small script to download videos.I'm facing problem when trying to pass integer into subprocess.call Thank you in advance
# test url for analysis
URL = 'https://www.youtube.com/watch?v=7WauUpq4N8I'
import subprocess
subprocess.call("youtube-dl -F '%s'" %URL, shell=True)
print
# outlist numerical list of options
#input choice
Q = raw_input('Please select download quality from above ')
print
# pass input Q (integer) to subprocess.call
import subprocess
subprocess.call(["youtube-dl -f "] + Q ,["'%s'" %URL], shell=True)
Traceback (most recent call last):
File "./youtube.py", line 21, in <module>
subprocess.call(["youtube-dl -f "] + Q ,["'%s'" %URL], shell=True)
TypeError: can only concatenate list (not "str") to list
Upvotes: 0
Views: 1941
Reputation: 69914
The error message is telling you that you cannot concatenating a list (ex: ['foo', 'bar']
) to a string (ex: 'baz'
). What you probably want to do is wrap your single argument in a list or more succintly, make it part of the original list:
(wrapping it in a list)
# SNIP
import subprocess
subprocess.call(["youtube-dl", "-f "] + [Q] + [URL])
(making it part of the original list
# SNIP
import subprocess
subprocess.call(['youtube-dl', '-f', Q, URL])
Upvotes: 2