-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
33 lines (28 loc) · 1.14 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import datetime as dt
from subprocess import run, PIPE
from ranger.api.commands import Command
def duration(filename: str) -> str:
video = '"' + filename + '"'
cmd = "ffmpeg -i " + video + " 2>&1 | grep Duration | cut -d ' ' -f 4 | sed s/,//"
output = run(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE, shell=True)
return str(output.stdout, 'UTF-8').rstrip('\n')
def parse_delta(entry):
h, m, s = entry.split(':')
return dt.timedelta(hours=int(h), minutes=int(m), seconds=int(float(s)))
def duration_sum(timetable: list) -> str:
time_sum = dt.timedelta()
delta_times = list(map(parse_delta, timetable))
for time in delta_times:
time_sum += time
return str(time_sum)
class vuration(Command):
def execute(self):
if self.arg(1):
video_file = self.rest(1)
if self.fm.thisdir.marked_items:
video_file = [f.relative_path for f in self.fm.thistab.get_selection()]
timetable = list(map(duration,video_file))
self.fm.notify(duration_sum(timetable))
else:
video_file = self.fm.thisfile.path
self.fm.notify(duration(video_file))