ytdlp_flags.go
| 1 | package service |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "strings" |
| 6 | ) |
| 7 | |
| 8 | // reservedFlags are yt-dlp options VidArchive always sets itself; user custom |
| 9 | // flags must not pass them (or a conflicting inverse). The value describes what |
| 10 | // the option controls, for the failure message. |
| 11 | var reservedFlags = map[string]string{ |
| 12 | "-o": "the output template", |
| 13 | "--output": "the output template", |
| 14 | "-P": "the download path", |
| 15 | "--paths": "the download path", |
| 16 | "--cookies": "cookies (set these in Settings instead)", |
| 17 | "--no-cookies": "cookies (set these in Settings instead)", |
| 18 | "--newline": "progress output formatting (VidArchive sets this to stream logs)", |
| 19 | |
| 20 | // These hand yt-dlp an arbitrary command or binary to run. VidArchive passes |
| 21 | // custom flags through verbatim, so allowing them would turn the preset form |
| 22 | // into remote command execution. |
| 23 | "--exec": "running external commands (not permitted)", |
| 24 | "--exec-before-download": "running external commands (not permitted)", |
| 25 | "--postprocessor-args": "post-processor arguments (not permitted)", |
| 26 | "--ppa": "post-processor arguments (not permitted)", |
| 27 | "--downloader": "selecting an external downloader (not permitted)", |
| 28 | "--external-downloader": "selecting an external downloader (not permitted)", |
| 29 | "--downloader-args": "external downloader arguments (not permitted)", |
| 30 | "--external-downloader-args": "external downloader arguments (not permitted)", |
| 31 | } |
| 32 | |
| 33 | // reservedSubscriptionFlags are additionally reserved for subscription runs, |
| 34 | // where VidArchive drives info-json writing and the refresh mode. |
| 35 | var reservedSubscriptionFlags = map[string]string{ |
| 36 | "--write-info-json": "info-json writing (needed to track item identity)", |
| 37 | "--no-write-info-json": "info-json writing (needed to track item identity)", |
| 38 | "--download-archive": "the download archive (managed by Skip mode)", |
| 39 | "--no-download-archive": "the download archive (managed by Skip mode)", |
| 40 | "--skip-download": "media downloading (managed by Metadata mode)", |
| 41 | "--no-skip-download": "media downloading (managed by Metadata mode)", |
| 42 | } |
| 43 | |
| 44 | // checkReservedFlags rejects custom flags that clash with options VidArchive |
| 45 | // controls, naming the offender. It matches both "--flag" and "--flag=value". |
| 46 | func checkReservedFlags(customFlags string, isSubscription bool) error { |
| 47 | for _, tok := range strings.Fields(customFlags) { |
| 48 | // Both "--flag value" and "--flag=value" name the same option. |
| 49 | name, _, _ := strings.Cut(tok, "=") |
| 50 | |
| 51 | desc, ok := reservedFlags[name] |
| 52 | if !ok && isSubscription { |
| 53 | desc, ok = reservedSubscriptionFlags[name] |
| 54 | } |
| 55 | if ok { |
| 56 | return fmt.Errorf("custom flag %q conflicts with VidArchive's handling of %s; remove it and try again", tok, desc) |
| 57 | } |
| 58 | } |
| 59 | return nil |
| 60 | } |
| 61 |