2 from __future__ import unicode_literals
6 import xml.etree.ElementTree as etree
8 from .common import InfoExtractor
25 'username_field': 'username',
26 'password_field': 'password',
29 'name': 'DIRECTV NOW',
30 'username_field': 'email',
31 'password_field': 'loginpassword',
35 'username_field': 'UserName',
36 'password_field': 'UserPassword',
39 'name': 'Comcast XFINITY',
40 'username_field': 'user',
41 'password_field': 'passwd',
44 'name': 'Time Warner Cable | Spectrum',
45 'username_field': 'Ecom_User_ID',
46 'password_field': 'Ecom_Password',
49 'name': 'Bright House Networks | Spectrum',
50 'username_field': 'j_username',
51 'password_field': 'j_password',
54 'name': 'Charter Spectrum',
55 'username_field': 'IDToken1',
56 'password_field': 'IDToken2',
59 'name': 'Verizon FiOS',
60 'username_field': 'IDToken1',
61 'password_field': 'IDToken2',
64 'name': '3 Rivers Communications'
67 'name': 'Access Montana'
69 'acecommunications': {
73 'name': 'Acme Communications'
76 'name': 'Adams Cable Service'
79 'name': 'Albany Mutual Telephone'
82 'name': 'Algona Municipal Utilities'
85 'name': 'All West Communications'
88 'name': 'Allen\'s Communications'
91 'name': 'Alliance Communications'
94 'name': 'ALLO Communications'
97 'name': 'Alpine Communications'
100 'name': 'American Broadband'
103 'name': 'American Broadband Missouri'
106 'name': 'American Community Networks'
109 'name': 'American Warrior Networks'
112 'name': 'Amherst Telephone/Tomorrow Valley'
118 'name': 'Arkwest Communications'
121 'name': 'Arthur Mutual Telephone Company'
127 'name': 'Ashland Home Net'
130 'name': 'Astound (now Wave)'
133 'name': 'ATC Broadband'
136 'name': 'ATC Communications'
139 'name': 'Ayersville Communications'
142 'name': 'Baldwin Lightstream'
148 'name': 'Bardstown Cable TV'
151 'name': 'Bay Country Communications'
154 'name': 'Beaver Creek Cooperative Telephone'
157 'name': 'Beaver Valley Cable'
160 'name': 'Bee Line Cable'
163 'name': 'Beehive Broadband'
169 'name': 'Bellevue Municipal Cable'
172 'name': 'Ben Lomand Connect / BLTV'
178 'name': 'Big Sandy Broadband'
181 'name': 'Bledsoe Telephone Cooperative'
184 'name': 'Blue Valley Tele-Communications'
187 'name': 'Brandenburg Telephone Co.'
190 'name': 'Bristol Tennessee Essential Services'
193 'name': 'Broadstripe'
196 'name': 'BTC Communications'
199 'name': 'BTC Vision - Nahunta'
202 'name': 'Bulloch Telephone Cooperative'
205 'name': 'Butler-Bremer Communications'
208 'name': 'C Spire SNAP'
211 'name': 'Cable Services Inc.'
214 'name': 'CableAmerica'
217 'name': 'CableSouth Media 3'
220 'name': 'Cam-Tel Company'
223 'name': 'Cameron Communications'
226 'name': 'Canby Telcom'
232 'name': 'Carnegie Cable'
241 'name': 'Catalina Broadband Solutions'
244 'name': 'CC Communications'
247 'name': 'CDE Lightband'
250 'name': 'Cedar Falls Utilities'
253 'name': 'Celect-Bloomer Telephone Area'
256 'name': 'Celect-Bruce Telephone Area'
259 'name': 'Celect-Citizens Connected Area'
262 'name': 'Celect-Elmwood/Spring Valley Area'
265 'name': 'Celect-Mosaic Telecom'
268 'name': 'Celect-West WI Telephone Area'
271 'name': 'Cellcom/Nsight Telservices'
277 'name': 'Central Scott / CSTV'
280 'name': 'Chaparral CableVision'
283 'name': 'Chariton Valley Communication Corporation, Inc.'
286 'name': 'Chatmoss Cablevision'
289 'name': 'Cherokee Communications'
292 'name': 'Chesapeake Bay Communications'
295 'name': 'Cim-Tel Cable, LLC.'
298 'name': 'Citizens Cablevision - Floyd, VA'
301 'name': 'Citizens Cablevision, Inc.'
304 'name': 'Citizens Fiber'
307 'name': 'Citizens Mutual'
310 'name': 'Citizens Telephone Corporation'
313 'name': 'City Of Monroe'
322 'name': 'Clarence Telephone and Cedar Communications'
325 'name': 'Clear Choice Communications'
328 'name': 'Click! Cable TV'
334 'name': 'CML Telephone Cooperative Association'
340 'name': 'Co-Mo Connect'
343 'name': 'Coast Communications'
346 'name': 'Coaxial Cable TV'
349 'name': 'Cobalt TV (Mid-State Community TV)'
352 'name': 'Columbia Power & Water Systems'
355 'name': 'Columbus Telephone'
358 'name': 'Communications 1 Cablevision, Inc.'
361 'name': 'Community Cable & Broadband'
364 'name': 'Community Communications Company'
370 'name': 'Complete Communication Services'
376 'name': 'ComSouth Telesys'
378 'consolidatedcable': {
379 'name': 'Consolidated'
382 'name': 'Conway Corporation'
385 'name': 'Coon Valley Telecommunications Inc'
388 'name': 'Cooperative Telephone Company'
394 'name': 'Craw-Kan Telephone'
397 'name': 'Crestview Cable Communications'
403 'name': 'Crosslake Communications'
406 'name': 'CTC - Brainerd MN'
409 'name': 'CTV-Beam - East Alabama'
412 'name': 'Cunningham Telephone & Cable'
415 'name': 'D & P Communications'
418 'name': 'Dakota Central Telecommunications'
421 'name': 'Delcambre Telephone LLC'
424 'name': 'Delta Telephone Company'
430 'name': 'Direct Communications'
433 'name': 'Doylestown Cable TV'
442 'name': 'DTC Cable (Delhi)'
445 'name': 'Dumont Telephone Company'
448 'name': 'Dunkerton Telephone Cooperative'
451 'name': 'Duo County Telecom'
454 'name': 'Eagle Communications'
457 'name': 'East Arkansas Cable TV'
460 'name': 'EATEL Video, LLC'
466 'name': 'Emery Telcom Video LLC'
469 'name': 'Empire Access'
472 'name': 'Endeavor Communications'
475 'name': 'Enhanced Telecommunications Corporation'
481 'name': 'EPB Smartnet'
484 'name': 'EPlus Broadband'
490 'name': 'Etex Communications'
493 'name': 'F&B Communications'
496 'name': 'Falcon Broadband'
499 'name': 'FamilyView CableVision'
502 'name': 'Farmers Mutual Telephone Company'
505 'name': 'Fayetteville Public Utilities'
511 'name': 'Fidelity Communications'
514 'name': 'FJ Communications'
517 'name': 'Flint River Communications'
520 'name': 'FMT - Jesup'
523 'name': 'Foothills Communications'
526 'name': 'Forsyth CableNet'
529 'name': 'Frankfort Plant Board'
532 'name': 'Franklin Telephone Company'
538 'name': 'Full Channel, Inc.'
541 'name': 'Gardonville Cooperative Telephone Association'
544 'name': 'GBT Communications, Inc.'
547 'name': 'Genuine Telecom'
550 'name': 'Giant Communications'
553 'name': 'Glasgow EPB'
556 'name': 'Glenwood Telecommunications'
559 'name': 'GLW Broadband Inc.'
562 'name': 'Golden West Cablevision'
565 'name': 'Grantsburg Telcom'
568 'name': 'Great Plains Communications'
571 'name': 'Gridley Cable Inc'
574 'name': 'H&B Cable Services'
577 'name': 'Haefele TV Inc.'
580 'name': 'Halstad Telephone Company'
583 'name': 'Harlan Municipal Utilities'
586 'name': 'Hart Communications'
589 'name': 'Hartelco TV'
592 'name': 'Heart of Iowa Communications Cooperative'
595 'name': 'Hickory Telephone Company'
598 'name': 'Highland Communication Services'
601 'name': 'Highland Media'
604 'name': 'Hilliary Communications'
607 'name': 'Hinton CATV Co.'
610 'name': 'HomeTel Entertainment, Inc.'
613 'name': 'Hood Canal Communications'
616 'name': 'Hope - Prescott Cable TV'
619 'name': 'Horizon Cable TV, Inc.'
622 'name': 'Horizon Chillicothe Telephone'
625 'name': 'HTC Communications Co. - IL'
628 'name': 'HTC Communications, Inc. - IA'
631 'name': 'Huxley Communications'
634 'name': 'ImOn Communications'
637 'name': 'Independence Telecommunications'
640 'name': 'Inland Networks'
643 'name': 'Innovative Cable TV St Croix'
646 'name': 'Innovative Cable TV St Thomas-St John'
649 'name': 'Inside Connect Cable'
652 'name': 'Integra Telecom'
655 'name': 'Interstate Telecommunications Coop'
658 'name': 'Irvine Cable'
661 'name': 'K2 Communications'
664 'name': 'Kalida Telephone Company, Inc.'
667 'name': 'Kalona Cooperative Telephone Company'
673 'name': 'KPU Telecommunications'
676 'name': 'Kuhn Communications, Inc.'
679 'name': 'Lakeland Communications'
685 'name': 'Laurel Highland Total Communications, Inc.'
688 'name': 'Lehigh Valley Cooperative Telephone'
691 'name': 'Limestone Cable/Bracken Cable'
703 'name': 'LocalTel Communications'
706 'name': 'Longview - Kilgore Cable TV'
709 'name': 'Lonsdale Video Ventures, LLC'
712 'name': 'Lost Nation-Elwood Telephone Co.'
715 'name': 'LPC Connect'
718 'name': 'Lumos Networks'
721 'name': 'Madison Communications'
724 'name': 'Madison County Cable Inc.'
727 'name': 'Mahaska Communication Group'
730 'name': 'Marne & Elk Horn Telephone Company'
733 'name': 'McClure Telephone Co.'
739 'name': 'Merrimac Communications Ltd.'
748 'name': 'Mid-Hudson Cable'
751 'name': 'Mid-Rivers Communications'
754 'name': 'Midstate Communications'
757 'name': 'Milford Communications'
766 'name': 'Mitchell Telecom'
772 'name': 'Mon-Cre TVE'
775 'name': 'Mountain Telephone'
778 'name': 'Mountain Village Cable'
781 'name': 'MTA Communications, LLC'
787 'name': 'MTC Technologies'
793 'name': 'MTCO Communications'
796 'name': 'Mulberry Telecommunications'
799 'name': 'Murray Electric System'
802 'name': 'MUS FiberNET'
805 'name': 'Muscatine Power & Water'
817 'name': 'Nebraska Central Telecom, Inc.'
820 'name': 'Nelsonville TV Cable'
826 'name': 'New Hope Telephone Cooperative'
832 'name': 'NineStar Connect'
838 'name': 'Nortex Communications'
841 'name': 'North Central Telephone Cooperative'
844 'name': 'Northland Communications'
847 'name': 'Northwest Communications'
850 'name': 'Norwood Light Broadband'
853 'name': 'Nsight Telservices'
859 'name': 'NTS Communications'
871 'name': 'OmniTel Communications'
874 'name': 'OneSource Communications'
877 'name': 'Opelika Power Services'
886 'name': 'OTEC Communication Company'
889 'name': 'Packerland Broadband'
892 'name': 'Panora Telco/Guthrie Center Communications'
895 'name': 'Park Region Telephone & Otter Tail Telcom'
898 'name': 'Partner Communications Cooperative'
904 'name': 'Paul Bunyan Communications'
907 'name': 'Pembroke Telephone Company'
910 'name': 'Peoples Rural Telephone Cooperative'
913 'name': 'PES Energize'
916 'name': 'Philippi Communications System'
919 'name': 'Phonoscope Cable'
922 'name': 'Pine Belt Communications, Inc.'
925 'name': 'Pine Bluff Cable TV'
928 'name': 'Pineland Telephone Cooperative'
931 'name': 'Pinpoint Communications'
934 'name': 'Pioneer Broadband'
937 'name': 'Pioneer Communications'
940 'name': 'Pioneer DTV'
943 'name': 'Plant TiftNet, Inc.'
952 'name': 'Polar Cablevision'
955 'name': 'Pottawatomie Telephone Co.'
958 'name': 'Premier Communications'
970 'name': 'Quality Cablevision'
973 'name': 'Radcliffe Telephone Company'
976 'name': 'Rainbow Communications'
979 'name': 'Rainier Connect'
982 'name': 'Ralls Technologies'
985 'name': 'RC Technologies'
988 'name': 'Red River Communications'
991 'name': 'Reedsburg Utility Commission'
994 'name': 'Reliance Connects- Oregon'
997 'name': 'Reserve Telecommunications'
1000 'name': 'Resort TV Cable'
1003 'name': 'Richland Grant Telephone Cooperative, Inc.'
1006 'name': 'River Valley Telecommunications Coop'
1009 'name': 'Rock Port Cablevision'
1015 'name': 'RTC Communication Corp'
1018 'name': 'RTC-Reservation Telephone Coop.'
1021 'name': 'RTEC Communications'
1027 'name': 'San Bruno Cable TV'
1033 'name': 'SCI Broadband-Savage Communications Inc.'
1036 'name': 'Scottsboro Electric Power Board'
1039 'name': 'Scranton Telephone Company'
1048 'name': 'Sherwood Mutual Telephone Association, Inc.'
1051 'name': 'Silver Star Communications'
1054 'name': 'Sjoberg\'s Inc.'
1060 'name': 'SkyBest TV'
1063 'name': 'Smithville Communications'
1069 'name': 'South Central Rural Telephone Cooperative'
1072 'name': 'South Holt Cablevision, Inc.'
1075 'name': 'South Slope Cooperative Communications'
1078 'name': 'Spanish Fork Community Network'
1081 'name': 'Spencer Municipal Utilities'
1084 'name': 'Spillway Communications, Inc.'
1090 'name': 'St. Maarten Cable TV'
1093 'name': 'Star Communications'
1099 'name': 'STRATA Networks'
1102 'name': 'Sumner Cable TV'
1105 'name': 'Surry TV/PCSI TV'
1108 'name': 'Swayzee Communications'
1111 'name': 'Sweetwater Cable Television Co'
1113 'weh010-talequah': {
1114 'name': 'Tahlequah Cable TV'
1120 'name': 'Tele-Media Company'
1123 'name': 'The Community Agency'
1126 'name': 'Three River'
1129 'name': 'Town & Country Technologies'
1132 'name': 'Trans-Video'
1135 'name': 'Trenton TV Cable Company'
1138 'name': 'Tri County Communications Cooperative'
1141 'name': 'TriCounty Telecom'
1144 'name': 'TrioTel Communications, Inc.'
1147 'name': 'Troy Cablevision, Inc.'
1153 'name': 'Tullahoma Utilities Board'
1156 'name': 'TV Cable of Rensselaer'
1165 'name': 'Twin Lakes'
1168 'name': 'Twin Valley'
1171 'name': 'Union Telephone Company'
1174 'name': 'United Communications - TN'
1177 'name': 'United Services'
1183 'name': 'USA Communications'
1186 'name': 'USA Communications/Shellsburg, IA'
1189 'name': 'Valley TeleCom Group'
1192 'name': 'Valley Telecommunications'
1195 'name': 'Valparaiso Broadband'
1198 'name': 'Vast Broadband'
1201 'name': 'Venture Communications Cooperative, Inc.'
1204 'name': 'Vernon Communications Co-op'
1206 'weh010-vicksburg': {
1207 'name': 'Vicksburg Video'
1210 'name': 'Vision Communications'
1213 'name': 'Volcano Vision, Inc.'
1216 'name': 'VolFirst / BLTV'
1225 'name': 'Vyve Broadband'
1228 'name': 'Wabash Mutual Telephone'
1231 'name': 'Waitsfield Cable'
1234 'name': 'Walnut Communications'
1240 'name': 'Waverly Communications Utility'
1246 'name': 'Webster-Calhoun Cooperative Telephone Association'
1249 'name': 'West Alabama TV Cable'
1252 'name': 'West Carolina Communications'
1255 'name': 'West Central Telephone Association'
1258 'name': 'West River Cooperative Telephone Company'
1261 'name': 'WesTel Systems'
1264 'name': 'Western Iowa Networks'
1267 'name': 'Whidbey Telecom'
1270 'name': 'White County Cable TV'
1279 'name': 'Wilkes Communications, Inc./RiverStreet Networks'
1282 'name': 'Wilson Communications'
1285 'name': 'Windomnet/SMBS'
1288 'name': 'Windstream Cable TV'
1291 'name': 'Winnebago Cooperative Telecom Association'
1297 'name': 'WTC Communications, Inc.'
1300 'name': 'Wyandotte Cable'
1303 'name': 'X-Stream Services'
1306 'name': 'XIT Communications'
1309 'name': 'Yelcot Communications'
1315 'name': 'Zito Media'
1320 class AdobePassIE(InfoExtractor):
1321 _SERVICE_PROVIDER_TEMPLATE = 'https://sp.auth.adobe.com/adobe-services/%s'
1322 _USER_AGENT = 'Mozilla/5.0 (X11; Linux i686; rv:47.0) Gecko/20100101 Firefox/47.0'
1323 _MVPD_CACHE = 'ap-mvpd'
1325 _DOWNLOADING_LOGIN_PAGE = 'Downloading Provider Login Page'
1327 def _download_webpage_handle(self, *args, **kwargs):
1328 headers = kwargs.get('headers', {})
1329 headers.update(self.geo_verification_headers())
1330 kwargs['headers'] = headers
1331 return super(AdobePassIE, self)._download_webpage_handle(
1332 *args, **compat_kwargs(kwargs))
1335 def _get_mvpd_resource(provider_id, title, guid, rating):
1336 channel = etree.Element('channel')
1337 channel_title = etree.SubElement(channel, 'title')
1338 channel_title.text = provider_id
1339 item = etree.SubElement(channel, 'item')
1340 resource_title = etree.SubElement(item, 'title')
1341 resource_title.text = title
1342 resource_guid = etree.SubElement(item, 'guid')
1343 resource_guid.text = guid
1344 resource_rating = etree.SubElement(item, 'media:rating')
1345 resource_rating.attrib = {'scheme': 'urn:v-chip'}
1346 resource_rating.text = rating
1347 return '<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/">' + etree.tostring(channel).decode() + '</rss>'
1349 def _extract_mvpd_auth(self, url, video_id, requestor_id, resource):
1350 def xml_text(xml_str, tag):
1351 return self._search_regex(
1352 '<%s>(.+?)</%s>' % (tag, tag), xml_str, tag)
1354 def is_expired(token, date_ele):
1355 token_expires = unified_timestamp(re.sub(r'[_ ]GMT', '', xml_text(token, date_ele)))
1356 return token_expires and token_expires <= int(time.time())
1358 def post_form(form_page_res, note, data={}):
1359 form_page, urlh = form_page_res
1360 post_url = self._html_search_regex(r'<form[^>]+action=(["\'])(?P<url>.+?)\1', form_page, 'post url', group='url')
1361 if not re.match(r'https?://', post_url):
1362 post_url = compat_urlparse.urljoin(urlh.geturl(), post_url)
1363 form_data = self._hidden_inputs(form_page)
1364 form_data.update(data)
1365 return self._download_webpage_handle(
1366 post_url, video_id, note, data=urlencode_postdata(form_data), headers={
1367 'Content-Type': 'application/x-www-form-urlencoded',
1370 def raise_mvpd_required():
1371 raise ExtractorError(
1372 'This video is only available for users of participating TV providers. '
1373 'Use --ap-mso to specify Adobe Pass Multiple-system operator Identifier '
1374 'and --ap-username and --ap-password or --netrc to provide account credentials.', expected=True)
1376 def extract_redirect_url(html, url=None, fatal=False):
1377 # TODO: eliminate code duplication with generic extractor and move
1378 # redirection code into _download_webpage_handle
1379 REDIRECT_REGEX = r'[0-9]{,2};\s*(?:URL|url)=\'?([^\'"]+)'
1380 redirect_url = self._search_regex(
1381 r'(?i)<meta\s+(?=(?:[a-z-]+="[^"]+"\s+)*http-equiv="refresh")'
1382 r'(?:[a-z-]+="[^"]+"\s+)*?content="%s' % REDIRECT_REGEX,
1383 html, 'meta refresh redirect',
1384 default=NO_DEFAULT if fatal else None, fatal=fatal)
1385 if not redirect_url:
1388 redirect_url = compat_urlparse.urljoin(url, unescapeHTML(redirect_url))
1392 'ap_42': 'anonymous',
1393 'ap_11': 'Linux i686',
1394 'ap_z': self._USER_AGENT,
1395 'User-Agent': self._USER_AGENT,
1398 guid = xml_text(resource, 'guid') if '<' in resource else resource
1401 requestor_info = self._downloader.cache.load(self._MVPD_CACHE, requestor_id) or {}
1402 authn_token = requestor_info.get('authn_token')
1403 if authn_token and is_expired(authn_token, 'simpleTokenExpires'):
1406 # TODO add support for other TV Providers
1407 mso_id = self._downloader.params.get('ap_mso')
1409 raise_mvpd_required()
1410 username, password = self._get_login_info('ap_username', 'ap_password', mso_id)
1411 if not username or not password:
1412 raise_mvpd_required()
1413 mso_info = MSO_INFO[mso_id]
1415 provider_redirect_page_res = self._download_webpage_handle(
1416 self._SERVICE_PROVIDER_TEMPLATE % 'authenticate/saml', video_id,
1417 'Downloading Provider Redirect Page', query={
1420 'requestor_id': requestor_id,
1421 'no_iframe': 'false',
1422 'domain_name': 'adobe.com',
1423 'redirect_url': url,
1426 if mso_id == 'Comcast_SSO':
1427 # Comcast page flow varies by video site and whether you
1428 # are on Comcast's network.
1429 provider_redirect_page, urlh = provider_redirect_page_res
1430 if 'automatically signing you in' in provider_redirect_page:
1431 oauth_redirect_url = self._html_search_regex(
1432 r'window\.location\s*=\s*[\'"]([^\'"]+)',
1433 provider_redirect_page, 'oauth redirect')
1434 self._download_webpage(
1435 oauth_redirect_url, video_id, 'Confirming auto login')
1437 if '<form name="signin"' in provider_redirect_page:
1438 provider_login_page_res = provider_redirect_page_res
1439 elif 'http-equiv="refresh"' in provider_redirect_page:
1440 oauth_redirect_url = extract_redirect_url(
1441 provider_redirect_page, fatal=True)
1442 provider_login_page_res = self._download_webpage_handle(
1443 oauth_redirect_url, video_id,
1444 self._DOWNLOADING_LOGIN_PAGE)
1446 provider_login_page_res = post_form(
1447 provider_redirect_page_res,
1448 self._DOWNLOADING_LOGIN_PAGE)
1450 mvpd_confirm_page_res = post_form(
1451 provider_login_page_res, 'Logging in', {
1452 mso_info['username_field']: username,
1453 mso_info['password_field']: password,
1455 mvpd_confirm_page, urlh = mvpd_confirm_page_res
1456 if '<button class="submit" value="Resume">Resume</button>' in mvpd_confirm_page:
1457 post_form(mvpd_confirm_page_res, 'Confirming Login')
1458 elif mso_id == 'Verizon':
1459 # In general, if you're connecting from a Verizon-assigned IP,
1460 # you will not actually pass your credentials.
1461 provider_redirect_page, urlh = provider_redirect_page_res
1462 if 'Please wait ...' in provider_redirect_page:
1463 saml_redirect_url = self._html_search_regex(
1464 r'self\.parent\.location=(["\'])(?P<url>.+?)\1',
1465 provider_redirect_page,
1466 'SAML Redirect URL', group='url')
1467 saml_login_page = self._download_webpage(
1468 saml_redirect_url, video_id,
1469 'Downloading SAML Login Page')
1471 saml_login_page_res = post_form(
1472 provider_redirect_page_res, 'Logging in', {
1473 mso_info['username_field']: username,
1474 mso_info['password_field']: password,
1476 saml_login_page, urlh = saml_login_page_res
1477 if 'Please try again.' in saml_login_page:
1478 raise ExtractorError(
1479 'We\'re sorry, but either the User ID or Password entered is not correct.')
1480 saml_login_url = self._search_regex(
1481 r'xmlHttp\.open\("POST"\s*,\s*(["\'])(?P<url>.+?)\1',
1482 saml_login_page, 'SAML Login URL', group='url')
1483 saml_response_json = self._download_json(
1484 saml_login_url, video_id, 'Downloading SAML Response',
1485 headers={'Content-Type': 'text/xml'})
1486 self._download_webpage(
1487 saml_response_json['targetValue'], video_id,
1488 'Confirming Login', data=urlencode_postdata({
1489 'SAMLResponse': saml_response_json['SAMLResponse'],
1490 'RelayState': saml_response_json['RelayState']
1492 'Content-Type': 'application/x-www-form-urlencoded'
1495 # Some providers (e.g. DIRECTV NOW) have another meta refresh
1496 # based redirect that should be followed.
1497 provider_redirect_page, urlh = provider_redirect_page_res
1498 provider_refresh_redirect_url = extract_redirect_url(
1499 provider_redirect_page, url=urlh.geturl())
1500 if provider_refresh_redirect_url:
1501 provider_redirect_page_res = self._download_webpage_handle(
1502 provider_refresh_redirect_url, video_id,
1503 'Downloading Provider Redirect Page (meta refresh)')
1504 provider_login_page_res = post_form(
1505 provider_redirect_page_res, self._DOWNLOADING_LOGIN_PAGE)
1506 mvpd_confirm_page_res = post_form(provider_login_page_res, 'Logging in', {
1507 mso_info.get('username_field', 'username'): username,
1508 mso_info.get('password_field', 'password'): password,
1510 if mso_id != 'Rogers':
1511 post_form(mvpd_confirm_page_res, 'Confirming Login')
1513 session = self._download_webpage(
1514 self._SERVICE_PROVIDER_TEMPLATE % 'session', video_id,
1515 'Retrieving Session', data=urlencode_postdata({
1517 'requestor_id': requestor_id,
1518 }), headers=mvpd_headers)
1519 if '<pendingLogout' in session:
1520 self._downloader.cache.store(self._MVPD_CACHE, requestor_id, {})
1523 authn_token = unescapeHTML(xml_text(session, 'authnToken'))
1524 requestor_info['authn_token'] = authn_token
1525 self._downloader.cache.store(self._MVPD_CACHE, requestor_id, requestor_info)
1527 authz_token = requestor_info.get(guid)
1528 if authz_token and is_expired(authz_token, 'simpleTokenTTL'):
1531 authorize = self._download_webpage(
1532 self._SERVICE_PROVIDER_TEMPLATE % 'authorize', video_id,
1533 'Retrieving Authorization Token', data=urlencode_postdata({
1534 'resource_id': resource,
1535 'requestor_id': requestor_id,
1536 'authentication_token': authn_token,
1537 'mso_id': xml_text(authn_token, 'simpleTokenMsoID'),
1539 }), headers=mvpd_headers)
1540 if '<pendingLogout' in authorize:
1541 self._downloader.cache.store(self._MVPD_CACHE, requestor_id, {})
1544 if '<error' in authorize:
1545 raise ExtractorError(xml_text(authorize, 'details'), expected=True)
1546 authz_token = unescapeHTML(xml_text(authorize, 'authzToken'))
1547 requestor_info[guid] = authz_token
1548 self._downloader.cache.store(self._MVPD_CACHE, requestor_id, requestor_info)
1550 mvpd_headers.update({
1551 'ap_19': xml_text(authn_token, 'simpleSamlNameID'),
1552 'ap_23': xml_text(authn_token, 'simpleSamlSessionIndex'),
1555 short_authorize = self._download_webpage(
1556 self._SERVICE_PROVIDER_TEMPLATE % 'shortAuthorize',
1557 video_id, 'Retrieving Media Token', data=urlencode_postdata({
1558 'authz_token': authz_token,
1559 'requestor_id': requestor_id,
1560 'session_guid': xml_text(authn_token, 'simpleTokenAuthenticationGuid'),
1561 'hashed_guid': 'false',
1562 }), headers=mvpd_headers)
1563 if '<pendingLogout' in short_authorize:
1564 self._downloader.cache.store(self._MVPD_CACHE, requestor_id, {})
1567 return short_authorize