Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions resources/lib/twitch/api/usher.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def _legacy_video(video_id):
return q


def live_request(channel, platform=keys.WEB, headers={}):
def live_request(channel, platform=keys.WEB, headers={}, supported_codecs=None):
token = channel_token(channel, platform=platform, headers=headers)
token = get_access_token(token)

Expand All @@ -112,6 +112,8 @@ def live_request(channel, platform=keys.WEB, headers={}):
q.add_param(keys.PLAYLIST_INCLUDE_FRAMERATE, Boolean.TRUE)
q.add_param(keys.RTQOS, keys.CONTROL)
q.add_param(keys.PLAYER_BACKEND, keys.MEDIAPLAYER)
if supported_codecs:
q.add_param('supported_codecs', supported_codecs)
url = '?'.join([q.url, urlencode(q.params)])
request_dict = {
'url': url,
Expand All @@ -122,7 +124,7 @@ def live_request(channel, platform=keys.WEB, headers={}):


@query
def _live(channel, token, headers={}):
def _live(channel, token, headers={}, supported_codecs=None):
signature = token[keys.SIGNATURE]
access_token = token[keys.VALUE]

Expand All @@ -139,22 +141,24 @@ def _live(channel, token, headers={}):
q.add_param(keys.PLAYLIST_INCLUDE_FRAMERATE, Boolean.TRUE)
q.add_param(keys.RTQOS, keys.CONTROL)
q.add_param(keys.PLAYER_BACKEND, keys.MEDIAPLAYER)
if supported_codecs:
q.add_param('supported_codecs', supported_codecs)
return q


@m3u8
def live(channel, platform=keys.WEB, headers={}):
def live(channel, platform=keys.WEB, headers={}, supported_codecs=None):
token = channel_token(channel, platform=platform, headers=headers)
token = get_access_token(token)
if not token:
return ACCESS_TOKEN_EXCEPTION
elif isinstance(token, dict) and 'error' in token:
return token
else:
return _live(channel, token, headers=headers)
return _live(channel, token, headers=headers, supported_codecs=supported_codecs)


def video_request(video_id, platform=keys.WEB, headers={}):
def video_request(video_id, platform=keys.WEB, headers={}, supported_codecs=None):
video_id = valid_video_id(video_id)
if video_id:
token = vod_token(video_id, platform=platform, headers=headers)
Expand All @@ -178,6 +182,8 @@ def video_request(video_id, platform=keys.WEB, headers={}):
q.add_param(keys.PLAYLIST_INCLUDE_FRAMERATE, Boolean.TRUE)
q.add_param(keys.RTQOS, keys.CONTROL)
q.add_param(keys.PLAYER_BACKEND, keys.MEDIAPLAYER)
if supported_codecs:
q.add_param('supported_codecs', supported_codecs)
q.add_param(keys.BAKING_BREAD, Boolean.TRUE)
q.add_param(keys.BAKING_BROWNIES, Boolean.TRUE)
q.add_param(keys.BAKING_BROWNIES_TIMEOUT, 1050)
Expand All @@ -193,7 +199,7 @@ def video_request(video_id, platform=keys.WEB, headers={}):


@query
def _vod(video_id, token, headers={}):
def _vod(video_id, token, headers={}, supported_codecs=None):
signature = token[keys.SIGNATURE]
access_token = token[keys.VALUE]

Expand All @@ -208,14 +214,16 @@ def _vod(video_id, token, headers={}):
q.add_param(keys.PLAYLIST_INCLUDE_FRAMERATE, Boolean.TRUE)
q.add_param(keys.RTQOS, keys.CONTROL)
q.add_param(keys.PLAYER_BACKEND, keys.MEDIAPLAYER)
if supported_codecs:
q.add_param('supported_codecs', supported_codecs)
q.add_param(keys.BAKING_BREAD, Boolean.TRUE)
q.add_param(keys.BAKING_BROWNIES, Boolean.TRUE)
q.add_param(keys.BAKING_BROWNIES_TIMEOUT, 1050)
return q


@m3u8
def video(video_id, platform=keys.WEB, headers={}):
def video(video_id, platform=keys.WEB, headers={}, supported_codecs=None):
video_id = valid_video_id(video_id)
if video_id:
token = vod_token(video_id, platform=platform, headers=headers)
Expand All @@ -226,7 +234,7 @@ def video(video_id, platform=keys.WEB, headers={}):
elif isinstance(token, dict) and 'error' in token:
return token
else:
return _vod(video_id, token, headers=headers)
return _vod(video_id, token, headers=headers, supported_codecs=supported_codecs)
else:
raise NotImplementedError('Unknown Video Type')

Expand Down