<%*
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 += <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>
%>
<%* if (title.toLowerCase().contains("java")) { tR += "[[Java]]" } %>
<%* await tp.file.move(/💧 Fuentes/📺 Videos/${title}
) %>