From be78d588b15de8f813db7a9fd2dd07acfdba8864 Mon Sep 17 00:00:00 2001 From: stratuma Date: Wed, 15 May 2024 23:48:45 +0200 Subject: [PATCH] added total downloaded calc --- pages/index.vue | 9 ++++++--- src/api/routes/service/service.controller.ts | 3 ++- src/api/routes/service/service.service.ts | 15 ++++++++++++--- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/pages/index.vue b/pages/index.vue index 6107807..9a852fe 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -62,14 +62,15 @@ {{ (p.media as ADNEpisode).show.title }} Season {{ (p.media as ADNEpisode).season ? (p.media as ADNEpisode).season : 1 }} Episode {{ (p.media as ADNEpisode).shortNumber }} -
+
{{ p.quality }}p
{{ p.format }}
Dubs: {{ p.dub.map((t) => t.name).join(', ') }}
Subs: {{ p.sub.length !== 0 ? p.sub.map((t) => t.name).join(', ') : '-' }}
-
+
+
{{ (p.totaldownloaded / Math.pow(1024, 2)).toFixed(2) }} MB
{{ p.partsdownloaded }}/{{ p.partsleft }}
-
{{ p.downloadspeed }} MB/s
+
{{ p.downloadspeed }} MB/s
@@ -95,6 +96,7 @@ const playlist = ref< partsleft: number partsdownloaded: number downloadspeed: number + totaldownloaded: number quality: number service: string format: string @@ -113,6 +115,7 @@ const getPlaylist = async () => { partsleft: number partsdownloaded: number downloadspeed: number + totaldownloaded: number quality: number service: string format: string diff --git a/src/api/routes/service/service.controller.ts b/src/api/routes/service/service.controller.ts index 859be56..297854e 100644 --- a/src/api/routes/service/service.controller.ts +++ b/src/api/routes/service/service.controller.ts @@ -124,7 +124,8 @@ export async function getPlaylistController(request: FastifyRequest, reply: Fast ...v.dataValues, partsleft: found.partsToDownload, partsdownloaded: found.downloadedParts, - downloadspeed: found.downloadSpeed.toFixed(2) + downloadspeed: found.downloadSpeed.toFixed(2), + totaldownloaded: found.totalDownloaded } } } diff --git a/src/api/routes/service/service.service.ts b/src/api/routes/service/service.service.ts index 812820e..728fcb8 100644 --- a/src/api/routes/service/service.service.ts +++ b/src/api/routes/service/service.service.ts @@ -118,6 +118,7 @@ var downloading: Array<{ downloadedParts: number partsToDownload: number downloadSpeed: number + totalDownloaded: number }> = [] // Get Downloading Episodes @@ -195,7 +196,8 @@ export async function downloadADNPlaylist( id: downloadID, downloadedParts: 0, partsToDownload: 0, - downloadSpeed: 0 + downloadSpeed: 0, + totalDownloaded: 0 }) if (!season) { @@ -318,7 +320,8 @@ export async function downloadCrunchyrollPlaylist( id: downloadID, downloadedParts: 0, partsToDownload: 0, - downloadSpeed: 0 + downloadSpeed: 0, + totalDownloaded: 0 }) await updatePlaylistByID(downloadID, 'downloading') @@ -685,7 +688,8 @@ async function downloadParts(parts: { filename: string; url: string }[], downloa const path = await createFolder() const dn = downloading.find((i) => i.id === downloadID) - let totalDownloadedBytes = 0 + let totalDownloadedBytes = 0; + let totalSizeBytes = 0; let startTime = Date.now() for (const [index, part] of parts.entries()) { @@ -700,9 +704,12 @@ async function downloadParts(parts: { filename: string; url: string }[], downloa const readableStream = Readable.from(body as any) let partDownloadedBytes = 0 + let partSizeBytes = 0; + readableStream.on('data', (chunk) => { partDownloadedBytes += chunk.length totalDownloadedBytes += chunk.length + totalSizeBytes += chunk.length; }) await finished(readableStream.pipe(stream)) @@ -710,10 +717,12 @@ async function downloadParts(parts: { filename: string; url: string }[], downloa console.log(`Fragment ${index + 1} downloaded`) if (dn) { + const tot = totalSizeBytes dn.downloadedParts++ const endTime = Date.now() const durationInSeconds = (endTime - startTime) / 1000 dn.downloadSpeed = totalDownloadedBytes / 1024 / 1024 / durationInSeconds + dn.totalDownloaded = tot; } success = true