Skip to content

Instantly share code, notes, and snippets.

@RubenZagon
Created December 27, 2022 16:47
Show Gist options
  • Save RubenZagon/7ecf0e4af7e78aa331e56d5e2e507fb0 to your computer and use it in GitHub Desktop.
Save RubenZagon/7ecf0e4af7e78aa331e56d5e2e507fb0 to your computer and use it in GitHub Desktop.
Template para Obsidian con el que agilizar el crear una nueva '💧 Fuente' de un 📺 Vídeo de YouTube del que ir extrayendo notas. ⚠️ Cosas a tener en cuenta: - Es necesario crear una API_KEY del servicio de Google "YouTube Data API v3" ⚠️

<%* videoUrl = await tp.system.prompt("URL del vídeo de YouTube");
async function getVideoData() {

const videoId = videoUrl.substring(32);
const apiKey = 'YOUR_API_KEY';  

const url = `https://www.googleapis.com/youtube/v3/videos?part=snippet&id=${videoId}&key=${apiKey}`;  

try {  
    const response = await fetch(url);  
    const data = await response.json();  

    if (response.ok) {  
        const video = data.items[0].snippet;  
        title = video.title;  
        author = video.channelTitle;  
        publish_date = video.publishedAt.match(/\d{4}-\d{2}-\d{2}/g)[0];  
        year = video.publishedAt.match(/\d{4}/g)[0];
        id = videoId;  

        await tp.file.rename(`${author} - ${title}`)  

    } else {  
        quote = "An error ocurred";  
        console.log(data);  
    }  
} catch (error) {  
    console.error(error);  
}  

}

await getVideoData(); tR += "---"; // Hack para evitar que haya un salto de línea extra en la cabecera %> <%* if (title.toLowerCase().contains("java")) { tR += "tags: fuentes/youtube en/java #en/" } else { tR += "tags: fuentes/youtube #en/" } %> published_on: <%* tR +=${publish_date} %> alias: <%* tR += ${year} %> 📺 <%* tR += ${title} %>

Author:: [[<%* tR += ${author} %>]]
URL:: <%* tR += ${videoUrl} %>

<%* tR += ${title} %>

<%* tR += <iframe width="560" height="315" src="https://www.youtube.com/embed/${id}" title="YouTube video player" frameBorder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowFullScreen></iframe> %>

Links

<%* if (title.toLowerCase().contains("java")) { tR += "[[Java]]" } %>

<%* await tp.file.move(/💧 Fuentes/📺 Videos/${title}) %>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment