From 2ffcc889af189694c9f3e049150ece3cd22019e4 Mon Sep 17 00:00:00 2001 From: 0x1d Date: Tue, 18 Nov 2025 12:44:05 +0100 Subject: [PATCH] fix: VOD download --- internal/downloader/downloader.go | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/internal/downloader/downloader.go b/internal/downloader/downloader.go index 0b925b4..948b0c4 100644 --- a/internal/downloader/downloader.go +++ b/internal/downloader/downloader.go @@ -87,16 +87,9 @@ func Download(ctx context.Context, sourceURL, outputName string) error { return nil } - // For livestreams, set up keyboard input handler for "q" key - // Check if this might be a livestream by creating a cancellable context - playlistCtx, cancel := context.WithCancel(ctx) - defer cancel() - - // Start keyboard input handler in a goroutine - // This will work for both livestreams and VOD, but only matters for livestreams - go watchForQuitKey(cancel) - - return downloadPlaylist(playlistCtx, client, parsed, outputName) + // Use the original context for VOD downloads + // For livestreams, a cancellable context will be created in downloadPlaylist + return downloadPlaylist(ctx, client, parsed, outputName) } // watchForQuitKey watches for "q" keypress and cancels the context @@ -182,6 +175,13 @@ func downloadPlaylist(ctx context.Context, client *http.Client, parsed *url.URL, isLiveStream := !mediaPlaylist.Closed if isLiveStream { + // For livestreams, create a cancellable context for keyboard input + liveCtx, cancel := context.WithCancel(ctx) + defer cancel() + + // Start keyboard input handler in a goroutine for livestreams only + go watchForQuitKey(cancel) + // For livestreams, write to a permanent .ts file tsName := ensureTSExtension(name) tsFile, err := os.Create(tsName) @@ -189,8 +189,7 @@ func downloadPlaylist(ctx context.Context, client *http.Client, parsed *url.URL, return fmt.Errorf("create output file: %w", err) } // downloadLiveStream handles file closing - // Note: keyboard input handler is already set up in Download() - return downloadLiveStream(ctx, client, finalURL, mediaPlaylist, tsFile, name) + return downloadLiveStream(liveCtx, client, finalURL, mediaPlaylist, tsFile, name) } // For VOD (Video on Demand), use temp file and convert to MP4