0

Storing the metadata for a video using in a file using youtube-dl can be done in bash by calling

youtube-dl -j https://www.youtube.com/watch?v=${video_id} > metadata.json

However, when the video is referenced in the context of a playlist, that is, by calling

youtube-dl -j https://www.youtube.com/watch?v=${video_id}&list=${list_id}&index=${index} > metadata.json

then youtube-dl forks or detaches from the shell (am I understanding this correctly?) and the output is sent to the terminal instead of to the file. The process seems to get stuck waiting for something. It can be terminated using ctrl-c.

Why does youtube-dl do this and can I prevent it from happening? I want to store the metadata related to the playlist as well as the metadata related to the video.

2
  • Can you show an actual example of this happening? I could see it happening if the URL was not properly quoted. Commented Jun 4, 2022 at 6:57
  • You are right. I had forgotten to quote the url.
    – fuumind
    Commented Jun 4, 2022 at 7:45

1 Answer 1

1

The shell puts processes in background if you run them with the & operator.

Because the YouTube URLs in question have an "&" separating query parameters, they must be quoted to prevent the shell from interpreting that "&" as an operator – either put the whole URL in double quotes (recommended if you also use variables in the URL), or at least prefix the & with a backslash:

"https://host?a=b&c=d"

https//host?a=b\&c=d

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .