nilaoda/N_m3u8DL-RE · error · Exception

Download init file failed!

Error message

Download init file failed!

What it means

SimpleLiveRecordManager2.RecordStreamAsync (live recording mode) downloads the MP4 init segment before recording; a failed init download aborts the recording. Same contract as the VOD manager: result.Success must be true.

Solutions

  1. Restart the recording — init downloads usually fail transiently
  2. Verify the init URL from the current live playlist is reachable with curl
  3. Check auth headers/cookies for the live CDN
  4. Avoid heavy proxy usage or configure a reliable proxy via --proxy
Defensive patterns

Strategy: retry

Validate before calling

using var resp = await new HttpClient().SendAsync(new HttpRequestMessage(HttpMethod.Head, playlist.MediaInit.Url));
if (!resp.IsSuccessStatusCode) throw new Exception("live init segment unreachable");

Type guard

static bool IsSuccess(DownloadResult r) => r is { Success: true };

Try / catch

try { await RecordStreamAsync(...); }
catch (Exception ex) when (ex.Message == "Download init file failed!")
{
    logger.Warn("live init download failed; restarting recording");
    await RestartRecordingAsync();
}

Prevention

When it happens

Trigger: Downloader.DownloadSegmentAsync for streamSpec.Playlist.MediaInit returns Success == false while recording a live stream — server refused, timeout, or the live playlist's init URL rotated/expired.

Common situations: Long live recordings where the signed init URL expired; CDN issues; proxies interrupting the connection at recording start.

Understand the failure class

Background: 'Something went wrong' / 'Request failed (500)' / 'HTTP error! status: 404' — what failed HTTP requests actually mean and how to find the real cause — this error's family across 28 libraries.

Related errors


AI-assisted analysis of nilaoda/N_m3u8DL-RE@e113dee70c (2026-09-13). Data as JSON: /api/errors/fdf812117ad0bcc4. Report an issue: GitHub.

Appendix: source

Thrown at src/N_m3u8DL-RE/DownloadManager/SimpleLiveRecordManager2.cs:218

            Logger.DebugMarkUp(string.Join(",", segments.Select(sss => GetSegmentName(sss, false, false))));

            // 下载init
            if (!initDownloaded && streamSpec.Playlist?.MediaInit != null) 
            {
                task.MaxValue += 1;
                // 对于fMP4,自动开启二进制合并
                if (!DownloaderConfig.MyOptions.BinaryMerge && streamSpec.MediaType != MediaType.SUBTITLES)
                {
                    DownloaderConfig.MyOptions.BinaryMerge = true;
                    Logger.WarnMarkUp($"[darkorange3_1]{ResString.autoBinaryMerge}[/]");
                }

                var path = Path.Combine(tmpDir, "_init.mp4.tmp");
                var result = await Downloader.DownloadSegmentAsync(streamSpec.Playlist.MediaInit, path, speedContainer, headers);
                FileDic[streamSpec.Playlist.MediaInit] = result;
                if (result is not { Success: true })
                {
                    throw new Exception("Download init file failed!");
                }
                mp4InitFile = result.ActualFilePath;
                task.Increment(1);

                // 读取mp4信息
                if (result is { Success: true })
                {
                    currentKID = MP4DecryptUtil.GetMP4Info(result.ActualFilePath).KID;
                    // MPD的cenc:default_KID优先
                    if (streamSpec.Playlist?.MediaInit?.EncryptInfo.KID != null)
                    {
                        currentKID = streamSpec.Playlist.MediaInit.EncryptInfo.KID;
                        Logger.WarnMarkUp($"[grey]KID (from MPD): {currentKID}[/]");
                    }
                    // 从文件读取KEY
                    await SearchKeyAsync(currentKID);
                    // 实时解密
                    if ((streamSpec.Playlist.MediaInit.IsEncrypted || !string.IsNullOrEmpty(currentKID)) && DownloaderConfig.MyOptions.MP4RealTimeDecryption && !string.IsNullOrEmpty(currentKID) && StreamExtractor.ExtractorType != ExtractorType.MSS)

View on GitHub (pinned to e113dee70c)