- {' '}
- {' '}
+
+
+
+
{progress ? : null}
@@ -161,14 +185,14 @@ export function App() {
:
null
}
- Once you close the page the download will continue in the background.
+ Once you close this page the download will continue in the background.
It won't be possible retriving the progress though.
Made with ❤️ by Marcobaobao
diff --git a/frontend/src/components/Statistics.tsx b/frontend/src/components/Statistics.tsx
new file mode 100644
index 0000000..8dc998c
--- /dev/null
+++ b/frontend/src/components/Statistics.tsx
@@ -0,0 +1,12 @@
+import React, { useState } from "react";
+import { IDLSpeed } from "../interfaces";
+
+export function Statistics(props: any) {
+ const [dataset, setDataset] = useState>()
+
+ return (
+
+
+
+ )
+}
\ No newline at end of file
diff --git a/frontend/src/interfaces.tsx b/frontend/src/interfaces.tsx
index acad891..9b28602 100644
--- a/frontend/src/interfaces.tsx
+++ b/frontend/src/interfaces.tsx
@@ -2,7 +2,14 @@ export interface IMessage {
status: string,
progress?: string,
size?: string,
- dlSpeed?: string
+ dlSpeed?: string | IDLSpeed
+}
+
+export interface IDLInfo {
+ title: string,
+ thumbnail: string,
+ upload_date?: string | Date,
+ duration?: number
}
export interface IDLSpeed {
diff --git a/frontend/src/utils.ts b/frontend/src/utils.ts
index 7b99e3c..dc368b6 100644
--- a/frontend/src/utils.ts
+++ b/frontend/src/utils.ts
@@ -6,4 +6,11 @@ export function validateIP(ipAddr: string): boolean {
export function validateDomain(domainName: string): boolean {
let domainRegex = /[^@ \t\r\n]+.[^@ \t\r\n]+\.[^@ \t\r\n]+/
return domainRegex.test(domainName) || domainName === 'localhost'
+}
+
+export function ellipsis(str: string, lim: number): string {
+ if (str) {
+ return str.length > lim ? `${str.substr(0, lim)}...` : str
+ }
+ return ''
}
\ No newline at end of file
diff --git a/lib/downloader.js b/lib/downloader.js
index 287c91a..0b47392 100644
--- a/lib/downloader.js
+++ b/lib/downloader.js
@@ -14,22 +14,27 @@ catch (e) {
const isWindows = process.platform === 'win32'
const download = (socket, url) => {
+ if (url === '' || url === null) {
+ socket.emit('progress', { status: 'Done!' })
+ return
+ }
+
+ getDownloadInfo(socket, url)
+
const ytldp = spawn(`./lib/yt-dlp${isWindows ? '.exe' : ''}`,
['-o', `${settings.download_path || 'downloads/'}%(title)s.%(ext)s`, url]
)
- from(ytldp.stdout) // stout as observable
+ from(ytldp.stdout) // stdout as observable
.pipe(throttle(() => interval(500))) // discard events closer than 500ms
.subscribe({
next: (stdout) => {
- let _stdout = String(stdout)
- socket.emit('progress', formatter(_stdout)) // finally, emit
+ //let _stdout = String(stdout)
+ socket.emit('progress', formatter(String(stdout))) // finally, emit
//logger('download', `Fetching ${stdout}`)
- console.log(formatter(_stdout))
},
complete: () => {
socket.emit('progress', { status: 'Done!' })
- logger('download', 'Done!')
}
})
@@ -39,15 +44,29 @@ const download = (socket, url) => {
})
}
+const getDownloadInfo = (socket, url) => {
+ let stdoutChunks = [];
+ const ytdlpInfo = spawn(`./lib/yt-dlp${isWindows ? '.exe' : ''}`, ['-s', '-j', url]);
+
+ ytdlpInfo.stdout.on('data', (data) => {
+ stdoutChunks.push(data)
+ })
+
+ ytdlpInfo.on('exit', () => {
+ const buffer = Buffer.concat(stdoutChunks)
+ const json = JSON.parse(buffer.toString())
+ socket.emit('info', json)
+ })
+}
+
const abortDownload = (socket) => {
const res = process.platform === 'win32' ?
spawn('taskkill', ['/IM', 'yt-dlp.exe', '/F', '/T']) :
spawn('killall', ['yt-dlp'])
- res.stdout.on('data', data => {
+ res.on('exit', () => {
socket.emit('progress', 'Aborted!')
- logger('download', `Aborting ${data.toString()}`)
+ logger('download', 'Aborting downloads')
})
- logger('download', 'Aborted')
}
const formatter = (stdout) => {
@@ -71,10 +90,9 @@ const formatter = (stdout) => {
default:
return { progress: '0' }
}
-
}
module.exports = {
download: download,
- abortDownload: abortDownload
-}
\ No newline at end of file
+ abortDownload: abortDownload,
+}
diff --git a/lib/yt-dlpCaller.js b/lib/yt-dlpCaller.js
deleted file mode 100644
index 3c45198..0000000
--- a/lib/yt-dlpCaller.js
+++ /dev/null
@@ -1,24 +0,0 @@
-const Readable = require('stream').Readable;
-
-class Subscription extends Readable{
- constructor(options) {
- super();
- if (!(this instanceof Subscription))
- return new Subscription(options);
-
- options = options || {};
- Readable.call(this, options);
-
- this.value = 0;
- }
- _read() {
- while(this.value <= 100){
- this.push(String(this.value++));
- }
- }
-}
-
-
-exports.subscribe = function(event, options){
- return new Subscription(options);
-}
\ No newline at end of file
diff --git a/package.json b/package.json
index 57edcf4..6251779 100644
--- a/package.json
+++ b/package.json
@@ -25,4 +25,4 @@
"devDependencies": {
"parcel": "^2.0.1"
}
-}
+}
\ No newline at end of file
diff --git a/server.js b/server.js
index 4bfa675..54a0f61 100644
--- a/server.js
+++ b/server.js
@@ -18,8 +18,8 @@ const io = new Server(server, {
})
io.on('connection', socket => {
- logger('ws', 'connesso')
-
+ logger('ws', `${socket.handshake.address} connected!`)
+ // message listeners
socket.on('send-url', args => {
logger('ws', args)
download(socket, args)
@@ -32,14 +32,14 @@ io.on('connection', socket => {
})
})
-io.on('disconnect', () => {
- logger('ws', 'disconnesso')
+io.on('disconnect', (socket) => {
+ logger('ws', `${socket.handshake.address} disconnected`)
})
app
.use(cors())
.use(serve(path.join(__dirname, 'dist')))
-console.log('[koa] Server started port', process.env.PORT || 3022)
+logger('koa', `Server started on port ${process.env.PORT || 3022}`)
server.listen(process.env.PORT || 3022)
\ No newline at end of file