From e8b2542f382886d3a89a1a238c5302f98ce364a8 Mon Sep 17 00:00:00 2001 From: HitomaruKonpaku Date: Sat, 30 Nov 2024 04:13:42 +0700 Subject: [PATCH] Add some delay before download to try to fix no audio vod? --- src/modules/TwitCastingCrawler.ts | 13 ++++++++++++- src/utils/Util.ts | 6 ++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/modules/TwitCastingCrawler.ts b/src/modules/TwitCastingCrawler.ts index c4a5669..8dcb6cb 100644 --- a/src/modules/TwitCastingCrawler.ts +++ b/src/modules/TwitCastingCrawler.ts @@ -66,13 +66,24 @@ export class TwitCastingCrawler extends EventEmitter { this.checkUserWithTimeout(user) return } + if (movie.live && !this.videoIds.has(movie.id)) { this.videoIds.add(movie.id) await this.getMoveMetadata(user, movie) + const movieUrl = TwitCastingUtil.getMovieUrl(user.id, movie.id) this.logger.warn(`${user.id} live: ${movieUrl}`) this.sendWebhooks(user, movie) - const output = path.join(configManager.getOutDir(), 'twitcasting', `[%(uploader_id)s][${Util.getTimeString()}] %(title)s (%(id)s).%(ext)s`) + + const output = path.join( + configManager.getOutDir(), + 'twitcasting', + `[%(uploader_id)s][${Util.getTimeString()}] %(title)s (%(id)s).%(ext)s`, + ) + + const sleepMs = Number(process.env.TWITCASTING_DOWNLOAD_DELAY) || 0 + await Util.sleep(sleepMs) + Downloader.downloadUrl(movieUrl, { output, // Add formatSort due to yt-dlp error diff --git a/src/utils/Util.ts b/src/utils/Util.ts index f735d7d..ae92f95 100644 --- a/src/utils/Util.ts +++ b/src/utils/Util.ts @@ -1,4 +1,10 @@ export class Util { + public static sleep(ms?: number) { + return new Promise((resolve) => { + setTimeout(() => resolve(null), ms) + }) + } + public static getTimeString(ms?: number): string { const date = ms ? new Date(ms)