Skip to content

armgit / my-yt

Public Imported from GitHub
0

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

JavaScript

download log

Christian Feie5b348e8af87
diff --git a/index.html b/index.html
index a3404a8..6798858 100644
--- a/index.html
+++ b/index.html
@@ -56,6 +56,7 @@
flex-wrap: wrap;
align-items: center;
width: 280px;
+ max-height: 300px;
text-align: left;
text-decoration: none;
color: black;
@@ -71,6 +72,8 @@
.hide-thumbnails .video img {
display: none !important;
visibility: hidden !important;
+ opacity: 0 !important;
+
}
.video span {
font-size: 12px;
@@ -88,6 +91,28 @@
.video .actions > * {
cursor: pointer;
}
+
+ .download-log {
+ position: fixed;
+ bottom: 10px;
+ right: 10px;
+ width: 300px;
+ overflow: hidden;
+ /* height: 200px; */
+ font-size: 10px;
+ background-color: white;
+ border: 1px solid lightgrey;
+ box-shadow: 2px 2px 10px rgba(0,0,0,0.1);
+ overflow-y: auto;
+ padding: 10px;
+ background-color: #f0f0f0;
+ color: #000;
+ border-radius: 8px;
+ }
+ .download-log .lines {
+ max-height: 100px;
+ overflow-y: scroll;
+ }
</style>
<style>
#open-settings {
@@ -165,6 +190,10 @@
<main>
<div class="channels-container"></div>
+ <details class="download-log">
+ <summary>Download Log</summary>
+ <div class="lines"></div>
+ </details>
</main>
@@ -179,6 +208,15 @@
const data = JSON.parse(message.data, {})
console.log('sse message', data)
+ if (data.type === 'download-log-line' && data.line) {
+ const downloadLog = document.querySelector('.download-log .lines');
+ const text = downloadLog.innerText
+ const lines = text.split('\n')
+ if (lines.length > 10) lines.length = 10
+ downloadLog.innerText = lines.join('\n') + '\n' + data.line
+ downloadLog.scrollTop = downloadLog.scrollHeight;
+ }
+
if (data.type === 'all' && data.videos) {
$channelsContainer.innerHTML = ''
diff --git a/server.js b/server.js
index cef29d1..67891a4 100644
--- a/server.js
+++ b/server.js
@@ -2,6 +2,7 @@ import http from 'http'
import { URL } from 'url'
import { execa } from 'execa'
import fs from 'fs'
+import { exec } from 'child_process'
fs.mkdirSync('./data', { recursive: true })
fs.mkdirSync('./data/videos', { recursive: true })
@@ -117,7 +118,11 @@ async function updateAndPersistVideosForChannel(repo, name) {
async function downloadVideo(id, repo) {
try {
- await execa({stdio:'inherit'})`yt-dlp -f mp4 ${id} -o ./data/videos/${id}.mp4`
+ for await (const line of execa`yt-dlp -f mp4 ${id} -o ./data/videos/${id}.mp4`.iterable()) {
+ broadcastSSE(JSON.stringify({type: 'download-log-line', line}), connections)
+ console.log(line)
+ }
+
repo.setVideoDownloaded(id)
console.log('Download completed')
} catch (error) {
@@ -272,6 +277,7 @@ function createServer ({repo, port = 3000}) {
fs.createReadStream(videoPath).pipe(res)
} catch (error) {
console.error('error reading file ' + videoPath)
+ console.error(error)
res.writeHead(404, { 'Content-Type': 'text/plain' })
res.end('Video not found')
}