From 363c621e45ddc72e9196154ec80046bfd05148fe Mon Sep 17 00:00:00 2001 From: SimplyBoo6 Date: Mon, 1 Jul 2024 14:46:11 +0000 Subject: [PATCH] Don't delete files when transcoding --- server/src/cache/transcoder.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/server/src/cache/transcoder.ts b/server/src/cache/transcoder.ts index e02a98f..1663252 100755 --- a/server/src/cache/transcoder.ts +++ b/server/src/cache/transcoder.ts @@ -285,14 +285,26 @@ export class Transcoder { media.metadata.qualityCache.push(targetHeight); - await ImportUtils.deleteFolder(`${Config.get().cachePath}/${media.hash}/${targetHeight}p`); - await ImportUtils.mkdir(`${Config.get().cachePath}/${media.hash}/${targetHeight}p`); + try { + await ImportUtils.mkdir(`${Config.get().cachePath}/${media.hash}/${targetHeight}p`); + } catch (err) { + console.warn('Failed to make cache dir, may already exist', media.hash, targetHeight, err); + } const segmentMetadata = await this.getStreamSegments(media); - for (const segment of segmentMetadata.standard) { + for (let i = 0; i < segmentMetadata.standard.length; i++) { + const segment = segmentMetadata.standard[i]; + if (!segment) { + throw new Error('Segment array modified during cache generation'); + } const filename = `${Config.get().cachePath}/${media.hash}/${targetHeight}p/data.ts?start=${segment.start}&end=${ segment.end }`; + const exists = await ImportUtils.exists(filename); + if (exists) { + continue; + } + await this.streamMedia( media, segment.start,