Created
May 8, 2022 11:57
-
-
Save marcus-crane/f2ef3863336e1c53a0b4d1968a8715b5 to your computer and use it in GitHub Desktop.
Obsidian script for creating a note with a YouTube video embed in it
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function youtube (tp) { | |
const url = await tp.system.clipboard() | |
const response = await fetch(`https://youtube.com/oembed?url=${url}&format=json`) | |
const data = await response.json() | |
const title = data.title.replaceAll("", "").replaceAll('"', '').replaceAll("\\", "").replaceAll("/", "").replaceAll("<", "").replaceAll(">", "").replaceAll(":", "").replaceAll("|", "").replaceAll("?", "") | |
tp.file.rename(title) | |
const regex = /v=(.*)/gm; | |
const m = regex.exec(url) | |
return m[1] | |
} | |
module.exports = youtube; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment