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.

I’m new to this, so bare with me :slight_smile:

I don’t know if there has been any changes from the time of creation of this post to now. Something doesn’t work as it should, when i do (or at least, i think i do) as instructed.

Am i completely missing the point with the template file attached here, shouldn’t it create the whole layout, or do i have to put in the detail fields to output properties above the thumbnail, which does also not show ?

I’m on Windows 11 and have changed the urls in the function to fit.

I just get the description under the video on Youtube in a big pile.

I also have stopped Windows Defender from deleting yt-dlp because of false flagging it, and i don’t get any warnings from running it - if it runs it at all, which i’m not sure, as this does not work.

I dropped this project here because i found this one, which works out of the box. Don’t need to install any other things for it to work :slight_smile:

I know it does not give time stamp links, and the time stamp template which is under the same Git, does not work either. But i can live with that :slight_smile:

Otherwise, if you know why this here doesn’t work, it would be great to know :slight_smile:

1 Like

Using yt-dlp to pull metadata and integrate it into an Obsidian Templater workflow is a smart way to keep track of key details without manually copying everything.

Having chapters with timestamps automatically inserted is a nice touch—it makes referencing specific parts of a video much easier.

If you ever need to convert video files for offline use or compatibility reasons, this tool might come in handy: https://www.movavi.com/video-converter/3gpp-converter.html. Really cool workflow—thanks for sharing!