Skip to content

Instantly share code, notes, and snippets.

@hezhao
Last active December 14, 2015 02:58
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save hezhao/5017266 to your computer and use it in GitHub Desktop.
Open Safari, start Google Hangout and stream it live to youtube. It also outputs and returns the iframe embed HTML containing the youtube link.
tell application "Safari" to activate
tell application "Safari"
tell window 1
set current tab to (make new tab with properties {URL:"http://hangout.google.com"})
end tell
delay 5
tell application "System Events"
-- navigate to "Name this hangout"
repeat 10 times
keystroke tab
end repeat
-- type in 'dance'
key code 2
key code 0
key code 45
key code 8
key code 14
-- enable "Hangouts on Air"
keystroke tab
keystroke space
-- click "I got it" button
keystroke tab
keystroke tab
keystroke return
delay 1
-- click "Hang out" button
repeat 13 times
keystroke tab
end repeat
keystroke return
delay 3
-- click "Start broadcast" button
repeat 11 times
keystroke tab
end repeat
keystroke return
delay 1
-- click "OK" button to confirm
keystroke tab
keystroke return
delay 15
-- reveal youtube url
repeat 3 times
keystroke tab
end repeat
keystroke space
delay 1
-- export url
keystroke "c" using {command down}
delay 1 -- essential (make sure text is copied)
set watchURL to the clipboard as text
log watchURL
end tell
end tell
return watchURL
import re
import subprocess
import os
def parseYoutubeLink(out):
# out = '<iframe width="420" height="315" src="http://www.youtube.com/embed/-rq2TjF_hkE" frameborder="0" allowfullscreen></iframe>'
url = None
srcstring = out.split()[3]
match = re.search('http://www.youtube.com/embed/', srcstring)
if match:
start, end = match.span()
vid = srcstring[end:-1]
url = 'http://youtu.be/' + vid
return url
def startHangoutProcess():
process = subprocess.Popen(['osascript', 'hangout.scpt'],
stdout = subprocess.PIPE, stderr = subprocess.PIPE)
return process
def getYoutubeLiveStreamUrl(p):
# blocking function
out, err = p.communicate()
if p.returncode:
print 'ERROR: ', err
return -1
liveURL = parseYoutubeLink(out)
return liveURL
if __name__ == '__main__':
p = startHangoutProcess()
liveURL = getYoutubeLiveStreamUrl(p)
print liveURL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment