Metadata-Version: 2.4
Name: mlength
Version: 0.1.0
Summary: gets the length of media files and caches the result
Author: purarue
License-Expression: MIT
Project-URL: Homepage, https://github.com/purarue/mlength
Keywords: media,length,duration,cache
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
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-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: click>=8.1.6
Requires-Dist: pymediainfo
Provides-Extra: testing
Requires-Dist: flake8; extra == "testing"
Requires-Dist: mypy; extra == "testing"
Dynamic: license-file

# mlength

gets the length of media files and caches the result

## Installation

Requires `python3.10+`

To install with pip, run:

```
pip install git+https://github.com/purarue/mlength
```

This requires either `ffprobe` (from `ffmpeg`) or [`mediainfo`](https://mediaarea.net/en/MediaInfo) to be installed.

## Usage

```
Usage: mlength [OPTIONS] MEDIA...

  Compute the duration of media files

  This caches the duration of media files in a cache directory, so that
  subsequent runs are faster. If media files are modified, the cache is recomputed

  MEDIA is a list of media files to compute the duration of

Options:
  --cache-dir PATH                Cache directory  [default: ~/.cache/mlength]
  --lib [mediainfo|ffprobe]       Library to use for parsing media files  [env
                                  var: MLENGTH_LIB; default: ffprobe]
  --cache / --no-cache            Enable/disable caching  [default: cache]
  -o, --operation [sum|max|min|avg]
                                  Operation to perform on the durations
  -d, --display [ms|s|m|human|path|all]
                                  Display format for durations
  --debug                         Enable debug mode
  --help                          Show this message and exit.
```

```bash
$ mlength sound.mpeg
00:00:02.95
$ mlength -d all sound.mpeg
2951|2.95|0.05|00:00:02.95|sound.mpeg
```

I use this in lots of small scripts:

Get the shortest media file in a directory, with the [list-movies](https://github.com/purarue/pura-utils/blob/main/shellscripts/list-movies) script:

- `list-music -X mlength -o sum` (find length of an album in current directory)
- `list-movies -X mlength -d path -o min` (find shortest movie in current directory)
- `list-movies -X mlength -d all | sort -n` (sort results by length)

If the media file is modified, the cache is recomputed.

### Tests

```bash
git clone 'https://github.com/purarue/mlength'
cd ./mlength
pip install '.[testing]'
flake8 ./mlength
mypy ./mlength
```
