Created
February 10, 2010 14:25
-
-
Save greenarrow/300342 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python | |
import os, re, time, pexpect | |
print dir(pexpect) | |
class CaptureError(Exception): | |
pass | |
class WebCapture(): | |
def __init__(self, filename, url, title): | |
self.filename = filename | |
self.url = url | |
self.title = title | |
self.paused = False | |
# TODO fetch title with urllib | |
def start(self): | |
#os.system("firefox --display=:0 %s" % self.url) | |
self.browser = pexpect.spawn("firefox --display=:0 %s" % self.url) | |
window_list = os.popen("xwininfo -display :0 -root -children -all|grep Firefox|grep %s" % self.title).read() | |
print window_list | |
result = re.search(r'(0x[0-9a-fA-F]+)', window_list) | |
if not result: | |
raise CaptureError | |
window_id = result.groups()[0] | |
window_data = os.popen("xwininfo -display :0 -id %s" % window_id).read() | |
result = re.search(r'Absolute upper-left X: (?P<x>\d+).+?Absolute upper-left Y: (?P<y>\d+).+?Width: (?P<w>\d+).+?Height: (?P<h>\d+)', window_data, re.DOTALL) | |
if not result: | |
raise CaptureError | |
data = result.groupdict() | |
# TODO check for recordmydesktop | |
#print "recordmydesktop -x %s -y %s -width %s -height %s -o %s" % ( data["x"], data["y"], data["w"], data["h"], self.filename ) | |
self.recorder = pexpect.spawn( "recordmydesktop -x %s -y %s -width %s -height %s -o %s" % ( data["x"], data["y"], data["w"], data["h"], self.filename ) ) | |
def stop(self, abort=False): | |
if abort: | |
self.recorder.kill( pexpect.signal.SIGABRT ) | |
else: | |
#self.recorder.kill( pexpect.signal.SIGTERM ) | |
self.recorder.send(chr(3)) | |
self.browser.kill( pexpect.signal.SIGTERM ) | |
#p.send(chr(3)) | |
def pause(self, state): | |
if state != self.paused: | |
self.paused = not self.paused | |
self.recorder.kill( pexpect.signal.SIGUSR1 ) | |
if __name__ == "__main__": | |
cap = WebCapture(filename="test2.ogv", url="http://www.google.com", title="Google") | |
cap.start() | |
time.sleep(5) | |
cap.stop() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment