forked from micahg/plugin.video.snnow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadobe.py
198 lines (153 loc) · 7.1 KB
/
adobe.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
import urllib, urllib2, xml.dom.minidom, uuid
from settings import Settings
from cookies import Cookies
class AdobePass:
CONFIG_URI = 'https://sp.auth.adobe.com/adobe-services/config/SportsnetNowCA'
SESSION_DEVICE_URI = 'https://sp.auth.adobe.com/adobe-services/sessionDevice'
PREAUTHORIZE_URI = 'https://sp.auth.adobe.com/adobe-services/1.0/preauthorize'
AUTHORIZE_URI = 'https://sp.auth.adobe.com/adobe-services/1.0/authorizeDevice'
DEVICE_SHORT_AUTHORIZE = 'https://sp.auth.adobe.com/adobe-services/1.0/deviceShortAuthorize'
USER_AGENT = 'AdobePassNativeClient/1.9.2 (Linux; U; Android 7.1.2; en-us)'
@staticmethod
def sessionDevice(streamProvider):
"""
Session Device.
"""
jar = Cookies.getCookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar))#,
#urllib2.HTTPHandler(debuglevel=1),
#urllib2.HTTPSHandler(debuglevel=1))
values = { 'requestor_id' : streamProvider.getRequestorID(),
'signed_requestor_id' : streamProvider.getSignedRequestorID(),
'_method' : 'GET',
'device_id' : streamProvider.getDeviceID()}
opener.addheaders = [('User-Agent', AdobePass.USER_AGENT)]
try:
resp = opener.open(AdobePass.SESSION_DEVICE_URI, urllib.urlencode(values))
except urllib2.URLError, e:
print e.args
return False
Cookies.saveCookieJar(jar)
resp_xml = resp.read()
dom = xml.dom.minidom.parseString(resp_xml)
result_node = dom.getElementsByTagName('result')[0]
tok_node = result_node.getElementsByTagName('authnToken')[0]
meta_node = result_node.getElementsByTagName('userMeta')[0]
token = tok_node.firstChild.nodeValue
meta = meta_node.firstChild.nodeValue
s = Settings.instance()
s.store('adobe', 'AUTHN_TOKEN', token)
s.store('adobe', 'USER_META', meta)
return True
@staticmethod
def preAuthorize(streamProvider, channels):
"""
Pre-authroize. This _should_ get a list of authorised channels.
@param streamProvider the stream provider (eg: the SportsnetNow
instance)
@param resource_ids a list of resources to preauthorise
@return a dictionary with each resource id as a key and boolean value
indicating if the resource could be authorised
"""
settings = Settings.instance().get('adobe')
values = { 'authentication_token' : settings['AUTHN_TOKEN'],
'requestor_id' : streamProvider.getRequestorID() }
value_str = urllib.urlencode(values)
for channel in channels:
value_str += '&' + urllib.urlencode({ 'resource_id' : channel['id'] })
jar = Cookies.getCookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar))
opener.addheaders = [('User-Agent', AdobePass.USER_AGENT)]
try:
resp = opener.open(AdobePass.PREAUTHORIZE_URI, value_str)
except urllib2.URLError, e:
print e.args
return None
Cookies.saveCookieJar(jar)
resp_xml = resp.read()
dom = xml.dom.minidom.parseString(resp_xml)
resources = {}
resources_node = dom.getElementsByTagName('resources')[0]
for resource_node in resources_node.getElementsByTagName('resource'):
id_node = resource_node.getElementsByTagName('id')[0]
auth_node = resource_node.getElementsByTagName('authorized')[0]
id_str = id_node.firstChild.nodeValue
auth = (auth_node.firstChild.nodeValue.lower() == 'true')
resources[id_str] = auth
return resources
@staticmethod
def authorizeDevice(streamProvider, mso_id, channel):
"""
Authorise the device for a particular channel.
@param streamProvider the stream provider (eg: the SportsnetNow
instance)
@param mso_id the MSO identifier (eg: 'Rogers')
@param channel the channel identifier
"""
settings = Settings.instance().get('adobe')
values = { 'resource_id' : channel,
'requestor_id' : streamProvider.getRequestorID(),
'signed_requestor_id' : streamProvider.getSignedRequestorID(),
'mso_id' : mso_id,
'authentication_token' : settings['AUTHN_TOKEN'],
'device_id' : streamProvider.getDeviceID(),
'userMeta' : '1' }
jar = Cookies.getCookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar))
opener.addheaders = [('User-Agent', AdobePass.USER_AGENT)]
try:
resp = opener.open(AdobePass.AUTHORIZE_URI, urllib.urlencode(values))
except urllib2.URLError, e:
print e.args
return False
Cookies.saveCookieJar(jar)
resp_xml = resp.read()
if resp_xml.find('notAuthorized') >= 0:
print "Unable to authorise for channel '" + channel + "'"
return False
try:
dom = xml.dom.minidom.parseString(resp_xml)
except:
print "Unable to parse device authorization xml."
return False
result_node = dom.getElementsByTagName('result')[0]
tok_node = result_node.getElementsByTagName('authzToken')[0]
token = tok_node.firstChild.nodeValue
s = Settings.instance().store('adobe', 'AUTHZ_TOKEN', token)
return True
@staticmethod
def getAuthnToken():
settings = Settings.instance().get('adobe')
if settings == None:
return None
if not 'AUTHN_TOKEN' in settings:
return None
return settings['AUTHN_TOKEN']
@staticmethod
def deviceShortAuthorize(streamProvider, mso_id):
"""
Authorise for a particular channel... a second time.
@param streamProvider the stream provider (eg: the SportsnetNow
instance)
@param mso_id the MSO identifier (eg: 'Rogers')
@return the session token required to authorise video the stream
"""
settings = Settings.instance().get('adobe')
values = { 'requestor_id' : streamProvider.getRequestorID(),
'signed_requestor_id' : streamProvider.getSignedRequestorID(),
'session_guid' : uuid.uuid4(),
'hashed_guid' : 'false',
'authz_token' : settings['AUTHZ_TOKEN'],
'mso_id' : mso_id,
'device_id' : streamProvider.getDeviceID() }
jar = Cookies.getCookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar))
opener.addheaders = [('User-Agent', AdobePass.USER_AGENT)]
try:
resp = opener.open(AdobePass.DEVICE_SHORT_AUTHORIZE, urllib.urlencode(values))
except urllib2.URLError, e:
print e.args
return ''
Cookies.saveCookieJar(jar)
resp_xml = resp.read()
return resp_xml