Created
January 28, 2018 21:09
This file contains hidden or 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
range_header = request.headers.get('Range', None) | |
if range_header: | |
from_bytes, until_bytes = range_header.replace('bytes=', '').split('-') | |
if not until_bytes: # No until bytes is set, set it to start + 3MB | |
until_bytes = int(from_bytes) + int(1024 * 1024 * 3) # 1MB * 3 = 3MB | |
# Get only what required from YouTube | |
headers = {'Range': 'bytes=%s-%s' % (from_bytes, until_bytes)} | |
r = requests.get(url, headers=headers) | |
data = r.content | |
# Generate response | |
rv = Response(data, 206, mimetype=mime, direct_passthrough=True) | |
rv.headers.add('Content-Range', r.headers.get('Content-Range')) | |
return rv |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment