Youtube video Templater with chapters and timecode links (and more data got from youtube API)

Hi!
I use YouTube heavily as a source of information and create a lot of “bibliographic” notes on videos, so I created a Templater template for that.

Template prompts a video url, then using yt-dlp get video metadata that includes some useful info like chapters with time codes, video duration, description, e.t.c. to be inserted in template.

Here is the code obsidian youtube templater · GitHub

created video page looks like this:

there is also notes section below with subheading for each video chapter:

time codes are external links that open a video in browser at corresponding time.

dependencies: yt-dlp and jq command line utils must be installed in system, details are in template comments.

My solution is based on someone else’s script (I don’t remember where I got it from), that ran one ytdlp process per one video property. The advantage of my template is that I make one call to yt-dlp -j "<video_url>" to query all fields at once in json, then use jq to filter out the results and not parse a huge json in obsidian runtime. This is much faster.

Hope, somebody will find this usable.

8 Likes

This looks great. I will have to try it out.

Do you think there is a way to add a screenshot of whatever time in video you specify?

I believe it’s impossible without downloading the entire video.

Cool template :tada: a few notes for other people who want to try it.

  • Needs Templater community plugin
  • If you run the flatpack version here is how i setup the cmd
sudo flatpak override md.obsidian.Obsidian --talk-name=org.freedesktop.Flatpak
sudo dnf install flatpak-spawn

and then the command looks like this →

flatpak-spawn --host yt-dlp -j "https://www.youtube.com/watch?v=${id}" | flatpak-spawn --host jq "${query}"

(@ll14m4n might be worth to look into the url parsing and support this as well)

Hi, this is very promising for me, thanks for sharing!

I’m trying to implement this on Windows are am stuck at this step shown in your Templater code:


You need to define user function in Templater plugin settings named "ytmeta" with the following command:

/opt/homebrew/yt-dlp -j "https://www.youtube.com/watch?v=${id}" | /opt/homebrew/jq "${query}"

replace /opt/homebrew with your path to yt-dlp and jq
*/ 

  1. Does defining user function mean to create a .js script file?
  2. How would I change the directory of the command to fit Windows (I installed jq with Scoop and use yt-dlp.exe, both of which I have the PATH information)

Thank you so much! Exciting to try out if this really works!

  1. User function code is defined in obsidian itself: Settings → Templater.

  2. sorry, I don’t know much about windows (last version I used was windows XP, lol). You might just write absolute pathes to yt-dlp.exe and jq.exe, where they are located, like C:\bla\bla\jq.exe. Though I doubt variable substitution like v=${id} and command chaining with pipe symbol will work in whatever shell is used in windows now, cos. it is syntax used in Bash and Bash-like shells on mac and linux…

Ok, ok, ok. I’m a month late. Just found this myself, and after playing around with it, here’s your answers:

  1. No (already covered nicely). Not in this case, at least.
  2. Turns out, it’s pretty easy:

Simply replace the ytmeta command:

/opt/homebrew/yt-dlp -j "https://www.youtube.com/watch?v=${id}" | /opt/homebrew/jq "${query}"

with:

<PATH1>yt-dlp.exe -j https://www.youtube.com/watch?v=%id% | <PATH2>jq "%query%"

replacing with the path to yt-dlp.exe,. Likewise and jq.exe.

The paths are only needed if yt-dlp.exe and jq.exe are not installed in a folder in your system path. Put them in the system path and you don’t need the paths at all.

The major change is ${var_name} gets replaced with %var_name%

1 Like

Consolidating the calls to yt-dlp into a single request and then filtering the results with jq is indeed a more efficient approach, reducing the processing time.

Using external tools and scripts to enhance your note-taking process is a great way to streamline your workflow.