Skip to content

Instantly share code, notes, and snippets.

@RubenZagon
Created December 27, 2022 16:45
Show Gist options
  • Select an option

  • Save RubenZagon/78a579ea1f126d77146fa51f12ac7c71 to your computer and use it in GitHub Desktop.

Select an option

Save RubenZagon/78a579ea1f126d77146fa51f12ac7c71 to your computer and use it in GitHub Desktop.

Revisions

  1. RubenZagon created this gist Dec 27, 2022.
    66 changes: 66 additions & 0 deletions create-source-video-obsidian.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,66 @@
    <%*
    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}`) %>