added total downloaded calc

This commit is contained in:
stratuma 2024-05-15 23:48:45 +02:00
parent b0b219fbc9
commit be78d588b1
3 changed files with 20 additions and 7 deletions

View File

@ -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 }}
</div>
<div class="flex flex-row gap-2 h-full items-end">
<div class="relative flex flex-row gap-2 h-full items-end">
<div class="text-xs">{{ p.quality }}p</div>
<div class="text-xs uppercase">{{ p.format }}</div>
<div class="text-xs">Dubs: {{ p.dub.map((t) => t.name).join(', ') }}</div>
<div class="text-xs">Subs: {{ p.sub.length !== 0 ? p.sub.map((t) => t.name).join(', ') : '-' }}</div>
<div class="flex flex-col ml-auto gap-0.5">
<div class="absolute flex flex-col ml-auto gap-0.5 right-0 bottom-0">
<div v-if="p.totaldownloaded && p.status === 'downloading'" class="text-xs ml-auto">{{ (p.totaldownloaded / Math.pow(1024, 2)).toFixed(2) }} MB</div>
<div v-if="p.partsleft && p.status === 'downloading'" class="text-xs ml-auto">{{ p.partsdownloaded }}/{{ p.partsleft }}</div>
<div v-if="p.downloadspeed && p.status === 'downloading'" class="text-xs">{{ p.downloadspeed }} MB/s</div>
<div v-if="p.downloadspeed && p.status === 'downloading'" class="text-xs ml-auto">{{ p.downloadspeed }} MB/s</div>
</div>
</div>
</div>
@ -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

View File

@ -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
}
}
}

View File

@ -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