-
-
Save chrisma/08f4a5c04c4b0047e484cd6e04115b67 to your computer and use it in GitHub Desktop.
Video board for terminal use
This file contains hidden or 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
#!/usr/bin/env python | |
import csv | |
import itertools | |
import os | |
import subprocess | |
import sys | |
import termios | |
import tty | |
import logging | |
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(): | |
logging.debug(video['title']) | |
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__': | |
logging.basicConfig(level=logging.WARNING) | |
logging.debug('Started') | |
logging.debug('CLI arguments: ' + ','.join(sys.argv[1:])) | |
main(sys.argv[1:]) |
This file contains hidden or 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 | |
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 | |
m,glWpTuE2vJM,Digital Engineering,151,2.5,fmt36_240p |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment