A clean and minimal youtube frontend, without all the ads and whistles
JavaScript
promises..
Christian Fei01cc55943cef
diff --git a/lib/server.js b/lib/server.jsindex 0ddc9dd..dc0b410 100644--- a/lib/server.js+++ b/lib/server.js@@ -50,7 +50,7 @@ export function createServer ({repo, connections = []}) {if (url.pathname === '/lib/store.js')return fileHandler('client/lib/store.js', 'application/javascript')(req, res)if (url.pathname === '/' || url.pathname === '/index.html')- return fileHandler('client/index.html', 'text/html')(req, res)+ return fileHandler('client/index.html', 'text/html')(req, res)res.writeHead(404, { 'Content-Type': 'text/plain' })res.end('Not found')})@@ -103,7 +103,8 @@ export function createServer ({repo, connections = []}) {broadcastSSE(JSON.stringify({type: 'download-log-line', line}), connections)).then(() =>broadcastSSE(JSON.stringify({type: 'downloaded', videoId: id}), connections))- .catch((error) => console.error(error))+ .catch((error) =>+ broadcastSSE(JSON.stringify({type: 'download-log-line', line: error.stderr}), connections))res.writeHead(200, { 'Content-Type': 'text/plain' })res.end('Download started')@@ -117,7 +118,8 @@ export function createServer ({repo, connections = []}) {broadcastSSE(JSON.stringify({type: 'download-log-line', line}), connections)).then(({summary, transcript}) =>broadcastSSE(JSON.stringify({type: 'summary', summary, transcript, videoId: id}), connections))- .catch((error) => console.error(error))+ .catch((error) =>+ broadcastSSE(JSON.stringify({type: 'download-log-line', line: error.stderr}), connections))res.writeHead(200, { 'Content-Type': 'text/plain' })res.end('Download started')diff --git a/lib/subtitles-summary.js b/lib/subtitles-summary.jsindex b621470..9b540a7 100644--- a/lib/subtitles-summary.js+++ b/lib/subtitles-summary.js@@ -3,24 +3,31 @@ import { getVideoSubtitles } from "./youtube.js"import { fetchCompletionLMSTUDIO } from "./llm.js"export async function summarizeVideo(id, repo, callback = () => {}) {- const transcript = await getVideoSubtitles(id, callback)- let cleanedTranscript = cleanTranscript(transcript)- console.log('cleanedTranscript.length', cleanedTranscript.length)- repo.setVideoTranscript(id, cleanedTranscript)- cleanedTranscript = cleanedTranscript.replace('\n', ' ')- // if (process.env.KEEP_SUBTITLES === 'true')- fs.writeFileSync(`./data/videos/${id}-sub.en.txt`, cleanedTranscript)-- const userPrompt = `-Extract the key points from the following video transcript:--${cleanedTranscript.replace('\n', ' ')}`- const systemPrompt = "You're a helpful assistant that sumarizes a video transcript in max 10 sentences, extracting the key points"- const summary = await fetchCompletionLMSTUDIO(systemPrompt, userPrompt)- repo.setVideoSummary(id, summary)-- console.log('Download completed', summary)- return {summary, transcript: cleanedTranscript}+ return new Promise(async (resolve, reject) => {+ try {+ const transcript = await getVideoSubtitles(id, callback)+ let cleanedTranscript = cleanTranscript(transcript)+ console.log('cleanedTranscript.length', cleanedTranscript.length)+ repo.setVideoTranscript(id, cleanedTranscript)+ cleanedTranscript = cleanedTranscript.replace('\n', ' ')+ // if (process.env.KEEP_SUBTITLES === 'true')+ fs.writeFileSync(`./data/videos/${id}-sub.en.txt`, cleanedTranscript)++ const userPrompt = `+ Extract the key points from the following video transcript:++ ${cleanedTranscript.replace('\n', ' ')}`+ const systemPrompt = "You're a helpful assistant that sumarizes a video transcript in max 10 sentences, extracting the key points"+ const summary = await fetchCompletionLMSTUDIO(systemPrompt, userPrompt)+ repo.setVideoSummary(id, summary)++ console.log('Download completed', summary)+ resolve({summary, transcript: cleanedTranscript})+ } catch (error) {+ console.error('Error summarizing video', id)+ reject(error)+ }+ })}export function cleanTranscript (transcript) {return transcriptdiff --git a/lib/youtube.js b/lib/youtube.jsindex 8814ff4..cb2701d 100644--- a/lib/youtube.js+++ b/lib/youtube.js@@ -2,26 +2,37 @@ import { execa } from 'execa'import fs from 'fs'export async function downloadVideo(id, repo, callback = () => {}) {- try {- for await (const line of execa`yt-dlp -f best[ext=mp4] ${id} -o ./data/videos/${id}.mp4`.iterable()) {- callback(line)+ return new Promise(async (resolve, reject) => {+ try {+ for await (const line of execa`yt-dlp -f best[ext=mp4] ${id} -o ./data/videos/${id}.mp4`.iterable()) {+ callback(line)+ }++ repo.setVideoDownloaded(id)+ console.log('Download completed')+ resolve(id)+ } catch (error) {+ console.error('Error downloading video:', error.stderr)+ reject(error)}-- repo.setVideoDownloaded(id)- console.log('Download completed')- } catch (error) {- console.error('Error downloading video:', error)- }+ })}export async function getVideoSubtitles (id, callback = () => {}) {- for await (const line of execa`yt-dlp --skip-download --write-subs --write-auto-subs --sub-lang en --sub-format ttml --convert-subs srt --default-search ytsearch ${id} -o ./data/videos/${id}-sub`.iterable()) {- callback(line)- }- const transcriptPath = `./data/videos/${id}-sub.en.srt`- const transcript = fs.readFileSync(transcriptPath, 'utf-8')- // if (process.env.KEEP_SUBTITLES !== 'true') fs.rmSync(transcriptPath)- return transcript+ return new Promise(async (resolve, reject) => {+ try {+ for await (const line of execa`yt-dlp --skip-download --write-subs --write-auto-subs --sub-lang en --sub-format ttml --convert-subs srt --default-search ytsearch ${id} -o ./data/videos/${id}-sub`.iterable()) {+ callback(line)+ }+ const transcriptPath = `./data/videos/${id}-sub.en.srt`+ const transcript = fs.readFileSync(transcriptPath, 'utf-8')+ // if (process.env.KEEP_SUBTITLES !== 'true') fs.rmSync(transcriptPath)+ resolve(transcript)+ } catch (error) {+ console.error('Error downloading video subtitles:', error.stderr)+ reject(error)+ }+ })}export async function getVideosFor(channelName) {