35 lines
928 B
Python
35 lines
928 B
Python
import subprocess
|
|
from pathlib import Path
|
|
import sys
|
|
import re
|
|
import os
|
|
|
|
|
|
|
|
droppedFile = sys.argv[1]
|
|
droppedName = Path(droppedFile).name
|
|
originalfiles = sys.orig_argv[2:]
|
|
|
|
#long path shenanigans
|
|
joined = (' '.join(originalfiles))
|
|
re.sub (' +', ' ', joined)
|
|
listed = re.split(r'(.+?mkv)', joined)
|
|
listed = list(filter(None, listed))
|
|
listed = [i.lstrip() for i in listed]
|
|
|
|
|
|
|
|
print(listed)
|
|
for each in listed:
|
|
arglist = ('ffprobe.exe -v error -show_entries format=duration -of csv=p=0 {each}').format(each=each)
|
|
cmd = subprocess.Popen(arglist, stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding='UTF-8')
|
|
out = cmd.communicate()[0]
|
|
|
|
out = out.strip()
|
|
|
|
duration = float(out)
|
|
|
|
duration -= 4
|
|
basename = os.path.basename(each)
|
|
trim = ('ffmpeg.exe -ss 00:00:00 -to {duration} -i {each} -c copy "trimed"{basename}').format(duration=duration, each=each, basename=basename)
|
|
subprocess.run(trim) |