1- #!/usr/bin/env python
1+ #!/usr/bin/env python3
22from pathlib import Path
33import subprocess
44from argparse import ArgumentParser
55import concurrent .futures
6- from asyncioffmpeg .ffplay import FFPLAY
6+ import shutil
7+
8+ from asyncioffmpeg import get_videos
9+
10+ EXE = shutil .which ("ffplay" )
11+ if not EXE :
12+ raise FileNotFoundError ("ffplay" )
713
814
915def ffplay (filein : Path ):
10- assert filein .is_file ()
1116
12- cmd = [FFPLAY , "-v" , "warning" , "-autoexit" , str (filein )]
17+ if not filein .is_file ():
18+ raise FileNotFoundError (filein )
19+
20+ cmd = [EXE , "-v" , "warning" , "-autoexit" , str (filein )]
1321
1422 subprocess .check_call (cmd )
1523
@@ -18,18 +26,12 @@ def ffplay(filein: Path):
1826 p = ArgumentParser (description = "Asynchronous playback with ThreadPool and FFplay" )
1927 p .add_argument ("path" , help = "directory where media files are kept" )
2028 p .add_argument (
21- "-suffix" ,
22- help = "file suffixes of desired media file types" ,
23- nargs = "+" ,
24- default = [".mp4" , ".avi" , ".ogv" , ".wmv" , ".flv" , ".mov" ],
29+ "-suffix" , help = "file suffixes of desired media file types" , nargs = "+" ,
2530 )
2631 P = p .parse_args ()
2732
28- path = Path (P .path ).expanduser ()
29- if not path .is_dir ():
30- raise FileNotFoundError (f"{ path } is not a directory" )
31-
32- flist = (f for f in path .iterdir () if f .is_file () and f .suffix in P .suffix )
33+ flist = get_videos (P .path , P .suffix )
34+ print ("found" , len (flist ), "files in" , P .path )
3335
3436 with concurrent .futures .ThreadPoolExecutor (max_workers = 2 , thread_name_prefix = "ffplay" ) as pool :
3537 pool .map (ffplay , flist )
0 commit comments