Skip to content

armgit / my-yt

Public Imported from GitHub
0

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

JavaScript

chore: make updating videos optional (for testing)

Christian Feif6cec1e3fc23
diff --git a/lib/server.js b/lib/server.js
index 2ea9353..e3825e7 100644
--- a/lib/server.js
+++ b/lib/server.js
@@ -7,20 +7,22 @@ import { handleSSE, broadcastSSE } from './sse.js'
import { downloadVideo, extractIdFromUrl, isUnsupportedUrl, isYouTubeUrl } from './youtube.js'
import { updateAndPersistVideos, updateAndPersistVideosForChannel } from './update-videos.js'
-export function createServer ({repo, connections = []}) {
- let lastAdded = Date.now()
- runUpdateVideos()
- setInterval(runUpdateVideos, 1000 * 60 * 10)
- function runUpdateVideos() {
- console.log('update videos')
- updateAndPersistVideos(repo, ({name, videos}) => {
- const newVideos = videos.filter(v => v.addedAt > lastAdded)
- lastAdded = Date.now()
- if (newVideos.length > 0) {
- console.log('new videos for channel', name, newVideos.length)
- broadcastSSE(JSON.stringify({type: 'new-videos', name, videos: newVideos}), connections)
- }
- })
+export function createServer ({repo, connections = [], updateVideos = true} = {}) {
+ if (updateVideos) {
+ let lastAdded = Date.now()
+ runUpdateVideos()
+ setInterval(runUpdateVideos, 1000 * 60 * 10)
+ function runUpdateVideos() {
+ console.log('update videos')
+ updateAndPersistVideos(repo, ({name, videos}) => {
+ const newVideos = videos.filter(v => v.addedAt > lastAdded)
+ lastAdded = Date.now()
+ if (newVideos.length > 0) {
+ console.log('new videos for channel', name, newVideos.length)
+ broadcastSSE(JSON.stringify({type: 'new-videos', name, videos: newVideos}), connections)
+ }
+ })
+ }
}
const llmSettings = {