Created
August 27, 2014 08:47
-
-
Save m1el/f6430aea404cb30fb2f4 to your computer and use it in GitHub Desktop.
playing past twitch broadcasts in mpv
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
#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