Get Title, Channel Name and Upload Date for YouTube link #432
Replies: 6 comments 8 replies
-
With live preview, the asterisk really throw off the link underlining due to video title becoming italic. So here's the same code as above but without the asterisk for those who would prefer it this way. <%*
let url = await tp.system.clipboard();
let page = await tp.obsidian.request({url});
let p = new DOMParser();
let doc = p.parseFromString(page, "text/html");
let $ = s => doc.querySelector(s);
%>[<%
$("link[itemprop='name']").getAttribute("content") %>, ▶ <%
$("meta[property='og:title']").content %>, (<%
$("meta[itemprop='uploadDate']").content.slice(0, 4) %>)](<%
$("link[rel='shortLinkUrl']").href %>) |
Beta Was this translation helpful? Give feedback.
-
How do you know which selectors to use in the querySelector? |
Beta Was this translation helpful? Give feedback.
-
Can we get Summary of Youtube Transcript or just the transcript of the video? |
Beta Was this translation helpful? Give feedback.
-
Thanks for great snippets! Btw, quite often Youtube titles contain characters that are not suitable for file names, so I modified the
Also I create alias in YAML frontmatter to maintain the original file name, just in case:
|
Beta Was this translation helpful? Give feedback.
-
How to use this template
<%*
let url = await tp.system.clipboard();
let page = await tp.obsidian.request({url});
let p = new DOMParser();
let doc = p.parseFromString(page, "text/html");
let $ = s => doc.querySelector(s);
%>[<%
$("link[itemprop='name']").getAttribute("content") %>, ▶ *<%
$("meta[property='og:title']").content %>*, (<%
$("meta[itemprop='uploadDate']").content.slice(0, 4) %>)](<%
$("link[rel='shortLinkUrl']").href %>)
I hope this will help Templater beginners like me who struggled to get this to work! Edit: added a comma and step to add a keyboard shortcut |
Beta Was this translation helpful? Give feedback.
-
To add to the existing snippets, here's mine which produces <%*
let url = await tp.system.clipboard();
let page = await tp.obsidian.request({url});
let p = new DOMParser();
let doc = p.parseFromString(page, "text/html");
let $ = s => doc.querySelector(s);
%>[<%
$("meta[property='og:title']").content %>](<%
$("link[rel='shortLinkUrl']").href %>) (YT <%
$("link[itemprop='name']").getAttribute("content") %> <%
$("meta[itemprop='uploadDate']").content.slice(0, 7)%>) Example: Automate Your Vault With Templater - How to Use Templater in Obsidian (YT FromSergio 2022-07) |
Beta Was this translation helpful? Give feedback.
-
Automatically format YouTube link as
[Channel Name, ▶ *Video Title*, (<upload-year>)](https://youtu.be/video-id)
Beta Was this translation helpful? Give feedback.
All reactions