Skip to main content

gets the length of media files and caches the result

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mlength-0.1.0.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mlength-0.1.0-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file mlength-0.1.0.tar.gz.

File metadata

  • Download URL: mlength-0.1.0.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for mlength-0.1.0.tar.gz
Algorithm Hash digest
SHA256 24fa0982f99538d20b4858cc90fcbeeb803928d9901406f545d88d20155ff953
MD5 319ce0dd77b34b114920170a9d077811
BLAKE2b-256 84f463f560f970eef889a3f61c8ecf9cc3935bb891eb92c55ae2353e2583095f

See more details on using hashes here.

File details

Details for the file mlength-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: mlength-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for mlength-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1e3a2b475984e75def1f818a56e6e5ac23a14e3363987a903c506dc4aa48c648
MD5 d5bc1e0f8fecef3aeac90eba0c64c352
BLAKE2b-256 3dde537959b7ddaada850c1b0ab5d47b490850d1edb03b22dc1724efce7f0e54

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page