-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathskype-record.py
executable file
·300 lines (264 loc) · 10.6 KB
/
skype-record.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
#!/usr/bin/env python
#This file is part of Private-Recorder.
#
#Foobar is free software: you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation, either version 3 of the License, or
#(at your option) any later version.
#
#Foobar is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.
#
#You should have received a copy of the GNU General Public License
#along with Private-Recorder. If not, see <http://www.gnu.org/licenses/>.
#
# copyright 2011, Richard Henwood <[email protected]>
try:
from lib.facade import Skype, CallPeople
import os
import sys
import signal
import subprocess as sub
import datetime
import time
import re
#import threading
#import pygtk, gtk, gobject
from RfPulse.src.RfPulseClient import RfPulseClient
from gi.repository import GObject
from gi.repository import Gtk
from gi.repository import Gdk
#from gi.repository import WebKit
except ImportError, e:
print "some required imports were not found: %s\n" % e
sys.exit(1)
# import pygtk
# pygtk.require("2.0")
# import glib as GObject
# import gtk as Gtk
# import webkit as WebKit
# from record_gui import RecordControlGui
except Exception, e:
print "some required imports were not found: %s\n" % e
sys.exit(1)
GObject.threads_init()
class Recorder():
def __init__(self):
self.record_them_proc = None
self.record_me_proc = None
self.mysink = 'waxdisknull'
self.my_pa_mods = []
self.current_call = None
self.gui = None
self.statusLabel = None
self.myvideo = '/dev/video2'
def setStatusLabel (self, label):
self.statusLabel = label
def callstart (self, call):
self.current_call = call
self.statusLabel.set_text("call in progress")
print "call has begun with xid: ", call.theirVideoXid
#self.connectAudio(call.theirAudio)
#self.connectAudio(call.yourAudio)
def recordstart (self, data=None):
if self.current_call is None:
print "No call currently in progress. Not recording.\n"
return
print "starting to record."
print "DO NOT MOVE THE SKYPE CALL WINDOW!"
if True:
recordthemCMD = ['/usr/bin/recordmydesktop',
'--no-cursor',
'--fps', '25',
'--device', 'pulse',
'--windowid', '%s' % self.current_call.theirVideoXid,
'--display', ':0',
'-o', 'them_%s-%s.ogv' % (self.current_call.callWith.replace(' ', '_').replace('/','-'),
datetime.datetime.now().strftime("%Y-%m-%dT%H%M%S"))]
#print " ".join(recordthemCMD)
#self.record_them_proc = sub.Popen(recordCMD, env={'PULSE_SOURCE':'waxdisknull.monitor'})
recordmeCMD = ['/usr/bin/ffmpeg',
'-f', 'alsa',
'-i', 'pulse',
'-acodec','vorbis',
'-f', 'video4linux2',
'-s','640x480',
'-i',self.myvideo,
'-r','25',
'-f','mpegts',
#'-vcodec','libtheora',
'me_%s-%s.mpeg' % (self.current_call.callWith.replace(' ', '_').replace('/','-'),
datetime.datetime.now().strftime("%Y-%m-%dT%H%M%S"))]
print "THEIR AUDIO %s\n\n\n\n" % self.current_call.theirAudio
self.record_them_proc = sub.Popen(recordthemCMD, env={'PULSE_SOURCE':self.current_call.theirAudio})
self.record_me_proc = sub.Popen(recordmeCMD, env={'PULSE_SOURCE':self.current_call.yourAudio})
print "\n\ntheir record pid = %s\n\n" % self.record_them_proc.pid
print "\n\nme record pid = %s\n\n" % self.record_me_proc.pid
def recordstop(self, data=None):
if self.current_call is None:
print "No call currently in progress. Ignoring stop.\n"
return
print 'RECORDING STOPPED:'
os.kill(self.record_them_proc.pid, signal.SIGTERM)
os.kill(self.record_me_proc.pid, signal.SIGTERM)
self.current_call = None
pass
''' debricated. '''
def __connectAudio(self, source):
paCMD = 'pactl load-module module-loopback source=%s sink=%s' % (source, self.mysink)
#print 'paCMD = %s' % paCMD
p = sub.Popen(paCMD,shell=True,stdout=sub.PIPE,stderr=sub.PIPE)
output, errors = p.communicate()
#print "pactl complete: output '%s' error '%s'" % (output.rstrip(), errors)
self.my_pa_mods.append(output.rstrip())
def setupAudio (self):
p = sub.Popen('pactl list | grep %s' % self.mysink, shell=True,stdout=sub.PIPE,stderr=sub.PIPE)
output, errors = p.communicate()
#print "is waxdisk available?: output '%s' error '%s'" % (output, errors)
if output.rstrip() == '':
print 'waxdisknull is not available.'
print 'creating null-sink:'
p = sub.Popen('pactl load-module module-null-sink sink_name="waxdisknull"',shell=True,stdout=sub.PIPE,stderr=sub.PIPE)
output, errors = p.communicate()
print 'errors: %s' % errors
def callend (self):
print 'call ended'
self.statusLabel.set_text("")
#self.cleanupAudio()
def cleanupAudio(self):
print "Checking for dangling Private-Recorder audio hooks.",
try:
self.waiting_to_connect = True
pa = RfPulseClient("skyperec tidyup")
pa.events['contextConnected'].append(self.paConnectHandler)
pa.connect()
while self.waiting_to_connect:
time.sleep(0.1)
pa.getModuleInfoList()
self.waiting_to_connect = True
pa.events['moduleInfoList'].append(self.paDataReady)
while self.waiting_to_connect:
time.sleep(0.1)
for mod in pa.modules:
if mod.name == "module-loopback":
if "sink=waxdisknull" in mod.argument:
self.paModRemove(mod.index)
print "removing dangling hook: %s %s" % (mod.index, mod.argument)
pa.disconnect()
except Exception, e:
print "broken: %s" % e
print "Private-Reocrder audio hook check complete."
def paConnectHandler(self, userData):
self.waiting_to_connect = False
def paDataReady(self, userData):
self.waiting_to_connect = False
def paModRemove(self, index):
paCMD = 'pactl unload-module %s' % index
p = sub.Popen(paCMD,shell=True,stdout=sub.PIPE,stderr=sub.PIPE)
output, errors = p.communicate()
print "removed mod index %s: output '%s' error '%s'" % (index, output, errors)
def cleanup(self):
self.cleanupAudio()
self.current_call = None
if self.record_them_proc is not None:
os.kill(self.record_them_proc.pid, signal.SIGTERM)
self.record_them_proc = None
if self.record_me_proc is not None:
os.kill(self.record_me_proc.pid, signal.SIGTERM)
self.record_me_proc = None
s = None
r = None
def main_quit(obj):
"""main_quit function, it stops the thread and the gtk's main loop"""
global s, r
#Stopping the thread and the gtk's main loop
s.stop()
#r.cleanup()
Gtk.main_quit()
def main():
global s, r
GObject.threads_init(None)
if not os.path.exists("/usr/bin/recordmydesktop"):
print "/usr/bin/recordmydesktop can't be found."
print "it must be installed before you can continue."
sys.exit(2)
if not os.path.exists("/usr/bin/ffmpeg"):
print "/usr/bin/ffmpeg can't be found."
print "it must be installed before you can continue."
sys.exit(2)
if not os.path.exists("/dev/video2"):
print '''can't find /dev/video2: please check you have
completed setup:
http://sites.google.com/site/richardhenwood/project/skype-record'''
sys.exit(3)
# get the pid of skype
# and while stepping through pids,
# check to see that gst is running.
skype_pid = None
gst_pid = None
ps = sub.Popen(['ps', 'x'], stdout=sub.PIPE)
out = ps.communicate()[0]
processes = out.split('\n')
for proc in processes:
bits = proc.split()
try:
if bits[4] == 'skype':
skype_pid = bits[0]
#break
if re.match(r'^gst.*$', bits[4]):
if bits[5] == 'v4l2src':
gst_pid = bits[0]
except IndexError, e:
print "Problem searching for skype in process list: %s" % e
if gst_pid is None:
print '''can't find gst. You must start it manually:
http://sites.google.com/site/richardhenwood/project/skype-record
TODO automate this step.'''
sys.exit(4)
if skype_pid is None:
print "skype pid cannot be found. Check skype is running."
sys.exit(5)
print "skype pid found: %s ." % skype_pid
print "--skype record has started ----"
print ""
print "You should see a small window to allow you to control recording."
print "During recording, there will be chatter in this window."
print "DO NOT CLOSE THIS TERMINAL WINDOW UNTIL YOUR RECORDING IS COMPLETE"
print "DO NOT CLOSE private-recorder window UNTIL YOUR RECORDING IS COMPLETE"
print ""
print "NOTE: a complete recording will say:"
print "...."
print "Cleanning up cache..."
print "Done!!!"
print "Goodbye!"
print ""
print ""
s = Skype(skype_pid)
r = Recorder()
# clean up incase we startying in a dirty state (i.e. s-r crashed last run)
#r.cleanupAudio()
window = Gtk.Window()
startbut = Gtk.Button("start recording")
startbut.connect("clicked", r.recordstart)
stopbut = Gtk.Button("stop recording")
stopbut.connect("clicked", r.recordstop)
statuslabel = Gtk.Label("")
fix = Gtk.Fixed()
fix.put(statuslabel, 20, 00)
fix.put(startbut, 20, 60)
fix.put(stopbut, 20, 120)
window.add(fix)
window.show_all()
window.connect('destroy', main_quit)
s.add_callstart_listener(r.callstart)
s.add_callend_listener(r.callend)
#r.setupAudio()
r.setStatusLabel(statuslabel)
Gdk.threads_enter()
s.start()
#Gtk.main()
Gdk.threads_leave()
if __name__ == '__main__':
sys.exit(main())