Skip to content

armgit / my-yt

Public Imported from GitHub
0

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

JavaScript

fix: update video once downloaded, set format

Christian Fei69d6b09cd315
diff --git a/client/components/video-element.js b/client/components/video-element.js
index 2147f21..961fba2 100644
--- a/client/components/video-element.js
+++ b/client/components/video-element.js
@@ -92,13 +92,8 @@ class VideoElement extends HTMLElement {
watchVideoHandler (event) {
event.preventDefault()
this.querySelector('.play.video-placeholder').outerHTML = /*html*/`<video controls width="400">
- <source src="/videos/${this.video.id}" type="video/webm" />
- <source src="/videos/${this.video.id}" type="video/mp4" />
- <track
- default
- kind="captions"
- srclang="en"
- src="/captions/${this.video.id}" />
+ <source src="/videos/${this.video.id}" type="video/${this.video.format}" />
+ <track default kind="captions" srclang="en" src="/captions/${this.video.id}" />
<p>
Your browser does not support the video tag.
Download the video instead <a href="/videos/${this.video.id}" target="_blank">here</a>
diff --git a/client/main.js b/client/main.js
index fc2542c..355d0bb 100644
--- a/client/main.js
+++ b/client/main.js
@@ -57,6 +57,7 @@ eventSource.onmessage = (message) => {
if (!$video.dataset['data']) return
const videoData = JSON.parse($video.dataset['data'])
videoData.downloaded = data.downloaded
+ if (data.video) Object.assign(videoData, data.video)
$video.dataset['data'] = JSON.stringify(videoData)
})
return
diff --git a/lib/server.js b/lib/server.js
index d19eca8..0f3110d 100644
--- a/lib/server.js
+++ b/lib/server.js
@@ -164,7 +164,8 @@ async function downloadVideoHandler(req, res, repo, connections = []) {
downloadVideo(id, repo, (line) =>
broadcastSSE(JSON.stringify({type: 'download-log-line', line}), connections))
.then(() => {
- broadcastSSE(JSON.stringify({type: 'downloaded', videoId: id, downloaded: true}), connections)
+ const video = repo.getVideo(id)
+ broadcastSSE(JSON.stringify({type: 'downloaded', videoId: id, downloaded: true, video}), connections)
if (external) broadcastSSE(JSON.stringify({type: 'new-videos', videos: [repo.getVideo(id)]}), connections)
})
.catch((error) =>