package service import ( "fmt" "strings" ) // reservedFlags are yt-dlp options VidArchive always sets itself; user custom // flags must not pass them (or a conflicting inverse). The value describes what // the option controls, for the failure message. var reservedFlags = map[string]string{ "-o": "the output template", "--output": "the output template", "-P": "the download path", "--paths": "the download path", "--cookies": "cookies (set these in Settings instead)", "--no-cookies": "cookies (set these in Settings instead)", "--newline": "progress output formatting (VidArchive sets this to stream logs)", // These hand yt-dlp an arbitrary command or binary to run. VidArchive passes // custom flags through verbatim, so allowing them would turn the preset form // into remote command execution. "--exec": "running external commands (not permitted)", "--exec-before-download": "running external commands (not permitted)", "--postprocessor-args": "post-processor arguments (not permitted)", "--ppa": "post-processor arguments (not permitted)", "--downloader": "selecting an external downloader (not permitted)", "--external-downloader": "selecting an external downloader (not permitted)", "--downloader-args": "external downloader arguments (not permitted)", "--external-downloader-args": "external downloader arguments (not permitted)", } // reservedSubscriptionFlags are additionally reserved for subscription runs, // where VidArchive drives info-json writing and the refresh mode. var reservedSubscriptionFlags = map[string]string{ "--write-info-json": "info-json writing (needed to track item identity)", "--no-write-info-json": "info-json writing (needed to track item identity)", "--download-archive": "the download archive (managed by Skip mode)", "--no-download-archive": "the download archive (managed by Skip mode)", "--skip-download": "media downloading (managed by Metadata mode)", "--no-skip-download": "media downloading (managed by Metadata mode)", } // checkReservedFlags rejects custom flags that clash with options VidArchive // controls, naming the offender. It matches both "--flag" and "--flag=value". func checkReservedFlags(customFlags string, isSubscription bool) error { for _, tok := range strings.Fields(customFlags) { // Both "--flag value" and "--flag=value" name the same option. name, _, _ := strings.Cut(tok, "=") desc, ok := reservedFlags[name] if !ok && isSubscription { desc, ok = reservedSubscriptionFlags[name] } if ok { return fmt.Errorf("custom flag %q conflicts with VidArchive's handling of %s; remove it and try again", tok, desc) } } return nil }