A clean and minimal youtube frontend, without all the ads and whistles
JavaScript
rm wip download single video
Christian Feid053dff24880
diff --git a/client/components/search-videos.js b/client/components/search-videos.jsindex 4b9081e..cbeda7a 100644--- a/client/components/search-videos.js+++ b/client/components/search-videos.js@@ -22,20 +22,6 @@ class SearchVideos extends HTMLElement {searchHandler (event) {event.preventDefault()const searchTerm = event.target.value.toLowerCase()- if (searchTerm.startsWith('https://')) {- if (event.key !== 'Enter') return- console.log('Downloading video...')- event.target.value = ''- // send request to server to download video- fetch('/download-video', {- method: 'POST',- headers: { 'Content-Type': 'application/json' },- body: JSON.stringify({ url: searchTerm })- })- .then(() => alert('Video downloaded successfully'))- .catch(error => alert('Error downloading video: ' + error.message))- return- }document.querySelectorAll('.video').forEach(video => {const videoData = JSON.parse(video.dataset['data'])if (diff --git a/lib/server.js b/lib/server.jsindex 6ee16c5..9e360bb 100644--- a/lib/server.js+++ b/lib/server.js@@ -106,21 +106,7 @@ export function createServer ({repo, connections = []}) {async function downloadVideoHandler(req, res, repo, connections = []) {const body = await getBody(req)- let { id, url } = JSON.parse(body)-- if (url) {- id = url.replace('https://www.youtube.com/watch?v=', '')- downloadVideo(id, repo, (line) =>- broadcastSSE(JSON.stringify({type: 'download-log-line', line}), connections))- .then((video) => {- broadcastSSE(JSON.stringify({type: 'new-videos', videos: [video]}), connections)- broadcastSSE(JSON.stringify({type: 'downloaded', videoId: video.id}), connections)- })- .catch((error) =>- broadcastSSE(JSON.stringify({type: 'download-log-line', line: error.stderr}), connections))-- return- }+ const { id} = JSON.parse(body)downloadVideo(id, repo, (line) =>broadcastSSE(JSON.stringify({type: 'download-log-line', line}), connections))diff --git a/lib/youtube.js b/lib/youtube.jsindex f92532f..a998e09 100644--- a/lib/youtube.js+++ b/lib/youtube.js@@ -22,15 +22,6 @@ export async function downloadVideo(id, repo, callback = () => {}) {console.log(line)callback(line)}- if (!repo.getVideo(id)) {- const video = await getVideoInformation(id)- console.log('downloaded video information', video)- repo.upsertVideos([video])- repo.setVideoDownloaded(id)- console.log('Download completed, new video added', id)- resolve(video)- return- }repo.setVideoDownloaded(id)console.log('Download completed')@@ -148,28 +139,3 @@ function parseRelativeTime(relativeTime) {console.error('Invalid relative time format', relativeTime);return null}--export async function getVideoInformation(id) {- if (id.startsWith('https://')) id = id.replace(/https:\/\/www\.youtube\.com\/watch\?v=/, '')- try {- const response = await fetch(`https://www.youtube.com/watch?v=${id}`, {- headers: fetchYoutubeHeaders- })- const text = await response.text()- return {- channelName: '',- title: '',- url: `https://www.youtube.com/watch?v=${id}`,- thumbnail: `https://img.youtube.com/vi/${id}/mqdefault.jpg`,- description: '',- id,- publishedTime: '',- publishedAt: parseRelativeTime('') || new Date(),- viewCount: '',- duration: '',- }- } catch (error) {- console.error('Error fetching video information:', error.message)- return null- }-}\ No newline at end of file