It's about how to get a list of URLs by using youtube_dl
. Although I have been trying all day long, I couldn't work it out. Thus I would like to ask help to translate the following command lines (partially in Linux) into Python codes. I mean in a .py
file.
To get JSON data, use command line: youtube-dl -j --flat-playlist 'https://www.youtube.com/c/3blue1brown/videos'
To parser use command line in Linux: youtube-dl -j --flat-playlist 'https://www.youtube.com/c/3blue1brown/videos' | jq -r '.id' | sed 's_^_https://youtube.com/v/_'
The codes above are from: https://web.archive.org/web/20180309061900/https://archive.zhimingwang.org/blog/2014-11-05-list-youtube-playlist-with-youtube-dl.html (The youtube link there was removed so I replaced the youtube link above)
You can use the same command to run inside a .py file using os as follows:
import os
os.system("youtube-dl -j --flat-playlist 'https://www.youtube.com/c/3blue1brown/videos'")
You can pipe the output of the above commands to a file and then process your json file in python.
It's great! Thanks!
I just aware that the output of the os.system can only be seen on the console. Is there any methods to use the outputs direct in python? I would like to use the outputs for further codes. Thanks.
Maybe take a look here: stackoverflow.com/questions/3503879/…
Or you can output the result of youtube-dl command to a file and then read from that file. e.g.,
os.system("youtube-dl -j --flat-playlist 'https://www.youtube.com/c/3blue1brown/videos' > tempfile.txt")