Skip to content
Permalink
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 45 lines (38 sloc) 1.33 KB
#!/usr/bin/env python3
import argparse
import pathlib
import re
import subprocess
import os
import shutil
import tempfile
parser = argparse.ArgumentParser()
parser.add_argument('vid_dirs', nargs='*')
parser.add_argument('--n', type=int, default=5)
parser.add_argument('--p')
parser.add_argument('--np')
args = parser.parse_args()
vids_by_dir = {}
for vid_dir in args.vid_dirs:
for root, dirs, files in os.walk(vid_dir):
files = [os.path.join(root, f) for f in files]
mp4_files = list(filter(lambda f: f.endswith('.mp4'), files))
if args.p is not None:
mp4_files = filter(lambda f: re.search(args.p, f) is not None,
mp4_files)
if args.np is not None:
mp4_files = filter(lambda f: re.search(args.np, f) is None,
mp4_files)
mp4_files = list(mp4_files)
if not mp4_files:
continue
mp4_files = sorted(mp4_files, key=lambda f: os.path.getmtime(f))
mp4_files = mp4_files[-args.n:]
vids_by_dir[pathlib.Path(root).parts[0]] = mp4_files[:]
temp_dir = tempfile.mkdtemp()
for dirname in vids_by_dir:
dirname_tmp = os.path.join(temp_dir, dirname)
os.mkdir(dirname_tmp)
for vid in vids_by_dir[dirname]:
shutil.copy(vid, dirname_tmp)
subprocess.run(f"t {temp_dir}/*", shell=True)
You can’t perform that action at this time.