{"record":{"id":"b8af55def7683e9f","repo":"SubtitleEdit/subtitleedit","slug":"yt-dlp-subtitle-download-exited-with-code-process","errorCode":null,"errorMessage":"yt-dlp subtitle download exited with code {process.ExitCode}.","messagePattern":"yt-dlp subtitle download exited with code (.+?)\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/ui/Logic/Download/YtDlpDownloadService.cs","lineNumber":396,"sourceCode":"\n        var stdoutTask = process.StandardOutput.ReadToEndAsync(cancellationToken);\n        var stderrTask = process.StandardError.ReadToEndAsync(cancellationToken);\n\n        try\n        {\n            await process.WaitForExitAsync(cancellationToken);\n        }\n        catch (OperationCanceledException)\n        {\n            TryKillProcess(process);\n            throw;\n        }\n\n        await stdoutTask;\n        if (process.ExitCode != 0)\n        {\n            var details = (await stderrTask).Trim();\n            throw new InvalidOperationException(\n                $\"yt-dlp subtitle download exited with code {process.ExitCode}.\" +\n                (string.IsNullOrEmpty(details) ? string.Empty : Environment.NewLine + details));\n        }\n    }\n\n    // The title fetch is a live network round-trip to the video site; cap it so\n    // a stalled extractor can't leave the save-as flow stuck behind a spinner.\n    private static readonly TimeSpan TitleFetchTimeout = TimeSpan.FromSeconds(15);\n\n    public async Task<string?> GetVideoTitleAsync(string url, CancellationToken cancellationToken)\n    {\n        cancellationToken.ThrowIfCancellationRequested();\n        if (!File.Exists(GetFullFileName()))\n        {\n            return null;\n        }\n\n        using var process = new Process","sourceCodeStart":378,"sourceCodeEnd":414,"githubUrl":"https://github.com/SubtitleEdit/subtitleedit/blob/17a9f0748781032255db3526b7215d2fb891e3af/src/ui/Logic/Download/YtDlpDownloadService.cs#L378-L414","documentation":"Thrown by DownloadSubtitlesOnlyAsync after the yt-dlp subtitle process exits non-zero. The captured stderr (read synchronously via ReadToEndAsync) is appended so the real yt-dlp error is visible. Mirrors error 372 but for the subtitle-only invocation which uses --skip-download.","triggerScenarios":"yt-dlp exits non-zero during a subtitle fetch: video has no subtitles, --sub-langs regex matched nothing, site extractor broke, network/geo-block, or an outdated yt-dlp.","commonSituations":"Requesting auto-subs on a video that has none; yt-dlp version too old for a changed subtitle endpoint; region-blocked video.","solutions":["Inspect the stderr in the exception message for the specific yt-dlp error.","Update yt-dlp (re-run DownloadYtDlp) to get current subtitle extractors.","Verify the video actually has subtitles in the requested language before requesting auto-subs.","Retry on transient network/geo errors or supply cookies for restricted videos."],"exampleFix":"// before\nawait _ytDlp.DownloadAutoGeneratedSubtitlesAsync(url, stem, ct);\n\n// after: distinguish 'no subtitles' from real failures\ncatch (InvalidOperationException ex)\n{\n    if (ex.Message.Contains(\"no subtitles\") || ex.Message.Contains(\"NO sub\"))\n        return; // acceptable: video has none\n    await _ytDlp.DownloadYtDlp(null, ct); // update extractor then retry\n    throw;\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { await svc.DownloadAutoGeneratedSubtitlesAsync(url, stem, ct); }\ncatch (InvalidOperationException ex)\n{\n    if (ex.Message.Contains(\"no subtitles\")) return; // acceptable\n    await svc.DownloadYtDlp(null, ct); throw; // update extractor, retry upstream\n}","preventionTips":["Keep yt-dlp current for working subtitle extractors.","Confirm the video has subtitles in the requested language before fetching."],"tags":["yt-dlp","process","exit-code","subtitles","network"],"backgroundTag":null,"analyzedSha":"17a9f0748781032255db3526b7215d2fb891e3af","analyzedAt":"2026-08-13T18:11:43.374Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}