A clean and minimal youtube frontend, without all the ads and whistles
JavaScript
chore: less logs
Christian Feiebb7d8c83be0
diff --git a/client/components/channels-list.js b/client/components/channels-list.jsindex f4f1343..bbed4f2 100644--- a/client/components/channels-list.js+++ b/client/components/channels-list.js@@ -44,7 +44,7 @@ class ChannelsList extends HTMLElement {}channelClick(event) {const $searchInput = document.querySelector('#search')- if (!$searchInput) return console.log('missing search field, skipping channel event register')+ if (!$searchInput) returnconst channel = `@${event.target.innerText}`const channels = this.querySelectorAll('.channel')diff --git a/client/components/search-videos.js b/client/components/search-videos.jsindex 4955a52..c447363 100644--- a/client/components/search-videos.js+++ b/client/components/search-videos.js@@ -37,7 +37,6 @@ class SearchVideos extends HTMLElement {headers: { 'Content-Type': 'application/json' },body: JSON.stringify({ id: searchTerm, external: true }),})- .then(() => console.log('Download started')).catch((error) => console.error('Error starting download:', error))event.target.value = ''returndiff --git a/client/components/video-element.js b/client/components/video-element.jsindex 5dbcdfa..2f19121 100644--- a/client/components/video-element.js+++ b/client/components/video-element.js@@ -100,7 +100,7 @@ class VideoElement extends HTMLElement {const downloadStartedText = '⚡️ Download started'let $downloadButton = event.target.classList.contains('.action') ? event.target : this.querySelector('.action.download')- if ($downloadButton.innerText === downloadStartedText) return console.log('already downloading')+ if ($downloadButton.innerText === downloadStartedText) returnelse $downloadButton.innerText = downloadStartedTextthis.classList.add('downloading')@@ -110,7 +110,6 @@ class VideoElement extends HTMLElement {headers: { 'Content-Type': 'application/json' },body: JSON.stringify({ id: this.video.id }),})- .then(() => console.log('Download started')).catch((error) => console.error('Error starting download:', error))}deleteVideoHandler (event) {@@ -122,7 +121,6 @@ class VideoElement extends HTMLElement {body: JSON.stringify({ id: this.video.id }),}).then(() => {- console.log('Video deleted')this.video.downloaded = falsethis.classList.remove('downloading')this.classList.remove('big')@@ -134,14 +132,13 @@ class VideoElement extends HTMLElement {summarizeVideoHandler (event) {event.preventDefault()const summaryStartedText = '⚡️ summary started'- if (event.target.innerText === summaryStartedText) return console.log('already summarizing')+ if (event.target.innerText === summaryStartedText) returnevent.target.innerText = summaryStartedTextfetch('/api/summarize-video', {method: 'POST',headers: { 'Content-Type': 'application/json' },body: JSON.stringify({ id: this.video.id }),})- .then(() => console.log('summary started')).catch((error) => console.error('Error starting summary:', error))}showSummaryHandler (event) {@@ -177,16 +174,11 @@ class VideoElement extends HTMLElement {filterByChannelHandler (event) {const $searchInput = document.querySelector('#search')const channel = `@${this.video.channelName}`- if ($searchInput && $searchInput.value !== channel) {- $searchInput.value = channel- } else {- $searchInput.value = ''- }+ $searchInput.value = ($searchInput && $searchInput.value !== channel) ? channel : ''$searchInput.dispatchEvent(new Event('keyup'))}registerVideoEvents (video) {video.addEventListener('play', () => {- console.log('video event play')this.classList.add('big')setTimeout(this.scrollIntoViewWithOffset.bind(this, document.querySelector('body > header').clientHeight, "smooth"), 110)this.pauseOtherVideos(video)diff --git a/client/components/video-quality-form.js b/client/components/video-quality-form.jsindex 177f739..17193b6 100644--- a/client/components/video-quality-form.js+++ b/client/components/video-quality-form.js@@ -6,13 +6,9 @@ class VideoQualityForm extends HTMLElement {this.render()this.registerEvents()- fetch('/api/video-quality', {- method: 'GET'- }).then(response => response.json())- .then((videoQuality) => {- console.log('video quality', videoQuality)- this.querySelector('#video-quality').value = +videoQuality- })+ fetch('/api/video-quality')+ .then(response => response.json())+ .then((videoQuality) => this.querySelector('#video-quality').value = +videoQuality).catch(error => console.error('Error:', error))}disconnectedCallback () {@@ -46,12 +42,9 @@ class VideoQualityForm extends HTMLElement {setVideoQualityHandler (event) {event.preventDefault()- console.log('change video quality', event.target.value)fetch('/api/video-quality', {method: 'POST',- headers: {- 'Content-Type': 'application/json'- },+ headers: { 'Content-Type': 'application/json' },body: event.target.value})}diff --git a/client/lib/router.js b/client/lib/router.jsindex 541ccf7..8456642 100644--- a/client/lib/router.js+++ b/client/lib/router.js@@ -1,12 +1,10 @@const routes = {'/': { template: document.getElementById('main-template'), async initialize() {- console.log('initialize /')-document.getElementById('home-link').classList.add('hide')let $videosContainer = document.querySelector('.main-videos-container')let videos = await fetch('/api/videos').then(res => res.json())- console.log('videos.length', videos.length)+if (videos.length === 0) {document.querySelector('empty-state').style.display = ''} else {@@ -31,8 +29,6 @@ const routes = {utils.applyShowBigPlayer(store.get(store.showBigPlayerKey))} },'/settings': { template: document.getElementById('settings-template'), async initialize () {- console.log('initalize /settings')-document.getElementById('home-link').classList.remove('hide')document.querySelector('search-videos #search').setAttribute('disabled', 'disabled')@@ -68,15 +64,11 @@ const routes = {}handleRoute()-addEventListener('popstate', (event) => {- console.log('popstate', location.pathname)- handleRoute()-})+addEventListener('popstate', handleRoute)document.querySelectorAll('[href="/"],[href="/settings"]').forEach(($el) => {$el.addEventListener('click', (event) => {event.preventDefault()const path = new URL($el.href, location.origin).pathname- console.log('navigating ->', path)history.pushState({}, '', path)var popStateEvent = new PopStateEvent('popstate', {})dispatchEvent(popStateEvent)@@ -84,8 +76,8 @@ document.querySelectorAll('[href="/"],[href="/settings"]').forEach(($el) => {})-function handleRoute(route = location.pathname) {- console.log('handling route', route)+function handleRoute() {+ const route = location.pathnameif (routes[route]) {document.querySelector('main').replaceChildren(routes[route].template.content.cloneNode(true))routes[route].initialize && routes[route].initialize()diff --git a/lib/repository.js b/lib/repository.jsindex 4d08d7d..8868f20 100644--- a/lib/repository.js+++ b/lib/repository.js@@ -13,25 +13,19 @@ export default class Repository {fs.mkdirSync(`${this.basePath}/videos`, { recursive: true })if (!fs.existsSync(this.paths.videos)) {- // console.log('initializing ', this.paths.videos)fs.writeFileSync(this.paths.videos, '[]')}if (!fs.existsSync(this.paths.channels)) {- // console.log('initializing ', this.paths.channels)fs.writeFileSync(this.paths.channels, '[]')}if (!fs.existsSync(this.paths.settings)) {- // console.log('initializing ', this.paths.settings)fs.writeFileSync(this.paths.settings, JSON.stringify({"videoQuality":720}, null, 2))}try {this.videos = JSON.parse(fs.readFileSync(this.paths.videos))- // console.log('read videos', this.videos.length)this.channels = JSON.parse(fs.readFileSync(this.paths.channels))- // console.log('read channels', this.channels.length)this.settings = JSON.parse(fs.readFileSync(this.paths.settings))- // console.log('read settings', this.settings)} catch (err) {console.error(err)}@@ -39,7 +33,6 @@ export default class Repository {fs.readdirSync(`${this.basePath}/videos`).forEach(file => {const format = file.substring(file.lastIndexOf('.') + 1)if (!['mp4', 'webm'].includes(format)) return- if (file.includes('.uncut.') || file.includes('.f')) return // skip .uncut. and formatsconst videoId = file.replace('.mp4', '').replace('.webm', '')const location = `${this.basePath}/videos/${file}`this.updateVideo(videoId, {downloaded: true, location, format})@@ -53,21 +46,17 @@ export default class Repository {}addChannel (name) {this.channels.push({name})- console.log('added channel', name)this.saveChannels()}deleteChannel (name) {this.channels.splice(this.channels.findIndex(c => c.name === name), 1)- console.log('removed channel', name)this.saveChannels()}saveChannels() {fs.writeFileSync(this.paths.channels, JSON.stringify(this.channels, null, 2))- console.log('saving channels', this.channels.length)}saveSettings() {fs.writeFileSync(this.paths.settings, JSON.stringify(this.settings, null, 2))- console.log('saving settings', this.settings)}getVideos (query = {}) {const isFiltering = Object.keys(query).length > 0 && query.filter@@ -76,7 +65,6 @@ export default class Repository {.sort((a, b) => +new Date(b.publishedAt) - +new Date(a.publishedAt))if (isFiltering) {- console.log({query})const searchTerm = query.filter.toLowerCase()if (searchTerm.startsWith('@')) {videos = videos.filter(v => {@@ -98,7 +86,6 @@ export default class Repository {return this.videos.find(v => v.id === id)}getChannelVideos (name) {- console.log('get channel videos', name)return this.videos.filter(v => v.channelName === name)}upsertVideos(videos) {@@ -109,7 +96,6 @@ export default class Repository {this.videos[index] = Object.assign(this.videos[index], v)} else {this.videos.push(v)- console.log('upsert video, insert', v.id)}})this.saveVideos()@@ -120,14 +106,11 @@ export default class Repository {Object.assign(this.videos[index], update)this.saveVideos()return this.videos[index]- } else {- console.log('cannot update video, video does not exist', id)}}deleteVideo(id) {this.videos = this.videos.map(v => {if (v.id === id) {- console.log('deleting video', id)return Object.assign(v, {downloaded: false})}return v@@ -137,7 +120,6 @@ export default class Repository {const files = fs.readdirSync(`${this.basePath}/videos`)files.forEach(file => {if (file.startsWith(id)) {- console.log('deleting video file', file)fs.unlinkSync(`${this.basePath}/videos/${file}`)}})@@ -150,7 +132,6 @@ export default class Repository {let ignored = falseif (index !== -1) {ignored = this.videos[index].ignored = !this.videos[index].ignored- console.log('set video ignored', id, ignored)} else {console.log('cannot set video ignored, video does not exist', id)}@@ -158,15 +139,12 @@ export default class Repository {return ignored}setVideoTranscript(id, transcript = '') {- console.log('set video transcript', id)return this.updateVideo(id, {transcript})}setVideoSummary(id, summary = '') {- console.log('set video summary', id)return this.updateVideo(id, {summary})}setVideoDownloaded(id, downloaded = true) {- console.log('set video downloaded', id)return this.updateVideo(id, {downloaded})}patchVideo(video) {diff --git a/lib/server.js b/lib/server.jsindex e392e47..292ede7 100644--- a/lib/server.js+++ b/lib/server.js@@ -301,8 +301,7 @@ function watchVideoHandler(req, res, repo) {const fileStream = fs.createReadStream(location, options)fileStream.on("error", error => {- console.log(`Error reading file ${location}.`)- console.log(error)+ console.error(`Error reading file ${location}.`, error)res.writeHead(500)res.end()})@@ -383,7 +382,6 @@ async function reclaimDiskSpaceHandler(req, res, repo) {function captionsHandler(req, res) {const captionsPath = './data' + req.url.replace('captions', 'videos') + '.en.vtt'- console.log(captionsPath)if (!fs.existsSync(captionsPath)) {res.writeHead(404)res.end()diff --git a/lib/subtitles-summary.js b/lib/subtitles-summary.jsindex f94c195..8366e48 100644--- a/lib/subtitles-summary.js+++ b/lib/subtitles-summary.js@@ -10,7 +10,6 @@ export async function summarizeVideo(id, repo, llmSettings = {}, callback = () =repo.setVideoTranscript(id, cleanedTranscript)cleanedTranscript = cleanedTranscript.replace('\n', ' ')fs.writeFileSync(`./data/videos/${id}.en.txt`, cleanedTranscript)- console.log('cleanedTranscript.length', cleanedTranscript.length)const userPrompt = `Extract the key points from the following video transcript:@@ -20,8 +19,6 @@ ${cleanedTranscript}`.trim()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, llmSettings)repo.setVideoSummary(id, summary)-- console.log('Summary completed')resolve({summary, transcript: cleanedTranscript})} catch (error) {console.error('Error summarizing video', id, error.message)diff --git a/lib/update-videos.js b/lib/update-videos.jsindex 2f2bd0f..2b81aba 100644--- a/lib/update-videos.js+++ b/lib/update-videos.js@@ -9,7 +9,6 @@ export async function updateAndPersistVideos (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)diff --git a/lib/youtube.js b/lib/youtube.jsindex b989885..dabc428 100644--- a/lib/youtube.js+++ b/lib/youtube.js@@ -24,7 +24,6 @@ export async function downloadVideo(id, repo, callback = () => {}) {format = location.substring(location.lastIndexOf('.') + 1)}}- console.log('downloaded file to', location)if (!repo.getVideo(id)) {const video = await getVideo(id)@@ -37,8 +36,6 @@ export async function downloadVideo(id, repo, callback = () => {}) {repo.updateVideo(id, {downloaded: true, location, format})normalizeSubtitleFiles(id)-- console.log('Download completed')resolve(id)} catch (error) {console.error(error)@@ -85,7 +82,6 @@ function normalizeSubtitleFiles (id) {}export async function getVideosFor(channelName) {try {- // console.log('fetching videos for', channelName)const response = await fetch(`https://www.youtube.com/${channelWithAt(channelName)}/videos`, {headers: fetchYoutubeHeaders})diff --git a/lib/yt-dlp.js b/lib/yt-dlp.jsindex c756dff..60812e5 100644--- a/lib/yt-dlp.js+++ b/lib/yt-dlp.js@@ -22,6 +22,5 @@ export function subtitles(id) {function getOptionalCookiesPath() {if (fs.existsSync('/app/cookies.txt')) return '/app/cookies.txt'if (fs.existsSync('./cookies.txt')) return './cookies.txt'- console.log('cookies not set')return}\ No newline at end of file