one liner to get youtube info

Never Gonna Give You Up


It’s a work in progress, but this will grab info about a youtube video and spit out some json.

Requires youtube-dl, jq and jq-duration (for changing duration from seconds to something more human readable).

Swap the ID $i for either the ID or full URL of the video as needed.

youtube-dl -j $i | jq 'include "duration"; { "title": .title, "duration": (.duration|duration(2)), "url": .webpage_url, "channel": .channel, "channel_url": .channel_url }'

The above produces something like this:

  "title": "Rick Astley - Never Gonna Give You Up (Official Music Video)",
  "duration": "3m 32s",
  "url": "",
  "channel": "Rick Astley",
  "channel_url": ""

I made a jinja template to make markdown text to use with the above :

* [{{ title }}]({{ url }}) ({{ duration }}) from [{{ channel }}]({{ channel_url }})

To use this, put the above in a file called (eg yt2md.j2) and call it by appending | jinja2 yt2md.j2 - to the youtube-dl command.

(note: the - appended to the end is required to get around a jinja2 cli bug)

The full command will then look like:

youtube-dl -j $i | jq 'include "duration"; { "title": .title, "duration": (.duration|duration(2)), "url": .webpage_url, "channel": .channel, "channel_url": .channel_url }' | jinja2 yt2md.j2 -