Skip to content

armgit / my-yt

Public Imported from GitHub
0

A clean and minimal youtube frontend, without all the ads and whistles

JavaScript

refactor: callback with err

Christian Feiaeca4446933c
diff --git a/lib/subtitles-summary.js b/lib/subtitles-summary.js
index 1e7d612..242a5e0 100644
--- a/lib/subtitles-summary.js
+++ b/lib/subtitles-summary.js
@@ -11,7 +11,7 @@ export async function summarizeVideo (id, repo, llmSettings = {}, callback = ()
repo.setVideoTranscript(id, cleanedTranscript)
cleanedTranscript = cleanedTranscript.replace('\n', ' ')
fs.writeFileSync(`./data/videos/${id}.en.txt`, cleanedTranscript)
- callback('prompting llm') // eslint-disable-line
+ callback(null, 'prompting llm') // eslint-disable-line
const userPrompt = `
Extract the key points from the following video transcript:
@@ -22,7 +22,7 @@ ${cleanedTranscript}`.trim()
Begin by summarizing it into a single paragraph, followed by a longer summary that expands on the key points.
Do not describe or mention the video itself. Simply summarize the points it makes. Focus on the overall or underlying takeaway, cause, reason.`
const summary = await llm.summarize(systemPrompt, userPrompt, llmSettings)
- callback('received summary') // eslint-disable-line
+ callback(null, 'received summary') // eslint-disable-line
repo.setVideoSummary(id, summary)
resolve({ summary, transcript: cleanedTranscript })
} catch (error) {
diff --git a/lib/youtube.js b/lib/youtube.js
index 52785ed..74a38d8 100644
--- a/lib/youtube.js
+++ b/lib/youtube.js
@@ -63,7 +63,7 @@ export async function getVideoSubtitles (id, callback = () => {}) {
if (!fs.existsSync(transcriptPath)) {
for await (const line of ytdlp.subtitles(id)) {
console.log(line)
- callback(line)
+ callback(null, line)
}
}
normalizeSubtitleFiles(id)
diff --git a/server/router/api.js b/server/router/api.js
index d7291c5..d570e54 100644
--- a/server/router/api.js
+++ b/server/router/api.js
@@ -137,8 +137,13 @@ async function summarizeVideoHandler (req, res, repo, connections = [], state =
state.summarizing = state.summarizing || {}
state.summarizing[id] = { lines: [] }
- summarizeVideo(id, repo, llmSettings, (line) => {
- broadcastSSE(JSON.stringify({ type: 'download-log-line', line }), connections)
+ summarizeVideo(id, repo, llmSettings, (err, line) => {
+ if (err) {
+ console.error(err)
+ broadcastSSE(JSON.stringify({ type: 'download-log-line', line: `Error summarizing video ${id}: ${err.message}` }), connections)
+ } else {
+ broadcastSSE(JSON.stringify({ type: 'download-log-line', line }), connections)
+ }
})
.then(({ summary, transcript }) =>
broadcastSSE(JSON.stringify({ type: 'summary', summary, transcript, videoId: id }), connections))