Skip to content

Instantly share code, notes, and snippets.

@yourcelf
Created May 18, 2012 22:59
Show Gist options
  • Select an option

  • Save yourcelf/2728011 to your computer and use it in GitHub Desktop.

Select an option

Save yourcelf/2728011 to your computer and use it in GitHub Desktop.

Revisions

  1. yourcelf revised this gist May 18, 2012. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions mplayer-rifftrax.py
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    #!/usr/bin/env python

    import sys
    import time
    import subprocess
  2. yourcelf renamed this gist May 18, 2012. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. yourcelf revised this gist May 18, 2012. 1 changed file with 36 additions and 3 deletions.
    39 changes: 36 additions & 3 deletions mplayer-rifftrax
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,35 @@
    import sys
    import time
    import subprocess

    def main(vid, aud):
    try:
    vidproc = subprocess.Popen(["mplayer", vid], stdin=subprocess.PIPE)
    audproc = subprocess.Popen(["mplayer", aud], stdin=subprocess.PIPE)

    while True:
    key = getch()
    if ord(key) == 3:
    raise KeyboardInterrupt
    elif key == 'd':
    print "Delaying video..."
    vidproc.stdin.write(' ')
    time.sleep(0.1)
    vidproc.stdin.write(' ')
    elif key == 'a':
    print "Delaying audio..."
    audproc.stdin.write(' ')
    time.sleep(0.1)
    audproc.stdin.write(' ')
    else:
    vidproc.stdin.write(key)
    audproc.stdin.write(key)
    except KeyboardInterrupt:
    pass
    finally:
    vidproc.kill()
    audproc.kill()

    class _Getch:
    """Gets a single character from standard input. Does not echo to the
    screen."""
    @@ -25,7 +57,6 @@ class _GetchUnix:
    termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
    return ch


    class _GetchWindows:
    def __init__(self):
    import msvcrt
    @@ -34,5 +65,7 @@ class _GetchWindows:
    import msvcrt
    return msvcrt.getch()


    getch = _Getch()
    getch = _Getch()

    if __name__ == "__main__":
    main(sys.argv[1], sys.argv[2])
  4. yourcelf created this gist May 18, 2012.
    38 changes: 38 additions & 0 deletions mplayer-rifftrax
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    class _Getch:
    """Gets a single character from standard input. Does not echo to the
    screen."""
    def __init__(self):
    try:
    self.impl = _GetchWindows()
    except ImportError:
    self.impl = _GetchUnix()

    def __call__(self): return self.impl()


    class _GetchUnix:
    def __init__(self):
    import tty, sys

    def __call__(self):
    import sys, tty, termios
    fd = sys.stdin.fileno()
    old_settings = termios.tcgetattr(fd)
    try:
    tty.setraw(sys.stdin.fileno())
    ch = sys.stdin.read(1)
    finally:
    termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
    return ch


    class _GetchWindows:
    def __init__(self):
    import msvcrt

    def __call__(self):
    import msvcrt
    return msvcrt.getch()


    getch = _Getch()