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': 'AT&T U-verse',
30 'username_field': 'userid',
31 'password_field': 'password',
34 'name': 'DIRECTV NOW',
35 'username_field': 'email',
36 'password_field': 'loginpassword',
40 'username_field': 'UserName',
41 'password_field': 'UserPassword',
44 'name': 'Comcast XFINITY',
45 'username_field': 'user',
46 'password_field': 'passwd',
49 'name': 'Time Warner Cable | Spectrum',
50 'username_field': 'Ecom_User_ID',
51 'password_field': 'Ecom_Password',
54 'name': 'Bright House Networks | Spectrum',
55 'username_field': 'j_username',
56 'password_field': 'j_password',
59 'name': 'Charter Spectrum',
60 'username_field': 'IDToken1',
61 'password_field': 'IDToken2',
64 'name': 'Verizon FiOS',
65 'username_field': 'IDToken1',
66 'password_field': 'IDToken2',
69 'name': '3 Rivers Communications'
72 'name': 'Access Montana'
74 'acecommunications': {
78 'name': 'Acme Communications'
81 'name': 'Adams Cable Service'
84 'name': 'Albany Mutual Telephone'
87 'name': 'Algona Municipal Utilities'
90 'name': 'All West Communications'
93 'name': 'Allen\'s Communications'
96 'name': 'Alliance Communications'
99 'name': 'ALLO Communications'
102 'name': 'Alpine Communications'
105 'name': 'American Broadband'
108 'name': 'American Broadband Missouri'
111 'name': 'American Community Networks'
114 'name': 'American Warrior Networks'
117 'name': 'Amherst Telephone/Tomorrow Valley'
123 'name': 'Arkwest Communications'
126 'name': 'Arthur Mutual Telephone Company'
132 'name': 'Ashland Home Net'
135 'name': 'Astound (now Wave)'
138 'name': 'ATC Broadband'
141 'name': 'ATC Communications'
144 'name': 'Ayersville Communications'
147 'name': 'Baldwin Lightstream'
153 'name': 'Bardstown Cable TV'
156 'name': 'Bay Country Communications'
159 'name': 'Beaver Creek Cooperative Telephone'
162 'name': 'Beaver Valley Cable'
165 'name': 'Bee Line Cable'
168 'name': 'Beehive Broadband'
174 'name': 'Bellevue Municipal Cable'
177 'name': 'Ben Lomand Connect / BLTV'
183 'name': 'Big Sandy Broadband'
186 'name': 'Bledsoe Telephone Cooperative'
189 'name': 'Blue Valley Tele-Communications'
192 'name': 'Brandenburg Telephone Co.'
195 'name': 'Bristol Tennessee Essential Services'
198 'name': 'Broadstripe'
201 'name': 'BTC Communications'
204 'name': 'BTC Vision - Nahunta'
207 'name': 'Bulloch Telephone Cooperative'
210 'name': 'Butler-Bremer Communications'
213 'name': 'C Spire SNAP'
216 'name': 'Cable Services Inc.'
219 'name': 'CableAmerica'
222 'name': 'CableSouth Media 3'
225 'name': 'Cam-Tel Company'
228 'name': 'Cameron Communications'
231 'name': 'Canby Telcom'
237 'name': 'Carnegie Cable'
246 'name': 'Catalina Broadband Solutions'
249 'name': 'CC Communications'
252 'name': 'CDE Lightband'
255 'name': 'Cedar Falls Utilities'
258 'name': 'Celect-Bloomer Telephone Area'
261 'name': 'Celect-Bruce Telephone Area'
264 'name': 'Celect-Citizens Connected Area'
267 'name': 'Celect-Elmwood/Spring Valley Area'
270 'name': 'Celect-Mosaic Telecom'
273 'name': 'Celect-West WI Telephone Area'
276 'name': 'Cellcom/Nsight Telservices'
282 'name': 'Central Scott / CSTV'
285 'name': 'Chaparral CableVision'
288 'name': 'Chariton Valley Communication Corporation, Inc.'
291 'name': 'Chatmoss Cablevision'
294 'name': 'Cherokee Communications'
297 'name': 'Chesapeake Bay Communications'
300 'name': 'Cim-Tel Cable, LLC.'
303 'name': 'Citizens Cablevision - Floyd, VA'
306 'name': 'Citizens Cablevision, Inc.'
309 'name': 'Citizens Fiber'
312 'name': 'Citizens Mutual'
315 'name': 'Citizens Telephone Corporation'
318 'name': 'City Of Monroe'
327 'name': 'Clarence Telephone and Cedar Communications'
330 'name': 'Clear Choice Communications'
333 'name': 'Click! Cable TV'
339 'name': 'CML Telephone Cooperative Association'
345 'name': 'Co-Mo Connect'
348 'name': 'Coast Communications'
351 'name': 'Coaxial Cable TV'
354 'name': 'Cobalt TV (Mid-State Community TV)'
357 'name': 'Columbia Power & Water Systems'
360 'name': 'Columbus Telephone'
363 'name': 'Communications 1 Cablevision, Inc.'
366 'name': 'Community Cable & Broadband'
369 'name': 'Community Communications Company'
375 'name': 'Complete Communication Services'
381 'name': 'ComSouth Telesys'
383 'consolidatedcable': {
384 'name': 'Consolidated'
387 'name': 'Conway Corporation'
390 'name': 'Coon Valley Telecommunications Inc'
393 'name': 'Cooperative Telephone Company'
399 'name': 'Craw-Kan Telephone'
402 'name': 'Crestview Cable Communications'
408 'name': 'Crosslake Communications'
411 'name': 'CTC - Brainerd MN'
414 'name': 'CTV-Beam - East Alabama'
417 'name': 'Cunningham Telephone & Cable'
420 'name': 'D & P Communications'
423 'name': 'Dakota Central Telecommunications'
426 'name': 'Delcambre Telephone LLC'
429 'name': 'Delta Telephone Company'
435 'name': 'Direct Communications'
438 'name': 'Doylestown Cable TV'
447 'name': 'DTC Cable (Delhi)'
450 'name': 'Dumont Telephone Company'
453 'name': 'Dunkerton Telephone Cooperative'
456 'name': 'Duo County Telecom'
459 'name': 'Eagle Communications'
462 'name': 'East Arkansas Cable TV'
465 'name': 'EATEL Video, LLC'
471 'name': 'Emery Telcom Video LLC'
474 'name': 'Empire Access'
477 'name': 'Endeavor Communications'
480 'name': 'Enhanced Telecommunications Corporation'
486 'name': 'EPB Smartnet'
489 'name': 'EPlus Broadband'
495 'name': 'Etex Communications'
498 'name': 'F&B Communications'
501 'name': 'Falcon Broadband'
504 'name': 'FamilyView CableVision'
507 'name': 'Farmers Mutual Telephone Company'
510 'name': 'Fayetteville Public Utilities'
516 'name': 'Fidelity Communications'
519 'name': 'FJ Communications'
522 'name': 'Flint River Communications'
525 'name': 'FMT - Jesup'
528 'name': 'Foothills Communications'
531 'name': 'Forsyth CableNet'
534 'name': 'Frankfort Plant Board'
537 'name': 'Franklin Telephone Company'
543 'name': 'Full Channel, Inc.'
546 'name': 'Gardonville Cooperative Telephone Association'
549 'name': 'GBT Communications, Inc.'
552 'name': 'Genuine Telecom'
555 'name': 'Giant Communications'
558 'name': 'Glasgow EPB'
561 'name': 'Glenwood Telecommunications'
564 'name': 'GLW Broadband Inc.'
567 'name': 'Golden West Cablevision'
570 'name': 'Grantsburg Telcom'
573 'name': 'Great Plains Communications'
576 'name': 'Gridley Cable Inc'
579 'name': 'H&B Cable Services'
582 'name': 'Haefele TV Inc.'
585 'name': 'Halstad Telephone Company'
588 'name': 'Harlan Municipal Utilities'
591 'name': 'Hart Communications'
594 'name': 'Hartelco TV'
597 'name': 'Heart of Iowa Communications Cooperative'
600 'name': 'Hickory Telephone Company'
603 'name': 'Highland Communication Services'
606 'name': 'Highland Media'
609 'name': 'Hilliary Communications'
612 'name': 'Hinton CATV Co.'
615 'name': 'HomeTel Entertainment, Inc.'
618 'name': 'Hood Canal Communications'
621 'name': 'Hope - Prescott Cable TV'
624 'name': 'Horizon Cable TV, Inc.'
627 'name': 'Horizon Chillicothe Telephone'
630 'name': 'HTC Communications Co. - IL'
633 'name': 'HTC Communications, Inc. - IA'
636 'name': 'Huxley Communications'
639 'name': 'ImOn Communications'
642 'name': 'Independence Telecommunications'
645 'name': 'Inland Networks'
648 'name': 'Innovative Cable TV St Croix'
651 'name': 'Innovative Cable TV St Thomas-St John'
654 'name': 'Inside Connect Cable'
657 'name': 'Integra Telecom'
660 'name': 'Interstate Telecommunications Coop'
663 'name': 'Irvine Cable'
666 'name': 'K2 Communications'
669 'name': 'Kalida Telephone Company, Inc.'
672 'name': 'Kalona Cooperative Telephone Company'
678 'name': 'KPU Telecommunications'
681 'name': 'Kuhn Communications, Inc.'
684 'name': 'Lakeland Communications'
690 'name': 'Laurel Highland Total Communications, Inc.'
693 'name': 'Lehigh Valley Cooperative Telephone'
696 'name': 'Limestone Cable/Bracken Cable'
708 'name': 'LocalTel Communications'
711 'name': 'Longview - Kilgore Cable TV'
714 'name': 'Lonsdale Video Ventures, LLC'
717 'name': 'Lost Nation-Elwood Telephone Co.'
720 'name': 'LPC Connect'
723 'name': 'Lumos Networks'
726 'name': 'Madison Communications'
729 'name': 'Madison County Cable Inc.'
732 'name': 'Mahaska Communication Group'
735 'name': 'Marne & Elk Horn Telephone Company'
738 'name': 'McClure Telephone Co.'
744 'name': 'Merrimac Communications Ltd.'
753 'name': 'Mid-Hudson Cable'
756 'name': 'Mid-Rivers Communications'
759 'name': 'Midstate Communications'
762 'name': 'Milford Communications'
771 'name': 'Mitchell Telecom'
777 'name': 'Mon-Cre TVE'
780 'name': 'Mountain Telephone'
783 'name': 'Mountain Village Cable'
786 'name': 'MTA Communications, LLC'
792 'name': 'MTC Technologies'
798 'name': 'MTCO Communications'
801 'name': 'Mulberry Telecommunications'
804 'name': 'Murray Electric System'
807 'name': 'MUS FiberNET'
810 'name': 'Muscatine Power & Water'
822 'name': 'Nebraska Central Telecom, Inc.'
825 'name': 'Nelsonville TV Cable'
831 'name': 'New Hope Telephone Cooperative'
837 'name': 'NineStar Connect'
843 'name': 'Nortex Communications'
846 'name': 'North Central Telephone Cooperative'
849 'name': 'Northland Communications'
852 'name': 'Northwest Communications'
855 'name': 'Norwood Light Broadband'
858 'name': 'Nsight Telservices'
864 'name': 'NTS Communications'
876 'name': 'OmniTel Communications'
879 'name': 'OneSource Communications'
882 'name': 'Opelika Power Services'
891 'name': 'OTEC Communication Company'
894 'name': 'Packerland Broadband'
897 'name': 'Panora Telco/Guthrie Center Communications'
900 'name': 'Park Region Telephone & Otter Tail Telcom'
903 'name': 'Partner Communications Cooperative'
909 'name': 'Paul Bunyan Communications'
912 'name': 'Pembroke Telephone Company'
915 'name': 'Peoples Rural Telephone Cooperative'
918 'name': 'PES Energize'
921 'name': 'Philippi Communications System'
924 'name': 'Phonoscope Cable'
927 'name': 'Pine Belt Communications, Inc.'
930 'name': 'Pine Bluff Cable TV'
933 'name': 'Pineland Telephone Cooperative'
936 'name': 'Pinpoint Communications'
939 'name': 'Pioneer Broadband'
942 'name': 'Pioneer Communications'
945 'name': 'Pioneer DTV'
948 'name': 'Plant TiftNet, Inc.'
957 'name': 'Polar Cablevision'
960 'name': 'Pottawatomie Telephone Co.'
963 'name': 'Premier Communications'
975 'name': 'Quality Cablevision'
978 'name': 'Radcliffe Telephone Company'
981 'name': 'Rainbow Communications'
984 'name': 'Rainier Connect'
987 'name': 'Ralls Technologies'
990 'name': 'RC Technologies'
993 'name': 'Red River Communications'
996 'name': 'Reedsburg Utility Commission'
999 'name': 'Reliance Connects- Oregon'
1002 'name': 'Reserve Telecommunications'
1005 'name': 'Resort TV Cable'
1008 'name': 'Richland Grant Telephone Cooperative, Inc.'
1011 'name': 'River Valley Telecommunications Coop'
1014 'name': 'Rock Port Cablevision'
1020 'name': 'RTC Communication Corp'
1023 'name': 'RTC-Reservation Telephone Coop.'
1026 'name': 'RTEC Communications'
1032 'name': 'San Bruno Cable TV'
1038 'name': 'SCI Broadband-Savage Communications Inc.'
1041 'name': 'Scottsboro Electric Power Board'
1044 'name': 'Scranton Telephone Company'
1053 'name': 'Sherwood Mutual Telephone Association, Inc.'
1056 'name': 'Silver Star Communications'
1059 'name': 'Sjoberg\'s Inc.'
1065 'name': 'SkyBest TV'
1068 'name': 'Smithville Communications'
1074 'name': 'South Central Rural Telephone Cooperative'
1077 'name': 'South Holt Cablevision, Inc.'
1080 'name': 'South Slope Cooperative Communications'
1083 'name': 'Spanish Fork Community Network'
1086 'name': 'Spencer Municipal Utilities'
1089 'name': 'Spillway Communications, Inc.'
1095 'name': 'St. Maarten Cable TV'
1098 'name': 'Star Communications'
1104 'name': 'STRATA Networks'
1107 'name': 'Sumner Cable TV'
1110 'name': 'Surry TV/PCSI TV'
1113 'name': 'Swayzee Communications'
1116 'name': 'Sweetwater Cable Television Co'
1118 'weh010-talequah': {
1119 'name': 'Tahlequah Cable TV'
1125 'name': 'Tele-Media Company'
1128 'name': 'The Community Agency'
1131 'name': 'Three River'
1134 'name': 'Town & Country Technologies'
1137 'name': 'Trans-Video'
1140 'name': 'Trenton TV Cable Company'
1143 'name': 'Tri County Communications Cooperative'
1146 'name': 'TriCounty Telecom'
1149 'name': 'TrioTel Communications, Inc.'
1152 'name': 'Troy Cablevision, Inc.'
1158 'name': 'Tullahoma Utilities Board'
1161 'name': 'TV Cable of Rensselaer'
1170 'name': 'Twin Lakes'
1173 'name': 'Twin Valley'
1176 'name': 'Union Telephone Company'
1179 'name': 'United Communications - TN'
1182 'name': 'United Services'
1188 'name': 'USA Communications'
1191 'name': 'USA Communications/Shellsburg, IA'
1194 'name': 'Valley TeleCom Group'
1197 'name': 'Valley Telecommunications'
1200 'name': 'Valparaiso Broadband'
1203 'name': 'Vast Broadband'
1206 'name': 'Venture Communications Cooperative, Inc.'
1209 'name': 'Vernon Communications Co-op'
1211 'weh010-vicksburg': {
1212 'name': 'Vicksburg Video'
1215 'name': 'Vision Communications'
1218 'name': 'Volcano Vision, Inc.'
1221 'name': 'VolFirst / BLTV'
1230 'name': 'Vyve Broadband'
1233 'name': 'Wabash Mutual Telephone'
1236 'name': 'Waitsfield Cable'
1239 'name': 'Walnut Communications'
1245 'name': 'Waverly Communications Utility'
1251 'name': 'Webster-Calhoun Cooperative Telephone Association'
1254 'name': 'West Alabama TV Cable'
1257 'name': 'West Carolina Communications'
1260 'name': 'West Central Telephone Association'
1263 'name': 'West River Cooperative Telephone Company'
1266 'name': 'WesTel Systems'
1269 'name': 'Western Iowa Networks'
1272 'name': 'Whidbey Telecom'
1275 'name': 'White County Cable TV'
1284 'name': 'Wilkes Communications, Inc./RiverStreet Networks'
1287 'name': 'Wilson Communications'
1290 'name': 'Windomnet/SMBS'
1293 'name': 'Windstream Cable TV'
1296 'name': 'Winnebago Cooperative Telecom Association'
1302 'name': 'WTC Communications, Inc.'
1305 'name': 'Wyandotte Cable'
1308 'name': 'X-Stream Services'
1311 'name': 'XIT Communications'
1314 'name': 'Yelcot Communications'
1320 'name': 'Zito Media'
1325 class AdobePassIE(InfoExtractor):
1326 _SERVICE_PROVIDER_TEMPLATE = 'https://sp.auth.adobe.com/adobe-services/%s'
1327 _USER_AGENT = 'Mozilla/5.0 (X11; Linux i686; rv:47.0) Gecko/20100101 Firefox/47.0'
1328 _MVPD_CACHE = 'ap-mvpd'
1330 _DOWNLOADING_LOGIN_PAGE = 'Downloading Provider Login Page'
1332 def _download_webpage_handle(self, *args, **kwargs):
1333 headers = self.geo_verification_headers()
1334 headers.update(kwargs.get('headers', {}))
1335 kwargs['headers'] = headers
1336 return super(AdobePassIE, self)._download_webpage_handle(
1337 *args, **compat_kwargs(kwargs))
1340 def _get_mvpd_resource(provider_id, title, guid, rating):
1341 channel = etree.Element('channel')
1342 channel_title = etree.SubElement(channel, 'title')
1343 channel_title.text = provider_id
1344 item = etree.SubElement(channel, 'item')
1345 resource_title = etree.SubElement(item, 'title')
1346 resource_title.text = title
1347 resource_guid = etree.SubElement(item, 'guid')
1348 resource_guid.text = guid
1349 resource_rating = etree.SubElement(item, 'media:rating')
1350 resource_rating.attrib = {'scheme': 'urn:v-chip'}
1351 resource_rating.text = rating
1352 return '<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/">' + etree.tostring(channel).decode() + '</rss>'
1354 def _extract_mvpd_auth(self, url, video_id, requestor_id, resource):
1355 def xml_text(xml_str, tag):
1356 return self._search_regex(
1357 '<%s>(.+?)</%s>' % (tag, tag), xml_str, tag)
1359 def is_expired(token, date_ele):
1360 token_expires = unified_timestamp(re.sub(r'[_ ]GMT', '', xml_text(token, date_ele)))
1361 return token_expires and token_expires <= int(time.time())
1363 def post_form(form_page_res, note, data={}):
1364 form_page, urlh = form_page_res
1365 post_url = self._html_search_regex(r'<form[^>]+action=(["\'])(?P<url>.+?)\1', form_page, 'post url', group='url')
1366 if not re.match(r'https?://', post_url):
1367 post_url = compat_urlparse.urljoin(urlh.geturl(), post_url)
1368 form_data = self._hidden_inputs(form_page)
1369 form_data.update(data)
1370 return self._download_webpage_handle(
1371 post_url, video_id, note, data=urlencode_postdata(form_data), headers={
1372 'Content-Type': 'application/x-www-form-urlencoded',
1375 def raise_mvpd_required():
1376 raise ExtractorError(
1377 'This video is only available for users of participating TV providers. '
1378 'Use --ap-mso to specify Adobe Pass Multiple-system operator Identifier '
1379 'and --ap-username and --ap-password or --netrc to provide account credentials.', expected=True)
1381 def extract_redirect_url(html, url=None, fatal=False):
1382 # TODO: eliminate code duplication with generic extractor and move
1383 # redirection code into _download_webpage_handle
1384 REDIRECT_REGEX = r'[0-9]{,2};\s*(?:URL|url)=\'?([^\'"]+)'
1385 redirect_url = self._search_regex(
1386 r'(?i)<meta\s+(?=(?:[a-z-]+="[^"]+"\s+)*http-equiv="refresh")'
1387 r'(?:[a-z-]+="[^"]+"\s+)*?content="%s' % REDIRECT_REGEX,
1388 html, 'meta refresh redirect',
1389 default=NO_DEFAULT if fatal else None, fatal=fatal)
1390 if not redirect_url:
1393 redirect_url = compat_urlparse.urljoin(url, unescapeHTML(redirect_url))
1397 'ap_42': 'anonymous',
1398 'ap_11': 'Linux i686',
1399 'ap_z': self._USER_AGENT,
1400 'User-Agent': self._USER_AGENT,
1403 guid = xml_text(resource, 'guid') if '<' in resource else resource
1406 requestor_info = self._downloader.cache.load(self._MVPD_CACHE, requestor_id) or {}
1407 authn_token = requestor_info.get('authn_token')
1408 if authn_token and is_expired(authn_token, 'simpleTokenExpires'):
1411 # TODO add support for other TV Providers
1412 mso_id = self._downloader.params.get('ap_mso')
1414 raise_mvpd_required()
1415 username, password = self._get_login_info('ap_username', 'ap_password', mso_id)
1416 if not username or not password:
1417 raise_mvpd_required()
1418 mso_info = MSO_INFO[mso_id]
1420 provider_redirect_page_res = self._download_webpage_handle(
1421 self._SERVICE_PROVIDER_TEMPLATE % 'authenticate/saml', video_id,
1422 'Downloading Provider Redirect Page', query={
1425 'requestor_id': requestor_id,
1426 'no_iframe': 'false',
1427 'domain_name': 'adobe.com',
1428 'redirect_url': url,
1431 if mso_id == 'Comcast_SSO':
1432 # Comcast page flow varies by video site and whether you
1433 # are on Comcast's network.
1434 provider_redirect_page, urlh = provider_redirect_page_res
1435 if 'automatically signing you in' in provider_redirect_page:
1436 oauth_redirect_url = self._html_search_regex(
1437 r'window\.location\s*=\s*[\'"]([^\'"]+)',
1438 provider_redirect_page, 'oauth redirect')
1439 self._download_webpage(
1440 oauth_redirect_url, video_id, 'Confirming auto login')
1442 if '<form name="signin"' in provider_redirect_page:
1443 provider_login_page_res = provider_redirect_page_res
1444 elif 'http-equiv="refresh"' in provider_redirect_page:
1445 oauth_redirect_url = extract_redirect_url(
1446 provider_redirect_page, fatal=True)
1447 provider_login_page_res = self._download_webpage_handle(
1448 oauth_redirect_url, video_id,
1449 self._DOWNLOADING_LOGIN_PAGE)
1451 provider_login_page_res = post_form(
1452 provider_redirect_page_res,
1453 self._DOWNLOADING_LOGIN_PAGE)
1455 mvpd_confirm_page_res = post_form(
1456 provider_login_page_res, 'Logging in', {
1457 mso_info['username_field']: username,
1458 mso_info['password_field']: password,
1460 mvpd_confirm_page, urlh = mvpd_confirm_page_res
1461 if '<button class="submit" value="Resume">Resume</button>' in mvpd_confirm_page:
1462 post_form(mvpd_confirm_page_res, 'Confirming Login')
1463 elif mso_id == 'Verizon':
1464 # In general, if you're connecting from a Verizon-assigned IP,
1465 # you will not actually pass your credentials.
1466 provider_redirect_page, urlh = provider_redirect_page_res
1467 if 'Please wait ...' in provider_redirect_page:
1468 saml_redirect_url = self._html_search_regex(
1469 r'self\.parent\.location=(["\'])(?P<url>.+?)\1',
1470 provider_redirect_page,
1471 'SAML Redirect URL', group='url')
1472 saml_login_page = self._download_webpage(
1473 saml_redirect_url, video_id,
1474 'Downloading SAML Login Page')
1476 saml_login_page_res = post_form(
1477 provider_redirect_page_res, 'Logging in', {
1478 mso_info['username_field']: username,
1479 mso_info['password_field']: password,
1481 saml_login_page, urlh = saml_login_page_res
1482 if 'Please try again.' in saml_login_page:
1483 raise ExtractorError(
1484 'We\'re sorry, but either the User ID or Password entered is not correct.')
1485 saml_login_url = self._search_regex(
1486 r'xmlHttp\.open\("POST"\s*,\s*(["\'])(?P<url>.+?)\1',
1487 saml_login_page, 'SAML Login URL', group='url')
1488 saml_response_json = self._download_json(
1489 saml_login_url, video_id, 'Downloading SAML Response',
1490 headers={'Content-Type': 'text/xml'})
1491 self._download_webpage(
1492 saml_response_json['targetValue'], video_id,
1493 'Confirming Login', data=urlencode_postdata({
1494 'SAMLResponse': saml_response_json['SAMLResponse'],
1495 'RelayState': saml_response_json['RelayState']
1497 'Content-Type': 'application/x-www-form-urlencoded'
1500 # Some providers (e.g. DIRECTV NOW) have another meta refresh
1501 # based redirect that should be followed.
1502 provider_redirect_page, urlh = provider_redirect_page_res
1503 provider_refresh_redirect_url = extract_redirect_url(
1504 provider_redirect_page, url=urlh.geturl())
1505 if provider_refresh_redirect_url:
1506 provider_redirect_page_res = self._download_webpage_handle(
1507 provider_refresh_redirect_url, video_id,
1508 'Downloading Provider Redirect Page (meta refresh)')
1509 provider_login_page_res = post_form(
1510 provider_redirect_page_res, self._DOWNLOADING_LOGIN_PAGE)
1511 mvpd_confirm_page_res = post_form(provider_login_page_res, 'Logging in', {
1512 mso_info.get('username_field', 'username'): username,
1513 mso_info.get('password_field', 'password'): password,
1515 if mso_id != 'Rogers':
1516 post_form(mvpd_confirm_page_res, 'Confirming Login')
1518 session = self._download_webpage(
1519 self._SERVICE_PROVIDER_TEMPLATE % 'session', video_id,
1520 'Retrieving Session', data=urlencode_postdata({
1522 'requestor_id': requestor_id,
1523 }), headers=mvpd_headers)
1524 if '<pendingLogout' in session:
1525 self._downloader.cache.store(self._MVPD_CACHE, requestor_id, {})
1528 authn_token = unescapeHTML(xml_text(session, 'authnToken'))
1529 requestor_info['authn_token'] = authn_token
1530 self._downloader.cache.store(self._MVPD_CACHE, requestor_id, requestor_info)
1532 authz_token = requestor_info.get(guid)
1533 if authz_token and is_expired(authz_token, 'simpleTokenTTL'):
1536 authorize = self._download_webpage(
1537 self._SERVICE_PROVIDER_TEMPLATE % 'authorize', video_id,
1538 'Retrieving Authorization Token', data=urlencode_postdata({
1539 'resource_id': resource,
1540 'requestor_id': requestor_id,
1541 'authentication_token': authn_token,
1542 'mso_id': xml_text(authn_token, 'simpleTokenMsoID'),
1544 }), headers=mvpd_headers)
1545 if '<pendingLogout' in authorize:
1546 self._downloader.cache.store(self._MVPD_CACHE, requestor_id, {})
1549 if '<error' in authorize:
1550 raise ExtractorError(xml_text(authorize, 'details'), expected=True)
1551 authz_token = unescapeHTML(xml_text(authorize, 'authzToken'))
1552 requestor_info[guid] = authz_token
1553 self._downloader.cache.store(self._MVPD_CACHE, requestor_id, requestor_info)
1555 mvpd_headers.update({
1556 'ap_19': xml_text(authn_token, 'simpleSamlNameID'),
1557 'ap_23': xml_text(authn_token, 'simpleSamlSessionIndex'),
1560 short_authorize = self._download_webpage(
1561 self._SERVICE_PROVIDER_TEMPLATE % 'shortAuthorize',
1562 video_id, 'Retrieving Media Token', data=urlencode_postdata({
1563 'authz_token': authz_token,
1564 'requestor_id': requestor_id,
1565 'session_guid': xml_text(authn_token, 'simpleTokenAuthenticationGuid'),
1566 'hashed_guid': 'false',
1567 }), headers=mvpd_headers)
1568 if '<pendingLogout' in short_authorize:
1569 self._downloader.cache.store(self._MVPD_CACHE, requestor_id, {})
1572 return short_authorize