Skip to content

Instantly share code, notes, and snippets.

@fliiiix
Created January 1, 2024 15:52
Show Gist options
  • Save fliiiix/75d699970046b0415512c256d41b3ac6 to your computer and use it in GitHub Desktop.
Save fliiiix/75d699970046b0415512c256d41b3ac6 to your computer and use it in GitHub Desktop.
Obsidian meda.ccc.de template
<%*
/*
Needs Templater community plugin!
*/
format_duration = (duration_seconds) => {
const duration_ms = duration_seconds * 1000
duration_h = Math.floor(moment.duration(duration_ms).asHours()) || ""
duration_m_s = moment.utc(duration_ms).format("mm:ss")
return [duration_h, duration_m_s].filter(Boolean).join(":")
}
clean_obsidian_link = (name) => {
//TODO bug for [] characters?
const filename_forbid_chars = /[*\/\\<>:|?"']/g
return name.replace(filename_forbid_chars, '_')
}
const url_input = await tp.system.prompt("Video URL")
const u = new URL(url_input);
const base_url = "https://media.ccc.de/public/events/"
const url = base_url + u.pathname.split('/').pop()
const meta_resp = await request(url)
const meta = JSON.parse(meta_resp)
const notes = "## Notes\n"
const filename = clean_obsidian_link('🧑‍💻 ' + meta.title)
await tp.file.rename(filename)
tR += `---
tags: [ccc, video]
channel: "[[media.ccc.de]]"
title: "${meta.title}"
duration: ${format_duration(meta.duration)}
publish_date: ${meta.date}
url: ${meta.frontend_link}
speaker: "[[${meta.persons}]]"
---
![Thumbnail](${meta.poster_url})
[Watch (${format_duration(meta.duration)})](${meta.frontend_link})
${notes}
## Description
\`\`\`
${meta.description}
\`\`\`
`
%>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment