A clean and minimal youtube frontend, without all the ads and whistles
JavaScript
feat: video bookmarks with timestamps and notes
Christian Fei8881b28b9776
diff --git a/README.md b/README.mdindex e91d9ac..0f30d8b 100644--- a/README.md+++ b/README.md@@ -20,6 +20,7 @@ A clean and minimal youtube frontend supported by yt-dlp, and optionally your lo- Play videos in background- Summarize video content using your local AI model (e.g. Ollama/LMStudio) or hosted provider (e.g. OpenAI, Anthropic)- Native Picture-in-Picture support+- Bookmark videos with timestamps and notes π (keyboard shortcut: press `b` while watching)- No dependencies (except for `nano-spawn`, which itself has no transient deps)- HTML/CSS only, no JS frameworks on client/server side- Subtitles using `<track>` element and WebVTT APIdiff --git a/client/components/search-videos.js b/client/components/search-videos.jsindex 05d334c..9bb4271 100644--- a/client/components/search-videos.js+++ b/client/components/search-videos.js@@ -21,6 +21,7 @@ class SearchVideos extends HTMLElement {const downloaded = searchParams.get('downloaded') || ''const summarized = searchParams.get('summarized') || ''const unwatched = searchParams.get('unwatched') || ''+ const bookmarked = searchParams.get('bookmarked') || ''const searchTerm = searchParams.get('filter') || ''this.querySelector('#search').value = searchTermthis.querySelector('#excluded').checked = excluded === 'true'@@ -28,6 +29,7 @@ class SearchVideos extends HTMLElement {this.querySelector('#downloaded').checked = downloaded === 'true'this.querySelector('#summarized').checked = summarized === 'true'this.querySelector('#unwatched').checked = unwatched === 'true'+ this.querySelector('#bookmarked').checked = bookmarked === 'true'}disconnectedCallback () {@@ -41,6 +43,7 @@ class SearchVideos extends HTMLElement {this.querySelector('#downloaded').addEventListener('change', this.searchHandler.bind(this))this.querySelector('#summarized').addEventListener('change', this.searchHandler.bind(this))this.querySelector('#unwatched').addEventListener('change', this.searchHandler.bind(this))+ this.querySelector('#bookmarked').addEventListener('change', this.searchHandler.bind(this))}unregisterEvents () {@@ -50,6 +53,7 @@ class SearchVideos extends HTMLElement {this.querySelector('#downloaded').removeEventListener('change', this.searchHandler.bind(this))this.querySelector('#summarized').removeEventListener('change', this.searchHandler.bind(this))this.querySelector('#unwatched').removeEventListener('change', this.searchHandler.bind(this))+ this.querySelector('#bookmarked').removeEventListener('change', this.searchHandler.bind(this))}render () {@@ -79,6 +83,10 @@ class SearchVideos extends HTMLElement {<input type="checkbox" id="unwatched"/><label for="unwatched">unwatched</label></div>+ <div class="flex-1">+ <input type="checkbox" id="bookmarked"/>+ <label for="bookmarked">π bookmarked</label>+ </div></div></details></div>@@ -114,6 +122,7 @@ class SearchVideos extends HTMLElement {const downloaded = this.querySelector('#downloaded').checkedconst summarized = this.querySelector('#summarized').checkedconst unwatched = this.querySelector('#unwatched').checked+ const bookmarked = this.querySelector('#bookmarked').checkedif (excluded) {this.querySelector('#ignored').disabled = true@@ -126,7 +135,7 @@ class SearchVideos extends HTMLElement {this.querySelector('#excluded').disabled = false}- const query = `?filter=${encodeURIComponent(searchTerm)}${excluded ? '&excluded=true' : ''}${downloaded ? '&downloaded=true' : ''}${ignored ? '&ignored=true' : ''}${summarized ? '&summarized=true' : ''}${unwatched ? '&unwatched=true' : ''}`+ const query = `?filter=${encodeURIComponent(searchTerm)}${excluded ? '&excluded=true' : ''}${downloaded ? '&downloaded=true' : ''}${ignored ? '&ignored=true' : ''}${summarized ? '&summarized=true' : ''}${unwatched ? '&unwatched=true' : ''}${bookmarked ? '&bookmarked=true' : ''}`window.history.pushState({}, '', query)fetch(ENDPOINTS.VIDEOS + query)diff --git a/client/components/video-element.js b/client/components/video-element.jsindex 3182356..372a794 100644--- a/client/components/video-element.js+++ b/client/components/video-element.js@@ -97,9 +97,54 @@ class VideoElement extends HTMLElement {: /* html */`<span tabindex="0" class="action show-summary" data-video-id="${this.video.id}">π Summary</span>`}<a href="https://www.youtube.com/watch?v=${this.video.id}" class="action open-externally" target="_blank">πΊ external</a><span tabindex="0" class="action watched" data-video-id="${this.video.id}">${store.isWatched(this.video.id) ? 'β Watched' : 'β Unwatched'}</span>+ <span tabindex="0" class="action bookmark" data-video-id="${this.video.id}">π Bookmark</span></div>`+ // Show bookmarks panel if video has bookmarks+ if (this.video.bookmarks && this.video.bookmarks.length > 0) {+ const actionContainer = this.querySelector('.actions')+ if (actionContainer && !this.querySelector('.bookmarks-list')) {+ const bookmarksHtml = `<div class="bookmarks-list" style="margin-top: 8px;">+ ${this.video.bookmarks.map(b => `<span tabindex="0" class="bookmark-item" data-bookmark-id="${b.id}" title="${(b.note || '').replace(/"/g, '"')}">π ${this.formatTime(b.time)}${b.note ? ' Β· ' + b.note : ''}</span>`).join('')}+ </div>`+ actionContainer.insertAdjacentHTML('afterend', bookmarksHtml)+ }+ }++ // Add bookmark dialog if not exists+ if (!document.querySelector('dialog#bookmark-dialog')) {+ const dialog = document.createElement('dialog')+ dialog.id = 'bookmark-dialog'+ dialog.innerHTML = /* html */`+ <form method="dialog" id="bookmark-form">+ <label>Time (seconds):</label>+ <input type="number" id="bookmark-time" step="0.1" min="0" value="0" />+ <label>Note:</label>+ <input type="text" id="bookmark-note" placeholder="What's happening here?" />+ <div style="margin-top: 12px; display: flex; gap: 8px;">+ <button type="submit">Save</button>+ <button type="button" id="cancel-bookmark-btn">Cancel</button>+ </div>+ </form>+ `+ document.body.appendChild(dialog)++ dialog.querySelector('#cancel-bookmark-btn').addEventListener('click', () => {+ dialog.close()+ })++ dialog.querySelector('#bookmark-form').addEventListener('submit', (e) => {+ e.preventDefault()+ const time = dialog.querySelector('#bookmark-time').value+ const note = dialog.querySelector('#bookmark-note').value+ this.addBookmarkAtTime(time, note)+ })++ // Also support keyboard shortcut (b key when video is playing)+ document.addEventListener('keydown', this.handleBookmarkKey.bind(this))+ }+if (window.state && window.state.downloading && window.state.downloading[this.video.id]) {this.dataset.downloading = 'true'}@@ -120,6 +165,17 @@ class VideoElement extends HTMLElement {addClickListener(this.querySelector('.action.watched'), this.toggleWatchedVideoHandler.bind(this))addClickListener(this.querySelector('.channel-name'), this.filterByChannelHandler.bind(this))addClickListener(this.querySelector('.play.video-placeholder'), this.watchVideoHandler.bind(this))+ addClickListener(this.querySelector('.action.bookmark'), this.toggleBookmarkDialog.bind(this))++ // Register bookmark item clicks to jump in video+ this.querySelectorAll('.bookmark-item').forEach(item => {+ addClickListener(item, this.jumpToBookmarkTime.bind(this))+ })++ // Register SSE bookmark events+ if (typeof window.addEventListenerSSE === 'function') {+ window.addEventListenerSSE('bookmark-added', this.handleBookmarkAdded.bind(this))+ }}unregisterEvents () {@@ -132,7 +188,17 @@ class VideoElement extends HTMLElement {removeClickListener(this.querySelector('.action.watched'), this.toggleWatchedVideoHandler.bind(this))removeClickListener(this.querySelector('.channel-name'), this.filterByChannelHandler.bind(this))removeClickListener(this.querySelector('.play.video-placeholder'), this.watchVideoHandler.bind(this))- this.querySelector('video') && this.unregisterVideoEvents(this.querySelector('video'))+ removeClickListener(this.querySelector('.action.bookmark'), this.toggleBookmarkDialog.bind(this))++ this.querySelectorAll('.bookmark-item').forEach(item => {+ removeClickListener(item, this.jumpToBookmarkTime.bind(this))+ })++ if (typeof window.removeEventListenerSSE === 'function') {+ window.removeEventListenerSSE('bookmark-added', this.handleBookmarkAdded.bind(this))+ }++ document.removeEventListener('keydown', this.handleBookmarkKey)}watchVideoHandler (event) {@@ -295,6 +361,129 @@ class VideoElement extends HTMLElement {const top = this.getBoundingClientRect().top - offset - document.body.getBoundingClientRect().topwindow.scrollTo({ top, behavior })}++ // === Bookmark Methods ===++ toggleBookmarkDialog (event) {+ event.preventDefault()+ const dialog = document.querySelector('dialog#bookmark-dialog')+ if (!dialog) return++ // Get current time from playing video, default to 0+ const video = this.querySelector('video')+ dialog.querySelector('#bookmark-time').value = video ? Math.round(video.currentTime * 10) / 10 : 0+ dialog.querySelector('#bookmark-note').value = ''++ // Store current video reference for the dialog submit handler+ dialog.dataset.videoId = this.video.id+ dialog.showModal()++ // Focus the time input for quick entry+ setTimeout(() => dialog.querySelector('#bookmark-time').focus(), 100)+ }++ addBookmarkAtTime (time, note = '') {+ const videoId = this.video.id+ fetch(ENDPOINTS.BOOKMARKS, {+ method: 'POST',+ headers: { 'Content-Type': 'application/json' },+ body: JSON.stringify({ id: videoId, time: parseFloat(time), note })+ })+ .then(res => {+ if (!res.ok) throw new Error('Failed to add bookmark')+ return res.json()+ })+ .then(bookmark => {+ addToast(`Bookmark saved at ${this.formatTime(bookmark.time)}`)+ document.querySelector('dialog#bookmark-dialog').close()++ // Refresh this video element to show the new bookmark+ const $videoElement = document.querySelector(`video-element[data-video-id="${videoId}"]`)+ if ($videoElement) {+ $videoElement.dispatchEvent(new CustomEvent('refresh'))+ }+ })+ .catch(error => {+ console.error('Error adding bookmark:', error)+ addToast('Failed to save bookmark')+ })+ }++ jumpToBookmarkTime (event) {+ event.preventDefault()+ const bookmarkId = parseInt(event.target.dataset.bookmarkId)+ const videoElement = document.querySelector(`video-element[data-video-id="${this.video.id}"]`)+ if (!videoElement) return++ // Find the video element's player+ const video = this.querySelector('video')+ if (!video) {+ // Start playing the video first, then seek+ this.watchVideoHandler({ preventDefault: () => {} })+ setTimeout(() => {+ const newVideo = this.querySelector('video')+ if (newVideo) {+ this.seekToBookmark(bookmarkId, newVideo)+ }+ }, 500)+ return+ }++ this.seekToBookmark(bookmarkId, video)+ }++ seekToBookmark (bookmarkId, video) {+ const bookmarks = this.video.bookmarks || []+ const bm = bookmarks.find(b => b.id === bookmarkId)+ if (bm && video) {+ video.currentTime = bm.time+ addToast(`Jumped to ${this.formatTime(bm.time)}`)+ }+ }++ handleBookmarkAdded (data) {+ if (data.videoId !== this.video.id) return+ // Refresh to show new bookmark in list+ const $videoElement = document.querySelector(`video-element[data-video-id="${data.videoId}"]`)+ if ($videoElement) {+ $videoElement.dispatchEvent(new CustomEvent('refresh'))+ }+ }++ handleBookmarkKey (event) {+ // Press 'b' when a video is playing to toggle bookmark dialog+ if (event.key === 'b' && !event.target.closest('input, textarea')) {+ const activeVideo = document.querySelector('video:played') || document.querySelector('video[autoplay]')+ if (activeVideo) {+ const videoEl = activeVideo.closest('video-element')+ if (videoEl) {+ const dialog = document.querySelector('dialog#bookmark-dialog')+ if (dialog && !dialog.open) {+ const time = Math.round(activeVideo.currentTime * 10) / 10+ dialog.querySelector('#bookmark-time').value = time+ dialog.dataset.videoId = videoEl.video.id+ dialog.showModal()+ }+ }+ }+ }++ // Press 'Escape' to close bookmark dialog+ if (event.key === 'Escape') {+ const dialog = document.querySelector('dialog#bookmark-dialog')+ if (dialog && dialog.open) {+ dialog.close()+ }+ }+ }++ formatTime (seconds) {+ const h = Math.floor(seconds / 3600)+ const m = Math.floor((seconds % 3600) / 60)+ const s = Math.floor(seconds % 60)+ if (h > 0) return `${h}:${String(m).padStart(2, '0')}:${String(s).padStart(2, '0')}`+ return `${m}:${String(s).padStart(2, '0')}`+ }}customElements.define('video-element', VideoElement)diff --git a/client/lib/api.js b/client/lib/api.jsindex 815ffbd..a227bca 100644--- a/client/lib/api.js+++ b/client/lib/api.js@@ -13,7 +13,10 @@ export const ENDPOINTS = {RECLAIM_DISK_SPACE: '/api/reclaim-disk-space',TRANSCODE_VIDEOS: '/api/transcode-videos',EXCLUDED_TERMS: '/api/excluded-terms',- WATCHED_VIDEO: '/api/watched-video'+ WATCHED_VIDEO: '/api/watched-video',+ BOOKMARKS: '/api/bookmarks',+ GET_BOOKMARKS: '/api/bookmarks/:id',+ DELETE_BOOKMARK: '/api/delete-bookmark'}export class ApiClient {diff --git a/client/main.css b/client/main.cssindex 9523f2f..e7fd254 100644--- a/client/main.css+++ b/client/main.css@@ -677,6 +677,114 @@ summary:hover {color: var(--text-hover);}+/* Bookmark styles */+.action.bookmark {+ color: #e67e22;+ cursor: pointer;+}++.action.bookmark:hover {+ color: #d35400;+}++.bookmarks-list {+ display: flex;+ flex-wrap: wrap;+ gap: 4px;+ padding: 6px 8px;+ background-color: var(--bg-input);+ border-radius: 4px;+ margin-top: 6px;+}++.bookmark-item {+ display: inline-block;+ padding: 2px 6px;+ background-color: var(--filter-button-bg);+ border-radius: 3px;+ font-size: 12px;+ cursor: pointer;+ color: var(--text-secondary);+ transition: all 0.15s ease;+}++.bookmark-item:hover {+ background-color: var(--active-channel);+ color: white;+}++/* Bookmark dialog styling */+dialog#bookmark-dialog {+ border: 1px solid var(--border-light);+ border-radius: 8px;+ padding: 1.5rem;+ background-color: var(--bg-primary);+ color: var(--text-primary);+ box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);+}++dialog#bookmark-dialog::backdrop {+ background: rgba(0, 0, 0, 0.5);+}++dialog#bookmark-dialog form {+ display: flex;+ flex-direction: column;+ gap: 10px;+ margin-bottom: 0;+}++dialog#bookmark-dialog label {+ font-weight: 600;+ font-size: 13px;+ color: var(--text-secondary);+}++dialog#bookmark-dialog input[type="number"],+dialog#bookmark-dialog input[type="text"] {+ width: 100%;+}++dialog#bookmark-dialog button {+ padding: 6px 16px;+ border-radius: 4px;+ cursor: pointer;+ background-color: var(--active-channel);+ color: white;+ border: none;+}++dialog#bookmark-dialog button[type="button"] {+ background-color: var(--filter-button-bg);+ color: var(--text-primary);+}++/* Bookmarks filter */+#bookmarks-filter {+ background-color: var(--filter-button-bg);+ color: var(--text-secondary);+}++#bookmarks-filter.active {+ background-color: var(--filter-button-active-bg);+ color: var(--filter-button-active-text);+}++/* Bookmarks count badge */+.bookmark-count {+ display: inline-block;+ min-width: 14px;+ height: 14px;+ line-height: 14px;+ text-align: center;+ background-color: var(--active-channel);+ color: white;+ border-radius: 7px;+ font-size: 10px;+ padding: 0 4px;+ margin-left: 2px;+}+#notifications-container {position: fixed;bottom: 4em;diff --git a/client/main.js b/client/main.jsindex f570fcd..e406ae4 100644--- a/client/main.js+++ b/client/main.js@@ -123,6 +123,13 @@ window.eventSource.onmessage = (message) => {})return}+ if (data.type === 'bookmark-added' && data.videoId) {+ ;[...document.querySelectorAll(`[data-video-id="${data.videoId}"]`)].forEach($video => {+ if (!$video.dataset.data) return+ $video.render()+ })+ return+ }console.warn('unhandled', data)} catch (err) {console.error('sse parse error', err)diff --git a/lib/repository.js b/lib/repository.jsindex ceee0b3..e9c2e94 100644--- a/lib/repository.js+++ b/lib/repository.js@@ -121,6 +121,10 @@ export default class Repository {videos = videos.filter(v => v.summary)}+ if (query.bookmarked === 'true') {+ videos = videos.filter(v => v.bookmarks && v.bookmarks.length > 0)+ }+const watchedVideos = this.getWatchedVideos()if (query.unwatched === 'true') {videos = videos.filter(v => !watchedVideos.includes(v.id))@@ -284,4 +288,61 @@ export default class Repository {this.settings.watchedVideos = watchedthis.saveSettings()}++ getVideoBookmarks (videoId) {+ const video = this.getVideo(videoId)+ return (video && video.bookmarks) || []+ }++ addBookmark (videoId, bookmark) {+ const video = this.getVideo(videoId)+ if (!video) return null+ if (!video.bookmarks) { video.bookmarks = [] }+ const newBookmark = Object.assign({ id: Date.now(), createdAt: Date.now() }, bookmark)+ video.bookmarks.push(newBookmark)+ this.saveVideos()+ return newBookmark+ }++ deleteBookmark (videoId, bookmarkId) {+ const video = this.getVideo(videoId)+ if (!video || !video.bookmarks) return false+ const index = video.bookmarks.findIndex(b => b.id === bookmarkId)+ if (index >= 0) {+ video.bookmarks.splice(index, 1)+ this.saveVideos()+ return true+ }+ return false+ }++ updateBookmark (videoId, bookmarkId, updates) {+ const video = this.getVideo(videoId)+ if (!video || !video.bookmarks) return null+ const bookmark = video.bookmarks.find(b => b.id === bookmarkId)+ if (!bookmark) return null+ Object.assign(bookmark, updates, { updatedAt: Date.now() })+ this.saveVideos()+ return bookmark+ }++ getVideoWithBookmarks (videoId) {+ const video = this.getVideo(videoId)+ if (!video) return null+ const result = Object.assign({}, video, { bookmarks: this.getVideoBookmarks(videoId) })+ return result+ }++ searchBookmarks (query = '') {+ const searchTerm = query.toLowerCase()+ const results = []+ for (const video of this.videos) {+ if (video.bookmarks && video.bookmarks.length > 0) {+ if (!searchTerm || video.bookmarks.some(b => (b.note || '').toLowerCase().includes(searchTerm))) {+ results.push(Object.assign({}, video, { bookmarks: this.getVideoBookmarks(video.id) }))+ }+ }+ }+ return results+ }}diff --git a/server/router/handlers/bookmarks.js b/server/router/handlers/bookmarks.jsnew file mode 100644index 0000000..e06a219--- /dev/null+++ b/server/router/handlers/bookmarks.js@@ -0,0 +1,49 @@+import { parseBody, broadcastMessage } from '../_helpers.js'+import { getRepository } from '../../service-container.js'++export function getBookmarksHandler (req, res, connections = [], state = {}) {+ const repo = getRepository()+ const id = req.url.replace('/api/bookmarks/', '').split('?')[0]+ if (!id) { res.writeHead(400); return res.end('Missing video ID') }+ const bookmarks = repo.getVideoBookmarks(id)+ res.writeHead(200, { 'Content-Type': 'application/json' })+ res.end(JSON.stringify(bookmarks))+}++export async function addBookmarkHandler (req, res, connections = []) {+ const repo = getRepository()+ const parsed = await parseBody(req, res)+ if (parsed === null) return+ const { id: videoId, time, note } = parsed+ if (!videoId) { res.writeHead(400); return res.end('Missing video ID') }+ const bookmark = repo.addBookmark(videoId, { time: parseFloat(time) || 0, note })+ if (!bookmark) { res.writeHead(404); return res.end('Video not found') }++ // Broadcast SSE to update all connected clients+ broadcastMessage('bookmark-added', { videoId, bookmark }, connections)++ res.writeHead(201, { 'Content-Type': 'application/json' })+ res.end(JSON.stringify(bookmark))+}++export async function deleteBookmarkHandler (req, res) {+ const repo = getRepository()+ const parsed = await parseBody(req, res)+ if (parsed === null) return+ const { id: videoId, bookmarkId } = parsed+ if (!videoId || !bookmarkId) { res.writeHead(400); return res.end('Missing video/bookmark ID') }+ const success = repo.deleteBookmark(videoId, bookmarkId)+ res.writeHead(success ? 200 : 404)+ res.end()+}++export function searchBookmarksHandler (req, res, connections = []) {+ const repo = getRepository()+ const urlParts = req.url.split('?')+ const query = new URLSearchParams(urlParts[1] || '').get('q') || ''+ const results = repo.searchBookmarks(query)+ res.writeHead(200, { 'Content-Type': 'application/json' })+ res.end(JSON.stringify(results))+}++export default { getBookmarksHandler, addBookmarkHandler, deleteBookmarkHandler, searchBookmarksHandler }diff --git a/server/router/index.js b/server/router/index.jsindex ccf81ba..66562a9 100644--- a/server/router/index.js+++ b/server/router/index.js@@ -4,6 +4,7 @@ import downloads from './handlers/downloads.js'import summaries from './handlers/summaries.js'import settings from './handlers/settings.js'import diskSpace from './handlers/disk-space.js'+import bookmarks from './handlers/bookmarks.js'import { scraperStatusHandler } from './handlers/health.js'const routeMap = {@@ -50,8 +51,19 @@ const routeMap = {'POST /api/watched-video': settings.toggleWatchedVideoHandler,// Scraper health: GET- 'GET /api/scraper-status': scraperStatusHandler-}+ 'GET /api/scraper-status': scraperStatusHandler,++ // Bookmarks: GET, POST+ 'GET /api/bookmarks': bookmarks.searchBookmarksHandler,+ 'POST /api/bookmarks': bookmarks.addBookmarkHandler,++ // Video Bookmarks: GET+ 'GET /api/bookmarks/:id': bookmarks.getBookmarksHandler,++ // Delete Bookmark: POST+ 'POST /api/delete-bookmark': bookmarks.deleteBookmarkHandler++} // route map ends hereexport default function apiHandler (req, res, connections = [], state = {}) {const path = req.url.split('?')[0]@@ -69,6 +81,9 @@ export default function apiHandler (req, res, connections = [], state = {}) {if (req.method === 'GET' && path.startsWith('/api/captions/')) {return videos.captionsHandler(req, res)}+ if (req.method === 'GET' && path.startsWith('/api/bookmarks/')) {+ return bookmarks.getBookmarksHandler(req, res, connections)+ }// 404 fallbackres.writeHead(404)