# =convert <path> <format> [start-end]: convert or trim audio, video and images
# with ffmpeg. Formats: mp3, mp4, gif (plus wav, m4a, flac, ogg, webm, mov, mkv,
# png, jpg, webp). Optional trim as seconds "start-end", for example 5-20.
# The result is a sibling file; an existing file is never overwritten.
#
# Rows are files: `emits: File` with an absolute `path`, so Enter opens the new
# file, Tab gives the file action card and Space previews it. There is
# deliberately NO `primary: true` action.
#
# Symlinks: the typed path is resolved first, so the new file is written beside the
# link's TARGET, not beside the link, and the original (the target) is never changed.
# The output name is reserved atomically (O_CREAT|O_EXCL), the work is written to a
# private temp file in the same folder and renamed onto that name, so nothing is ever
# overwritten and a failed run leaves no files behind.
#
# Sample data: `=convert demo` always shows fabricated rows. With no path typed
# the list opens on a "Try with sample data" row followed by the same rows.
# Every sample row says SAMPLE DATA and has no path (it is not a file). A typed
# path that fails, or a missing ffmpeg, gets an honest error row. There is no
# `detect:` gate on purpose: a gate would hide the app, and the demo with it,
# on a machine without ffmpeg.
schema_version: 1
runtime: bridge
id: convert
chip: convert
title: Convert or trim media
icon: film
description: "ffmpeg: convert a file to mp3, mp4, gif and more, with optional trim start-end in seconds. =convert demo shows sample data"
placeholder_examples: ["~/clips/talk.mov mp4", "~/clips/talk.mp4 mp3 30-90", "~/clips/talk.mp4 gif 5-12", "demo"]
emits: File

dispatch:
  confirm_label: 'Convert: {{query}}'
  confirm_hint: "Press ↵ to run · path, format, optional start-end seconds · writes a new sibling file"

bridge:
  command:
    macos:   "python3 {{scripts_dir}}/bolt-convert.py {{query}}"
    linux:   "python3 {{scripts_dir}}/bolt-convert.py {{query}}"
    windows: "python {{scripts_dir}}/bolt-convert.py {{query}}"
  parse: json
  timeout_seconds: 55

presentation:
  widget: list
  title_field: title
  subtitle_field: subtitle
  searchable: false
  # What happened, in words: which file was kept and which one is new. Enter,
  # Tab and Space on the row stay the launcher's file behaviour.
  right_widget:
    kind: markdown
    mode: selected_row
    bind:
      title: "{{row.title}}"
      subtitle: "{{row.subtitle}}"
      body: "{{row.body}}"
      actions: [copy-path]

actions:
  - { id: copy-path, kind: composer, target: row, label: Copy path, insert: "{{path}}" }
