fix: VOD download

This commit is contained in:
2025-11-18 12:44:05 +01:00
parent 0c0b39728c
commit 2ffcc889af

View File

@@ -87,16 +87,9 @@ func Download(ctx context.Context, sourceURL, outputName string) error {
return nil return nil
} }
// For livestreams, set up keyboard input handler for "q" key // Use the original context for VOD downloads
// Check if this might be a livestream by creating a cancellable context // For livestreams, a cancellable context will be created in downloadPlaylist
playlistCtx, cancel := context.WithCancel(ctx) return downloadPlaylist(ctx, client, parsed, outputName)
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)
} }
// watchForQuitKey watches for "q" keypress and cancels the context // 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 isLiveStream := !mediaPlaylist.Closed
if isLiveStream { 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 // For livestreams, write to a permanent .ts file
tsName := ensureTSExtension(name) tsName := ensureTSExtension(name)
tsFile, err := os.Create(tsName) 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) return fmt.Errorf("create output file: %w", err)
} }
// downloadLiveStream handles file closing // downloadLiveStream handles file closing
// Note: keyboard input handler is already set up in Download() return downloadLiveStream(liveCtx, client, finalURL, mediaPlaylist, tsFile, name)
return downloadLiveStream(ctx, client, finalURL, mediaPlaylist, tsFile, name)
} }
// For VOD (Video on Demand), use temp file and convert to MP4 // For VOD (Video on Demand), use temp file and convert to MP4