-
Notifications
You must be signed in to change notification settings - Fork 0
/
preview.py
52 lines (45 loc) · 1.43 KB
/
preview.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
from __future__ import print_function
from blessings import Terminal
from drawille import Canvas
from PIL import Image
from sys import argv, stdin, stderr
from os import path
import mplayer_sync
T = Terminal()
C = Canvas()
W = 240
H = 180
def draw_slide(fn, player):
img = Image.open(fn)
px = img.resize((W, H)).convert('L').load()
for x in xrange(W):
for y in xrange(H):
setter = C.set if px[x, y] > 127 else C.unset
setter(x, y)
with T.location(0, 0):
frame = C.frame(min_x=0, min_y=0, max_x=W, max_y=H)
print(T.white(frame.decode('utf-8')))
print('')
print('Slide {0} (player={1})'.format(fn, player))
def main(log):
log = [row.rstrip().split(',') for row in file(log)]
log.append(None) # guard
last_slide = None
print(log)
for player in mplayer_sync.monitor(stdin):
slide = next(n for n, t in enumerate(log) if t is None or (player * 29.97) < float(t[0]))
slide = log[slide - 1]
slide = slide[1] if slide is not None else None
if last_slide != slide:
draw_slide(slide, player)
last_slide = slide
if __name__ == '__main__':
try:
log = argv[1]
except IndexError:
print(('Usage: {0} timestamps.log'
'\n\nStandard input expects mplayer standard output.').format(argv[0]), file=stderr)
else:
main(log)