Public
Edited
Mar 18, 2023
Insert cell
Insert cell
import { viewof API_KEY, openai } from '@player1537/openai-convenience-library';
Insert cell
Insert cell
viewof AUTH = Inputs.text({
label: 'YouTube Transcript Auth (format "{username}:{password}")',
})
Insert cell
viewof SELECTION = Inputs.textarea({
rows: 24,
cols: 80,
})
Insert cell
videos = {
const root = md([SELECTION]);
const as = Array.from(root.querySelectorAll('a[href^="https://www.youtube.com/watch?v="][title]'));
const videos = as.filter((_, i) => i < 1).map((a) => ({
href: a.href,
id: (new URL(a.href)).searchParams.get('v'),
title: a.title,
transcript: null,
}));

for (const video of videos) {
const transcript = await TRANSCRIPT(video.id);
video.transcript = transcript;
}

return videos;

async function TRANSCRIPT(id) {
const response = await fetch(`https://youtube.is.mediocreatbest.xyz/transcript/${id}`, {
mode: 'cors',
headers: {
'Accept': 'application/json',
'Authorization': `Basic ${btoa(AUTH)}`,
},
});

const json = await response.json();
return json;
};
};
Insert cell
{
return htl.html`
<details>
<summary>Summaries of ${summaries.length} videos</summary>
${summaries.map((d, i) => htl.html.fragment`
<details>
<summary>Summary ${i+1}: ${d.title}</summary>
${d.summaries.map((summary) => htl.html.fragment`
<textarea rows=24 cols=80>${summary}
`/* htl.html.fragment */)}
`/* htl.html.fragment */)}
`/* htl.html */;
}
Insert cell
summaries = {
await (yield button('Execute')).promise;

const ret = [];
for (const video of videos) {
const summaries = await SUMMARIZE(video);
ret.push({ ...video, summaries });
yield ret;
}

return ret;

async function SUMMARIZE(video) {
const requests = openai.complete`
Summarize the following video transcript in 100 words.
Title: ${video.title}
Transcript: ${openai.split`${video.transcript}`}
100 word summary:
`;

const responses = await openai.request(requests);

return responses;
}
}
Insert cell
{
await (yield button('Execute')).promise;

const response = await fetch('https://youtube.is.mediocreatbest.xyz/transcript/Puobu8NVK7Q', {
mode: 'cors',
headers: {
'Accept': 'text/plain',
'Authorization': `Basic ${btoa(AUTH)}`,
},
});

const text = await response.text();
return yield text;
}
Insert cell
import { button } from '@player1537/utilities';
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more