Skip to content

Instantly share code, notes, and snippets.

@blha303
Last active December 19, 2015 21:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blha303/efbea7402a9754f5fd5e to your computer and use it in GitHub Desktop.
Save blha303/efbea7402a9754f5fd5e to your computer and use it in GitHub Desktop.
from urllib2 import urlopen
import json
from sys import argv, exit
def getswfaddr(channelname):
return urlopen("http://www.justin.tv/widgets/live_embed_player.swf?channel=" + channelname).geturl().split("&userAgent")[0]
def getstreaminfo(channelname):
data = json.loads(urlopen("http://usher.justin.tv/find/%s.json?type=any" % channelname.lower()).read())
newd = {}
for i in data:
newd[i['display']] = i
return newd
def buildcmdline(channelname, data, quality="360p"):
data = data[quality]
if not "live-cdn" in data["connect"] and not "justintvlivefs" in data["connect"]:
justinlegacyparams = '-j "%s"' % data["token"].replace('"', r'\"')
else:
justinlegacyparams = ""
out = '-r "%s/%s" %s --swfVfy "%s" -v -o -' % (data["connect"], data["play"], justinlegacyparams, getswfaddr(channelname))
return out
def main():
if len(argv) < 2:
print "Usage: %s channelname [quality]"
exit(2)
if len(argv) > 2:
quality = argv[2]
else:
quality = "360p"
channelname = argv[1]
data = getstreaminfo(channelname)
print buildcmdline(channelname, data, quality=quality)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment