A clean and minimal youtube frontend, without all the ads and whistles
JavaScript
refactor: extract update videos fns
Christian Feifd4b3b8ac6b4
diff --git a/lib/server.js b/lib/server.jsindex af8792c..85bd9aa 100644--- a/lib/server.js+++ b/lib/server.js@@ -3,7 +3,8 @@ import { URL } from 'url'import fs from 'fs'import { summarizeVideo } from './subtitles-summary.js'import { handleSSE, broadcastSSE } from './sse.js'-import { downloadVideo, getVideosFor } from './youtube.js'+import { downloadVideo } from './youtube.js'+import { updateAndPersistVideos, updateAndPersistVideosForChannel } from './update-videos.js'export function createServer ({repo, connections = []}) {let lastAdded = Date.now()@@ -242,21 +243,3 @@ export function createServer ({repo, connections = []}) {return res.end(JSON.stringify(repo.toggleIgnoreVideo(id)))}}--async function updateAndPersistVideos (repo, callback = () => {}) {- const channels = repo.getChannels()- for (const channel of channels) {- await updateAndPersistVideosForChannel(channel.name, repo, callback)- }-}--async function updateAndPersistVideosForChannel(name, repo, callback = () => {}) {- let videos = await getVideosFor(name)- console.log('received videos for ', name, videos?.length)- if (videos) {- videos = videos.map(v => repo.patchVideo(v))- repo.upsertVideos(videos)- callback({name, videos})- }- return videos-}diff --git a/lib/update-videos.js b/lib/update-videos.jsnew file mode 100644index 0000000..1d36818--- /dev/null+++ b/lib/update-videos.js@@ -0,0 +1,19 @@+import { getVideosFor } from './youtube.js'++export async function updateAndPersistVideos (repo, callback = () => {}) {+ const channels = repo.getChannels()+ for (const channel of channels) {+ await updateAndPersistVideosForChannel(channel.name, repo, callback)+ }+}++export async function updateAndPersistVideosForChannel(name, repo, callback = () => {}) {+ let videos = await getVideosFor(name)+ console.log('received videos for ', name, videos?.length)+ if (videos) {+ videos = videos.map(v => repo.patchVideo(v))+ repo.upsertVideos(videos)+ callback({name, videos})+ }+ return videos+}