nilaoda/N_m3u8DL-RE · error · ArgumentException

Input must be KEY or KID:KEY format.

Error message

Input must be KEY or KID:KEY format.

What it means

The --key option accepts either a bare KEY or a KID:KEY pair. After splitting on ':' and trimming/removing empties, anything with more than two parts (or, unreachable here, fewer than one) is rejected with ArgumentException("Input must be KEY or KID:KEY format.").

Solutions

  1. Reduce the input to exactly "KID:KEY" (two parts) or just "KEY".
  2. Strip scheme prefixes and any trailing ':IV' or ':extra' components.
  3. If the tool supports multiple keys, pass separate --key options instead of colon-chaining.
  4. Verify KID and KEY are each valid 16-byte HEX/Base64 (see the KEY-format error).

Example fix

// before
--key "kid:key:iv"
// after
--key "kid:key"
Defensive patterns

Strategy: validation

Validate before calling

var parts = input.Split(':', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
if (parts.Length is < 1 or > 2) throw new FormatException("Use KEY or KID:KEY");

Type guard

bool IsKeyOrKidKey(string s) { var p = s.Split(':'); return p.Length == 1 || p.Length == 2; }

Try / catch

try { ParseKeys(input); }
catch (ArgumentException ex) { Console.Error.WriteLine($"{ex.Message} Got: '{input}'"); }

Prevention

When it happens

Trigger: Passing a value with two or more colons such as "kid:key:extra", or a full URI-form key like "urn:uuid:kid:key"; only "KEY" or "KID:KEY" are accepted.

Common situations: Users paste a full license/URI string containing multiple colons, include a scheme prefix (e.g. 'key:'), or combine kid:key:iv triples from other tools that use a different delimiter.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


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

Appendix: source

Thrown at src/N_m3u8DL-RE/CommandLine/CommandInvoker.cs:266

        var keys = new List<string>();
        var inputs = result.Tokens.Select(t => t.Value).ToList();

        try
        {
            foreach (var input in inputs)
            {
                // 已匹配标准格式的,直接添加
                if (PairKeyRegex().IsMatch(input) || IdHexKeyRegex().IsMatch(input) || SingleHexKeyRegex().IsMatch(input))
                {
                    keys.Add(input);
                    continue;
                }

                // 拆分KID:KEY
                var parts = input.Split(':', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);

                if (parts.Length is < 1 or > 2)
                    throw new ArgumentException("Input must be KEY or KID:KEY format.");

                if (parts.Length == 1)
                {
                    var key = ParsePart(parts[0], "KEY");
                    keys.Add(key);
                }
                else // KID:KEY
                {
                    var kid = ParsePart(parts[0], "KID");
                    var key = ParsePart(parts[1], "KEY");
                    keys.Add($"{kid}:{key}");
                }
            }

            return [.. keys];
        }
        catch (Exception ex)
        {

View on GitHub (pinned to e113dee70c)