Skip to content

Instantly share code, notes, and snippets.

@marcus-crane
Created May 8, 2022 11:57
Show Gist options
  • Save marcus-crane/f2ef3863336e1c53a0b4d1968a8715b5 to your computer and use it in GitHub Desktop.
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
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