#compdef auto-editor

_auto-editor() {
  local -a subcommands options cache_options desc_options info_options levels_options subdump_options waveform_options whisper_options completion_options
  subcommands=(
    'cache'
    'desc:Display a media file'\''s description metadata'
    'info:Retrieve information and properties about media files
Usage: <file> [options] | -encoders <ext> | -decoders <ext>'
    'levels:Display loudness over time'
    'subdump:Dump text-based subtitles to stdout with formatting stripped out'
    'waveform:Draw waveforms for GUI. Unstable interface'
    'whisper:Transcribe audio with ggml models
Usage: <file> <model> [options]'
    'completion:Generate completions for shells'
  )
  options=(
    '-e:Set an expression which determines how to make auto edits. (default is "audio")'
    '--edit:Set an expression which determines how to make auto edits. (default is "audio")'
    '-w\:1:When a segment is active (defined by --edit) do an action. The default action being '\''nil'\'''
    '--when-normal:When a segment is active (defined by --edit) do an action. The default action being '\''nil'\'''
    '--when-active:When a segment is active (defined by --edit) do an action. The default action being '\''nil'\'''
    '-w\:0:When a segment is inactive (defined by --edit) do an action. The default action being '\''cut'\''. See the ]8;;https\://auto-editor.com/ref/actions\actions reference]8;;\ for all available actions.'
    '--when-silent:When a segment is inactive (defined by --edit) do an action. The default action being '\''cut'\''. See the ]8;;https\://auto-editor.com/ref/actions\actions reference]8;;\ for all available actions.'
    '--when-inactive:When a segment is inactive (defined by --edit) do an action. The default action being '\''cut'\''. See the ]8;;https\://auto-editor.com/ref/actions\actions reference]8;;\ for all available actions.'
    '-m:Set sections near "loud" as "loud" too if section is less than LENGTH away. (default is "0.2s")'
    '--margin:Set sections near "loud" as "loud" too if section is less than LENGTH away. (default is "0.2s")'
    '-s:Make sections '\''smoother'\'' by applying minimum cut and minimum clip rules. (default is 0.2s,0.1s)'
    '--smooth:Make sections '\''smoother'\'' by applying minimum cut and minimum clip rules. (default is 0.2s,0.1s)'
    '--transition:Add linked video/audio cross-dissolves at cuts and fades at the timeline ends.'
    '-o:Set the name/path of the new output file'
    '--output:Set the name/path of the new output file'
    '--cut-out:Set segment(s) that will be cut/removed'
    '--cut:Set segment(s) that will be cut/removed'
    '--add-in:Set segment(s) that are leaved "as is", overriding other actions'
    '--keep:Set segment(s) that are leaved "as is", overriding other actions'
    '--set-speed:Set segment(s) to a SPEED, overriding other actions'
    '--set-speed-for-range:Set segment(s) to a SPEED, overriding other actions'
    '--set-action:Set a time segment to an ACTION, overriding other actions'
    '-ex:Choose the export mode'
    '--export:Choose the export mode'
    '-tb:Set timeline frame rate'
    '--time-base:Set timeline frame rate'
    '-r:Set timeline frame rate'
    '-fps:Set timeline frame rate'
    '--frame-rate:Set timeline frame rate'
    '-ar:Set timeline sample rate'
    '--sample-rate:Set timeline sample rate'
    '-res:Set timeline width and height'
    '--resolution:Set timeline width and height'
    '-b:Set the background as a solid RGB color'
    '-bg:Set the background as a solid RGB color'
    '--background:Set the background as a solid RGB color'
    '--yt-dlp-location:Set a custom path to ]8;;https\://github.com/yt-dlp/yt-dlp\yt-dlp]8;;\'
    '--output-format:Set the yt-dlp output file template (--output, -o)'
    '--yt-dlp-extras:Add extra options for yt-dlp. Must be in quotes'
    '--progress:Set what type of progress bar to use'
    '--debug:Show debugging messages and values'
    '-q:Display less output'
    '--quiet:Display less output'
    '--preview:Show stats on how the input will be cut and halt'
    '--stats:Show stats on how the input will be cut and halt'
    '-vn:Disable the inclusion of video streams'
    '-an:Disable the inclusion of audio streams'
    '-sn:Disable the inclusion of subtitle streams'
    '-dn:Disable the inclusion of data streams'
    '--faststart:Enable movflags +faststart, recommended for web (default)'
    '--no-faststart:Disable movflags +faststart, will be faster for large files'
    '--fragmented:Use ]8;;https\://ffmpeg.org/ffmpeg-formats.html#Fragmentation\fragmented]8;;\ mp4/mov to allow playback before video is complete.'
    '--no-fragmented:Do not use fragmented mp4/mov for better compatibility (default)'
    '-c\:v:Set video codec for output media'
    '-vcodec:Set video codec for output media'
    '--video-codec:Set video codec for output media'
    '-b\:v:Set the number of bits per second for video'
    '--video-bitrate:Set the number of bits per second for video'
    '-crf:Set the Constant Rate Factor for quality-based encoding. Lower = better quality. [0-63]'
    '-profile\:v:Set the video profile. For h264\: high, main, or baseline'
    '-vprofile:Set the video profile. For h264\: high, main, or baseline'
    '-preset:Set the video encoder'\''s preset (e.g. ultrafast, medium, slow)'
    '--preset:Set the video encoder'\''s preset (e.g. ultrafast, medium, slow)'
    '-pix_fmt:Set the output pixel format (e.g. yuv420p, yuv420p10le)'
    '--pix-fmt:Set the output pixel format (e.g. yuv420p, yuv420p10le)'
    '--scale:Scale the output video'\''s resolution by NUM factor'
    '--no-seek:Disable file seeking when rendering video. Helpful for debugging desync issues'
    '-c\:a:Set audio codec for output media'
    '-acodec:Set audio codec for output media'
    '--audio-codec:Set audio codec for output media'
    '-layout:Set the audio layout for the output media/timeline'
    '--audio-layout:Set the audio layout for the output media/timeline'
    '-b\:a:Set the number of bits per second for audio'
    '--audio-bitrate:Set the number of bits per second for audio'
    '--mix-audio-streams:Mix all audio streams together into one'
    '-anorm:Apply audio normalizing (either ebu or peak). Applied right before rendering the output file'
    '--audio-normalize:Apply audio normalizing (either ebu or peak). Applied right before rendering the output file'
    '--no-cache:Disable reading and writing cache files'
    '--open:Open the output file after editing is done'
    '--no-open:Do not open the output file after editing is done (default)'
    '-k:Provide a license key, which activates certain features'
    '--license-key:Provide a license key, which activates certain features'
    '-V:Show info about this program or option'
    '-v:Show info about this program or option'
    '--version:Show info about this program or option'
  )
  cache_options=(
  )
  desc_options=(
  )
  info_options=(
    '--json:Print the information as JSON'
    '-encoders:Show all usable encoders for a given container extension'
    '-decoders:Show all usable decoders for a given container extension'
    '-codecs:Show all usable codecs for a given container extension'
  )
  levels_options=(
    '--edit:Set the kind of detection to analyze with (default audio)'
    '-tb:Set the timebase/chunk rate to analyze at (default 30)'
    '--timebase:Set the timebase/chunk rate to analyze at (default 30)'
    '--display:Set the output format {float|d16} (default float)'
    '--no-cache:Disable reading and writing cache files'
  )
  subdump_options=(
    '--json:Print the subtitles as JSON'
  )
  waveform_options=(
    '--stream:Set which audio stream to analyze (default 0)'
    '--channel:Set one or more comma-separated audio channels to draw'
    '--samples-per-bucket:Number of audio samples per drawn bucket (default 256)'
    '--start-sample:First audio sample to analyze from (default 0)'
    '--length-samples:Number of samples to analyze, -1 for all (default -1)'
    '--display:Set the output format {float|d16} (default float)'
    '--no-cache:Disable reading and writing cache files'
  )
  whisper_options=(
    '--debug:Show debugging messages and values'
    '-sw:Output one word per cue instead of full segments'
    '--split-word:Output one word per cue instead of full segments'
    '--split-words:Output one word per cue instead of full segments'
    '-l:Set the language instead of using "auto". Examples\: en, ja'
    '--language:Set the language instead of using "auto". Examples\: en, ja'
    '-f:Output in a specific format {text|srt|json} (default text)'
    '--format:Output in a specific format {text|srt|json} (default text)'
    '-o:Choose where to output (defaults to stdout)'
    '--output:Choose where to output (defaults to stdout)'
    '-tr:Translate from source language to english'
    '--translate:Translate from source language to english'
    '--queue:The maximum size in seconds of a single transcribed segment (default 30)'
    '--prompt:Bias transcription toward given vocabulary/spelling (e.g. names, jargon)'
    '--threads:Number of CPU threads for whisper processing (default 4)'
    '-t:The loudness (0-1) below which audio is treated as silence and skipped, like the audio edit method (default 0.04)'
    '--threshold:The loudness (0-1) below which audio is treated as silence and skipped, like the audio edit method (default 0.04)'
  )
  completion_options=(
    '-s:Shell type\: {zsh}'
    '--shell:Shell type\: {zsh}'
  )
  if (( CURRENT == 2 )); then
    _describe 'command' subcommands
    _describe 'option' options
    _files
  else
    case "$words[2]" in
      cache)
        _describe 'option' cache_options
        ;;
      desc)
        _describe 'option' desc_options
        _files
        ;;
      info)
        _describe 'option' info_options
        _files
        ;;
      levels)
        _describe 'option' levels_options
        _files
        ;;
      subdump)
        _describe 'option' subdump_options
        _files
        ;;
      waveform)
        _describe 'option' waveform_options
        _files
        ;;
      whisper)
        _describe 'option' whisper_options
        _files
        ;;
      completion)
        _describe 'option' completion_options
        ;;
      *)
        _describe 'option' options
        _files
        ;;
    esac
  fi
}

_auto-editor "$@"

