Warm tip: This article is reproduced from serverfault.com, please click

Translate youtube_dl command line into python .py file

发布于 2020-11-29 16:27:21

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.

  1. To get JSON data, use command line: youtube-dl -j --flat-playlist 'https://www.youtube.com/c/3blue1brown/videos'

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

Questioner
rtt0012
Viewed
0
Mayank Singhal 2020-11-30 00:56:07

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.