<%* const videoURL = await tp.system.prompt("Enter YouTube URL:"); if (!videoURL) { tR += "⚠️ No URL provided."; return; } // Function to clean illegal characters from filenames function cleanFileName(title) { const invalidChars = /[\\/:*?"<>|]/g; return title.replace(invalidChars, ""); } // Function to make YAML-safe text (handle colons & quotes) function makeYAMLSafe(text) { return `"${text.replace(/"/g, "'")}"`; // Wrap in quotes & replace double quotes with single quotes } // Fetch metadata from YouTube oEmbed API const data = await requestUrl({ url: `https://youtube.com/oembed?url=${videoURL}&format=json` }); const title = data.json.title; const cleanedTitle = cleanFileName(title); const truncatedTitle = cleanedTitle.length > 24 ? cleanedTitle.substring(0, 24) : cleanedTitle; const author = data.json.author_name; const thumbnailURL = data.json.thumbnail_url; const provider = data.json.provider_name; const providerURL = data.json.provider_url; // Set note title dynamically await tp.file.rename(cleanedTitle); // Format as markdown (cursor placement included) tR += `--- title: ${makeYAMLSafe(title)} author: "[[${author}]]" source: YouTube url: ${videoURL} thumbnail: ${thumbnailURL} --- By [[${author}]] on [${provider}](${providerURL}) ![embedded](${videoURL})`; %> ## Notes <% tp.file.cursor() %>