Coverage for pyguymer3/media/does_media_have_video.py: 78%

18 statements  

« prev     ^ index     » next       coverage.py v7.9.2, created at 2025-07-08 18:47 +0000

1#!/usr/bin/env python3 

2 

3# Define function ... 

4def does_media_have_video( 

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 """ 

16 Return True/False if the media has video. 

17 """ 

18 

19 # Import standard modules ... 

20 import shutil 

21 

22 # Import sub-functions ... 

23 from .__ffprobe__ import __ffprobe__ 

24 from .ffprobe import ffprobe 

25 

26 # ************************************************************************** 

27 

28 # Try to find the paths if the user did not provide them ... 

29 if ffprobePath is None: 

30 ffprobePath = shutil.which("ffprobe") 

31 assert ffprobePath is not None, "\"ffprobe\" is not installed" 

32 

33 # ************************************************************************** 

34 

35 # Make sure that this fname/playlist combination is in the global dictionary ... 

36 if fname not in __ffprobe__: 

37 __ffprobe__[fname] = {} 

38 if playlist not in __ffprobe__[fname]: 

39 if debug: 

40 print(f"INFO: Running ffprobe(\"{fname}\", {playlist:d}) ...") 

41 __ffprobe__[fname][playlist] = ffprobe( 

42 fname, 

43 cwd = cwd, 

44 ensureNFC = ensureNFC, 

45 ffprobePath = ffprobePath, 

46 playlist = playlist, 

47 timeout = timeout, 

48 ) 

49 

50 # Loop over streams ... 

51 for stream in __ffprobe__[fname][playlist]["streams"]: 

52 # Skip stream if it is not video ... 

53 if stream["codec_type"].strip().lower() != "video": 

54 continue 

55 

56 # Return answer ... 

57 return True 

58 

59 # Return error ... 

60 return False