Created
November 12, 2014 16:43
-
-
Save lehmannro/2f51c5b477defcd020f2 to your computer and use it in GitHub Desktop.
Video board for terminal use
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
import itertools | |
import os | |
import subprocess | |
import sys | |
import termios | |
import tty | |
CONFIG_FILE = 'videos.cfg' | |
YOUTUBE = 'http://www.youtube.com/watch?v=%s' | |
def read(path): | |
with open(path) as f: | |
lines = itertools.chain(["key,uri,title,start,length,format"], f) | |
reader = csv.DictReader(lines) | |
return dict((line['key'], line) for line in reader) | |
def setup(videos): | |
try: | |
os.makedirs('cache') | |
except OSError: | |
pass | |
for video in videos.values(): | |
cmd = ['quvi', YOUTUBE % video['uri'], | |
'--exec', 'wget %%u -O cache/%s' % video['uri']] | |
if video['format']: | |
cmd.extend(['--format', video['format']]) | |
subprocess.call(cmd) | |
def loop(videos): | |
fd = sys.stdin.fileno() | |
old = termios.tcgetattr(fd) | |
tty.setraw(fd) | |
try: | |
while 1: | |
ch = sys.stdin.read(1) | |
if ch == '\x03': # Ctrl-C | |
break | |
if ch in videos: | |
video = videos[ch] | |
subprocess.call(['mplayer', '-fs', 'cache/%s' % video['uri'], | |
'-ss', video['start'], '-endpos', video['length']], | |
stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
finally: | |
tty.setcbreak(fd) | |
termios.tcsetattr(fd, termios.TCSADRAIN, old) | |
def main(args): | |
videos = read(CONFIG_FILE) | |
for video in videos.values(): | |
print "%s: %s" % (video['key'], video['title']) | |
if args == ['setup']: | |
setup(videos) | |
else: | |
loop(videos) | |
if __name__ == '__main__': | |
main(sys.argv[1:]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
r,oShTJ90fC34,Rimshot,0,1 | |
L,hiEjinEXBkk,Awkward laughter,0,3 | |
1,hvlHi7iTdaw,One more thing,6.2,1.7 | |
0,f7TboWvVERU,10 Minuten,54,0.9 | |
i,-VkLbiDAouM,Internet ist für uns alle Neuland,7,3.5 | |
c,wvsboPUjrGc,I love this company!,62.5,6.5 | |
d,8To-6VIJZRE,Developers developers developers,0,5 | |
l,-Gh1lTcwdGY,Fuck it - we'll do it live,3.5,3 | |
h,knshF6wmu_A,Hacker mögen immer irgendwas hacken können,0,3 | |
y,9qpZ2sqCRyg,Yeah (Rosetta landing),118,3,fmt36_240p |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment