nilaoda/N_m3u8DL-RE · error · Exception

ResString.loadUrlFailed

Error message

ResString.loadUrlFailed

What it means

StreamExtractor.LoadSourceFromUrlAsync fetches the playlist/stream source from a URL (or reads a local file) and then parses the text. If the resulting rawText is null or whitespace — meaning the fetch produced no content — it throws ResString.loadUrlFailed. This guards downstream parsers (M3U8, etc.) from empty input.

Solutions

  1. Verify the URL returns non-empty content (curl the URL and inspect the body).
  2. Check required headers/cookies (User-Agent, Referer, auth) that the server may demand before serving content.
  3. If loading a local file, confirm the file exists and is non-empty.
  4. Inspect proxy/VPN/firewall interference; retry the request.
  5. Catch the exception and surface the raw response (status code, body length) to diagnose the upstream server.

Example fix

// before
var text = await DownloadTextAsync(url);
// after
var text = await DownloadTextAsync(url);
if (string.IsNullOrWhiteSpace(text))
    throw new Exception($"loadUrlFailed: empty response (status={status}, len={text?.Length ?? 0}) from {url}");
Defensive patterns

Strategy: try-catch

Validate before calling

// probe the URL before handing it to StreamExtractor
using var resp = await httpClient.GetAsync(url, HttpCompletionOption.ResponseHeadersRead);
if (!resp.IsSuccessStatusCode) throw new HttpRequestException($"HTTP {(int)resp.StatusCode} for {url}");
var probe = await resp.Content.ReadAsStringAsync();
if (string.IsNullOrWhiteSpace(probe)) throw new InvalidDataException($"empty response from {url}");

Try / catch

try { await extractor.LoadSourceFromUrlAsync(url); }
catch (Exception ex) when (ex.Message == ResString.loadUrlFailed) {
    logger.Error($"Failed to load source from {url}: empty or blank response");
    // retry with different headers or fail over to a mirror URL
}

Prevention

When it happens

Trigger: LoadSourceFromUrlAsync is called with a URL whose response body is empty/whitespace, a local file that is empty, or the underlying download returned nothing.

Common situations: Server returns 200 with empty body; network middleware strips the body; the local file path points to an empty file; proxy or firewall intercepts the request; URL points to a page that requires cookies/headers.

Related errors


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

Appendix: source

Thrown at src/N_m3u8DL-RE.Parser/StreamExtractor.cs:52

            this.rawText = await File.ReadAllTextAsync(uri.LocalPath);
            parserConfig.OriginalUrl = parserConfig.Url = url;
        }
        else if (url.StartsWith("http"))
        {
            parserConfig.OriginalUrl = url;
            (this.rawText, url) = await HTTPUtil.GetWebSourceAndNewUrlAsync(url, parserConfig.Headers);
            parserConfig.Url = url;
        }
        else if (File.Exists(url))
        {
            url = Path.GetFullPath(url);
            this.rawText = await File.ReadAllTextAsync(url);
            parserConfig.OriginalUrl = parserConfig.Url = new Uri(url).AbsoluteUri;
        }

        if (string.IsNullOrWhiteSpace(rawText))
        {
            throw new Exception(ResString.loadUrlFailed);
        }
        
        this.rawText = rawText.Trim();
        LoadSourceFromText(this.rawText);
    }

    [MemberNotNull(nameof(rawText), nameof(extractor))]
    private void LoadSourceFromText(string rawText)
    {
        var rawType = "txt";
        rawText = rawText.Trim();
        this.rawText = rawText;
        if (rawText.StartsWith(HLSTags.ext_m3u))
        {
            Logger.InfoMarkUp(ResString.matchHLS);
            extractor = new HLSExtractor(parserConfig);
            rawType = "m3u8";
        }

View on GitHub (pinned to e113dee70c)