see api.md for docs
also:
- allow passing arguments when using CLI to pass to second instance
- allow opening files from API
- improve docs
#980#974#1347
LosslessCut can be controlled via a HTTP API, if it is being run with the command line option `--http-api`. See also [CLI](cli.md). **Note that the HTTP API is experimental and may change at any time.**
LosslessCut can be controlled via a HTTP API, if it is being run with the command line option `--http-api`. **Note that the HTTP API is experimental and may change at any time.**
## Programmatically opening a file
This must be done with [the CLI](cli.md).
See also [CLI](cli.md).
## Enabling the API
To enable the API, run LosslessCut from the command line with this flag:
```bash
LosslessCut --http-api
```
## API endpoints
### `POST /api/action/:action`
## Action endpoint: `POST /api/action/:action`
Execute a keyboard shortcut `action`, similar to the `--keyboard-action` CLI option. This is different from the CLI in that most of the actions will wait for the action to finish before responding to the HTTP request (but not all).
Execute a keyboard shortcut `action`, similar to the `--keyboard-action` CLI option. This is different from the CLI in that most of the actions (but not all) will wait for the action to finish before responding to the HTTP request.
See [Available keyboard actions](cli.md#available-keyboard-actions).
#### Example
### Example actions
Export the currently opened file:
```bash
curl -X POST http://localhost:8080/api/action/export
```
@ -33,6 +30,10 @@ Seek to time:
curl -X POST http://localhost:8080/api/action/goToTimecodeDirect --json '{"time": "09:11"}'
```
Open one or more files:
```bash
curl -X POST http://localhost:8080/api/action/openFiles --json '["/path/to/file.mp4"]'
```
### Batch example
@ -52,3 +53,24 @@ for PROJECT in /path/to/folder/with/projects/*.llc
curl -X POST http://localhost:8080/api/action/closeCurrentFile
done
```
## Await event endpoint
This special endpoint allows you to wait for a certain event to occur in the app. The endpoint will hang and respond/return only when the event fires. Below are supported events.
### Event: `export-start`
Emitted when the export operation starts. The endpoint will return JSON `{ path: string }`.
### Event: `export-complete`
Emitted when the export operation completes (either success or failure). If successful, the endpoint will return JSON `{ paths: string[] }`.
#### Examples
Run a command after each file that has completed exporting:
```bash
while true; do
echo 'Do something with exported file path:' $(curl -s -X POST http://localhost:8080/api/await-event/export-complete | jq -r '.paths[0]')
See [available settings](https://github.com/mifi/lossless-cut/blob/master/src/main/configStore.ts). Note that this is subject to change in newer versions. ⚠️ If you specify incorrect values it could corrupt your configuration file. You may use JSON or JSON5. Example:
If you have the "Allow multiple instances" setting enabled, you can control a running instance of LosslessCut from the outside, using for example a command line. You do this by issuing messages to it through the `LosslessCut` command. Currently only keyboard actions are supported, and you can open files. *Note that this is considered experimental and the API may change at any time.*
### Open files in running instance
```bash
LosslessCut file1.mp4 file2.mkv
```
### Keyboard actions, `--keyboard-action`
Simulate a keyboard press action in an already running instance of LosslessCut. Note that the command will return immediately, so if you want to run multiple actions in a sequence, you have to `sleep` for a few seconds between the commands. Alternatively if you want to wait until an action has finished processing, you can use the [HTTP API](api.md) instead. Note that the HTTP API does not support opening files, and it is currently not possible to wait for a file to have finished opening.
Simulate a keyboard press action in an already running instance of LosslessCut. **Note that the command will return immediately**, so if you want to run multiple actions in a sequence, you have to `sleep` for a few seconds between the commands. Alternatively if you want to wait until an action has finished processing, use the [HTTP API](api.md) instead.
### Available keyboard actions
A list of the available action names can be found in the "Keyboard shortcuts" dialog in the app. Note that you don't have to bind them to any key before using them.
Example:
#### Example keyboard actions
Open a file and export it:
```bash
# Open a file in an already running instance
LosslessCut file.mp4
@ -63,8 +71,11 @@ sleep 3 # hopefully the file has loaded by now
errorToast(i18n.t('No tracks selected for export'));
@ -1174,7 +1178,9 @@ function App() {
}
// Note: this should be after cleanup, so we don't accidentally open two dialogs at the same time, leading to error *and* success dialog simultaneously https://github.com/mifi/lossless-cut/issues/2609