Skip to content

Instantly share code, notes, and snippets.

@m1el
Created August 27, 2014 08:47
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 m1el/f6430aea404cb30fb2f4 to your computer and use it in GitHub Desktop.
Save m1el/f6430aea404cb30fb2f4 to your computer and use it in GitHub Desktop.
playing past twitch broadcasts in mpv
#license=WTFPLv2
#playing past twitch broadcasts in mpv
import sys, os, re
import requests
import json
urlfmt = 'https://api.twitch.tv/api/videos/a{}'
if __name__ == '__main__':
if len(sys.argv) < 2:
print('not enough arguments! pass broadcast url.')
sys.exit(1)
url = sys.argv[1]
qual = sys.argv[2] if len(sys.argv) > 2 else 'live'
mat = re.match(r'.*?(\d+)$', url)
vid = None
if mat:
vid = mat.groups()[0]
else:
print('cannot parse broadcast url!')
sys.exit(1)
resp = requests.get(urlfmt.format(vid))
data = json.loads(resp.text)
chunks = [c['url'] for c in data['chunks'][qual]]
os.spawnv(os.P_WAIT, 'mpv', chunks + ['--cache=500000'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment