I prefer commands over python since it has well-explained documentation. So I suggest you make a bash script that contains your preferred command. Then run the python program that will call the bash-script and runs your commands.
Linux: yt_script.sh:
#!/bin/sh
youtube-dl $1 -x --audio-format mp3 --add-metadata --xattrs --embed-thumbnail --prefer-ffmpeg --postprocessor-args "-metadata comment='my comment'" -o 'yt_%(id)s_.mp3' --verbose
exit 0
and in the python file you call the bash script giving the url as a parameter.
python_program.py:
import subprocess
subprocess.call(["Path/to/yt_script.sh","https://www.youtube.com/watch?v=5wK5-ChsDsQ"])
Don't forget to give your script the correct permissions by typing chmod u+x Path/to/yt_script.sh
in the terminal.
Then run python /Path/to/python_program.py
to run the program from terminal.
You may also need to pass arguments (youtube URLs) to the command.
You can do that by editing "python_program.py" as following:
import subprocess
import sys
subprocess.call(["Path/to/yt_script.sh",sys.argv[1]])
Then all you have to do is to open the terminal, run the python program, add the YouTube URL at the end of the command as follows:python /Path/to/python_program.py https://www.youtube.com/watch?v=z60S2DCqDpY
I hope this clears things out!
sudo
to download a file?) – Ribband