mprobe 0.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,48 @@
1
+ Metadata-Version: 2.4
2
+ Name: mprobe
3
+ Version: 0.0.1
4
+ Summary: Read video and audio metadata using ffprobe or avprobe
5
+ Author-email: pi11 <webii@pm.me>
6
+ Project-URL: Homepage, https://github.com/pi11/mprobe
7
+ Project-URL: Issues, https://github.com/pi11/mprobe/issues
8
+ Keywords: video,audio,metadata,ffprobe,avprobe
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Programming Language :: Python :: 3 :: Only
11
+ Classifier: Operating System :: OS Independent
12
+ Classifier: Topic :: Multimedia :: Sound/Audio
13
+ Classifier: Topic :: Multimedia :: Video
14
+ Requires-Python: >=3.10
15
+ Description-Content-Type: text/x-rst
16
+ License-File: THIRD_PARTY_NOTICES
17
+ Dynamic: license-file
18
+
19
+ mprobe
20
+ ======
21
+
22
+ Read video and audio metadata with Python 3.10+ and ffprobe (or avprobe).
23
+ Install `FFmpeg <https://ffmpeg.org/download.html>`_ separately and ensure
24
+ ``ffprobe`` is on your PATH; pip does not install it.
25
+
26
+ Install and use
27
+ ---------------
28
+
29
+ .. code-block:: console
30
+
31
+ python -m pip install mprobe
32
+
33
+ .. code-block:: python
34
+
35
+ from mprobe import mediainfo
36
+
37
+ info = mediainfo("video.mp4", timeout=30)
38
+ print(info.get("duration")) # seconds, as a string
39
+ print(info.get("format_name"))
40
+
41
+ Accepts strings and pathlib paths. Values are strings; ``TAG`` and
42
+ ``DISPOSITION`` contain dictionaries. Repeated fields use the last stream's
43
+ value, then the container's value. Fields vary by file and may be absent.
44
+ Missing probes raise ``FileNotFoundError``; invalid or missing media raise
45
+ ``subprocess.CalledProcessError`` (details in ``stderr``). A timeout raises
46
+ ``subprocess.TimeoutExpired``.
47
+
48
+ Inspired by `pydub <https://github.com/jiaaro/pydub>`_.
@@ -0,0 +1,6 @@
1
+ mprobe.py,sha256=EFCE0666vXLl8-fmwgttPBrkEQOOap4Oldotszbh9uY,2234
2
+ mprobe-0.0.1.dist-info/licenses/THIRD_PARTY_NOTICES,sha256=YLQdAgrTDeutLmXY6ww5lr9dU7oz7RmYwhmUvZ3X2Ng,1199
3
+ mprobe-0.0.1.dist-info/METADATA,sha256=1zE0VrGD9Iov6Ip67tJ7LVjlD5b3gjzsVmM4S_L3SRc,1623
4
+ mprobe-0.0.1.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
5
+ mprobe-0.0.1.dist-info/top_level.txt,sha256=Kz-V0DTTyYSAe_sYYu4C3WF2VKXNA1EmPfx4k8DGu88,7
6
+ mprobe-0.0.1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.0.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,23 @@
1
+ The metadata parsing API was inspired by pydub:
2
+ https://github.com/jiaaro/pydub
3
+
4
+ pydub is distributed under the MIT license:
5
+
6
+ Copyright (c) 2011 James Robert, http://jiaaro.com
7
+
8
+ Permission is hereby granted, free of charge, to any person obtaining
9
+ a copy of this software and associated documentation files (the
10
+ "Software"), to deal in the Software without restriction, including
11
+ without limitation the rights to use, copy, modify, merge, publish,
12
+ distribute, sublicense, and/or sell copies of the Software, and to
13
+ permit persons to whom the Software is furnished to do so, subject to
14
+ the following conditions:
15
+ The above copyright notice and this permission notice shall be
16
+ included in all copies or substantial portions of the Software.
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1 @@
1
+ mprobe
mprobe.py ADDED
@@ -0,0 +1,59 @@
1
+ """Read video/audio metadata using ffprobe or avprobe, inspired by pydub."""
2
+
3
+ import os
4
+ import shutil
5
+ import subprocess
6
+
7
+
8
+ def which(program):
9
+ """Return the executable's path, or None when it is not on PATH."""
10
+ return shutil.which(program)
11
+
12
+
13
+ def get_prober_name():
14
+ """Return an available probe executable, preferring ffprobe."""
15
+ for program in ("ffprobe", "avprobe"):
16
+ executable = which(program)
17
+ if executable:
18
+ return executable
19
+ raise FileNotFoundError("Install FFmpeg (ffprobe) or Libav (avprobe) and add it to PATH")
20
+
21
+
22
+ def mediainfo(filepath, *, timeout=None):
23
+ """Return a dictionary of media metadata with string values.
24
+
25
+ TAG and DISPOSITION fields are nested dictionaries. Repeated fields are
26
+ overwritten by later streams and then container metadata, as in the
27
+ original API. filepath may be a string or a path-like object.
28
+
29
+ Raise FileNotFoundError when no prober is installed, CalledProcessError
30
+ when probing fails (with diagnostics in stderr), or TimeoutExpired when
31
+ the optional timeout in seconds is exceeded.
32
+ """
33
+ prober = get_prober_name()
34
+ args = ["-v", "error", "-show_format", "-show_streams", "-i", os.fsdecode(filepath)]
35
+ options = dict(stdout=subprocess.PIPE, stderr=subprocess.PIPE,
36
+ encoding="utf-8", errors="replace", timeout=timeout)
37
+
38
+ if os.path.basename(prober).lower() in ("avprobe", "avprobe.exe"):
39
+ # Older Libav versions require the legacy key=value writer.
40
+ result = subprocess.run([prober, "-of", "old"] + args, **options)
41
+ if result.returncode:
42
+ result = subprocess.run([prober] + args, check=True, **options)
43
+ else:
44
+ result = subprocess.run([prober] + args, check=True, **options)
45
+
46
+ info = {}
47
+ for line in result.stdout.splitlines():
48
+ key, separator, value = line.partition("=")
49
+ if not separator:
50
+ continue
51
+ namespace, separator, nested_key = key.partition(":")
52
+ if separator:
53
+ nested = info.get(namespace)
54
+ if not isinstance(nested, dict):
55
+ nested = info[namespace] = {}
56
+ nested[nested_key] = value
57
+ else:
58
+ info[key] = value
59
+ return info