Coverage for pyguymer3/media/return_media_duration.py: 78%
18 statements
« prev ^ index » next coverage.py v7.9.2, created at 2025-07-08 18:47 +0000
« prev ^ index » next coverage.py v7.9.2, created at 2025-07-08 18:47 +0000
1#!/usr/bin/env python3
3# Define function ...
4def return_media_duration(
5 fname,
6 /,
7 *,
8 cwd = None,
9 debug = __debug__,
10 ensureNFC = True,
11 ffprobePath = None,
12 playlist = -1,
13 timeout = 60.0,
14):
15 # Import standard modules ...
16 import shutil
18 # Import sub-functions ...
19 from .__ffprobe__ import __ffprobe__
20 from .ffprobe import ffprobe
22 # **************************************************************************
24 # Try to find the paths if the user did not provide them ...
25 if ffprobePath is None:
26 ffprobePath = shutil.which("ffprobe")
27 assert ffprobePath is not None, "\"ffprobe\" is not installed"
29 # **************************************************************************
31 # Make sure that this fname/playlist combination is in the global dictionary ...
32 if fname not in __ffprobe__:
33 __ffprobe__[fname] = {}
34 if playlist not in __ffprobe__[fname]:
35 if debug:
36 print(f"INFO: Running ffprobe(\"{fname}\", {playlist:d}) ...")
37 __ffprobe__[fname][playlist] = ffprobe(
38 fname,
39 cwd = cwd,
40 ensureNFC = ensureNFC,
41 ffprobePath = ffprobePath,
42 playlist = playlist,
43 timeout = timeout,
44 )
46 # Return duration ...
47 form = __ffprobe__[fname][playlist]["format"]
48 dur = -1.0 # [s]
49 if "duration" in form:
50 dur = float(form["duration"]) # [s]
51 return dur