From bf0843dd1d8fbaa7c06cdc6110f45d46ca6b4052 Mon Sep 17 00:00:00 2001 From: Max Isom Date: Sun, 15 Mar 2020 15:13:12 -0500 Subject: [PATCH] Don't cache livestreams --- src/services/player.ts | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/services/player.ts b/src/services/player.ts index 346b10a..dfdf4b0 100644 --- a/src/services/player.ts +++ b/src/services/player.ts @@ -106,14 +106,11 @@ export default class { } private getCachedPath(url: string): string { - const hash = hasha(url); - return path.join(this.cacheDir, `${hash}.webm`); + return path.join(this.cacheDir, hasha(url)); } private getCachedPathTemp(url: string): string { - const hash = hasha(url); - - return path.join('/tmp', `${hash}.webm`); + return path.join('/tmp', hasha(url)); } private async isCached(url: string): Promise { @@ -191,13 +188,6 @@ export default class { } } - const cacheTempPath = this.getCachedPathTemp(url); - const cacheStream = createWriteStream(cacheTempPath); - - cacheStream.on('finish', async () => { - await fs.rename(cacheTempPath, cachedPath); - }); - let youtubeStream: Readable; if (canDirectPlay) { @@ -217,7 +207,17 @@ export default class { youtubeStream.pipe(capacitor); - capacitor.createReadStream().pipe(cacheStream); + // Don't cache livestreams + if (!info.player_response.videoDetails.isLiveContent) { + const cacheTempPath = this.getCachedPathTemp(url); + const cacheStream = createWriteStream(cacheTempPath); + + cacheStream.on('finish', async () => { + await fs.rename(cacheTempPath, cachedPath); + }); + + capacitor.createReadStream().pipe(cacheStream); + } return capacitor.createReadStream(); }