Metadata-Version: 2.4
Name: asciinema-scene
Version: 1.2.2
Summary: Toolbox to edit asciinema screencasts (sciine)
Author: Jerome Dumonteil
Author-email: Jerome Dumonteil <jerome.dumonteil@gmail.com>
License-Expression: MIT
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Requires-Dist: click>=8.3.0,<9
Requires-Python: >=3.10, <4.0
Project-URL: Changelog, https://github.com/jdum/asciinema-scene/blob/master/CHANGES.md
Project-URL: Documentation, https://jdum.github.io/asciinema-scene/
Project-URL: Repository, https://github.com/jdum/asciinema-scene
Description-Content-Type: text/markdown

# asciinema-scene

[![Release](https://img.shields.io/github/v/release/jdum/asciinema-scene)](https://img.shields.io/github/v/release/jdum/asciinema-scene)
[![Build status](https://img.shields.io/github/actions/workflow/status/jdum/asciinema-scene/main.yml?branch=main)](https://github.com/jdum/asciinema-scene/actions/workflows/main.yml?query=branch%3Amain)
[![codecov](https://codecov.io/gh/jdum/asciinema-scene/branch/main/graph/badge.svg)](https://codecov.io/gh/jdum/asciinema-scene)
[![Commit activity](https://img.shields.io/github/commit-activity/m/jdum/asciinema-scene)](https://img.shields.io/github/commit-activity/m/jdum/asciinema-scene)
[![License](https://img.shields.io/github/license/jdum/asciinema-scene)](https://img.shields.io/github/license/jdum/asciinema-scene)

`asciinema-scene` provides the `sciine` command line toolkit for editing screen casts produced by [asciinema](https://asciinema.org/).

`sciine` takes as input the content of a screencast, apply a unitary transformation and returns the transformed content.


## Installation

Installation from Pypi (recommended):

``` bash
pip install asciinema-scene
```

Installation from sources:

```bash
uv sync
```

After installation from sources, you can check everything is working

```bash
uv run pytest
```

## Usage


### Commandes


There are 4 types of commands:

- content information commands:
    - [status](#command-status)
    - [header](#command-header)
    - [show](#command-show)


- commands applying to a portion of the content:
    - [copy](#command-copy)
    - [cut](#command-cut)
    - [speed](#command-speed)
    - [minimum](#command-minimum)
    - [maximum](#command-maximum)
    - [quantize](#command-quantize)
    - [include](#command-include)


- command applying to a single frame:
    - [insert](#command-insert)
    - [replace](#command-replace)
    - [delete](#command-delete)


- command modifying content via regular expressions:
    - [text-delete](#command-text-delete)
    - [text-merge](#command-text-merge)
    - [text-replace](#command-text-replace)


``` script
Usage: sciine [OPTIONS] COMMAND [ARGS]...

Options:
  --version  Show the version and exit.
  --help     Show this message and exit.

Commands:
  copy          Copy content between START and END timecodes.
  cut           Cut content between START and END timecodes.
  delete        Delete the frame with timecode >= TIMECODE.
  header        Print the header field of the content.
  include       Include the content of a .cast file at the timecode...
  insert        Insert a frame at the TIMECODE position.
  maximum       Set maximum duration of each frame.
  minimum       Set minimum duration of each frame.
  quantize      Set the duration of frames in duration range to DURATION.
  replace       Replace the text of frame with timecode >= TIMECODE by TEXT.
  show          Print detail of frames, from START to END (max LINES).
  speed         Change the speed of the screen cast.
  status        Print informations about the content (duration, ...).
  text-delete   Delete frames matching the text regex between START and END.
  text-merge    Merge successive frames matching the regex between START...
  text-replace  Replace text in frames matching the regex between START...
```

---

### Input / output

By default, `sciine` reads content from standard input and returns the result to standard output. The `--input` and `--output` options allow reading/writing from files (`sciine` can also read from a compressed `.zip` or `.gz` file). `sciine` does not modify the input file.

``` bash
-i, --input PATH   Input .cast file, default is stdin.
-o, --output PATH  Output .cast file, default is stdout.
```

Example:

Speed up a screencast and play a sub-part of it, using pipe redirection.


``` bash
sciine speed 2.0 --input short.cast | sciine copy --start 1.4 --end 2.4| asciinema play -
```

---

## Command `status`

``` script
Usage: sciine status [OPTIONS]

  Print informations about the content (duration, ...).

Options:
  -i, --input PATH  Input .cast file, default is stdin.
  --help            Show this message and exit.
```

Example:

Use `status` to see the number of frames and the duration of the screecast.


``` bash
sciine status --input short.cast
Input: short.cast
Date: 2023-05-28 11:15:06+00:00
Frames: 22
Duration: 6.135993
```

---

## Command `header`

``` script
Usage: sciine header [OPTIONS]

  Print the header field of the content.

Options:
  -i, --input PATH  Input .cast file, default is stdin.
  --help            Show this message and exit.
```

Example:

Display the original header.

``` bash
sciine header -i short.cast
{'env': {'SHELL': '/bin/bash', 'TERM': 'linux'},
 'height': 36,
 'timestamp': 1685272506,
 'version': 2,
 'width': 133}
```

---

## Command `show`

``` script
Usage: sciine show [OPTIONS]

  Print detail of frames, from START to END (max LINES).

  Each line prints the timecode, duration and text of the frame. If no START
  timecode is provided, start from the beginning. If no END timecode is
  provided, display all lines until the end, or LINES lines

Options:
  -s, --start FLOAT    Start timecode (sec), default is 0.0.
  -e, --end FLOAT      End timecode (sec), default is EOF.
  -l, --lines INTEGER  Number of lines to show.
  -p, --precise        Show all digits of time codes.
  -t, --text           Show message field as plain text.
  -i, --input PATH     Input .cast file, default is stdin.
  --help               Show this message and exit.
```

Example:

Display the first 5 lines and the precise duration of the frames.

``` bash
sciine show --lines 5 --precise  -i short.cast
  0.000000│ 0.894038│ 'e'
  0.894038│ 0.104510│ 'c'
  0.998548│ 0.164761│ 'h'
  1.163309│ 0.300601│ 'o'
  1.463910│ 0.392259│ ' '
```

---

## Command `copy`

``` script
Usage: sciine copy [OPTIONS]

  Copy content between START and END timecodes.

Options:
  -s, --start FLOAT  Start timecode (sec), default is 0.0.
  -e, --end FLOAT    End timecode (sec), default is EOF.
  -i, --input PATH   Input .cast file, default is stdin.
  -o, --output PATH  Output .cast file, default is stdout.
  --help             Show this message and exit.
```

Example:

Play content between 0.05 and 1.2 seconds.

``` bash
sciine copy --start 0.05 --end 1.2 -i short.cast | asciinema play -
```

---

## Command `cut`

``` script
Usage: sciine cut [OPTIONS]

  Cut content between START and END timecodes.

  If no START timecode is provided, cut from the beginning. If no END timecode
  is provided, cut until the end.

Options:
  -s, --start FLOAT  Start timecode (sec), default is 0.0.
  -e, --end FLOAT    End timecode (sec), default is EOF.
  -a, --adjust       Adjust durations of frames at precise cut values.
  -i, --input PATH   Input .cast file, default is stdin.
  -o, --output PATH  Output .cast file, default is stdout.
  --help             Show this message and exit.
```

Example:

Cut end of content after 1.2 seconds.

``` bash
sciine cut --start 1.2 < short.cast | asciinema play -
```

---

## Command `speed`

``` script
Usage: sciine speed [OPTIONS] SPEED

  Change the speed of the screen cast.

  SPEED is the factor of acceleration. Use number below 1.0 to to slow down.
  If no START timecode is provided, modify speed from the beginning. If no END
  timecode is provided, modify speed until the end.

Options:
  -s, --start FLOAT  Start timecode (sec), default is 0.0.
  -e, --end FLOAT    End timecode (sec), default is EOF.
  -i, --input PATH   Input .cast file, default is stdin.
  -o, --output PATH  Output .cast file, default is stdout.
  --help             Show this message and exit.
```

Example:

Doubles the speed and displays the new duration.

``` bash
sciine speed 2.0 -i short.cast|sciine status
Input: sys.stdin
Date: 2023-06-03 11:10:23+00:00
Frames: 22
Duration: 3.067996
```

---

## Command `minimum`

``` script
Usage: sciine minimum [OPTIONS] DURATION

  Set minimum duration of each frame.

  The minimum duration of frames will be set to DURATION seconds, the
  timecodes will be adjusted accordingly. If no START timecode is provided,
  apply from the beginning. If no END timecode is provided, apply until the
  end.

Options:
  -s, --start FLOAT  Start timecode (sec), default is 0.0.
  -e, --end FLOAT    End timecode (sec), default is EOF.
  -i, --input PATH   Input .cast file, default is stdin.
  -o, --output PATH  Output .cast file, default is stdout.
  --help             Show this message and exit.
```

Example:

Set the frame duration to a minimum of 0.2s and display the new durations.

``` bash
sciine minimum 0.2 -i short.cast | sciine show -l 5 -p
  0.000000│ 0.894038│ 'e'
  0.894038│ 0.200000│ 'c'
  1.094038│ 0.200000│ 'h'
  1.294038│ 0.300601│ 'o'
  1.594639│ 0.392259│ ' '
```

---

## Command `maximum`

``` script
Usage: sciine maximum [OPTIONS] DURATION

  Set maximum duration of each frame.

  The duration of frames will be limited to DURATION seconds, the timecodes
  will be adjusted accordingly. If no START timecode is provided, apply from
  the beginning. If no END timecode is provided, apply until the end.

Options:
  -s, --start FLOAT  Start timecode (sec), default is 0.0.
  -e, --end FLOAT    End timecode (sec), default is EOF.
  -i, --input PATH   Input .cast file, default is stdin.
  -o, --output PATH  Output .cast file, default is stdout.
  --help             Show this message and exit.
```

Example:

Set the frame duration to a maximum of 0.2s and display the new durations.

``` bash
sciine maximum 0.2 -i short.cast | sciine show -l 5 -p
  0.000000│ 0.200000│ 'e'
  0.200000│ 0.104510│ 'c'
  0.304510│ 0.164761│ 'h'
  0.469271│ 0.200000│ 'o'
  0.669271│ 0.200000│ ' '
```

---

## Command `quantize`

``` script
Usage: sciine quantize [OPTIONS] RANGE_MIN RANGE_MAX DURATION

  Set the duration of frames in duration range to DURATION.

  Set the duration of frames to DURATION if their current duration is between
  RANGE_MIN and RANGE_MAX. If no START timecode is provided, apply from the
  beginning. If no END timecode is provided, apply until the end.

Options:
  -s, --start FLOAT  Start timecode (sec), default is 0.0.
  -e, --end FLOAT    End timecode (sec), default is EOF.
  -i, --input PATH   Input .cast file, default is stdin.
  -o, --output PATH  Output .cast file, default is stdout.
  --help             Show this message and exit.
```

Example:

Set the frame duration to 0.2s for all frames lasting between 0.1 and 0.4s.

``` bash
sciine quantize 0.1 0.4 0.2 -i short.cast | sciine show -l 5 -p
  0.000000│ 0.894038│ 'e'
  0.894038│ 0.200000│ 'c'
  1.094038│ 0.200000│ 'h'
  1.294038│ 0.200000│ 'o'
  1.494038│ 0.200000│ ' '
```

---

## Command `include`

``` script
Usage: sciine include [OPTIONS] TIMECODE INCLUDE_FILE

  Include the content of a .cast file at the timecode position.

  All frames of the INCLUDE_FILE .cast file will be copied in the current
  screen cast. The timecodes will be adjusted as required.

Options:
  -i, --input PATH   Input .cast file, default is stdin.
  -o, --output PATH  Output .cast file, default is stdout.
  --help             Show this message and exit.
```

Example:

Add the content of `long.cast` to the beginning of the screencast, and display the final duration.

``` bash
sciine include 0.0 long.cast.gz  -i short.cast|sciine status
Input: sys.stdin
Date: 2023-06-03 12:14:22+00:00
Frames: 71391
Duration: 22.925312
```

---

## Command `insert`

``` script
Usage: sciine insert [OPTIONS] TIMECODE DURATION TEXT [ETYPE]

  Insert a frame at the TIMECODE position.

  The frame will display TEXT during DURATION seconds. By default the event
  type ETYPE is set to "o".

Options:
  -b, --line-break   Add line break at end of text.
  -i, --input PATH   Input .cast file, default is stdin.
  -o, --output PATH  Output .cast file, default is stdout.
  --help             Show this message and exit.
```

Example:

Insert the string 'xyz' at position 2.0 for a duration of 0.1s. View content before and after the change.

``` bash
sciine show -l 8 -p -i short.cast
  0.000000│ 0.894038│ 'e'
  0.894038│ 0.104510│ 'c'
  0.998548│ 0.164761│ 'h'
  1.163309│ 0.300601│ 'o'
  1.463910│ 0.392259│ ' '
  1.856169│ 0.356967│ '"'
  2.213136│ 0.150277│ 'a'
  2.363413│ 0.511288│ ' '

sciine insert 2.0 0.1 "xyz" -i short.cast | sciine show -l 8 -p
  0.000000│ 0.894038│ 'e'
  0.894038│ 0.104510│ 'c'
  0.998548│ 0.164761│ 'h'
  1.163309│ 0.300601│ 'o'
  1.463910│ 0.392259│ ' '
  1.856169│ 0.356967│ '"'
  2.213136│ 0.100000│ 'xyz'
  2.313136│ 0.150277│ 'a'
```

---

## Command `replace`

``` script
Usage: sciine replace [OPTIONS] TIMECODE TEXT

  Replace the text of frame with timecode >= TIMECODE by TEXT.

Options:
  -i, --input PATH   Input .cast file, default is stdin.
  -o, --output PATH  Output .cast file, default is stdout.
  --help             Show this message and exit.
```

Example:

Replace the string 'xyz' at position 2.0 for a duration of 0.1s. View content before and after the change.

``` bash
sciine show -l 8 -p -i short.cast
  0.000000│ 0.894038│ 'e'
  0.894038│ 0.104510│ 'c'
  0.998548│ 0.164761│ 'h'
  1.163309│ 0.300601│ 'o'
  1.463910│ 0.392259│ ' '
  1.856169│ 0.356967│ '"'
  2.213136│ 0.150277│ 'a'
  2.363413│ 0.511288│ ' '

sciine replace 2.0 "xyz" -i short.cast | sciine show -l 8 -p
  0.000000│ 0.894038│ 'e'
  0.894038│ 0.104510│ 'c'
  0.998548│ 0.164761│ 'h'
  1.163309│ 0.300601│ 'o'
  1.463910│ 0.392259│ ' '
  1.856169│ 0.356967│ '"'
  2.213136│ 0.150277│ 'xyz'
  2.363413│ 0.511288│ ' '
```

---

## Command `delete`

``` script
Usage: sciine delete [OPTIONS] TIMECODE

  Delete the frame with timecode >= TIMECODE.

Options:
  -i, --input PATH   Input .cast file, default is stdin.
  -o, --output PATH  Output .cast file, default is stdout.
  --help             Show this message and exit.
```

Example:

Delete the frame at position 2.0. View content before and after the change.

``` bash
sciine show -l 8 -p -i short.cast
  0.000000│ 0.894038│ 'e'
  0.894038│ 0.104510│ 'c'
  0.998548│ 0.164761│ 'h'
  1.163309│ 0.300601│ 'o'
  1.463910│ 0.392259│ ' '
  1.856169│ 0.356967│ '"'
  2.213136│ 0.150277│ 'a'
  2.363413│ 0.511288│ ' '

sciine delete 2.0  -i short.cast | sciine show -l 8 -p
  0.000000│ 0.894038│ 'e'
  0.894038│ 0.104510│ 'c'
  0.998548│ 0.164761│ 'h'
  1.163309│ 0.300601│ 'o'
  1.463910│ 0.392259│ ' '
  1.856169│ 0.356967│ '"'
  2.213136│ 0.511288│ ' '
  2.724424│ 0.237965│ 's'
```

---

## Command `text-delete`

``` script
Usage: sciine text-delete [OPTIONS] TEXT

  Delete frames matching the text regex between START and END.

  If no START timecode is provided, delete from the beginning. If no END
  timecode is provided, delete until the end.

Options:
  -s, --start FLOAT  Start timecode (sec), default is 0.0.
  -e, --end FLOAT    End timecode (sec), default is EOF.
  -i, --input PATH   Input .cast file, default is stdin.
  -o, --output PATH  Output .cast file, default is stdout.
  --help             Show this message and exit.
```

Example:

Delete the frames from 3.0 seconds that match '{server}'. View content before and after the change.

``` bash
sciine show -s3 -i back.cast
  3.057│ 0.20│ '\x1b[K    \\ {server}\r'
  3.258│ 0.21│ '\x1b[K    | {server}\r'
  3.463│ 0.21│ '\x1b[K    / {server}\r'
  3.668│ 0.20│ '\x1b[K    - {server}\r'
  3.871│ 0.20│ '\x1b[K    \\ {server}\r'
  4.073│ 0.20│ '\x1b[K    | {server}\r'
  4.275│ 0.21│ '\x1b[K    / {server}\r'
  4.480│ 0.20│ '\x1b[K    - {server}\r'
  4.682│ 0.18│ '\x1b[K    \\ {server}\r'
  4.861│ 0.00│ '\x1b[K    \x1b[0m[\x1b[1mserver\x1b[0m] \x1b[32mSuccess\x1b[0m\r\n'

sciine text-delete -s3 -i back.cast '.*{server}' | sciine show -s3
  3.057│ 0.00│ '\x1b[K    \x1b[0m[\x1b[1mserver\x1b[0m] \x1b[32mSuccess\x1b[0m\r\n'
```

---

## Command `text-replace`

``` script
Usage: sciine text-replace [OPTIONS] TEXT REPLACEMENT

  Replace text in frames matching the regex between START and END.

  If no START timecode is provided, replace from the beginning. If no END
  timecode is provided, replace until the end.

Options:
  -s, --start FLOAT  Start timecode (sec), default is 0.0.
  -e, --end FLOAT    End timecode (sec), default is EOF.
  -i, --input PATH   Input .cast file, default is stdin.
  -o, --output PATH  Output .cast file, default is stdout.
  --help             Show this message and exit.
```

Example:

Replace in the frames from 3.0 seconds '. {server}' by 'box '. View content before and after the change.

``` bash
sciine show -s3 -i back.cast
  3.057│ 0.20│ '\x1b[K    \\ {server}\r'
  3.258│ 0.21│ '\x1b[K    | {server}\r'
  3.463│ 0.21│ '\x1b[K    / {server}\r'
  3.668│ 0.20│ '\x1b[K    - {server}\r'
  3.871│ 0.20│ '\x1b[K    \\ {server}\r'
  4.073│ 0.20│ '\x1b[K    | {server}\r'
  4.275│ 0.21│ '\x1b[K    / {server}\r'
  4.480│ 0.20│ '\x1b[K    - {server}\r'
  4.682│ 0.18│ '\x1b[K    \\ {server}\r'
  4.861│ 0.00│ '\x1b[K    \x1b[0m[\x1b[1mserver\x1b[0m] \x1b[32mSuccess\x1b[0m\r\n'

sciine text-replace -s3 -i back.cast '. {server}' 'box' | sciine show -s3
  3.057│ 0.20│ '\x1b[K    box\r'
  3.258│ 0.21│ '\x1b[K    box\r'
  3.463│ 0.21│ '\x1b[K    box\r'
  3.668│ 0.20│ '\x1b[K    box\r'
  3.871│ 0.20│ '\x1b[K    box\r'
  4.073│ 0.20│ '\x1b[K    box\r'
  4.275│ 0.21│ '\x1b[K    box\r'
  4.480│ 0.20│ '\x1b[K    box\r'
  4.682│ 0.18│ '\x1b[K    box\r'
  4.861│ 0.00│ '\x1b[K    \x1b[0m[\x1b[1mserver\x1b[0m] \x1b[32mSuccess\x1b[0m\r\n'
```

---

## Command `text-merge`

``` script
Usage: sciine text-merge [OPTIONS] TEXT

  Merge successive frames matching the regex between START and END.

  If no START timecode is provided, merge from the beginning. If no END
  timecode is provided, merge until the end.

Options:
  -s, --start FLOAT  Start timecode (sec), default is 0.0.
  -e, --end FLOAT    End timecode (sec), default is EOF.
  -i, --input PATH   Input .cast file, default is stdin.
  -o, --output PATH  Output .cast file, default is stdout.
  --help             Show this message and exit.
```

Example:

Merge frames from 3.0 seconds matching '. {server}', keeping total duration. View content before and after the change.

``` bash
sciine show -s3 -i back.cast
  3.057│ 0.20│ '\x1b[K    \\ {server}\r'
  3.258│ 0.21│ '\x1b[K    | {server}\r'
  3.463│ 0.21│ '\x1b[K    / {server}\r'
  3.668│ 0.20│ '\x1b[K    - {server}\r'
  3.871│ 0.20│ '\x1b[K    \\ {server}\r'
  4.073│ 0.20│ '\x1b[K    | {server}\r'
  4.275│ 0.21│ '\x1b[K    / {server}\r'
  4.480│ 0.20│ '\x1b[K    - {server}\r'
  4.682│ 0.18│ '\x1b[K    \\ {server}\r'
  4.861│ 0.00│ '\x1b[K    \x1b[0m[\x1b[1mserver\x1b[0m] \x1b[32mSuccess\x1b[0m\r\n'

sciine text-merge -s3 -i back.cast '. {server}' | sciine show -s3
  3.057│ 1.80│ '\x1b[K    \\ {server}\r'
  4.861│ 0.00│ '\x1b[K    \x1b[0m[\x1b[1mserver\x1b[0m] \x1b[32mSuccess\x1b[0m\r\n'
```

---

## Code source

**Github repository**: [https://github.com/jdum/asciinema-scene](https://github.com/jdum/asciinema-scene)

## License

This project is licensed under the MIT License (see the LICENSE file for details).
