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 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.
$ 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 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
git clone 'https://github.com/purarue/mlength'
cd ./mlength
pip install '.[testing]'
flake8 ./mlength
mypy ./mlength
Metadata
Release files for mlength 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| mlength-0.1.0.tar.gz | 5.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mlength-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 12.5 kB
Release files / mlength-0.1.0.tar.gz
| Download URL | mlength-0.1.0.tar.gz |
|---|---|
| Size | 5.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
24fa0982f99538d20b4858cc90fcbeeb803928d9901406f545d88d20155ff953
|
|
BLAKE2b-256 checksum How to use checksums |
84f463f560f970eef889a3f61c8ecf9cc3935bb891eb92c55ae2353e2583095f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.2
|
Release files / mlength-0.1.0-py3-none-any.whl
| Download URL | mlength-0.1.0-py3-none-any.whl |
|---|---|
| Size | 6.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1e3a2b475984e75def1f818a56e6e5ac23a14e3363987a903c506dc4aa48c648
|
|
BLAKE2b-256 checksum How to use checksums |
3dde537959b7ddaada850c1b0ab5d47b490850d1edb03b22dc1724efce7f0e54
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.2
|