]>
Commit | Line | Data |
---|---|---|
29f7c58a | 1 | from __future__ import unicode_literals |
2 | ||
3 | import json | |
4 | ||
5 | from .common import TokenGenerator | |
6 | ||
7 | ||
8 | class NFLTokenGenerator(TokenGenerator): | |
9 | _AUTHORIZATION = None | |
10 | ||
11 | def generate(ie, anvack, mcp_id): | |
12 | if not NFLTokenGenerator._AUTHORIZATION: | |
13 | reroute = ie._download_json( | |
14 | 'https://api.nfl.com/v1/reroute', mcp_id, | |
15 | data=b'grant_type=client_credentials', | |
16 | headers={'X-Domain-Id': 100}) | |
17 | NFLTokenGenerator._AUTHORIZATION = '%s %s' % (reroute.get('token_type') or 'Bearer', reroute['access_token']) | |
18 | return ie._download_json( | |
19 | 'https://api.nfl.com/v3/shield/', mcp_id, data=json.dumps({ | |
20 | 'query': '''{ | |
21 | viewer { | |
22 | mediaToken(anvack: "%s", id: %s) { | |
23 | token | |
24 | } | |
25 | } | |
26 | }''' % (anvack, mcp_id), | |
27 | }).encode(), headers={ | |
28 | 'Authorization': NFLTokenGenerator._AUTHORIZATION, | |
29 | 'Content-Type': 'application/json', | |
30 | })['data']['viewer']['mediaToken']['token'] |