A Python script to truncate recording sessions of asciinema. This tool is perfect for users who want to remove specific time intervals from their recorded sessions, ensuring the end result is clean and only showcases what's necessary.
- Removes specified time intervals from an
asciinemarecording.asciinemarecords in NDJSON format
- Automatically adjusts timestamps to maintain continuity after truncation.
- Maintains the integrity of the NDJSON structure of the recording.
- Python 3.x
- the requirements.txt only contains
json
- the requirements.txt only contains
- Jupyter Notebook (if you're running the script in Jupyter)
-
Record your terminal session with
asciinema.asciinema rec filename.cast
-
Run the script in a Jupyter Notebook or as a standalone script, providing:
- Path to the recorded
.castfile. - Path to an output file to save the processed contents.
- List of timestamp pairs representing the start and end of intervals you want to truncate.
# Run the script and get processing statistics processing_stats = truncate_asciinema(input_file="filename.cast", output_file="truncated.cast", timestamp_ranges=[(10, 20), (40, 60)]) # Print processing statistics for stat in processing_stats: print(stat)
- Path to the recorded
-
The script will create a new
.castfile with the specified intervals removed.
Here's a simple use case to better understand the script's functionality:
Input timestamps: 0, 3, 4, 6, 8, 10, 12, 15, 18, 20, 22, 25, 31, 49, 50
Timestamp ranges to truncate: (10, 20) and (30, 40)
Output timestamps: 0, 3, 4, 6, 8, 10, 13, 31, 32
See a truncated output file on teh asciinema website at https://asciinema.org/a/cPkBEGvwHSL2eE5OUzjeBClrl
Feedback and pull requests are welcome. If you find any issues or have suggestions, please write a comment.
This project is licensed under the MIT License.
Roadmap:
[ ] get feedback
[x] rework truncate_asciinema to not print stats
[ ] more tests
[ ] β¦