2 from __future__
import unicode_literals
7 import xml
.etree
.ElementTree
as etree
9 from .common
import InfoExtractor
10 from ..compat
import (
27 'username_field': 'username',
28 'password_field': 'password',
31 'name': 'AT&T U-verse',
32 'username_field': 'userid',
33 'password_field': 'password',
36 'name': 'DIRECTV NOW',
37 'username_field': 'email',
38 'password_field': 'loginpassword',
42 'username_field': 'username',
43 'password_field': 'password',
47 'username_field': 'UserName',
48 'password_field': 'UserPassword',
51 'name': 'Comcast XFINITY',
52 'username_field': 'user',
53 'password_field': 'passwd',
56 'name': 'Time Warner Cable | Spectrum',
57 'username_field': 'Ecom_User_ID',
58 'password_field': 'Ecom_Password',
61 'name': 'Bright House Networks | Spectrum',
62 'username_field': 'j_username',
63 'password_field': 'j_password',
66 'name': 'Charter Spectrum',
67 'username_field': 'IDToken1',
68 'password_field': 'IDToken2',
72 'username_field': 'IDToken1',
73 'password_field': 'IDToken2',
77 'username_field': 'ident'
80 'name': 'Verizon FiOS',
81 'username_field': 'IDToken1',
82 'password_field': 'IDToken2',
85 'name': 'Optimum/Cablevision',
86 'username_field': 'j_username',
87 'password_field': 'j_password',
90 'name': '3 Rivers Communications'
93 'name': 'Access Montana'
95 'acecommunications': {
99 'name': 'Acme Communications'
102 'name': 'Adams Cable Service'
105 'name': 'Albany Mutual Telephone'
108 'name': 'Algona Municipal Utilities'
111 'name': 'All West Communications'
114 'name': 'Allen\'s Communications'
117 'name': 'Alliance Communications'
120 'name': 'ALLO Communications'
123 'name': 'Alpine Communications'
126 'name': 'American Broadband'
129 'name': 'American Broadband Missouri'
132 'name': 'American Community Networks'
135 'name': 'American Warrior Networks'
138 'name': 'Amherst Telephone/Tomorrow Valley'
144 'name': 'Arkwest Communications'
147 'name': 'Arthur Mutual Telephone Company'
153 'name': 'Ashland Home Net'
156 'name': 'Astound (now Wave)'
159 'name': 'ATC Broadband'
162 'name': 'ATC Communications'
165 'name': 'Ayersville Communications'
168 'name': 'Baldwin Lightstream'
174 'name': 'Bardstown Cable TV'
177 'name': 'Bay Country Communications'
180 'name': 'Beaver Creek Cooperative Telephone'
183 'name': 'Beaver Valley Cable'
186 'name': 'Bee Line Cable'
189 'name': 'Beehive Broadband'
195 'name': 'Bellevue Municipal Cable'
198 'name': 'Ben Lomand Connect / BLTV'
204 'name': 'Big Sandy Broadband'
207 'name': 'Bledsoe Telephone Cooperative'
210 'name': 'Blue Valley Tele-Communications'
213 'name': 'Brandenburg Telephone Co.'
216 'name': 'Bristol Tennessee Essential Services'
219 'name': 'Broadstripe'
222 'name': 'BTC Communications'
225 'name': 'BTC Vision - Nahunta'
228 'name': 'Bulloch Telephone Cooperative'
231 'name': 'Butler-Bremer Communications'
234 'name': 'C Spire SNAP'
237 'name': 'Cable Services Inc.'
240 'name': 'CableAmerica'
243 'name': 'CableSouth Media 3'
246 'name': 'Cam-Tel Company'
249 'name': 'Cameron Communications'
252 'name': 'Canby Telcom'
258 'name': 'Carnegie Cable'
267 'name': 'Catalina Broadband Solutions'
270 'name': 'CC Communications'
273 'name': 'CDE Lightband'
276 'name': 'Cedar Falls Utilities'
279 'name': 'Celect-Bloomer Telephone Area'
282 'name': 'Celect-Bruce Telephone Area'
285 'name': 'Celect-Citizens Connected Area'
288 'name': 'Celect-Elmwood/Spring Valley Area'
291 'name': 'Celect-Mosaic Telecom'
294 'name': 'Celect-West WI Telephone Area'
297 'name': 'Cellcom/Nsight Telservices'
303 'name': 'Central Scott / CSTV'
306 'name': 'Chaparral CableVision'
309 'name': 'Chariton Valley Communication Corporation, Inc.'
312 'name': 'Chatmoss Cablevision'
315 'name': 'Cherokee Communications'
318 'name': 'Chesapeake Bay Communications'
321 'name': 'Cim-Tel Cable, LLC.'
324 'name': 'Citizens Cablevision - Floyd, VA'
327 'name': 'Citizens Cablevision, Inc.'
330 'name': 'Citizens Fiber'
333 'name': 'Citizens Mutual'
336 'name': 'Citizens Telephone Corporation'
339 'name': 'City Of Monroe'
348 'name': 'Clarence Telephone and Cedar Communications'
351 'name': 'Clear Choice Communications'
354 'name': 'Click! Cable TV'
360 'name': 'CML Telephone Cooperative Association'
366 'name': 'Co-Mo Connect'
369 'name': 'Coast Communications'
372 'name': 'Coaxial Cable TV'
375 'name': 'Cobalt TV (Mid-State Community TV)'
378 'name': 'Columbia Power & Water Systems'
381 'name': 'Columbus Telephone'
384 'name': 'Communications 1 Cablevision, Inc.'
387 'name': 'Community Cable & Broadband'
390 'name': 'Community Communications Company'
396 'name': 'Complete Communication Services'
402 'name': 'ComSouth Telesys'
404 'consolidatedcable': {
405 'name': 'Consolidated'
408 'name': 'Conway Corporation'
411 'name': 'Coon Valley Telecommunications Inc'
414 'name': 'Cooperative Telephone Company'
420 'name': 'Craw-Kan Telephone'
423 'name': 'Crestview Cable Communications'
429 'name': 'Crosslake Communications'
432 'name': 'CTC - Brainerd MN'
435 'name': 'CTV-Beam - East Alabama'
438 'name': 'Cunningham Telephone & Cable'
441 'name': 'D & P Communications'
444 'name': 'Dakota Central Telecommunications'
447 'name': 'Delcambre Telephone LLC'
450 'name': 'Delta Telephone Company'
456 'name': 'Direct Communications'
459 'name': 'Doylestown Cable TV'
468 'name': 'DTC Cable (Delhi)'
471 'name': 'Dumont Telephone Company'
474 'name': 'Dunkerton Telephone Cooperative'
477 'name': 'Duo County Telecom'
480 'name': 'Eagle Communications'
483 'name': 'East Arkansas Cable TV'
486 'name': 'EATEL Video, LLC'
492 'name': 'Emery Telcom Video LLC'
495 'name': 'Empire Access'
498 'name': 'Endeavor Communications'
501 'name': 'Enhanced Telecommunications Corporation'
507 'name': 'EPB Smartnet'
510 'name': 'EPlus Broadband'
516 'name': 'Etex Communications'
519 'name': 'F&B Communications'
522 'name': 'Falcon Broadband'
525 'name': 'FamilyView CableVision'
528 'name': 'Farmers Mutual Telephone Company'
531 'name': 'Fayetteville Public Utilities'
537 'name': 'Fidelity Communications'
540 'name': 'FJ Communications'
543 'name': 'Flint River Communications'
546 'name': 'FMT - Jesup'
549 'name': 'Foothills Communications'
552 'name': 'Forsyth CableNet'
555 'name': 'Frankfort Plant Board'
558 'name': 'Franklin Telephone Company'
564 'name': 'Full Channel, Inc.'
567 'name': 'Gardonville Cooperative Telephone Association'
570 'name': 'GBT Communications, Inc.'
573 'name': 'Genuine Telecom'
576 'name': 'Giant Communications'
579 'name': 'Glasgow EPB'
582 'name': 'Glenwood Telecommunications'
585 'name': 'GLW Broadband Inc.'
588 'name': 'Golden West Cablevision'
591 'name': 'Grantsburg Telcom'
594 'name': 'Great Plains Communications'
597 'name': 'Gridley Cable Inc'
600 'name': 'H&B Cable Services'
603 'name': 'Haefele TV Inc.'
606 'name': 'Halstad Telephone Company'
609 'name': 'Harlan Municipal Utilities'
612 'name': 'Hart Communications'
615 'name': 'Hartelco TV'
618 'name': 'Heart of Iowa Communications Cooperative'
621 'name': 'Hickory Telephone Company'
624 'name': 'Highland Communication Services'
627 'name': 'Highland Media'
630 'name': 'Hilliary Communications'
633 'name': 'Hinton CATV Co.'
636 'name': 'HomeTel Entertainment, Inc.'
639 'name': 'Hood Canal Communications'
642 'name': 'Hope - Prescott Cable TV'
645 'name': 'Horizon Cable TV, Inc.'
648 'name': 'Horizon Chillicothe Telephone'
651 'name': 'HTC Communications Co. - IL'
654 'name': 'HTC Communications, Inc. - IA'
657 'name': 'Huxley Communications'
660 'name': 'ImOn Communications'
663 'name': 'Independence Telecommunications'
666 'name': 'Inland Networks'
669 'name': 'Innovative Cable TV St Croix'
672 'name': 'Innovative Cable TV St Thomas-St John'
675 'name': 'Inside Connect Cable'
678 'name': 'Integra Telecom'
681 'name': 'Interstate Telecommunications Coop'
684 'name': 'Irvine Cable'
687 'name': 'K2 Communications'
690 'name': 'Kalida Telephone Company, Inc.'
693 'name': 'Kalona Cooperative Telephone Company'
699 'name': 'KPU Telecommunications'
702 'name': 'Kuhn Communications, Inc.'
705 'name': 'Lakeland Communications'
711 'name': 'Laurel Highland Total Communications, Inc.'
714 'name': 'Lehigh Valley Cooperative Telephone'
717 'name': 'Limestone Cable/Bracken Cable'
729 'name': 'LocalTel Communications'
732 'name': 'Longview - Kilgore Cable TV'
735 'name': 'Lonsdale Video Ventures, LLC'
738 'name': 'Lost Nation-Elwood Telephone Co.'
741 'name': 'LPC Connect'
744 'name': 'Lumos Networks'
747 'name': 'Madison Communications'
750 'name': 'Madison County Cable Inc.'
753 'name': 'Mahaska Communication Group'
756 'name': 'Marne & Elk Horn Telephone Company'
759 'name': 'McClure Telephone Co.'
765 'name': 'Merrimac Communications Ltd.'
774 'name': 'Mid-Hudson Cable'
777 'name': 'Mid-Rivers Communications'
780 'name': 'Midstate Communications'
783 'name': 'Milford Communications'
792 'name': 'Mitchell Telecom'
798 'name': 'Mon-Cre TVE'
801 'name': 'Mountain Telephone'
804 'name': 'Mountain Village Cable'
807 'name': 'MTA Communications, LLC'
813 'name': 'MTC Technologies'
819 'name': 'MTCO Communications'
822 'name': 'Mulberry Telecommunications'
825 'name': 'Murray Electric System'
828 'name': 'MUS FiberNET'
831 'name': 'Muscatine Power & Water'
843 'name': 'Nebraska Central Telecom, Inc.'
846 'name': 'Nelsonville TV Cable'
852 'name': 'New Hope Telephone Cooperative'
858 'name': 'NineStar Connect'
864 'name': 'Nortex Communications'
867 'name': 'North Central Telephone Cooperative'
870 'name': 'Northland Communications'
873 'name': 'Northwest Communications'
876 'name': 'Norwood Light Broadband'
879 'name': 'Nsight Telservices'
885 'name': 'NTS Communications'
897 'name': 'OmniTel Communications'
900 'name': 'OneSource Communications'
903 'name': 'Opelika Power Services'
912 'name': 'OTEC Communication Company'
915 'name': 'Packerland Broadband'
918 'name': 'Panora Telco/Guthrie Center Communications'
921 'name': 'Park Region Telephone & Otter Tail Telcom'
924 'name': 'Partner Communications Cooperative'
930 'name': 'Paul Bunyan Communications'
933 'name': 'Pembroke Telephone Company'
936 'name': 'Peoples Rural Telephone Cooperative'
939 'name': 'PES Energize'
942 'name': 'Philippi Communications System'
945 'name': 'Phonoscope Cable'
948 'name': 'Pine Belt Communications, Inc.'
951 'name': 'Pine Bluff Cable TV'
954 'name': 'Pineland Telephone Cooperative'
957 'name': 'Pinpoint Communications'
960 'name': 'Pioneer Broadband'
963 'name': 'Pioneer Communications'
966 'name': 'Pioneer DTV'
969 'name': 'Plant TiftNet, Inc.'
978 'name': 'Polar Cablevision'
981 'name': 'Pottawatomie Telephone Co.'
984 'name': 'Premier Communications'
996 'name': 'Quality Cablevision'
999 'name': 'Radcliffe Telephone Company'
1002 'name': 'Rainbow Communications'
1005 'name': 'Rainier Connect'
1008 'name': 'Ralls Technologies'
1011 'name': 'RC Technologies'
1014 'name': 'Red River Communications'
1017 'name': 'Reedsburg Utility Commission'
1020 'name': 'Reliance Connects- Oregon'
1023 'name': 'Reserve Telecommunications'
1026 'name': 'Resort TV Cable'
1029 'name': 'Richland Grant Telephone Cooperative, Inc.'
1032 'name': 'River Valley Telecommunications Coop'
1035 'name': 'Rock Port Cablevision'
1041 'name': 'RTC Communication Corp'
1044 'name': 'RTC-Reservation Telephone Coop.'
1047 'name': 'RTEC Communications'
1053 'name': 'San Bruno Cable TV'
1059 'name': 'SCI Broadband-Savage Communications Inc.'
1062 'name': 'Scottsboro Electric Power Board'
1065 'name': 'Scranton Telephone Company'
1074 'name': 'Sherwood Mutual Telephone Association, Inc.'
1077 'name': 'Silver Star Communications'
1080 'name': 'Sjoberg\'s Inc.'
1086 'name': 'SkyBest TV'
1089 'name': 'Smithville Communications'
1095 'name': 'South Central Rural Telephone Cooperative'
1098 'name': 'South Holt Cablevision, Inc.'
1101 'name': 'South Slope Cooperative Communications'
1104 'name': 'Spanish Fork Community Network'
1107 'name': 'Spencer Municipal Utilities'
1110 'name': 'Spillway Communications, Inc.'
1116 'name': 'St. Maarten Cable TV'
1119 'name': 'Star Communications'
1125 'name': 'STRATA Networks'
1128 'name': 'Sumner Cable TV'
1131 'name': 'Surry TV/PCSI TV'
1134 'name': 'Swayzee Communications'
1137 'name': 'Sweetwater Cable Television Co'
1139 'weh010-talequah': {
1140 'name': 'Tahlequah Cable TV'
1146 'name': 'Tele-Media Company'
1149 'name': 'The Community Agency'
1152 'name': 'Three River'
1155 'name': 'Town & Country Technologies'
1158 'name': 'Trans-Video'
1161 'name': 'Trenton TV Cable Company'
1164 'name': 'Tri County Communications Cooperative'
1167 'name': 'TriCounty Telecom'
1170 'name': 'TrioTel Communications, Inc.'
1173 'name': 'Troy Cablevision, Inc.'
1179 'name': 'Tullahoma Utilities Board'
1182 'name': 'TV Cable of Rensselaer'
1191 'name': 'Twin Lakes'
1194 'name': 'Twin Valley'
1197 'name': 'Union Telephone Company'
1200 'name': 'United Communications - TN'
1203 'name': 'United Services'
1209 'name': 'USA Communications'
1212 'name': 'USA Communications/Shellsburg, IA'
1215 'name': 'Valley TeleCom Group'
1218 'name': 'Valley Telecommunications'
1221 'name': 'Valparaiso Broadband'
1224 'name': 'Vast Broadband'
1227 'name': 'Venture Communications Cooperative, Inc.'
1230 'name': 'Vernon Communications Co-op'
1232 'weh010-vicksburg': {
1233 'name': 'Vicksburg Video'
1236 'name': 'Vision Communications'
1239 'name': 'Volcano Vision, Inc.'
1242 'name': 'VolFirst / BLTV'
1251 'name': 'Vyve Broadband'
1254 'name': 'Wabash Mutual Telephone'
1257 'name': 'Waitsfield Cable'
1260 'name': 'Walnut Communications'
1266 'name': 'Waverly Communications Utility'
1272 'name': 'Webster-Calhoun Cooperative Telephone Association'
1275 'name': 'West Alabama TV Cable'
1278 'name': 'West Carolina Communications'
1281 'name': 'West Central Telephone Association'
1284 'name': 'West River Cooperative Telephone Company'
1287 'name': 'WesTel Systems'
1290 'name': 'Western Iowa Networks'
1293 'name': 'Whidbey Telecom'
1296 'name': 'White County Cable TV'
1305 'name': 'Wilkes Communications, Inc./RiverStreet Networks'
1308 'name': 'Wilson Communications'
1311 'name': 'Windomnet/SMBS'
1314 'name': 'Windstream Cable TV'
1317 'name': 'Winnebago Cooperative Telecom Association'
1323 'name': 'WTC Communications, Inc.'
1326 'name': 'Wyandotte Cable'
1329 'name': 'X-Stream Services'
1332 'name': 'XIT Communications'
1335 'name': 'Yelcot Communications'
1341 'name': 'Zito Media'
1345 'username_field': 'username',
1346 'password_field': 'password',
1351 class AdobePassIE(InfoExtractor
):
1352 _SERVICE_PROVIDER_TEMPLATE
= 'https://sp.auth.adobe.com/adobe-services/%s'
1353 _USER_AGENT
= 'Mozilla/5.0 (X11; Linux i686; rv:47.0) Gecko/20100101 Firefox/47.0'
1354 _MVPD_CACHE
= 'ap-mvpd'
1356 _DOWNLOADING_LOGIN_PAGE
= 'Downloading Provider Login Page'
1358 def _download_webpage_handle(self
, *args
, **kwargs
):
1359 headers
= self
.geo_verification_headers()
1360 headers
.update(kwargs
.get('headers', {}))
1361 kwargs
['headers'] = headers
1362 return super(AdobePassIE
, self
)._download
_webpage
_handle
(
1363 *args
, **compat_kwargs(kwargs
))
1366 def _get_mvpd_resource(provider_id
, title
, guid
, rating
):
1367 channel
= etree
.Element('channel')
1368 channel_title
= etree
.SubElement(channel
, 'title')
1369 channel_title
.text
= provider_id
1370 item
= etree
.SubElement(channel
, 'item')
1371 resource_title
= etree
.SubElement(item
, 'title')
1372 resource_title
.text
= title
1373 resource_guid
= etree
.SubElement(item
, 'guid')
1374 resource_guid
.text
= guid
1375 resource_rating
= etree
.SubElement(item
, 'media:rating')
1376 resource_rating
.attrib
= {'scheme': 'urn:v-chip'}
1377 resource_rating
.text
= rating
1378 return '<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/">' + etree
.tostring(channel
).decode() + '</rss>'
1380 def _extract_mvpd_auth(self
, url
, video_id
, requestor_id
, resource
):
1381 def xml_text(xml_str
, tag
):
1382 return self
._search
_regex
(
1383 '<%s>(.+?)</%s>' % (tag
, tag
), xml_str
, tag
)
1385 def is_expired(token
, date_ele
):
1386 token_expires
= unified_timestamp(re
.sub(r
'[_ ]GMT', '', xml_text(token
, date_ele
)))
1387 return token_expires
and token_expires
<= int(time
.time())
1389 def post_form(form_page_res
, note
, data
={}):
1390 form_page
, urlh
= form_page_res
1391 post_url
= self
._html
_search
_regex
(r
'<form[^>]+action=(["\'])(?P
<url
>.+?
)\
1', form_page, 'post url
', group='url
')
1392 if not re.match(r'https?
://', post_url):
1393 post_url = compat_urlparse.urljoin(urlh.geturl(), post_url)
1394 form_data = self._hidden_inputs(form_page)
1395 form_data.update(data)
1396 return self._download_webpage_handle(
1397 post_url, video_id, note, data=urlencode_postdata(form_data), headers={
1398 'Content
-Type
': 'application
/x
-www
-form
-urlencoded
',
1401 def raise_mvpd_required():
1402 raise ExtractorError(
1403 'This video
is only available
for users of participating TV providers
. '
1404 'Use
--ap
-mso to specify Adobe Pass Multiple
-system operator Identifier
'
1405 'and --ap
-username
and --ap
-password
or --netrc to provide account credentials
.', expected=True)
1407 def extract_redirect_url(html, url=None, fatal=False):
1408 # TODO: eliminate code duplication with generic extractor and move
1409 # redirection code into _download_webpage_handle
1410 REDIRECT_REGEX = r'[0-9]{,2}
;\s
*(?
:URL|url
)=\'?
([^
\'"]+)'
1411 redirect_url = self._search_regex(
1412 r'(?i)<meta\s+(?=(?:[a-z-]+="[^
"]+"\s
+)*http
-equiv
="refresh")'
1413 r'(?
:[a
-z
-]+="[^"]+"\s+)*?content="%s' % REDIRECT_REGEX,
1414 html, 'meta refresh redirect
',
1415 default=NO_DEFAULT if fatal else None, fatal=fatal)
1416 if not redirect_url:
1419 redirect_url = compat_urlparse.urljoin(url, unescapeHTML(redirect_url))
1423 'ap_42
': 'anonymous
',
1424 'ap_11
': 'Linux i686
',
1425 'ap_z
': self._USER_AGENT,
1426 'User
-Agent
': self._USER_AGENT,
1429 guid = xml_text(resource, 'guid
') if '<' in resource else resource
1432 requestor_info = self._downloader.cache.load(self._MVPD_CACHE, requestor_id) or {}
1433 authn_token = requestor_info.get('authn_token
')
1434 if authn_token and is_expired(authn_token, 'simpleTokenExpires
'):
1437 # TODO add support for other TV Providers
1438 mso_id = self.get_param('ap_mso
')
1440 raise_mvpd_required()
1441 username, password = self._get_login_info('ap_username
', 'ap_password
', mso_id)
1442 if not username or not password:
1443 raise_mvpd_required()
1444 mso_info = MSO_INFO[mso_id]
1446 provider_redirect_page_res = self._download_webpage_handle(
1447 self._SERVICE_PROVIDER_TEMPLATE % 'authenticate
/saml
', video_id,
1448 'Downloading Provider Redirect Page
', query={
1451 'requestor_id
': requestor_id,
1452 'no_iframe
': 'false
',
1453 'domain_name
': 'adobe
.com
',
1454 'redirect_url
': url,
1457 if mso_id == 'Comcast_SSO
':
1458 # Comcast page flow varies by video site and whether you
1459 # are on Comcast's network
.
1460 provider_redirect_page
, urlh
= provider_redirect_page_res
1461 if 'automatically signing you in' in provider_redirect_page
:
1462 oauth_redirect_url
= self
._html
_search
_regex
(
1463 r
'window\.location\s*=\s*[\'"]([^\'"]+)',
1464 provider_redirect_page, 'oauth redirect
')
1465 self._download_webpage(
1466 oauth_redirect_url, video_id, 'Confirming auto login
')
1467 elif 'automatically signed
in with' in provider_redirect_page:
1468 # Seems like comcast is rolling up new way of automatically signing customers
1469 oauth_redirect_url = self._html_search_regex(
1470 r'continue:\s
*"(https://oauth.xfinity.com/oauth/authorize\?.+)"', provider_redirect_page,
1471 'oauth
redirect (signed
)')
1472 # Just need to process the request. No useful data comes back
1473 self._download_webpage(oauth_redirect_url, video_id, 'Confirming auto login
')
1475 if '<form name
="signin"' in provider_redirect_page:
1476 provider_login_page_res = provider_redirect_page_res
1477 elif 'http
-equiv
="refresh"' in provider_redirect_page:
1478 oauth_redirect_url = extract_redirect_url(
1479 provider_redirect_page, fatal=True)
1480 provider_login_page_res = self._download_webpage_handle(
1481 oauth_redirect_url, video_id,
1482 self._DOWNLOADING_LOGIN_PAGE)
1484 provider_login_page_res = post_form(
1485 provider_redirect_page_res,
1486 self._DOWNLOADING_LOGIN_PAGE)
1488 mvpd_confirm_page_res = post_form(
1489 provider_login_page_res, 'Logging
in', {
1490 mso_info['username_field
']: username,
1491 mso_info['password_field
']: password,
1493 mvpd_confirm_page, urlh = mvpd_confirm_page_res
1494 if '<button
class="submit" value
="Resume">Resume
</button
>' in mvpd_confirm_page:
1495 post_form(mvpd_confirm_page_res, 'Confirming Login
')
1496 elif mso_id == 'Philo
':
1497 # Philo has very unique authentication method
1498 self._download_webpage(
1499 'https
://idp
.philo
.com
/auth
/init
/login_code
', video_id, 'Requesting auth code
', data=urlencode_postdata({
1502 'send_confirm_link
': False,
1505 philo_code = compat_getpass('Type auth code you have received
[Return
]: ')
1506 self._download_webpage(
1507 'https
://idp
.philo
.com
/auth
/update
/login_code
', video_id, 'Submitting token
', data=urlencode_postdata({
1510 mvpd_confirm_page_res = self._download_webpage_handle('https
://idp
.philo
.com
/idp
/submit
', video_id, 'Confirming Philo Login
')
1511 post_form(mvpd_confirm_page_res, 'Confirming Login
')
1512 elif mso_id == 'Verizon
':
1513 # In general, if you're connecting
from a Verizon
-assigned IP
,
1514 # you will not actually pass your credentials.
1515 provider_redirect_page
, urlh
= provider_redirect_page_res
1516 # From non-Verizon IP, still gave 'Please wait', but noticed N==Y; will need to try on Verizon IP
1517 if 'Please wait ...' in provider_redirect_page
and '\'N\'== "Y"' not in provider_redirect_page
:
1518 saml_redirect_url
= self
._html
_search
_regex
(
1519 r
'self\.parent\.location=(["\'])(?P
<url
>.+?
)\
1',
1520 provider_redirect_page,
1521 'SAML Redirect URL
', group='url
')
1522 saml_login_page = self._download_webpage(
1523 saml_redirect_url, video_id,
1524 'Downloading SAML Login Page
')
1525 elif 'Verizon FiOS
- sign
in' in provider_redirect_page:
1526 # FXNetworks from non-Verizon IP
1527 saml_login_page_res = post_form(
1528 provider_redirect_page_res, 'Logging
in', {
1529 mso_info['username_field
']: username,
1530 mso_info['password_field
']: password,
1532 saml_login_page, urlh = saml_login_page_res
1533 if 'Please
try again
.' in saml_login_page:
1534 raise ExtractorError(
1535 'We
\'re sorry
, but either the User ID
or Password entered
is not correct
.')
1537 # ABC from non-Verizon IP
1538 saml_redirect_url = self._html_search_regex(
1539 r'var\surl\s
*=\s
*(["\'])(?P<url>.+?)\1',
1540 provider_redirect_page,
1541 'SAML Redirect URL', group='url')
1542 saml_redirect_url = saml_redirect_url.replace(r'\/', '/')
1543 saml_redirect_url = saml_redirect_url.replace(r'\-', '-')
1544 saml_redirect_url = saml_redirect_url.replace(r'\x26', '&')
1545 saml_login_page = self._download_webpage(
1546 saml_redirect_url, video_id,
1547 'Downloading SAML Login Page')
1548 saml_login_page, urlh = post_form(
1549 [saml_login_page, saml_redirect_url], 'Logging in', {
1550 mso_info['username_field']: username,
1551 mso_info['password_field']: password,
1553 if 'Please try again.' in saml_login_page:
1554 raise ExtractorError(
1555 'Failed to login, incorrect User ID or Password.')
1556 saml_login_url = self._search_regex(
1557 r'xmlHttp\.open\("POST
"\s*,\s*(["\'])(?P
<url
>.+?
)\
1',
1558 saml_login_page, 'SAML Login URL
', group='url
')
1559 saml_response_json = self._download_json(
1560 saml_login_url, video_id, 'Downloading SAML Response
',
1561 headers={'Content-Type': 'text/xml'})
1562 self._download_webpage(
1563 saml_response_json['targetValue
'], video_id,
1564 'Confirming Login
', data=urlencode_postdata({
1565 'SAMLResponse
': saml_response_json['SAMLResponse
'],
1566 'RelayState
': saml_response_json['RelayState
']
1568 'Content
-Type
': 'application
/x
-www
-form
-urlencoded
'
1570 elif mso_id == 'Spectrum
':
1571 # Spectrum's login
for is dynamically loaded via JS so we need to hardcode the flow
1572 # as a one-off implementation.
1573 provider_redirect_page
, urlh
= provider_redirect_page_res
1574 provider_login_page_res
= post_form(
1575 provider_redirect_page_res
, self
._DOWNLOADING
_LOGIN
_PAGE
)
1576 saml_login_page
, urlh
= provider_login_page_res
1577 relay_state
= self
._search
_regex
(
1578 r
'RelayState\s*=\s*"(?P<relay>.+?)";',
1579 saml_login_page
, 'RelayState', group
='relay')
1580 saml_request
= self
._search
_regex
(
1581 r
'SAMLRequest\s*=\s*"(?P<saml_request>.+?)";',
1582 saml_login_page
, 'SAMLRequest', group
='saml_request')
1584 mso_info
['username_field']: username
,
1585 mso_info
['password_field']: password
,
1586 'RelayState': relay_state
,
1587 'SAMLRequest': saml_request
,
1589 saml_response_json
= self
._download
_json
(
1590 'https://tveauthn.spectrum.net/tveauthentication/api/v1/manualAuth', video_id
,
1591 'Downloading SAML Response',
1592 data
=json
.dumps(login_json
).encode(),
1594 'Content-Type': 'application/json',
1595 'Accept': 'application/json',
1597 self
._download
_webpage
(
1598 saml_response_json
['SAMLRedirectUri'], video_id
,
1599 'Confirming Login', data
=urlencode_postdata({
1600 'SAMLResponse': saml_response_json
['SAMLResponse'],
1601 'RelayState': relay_state
,
1603 'Content-Type': 'application/x-www-form-urlencoded'
1605 elif mso_id
== 'slingtv':
1606 # SlingTV has a meta-refresh based authentication, but also
1607 # looks at the tab history to count the number of times the
1608 # browser has been on a page
1610 first_bookend_page
, urlh
= provider_redirect_page_res
1612 hidden_data
= self
._hidden
_inputs
(first_bookend_page
)
1613 hidden_data
['history'] = 1
1615 provider_login_page_res
= self
._download
_webpage
_handle
(
1616 urlh
.geturl(), video_id
, 'Sending first bookend',
1619 provider_association_redirect
, urlh
= post_form(
1620 provider_login_page_res
, 'Logging in', {
1621 mso_info
['username_field']: username
,
1622 mso_info
['password_field']: password
1625 provider_refresh_redirect_url
= extract_redirect_url(
1626 provider_association_redirect
, url
=urlh
.geturl())
1628 last_bookend_page
, urlh
= self
._download
_webpage
_handle
(
1629 provider_refresh_redirect_url
, video_id
,
1630 'Downloading Auth Association Redirect Page')
1631 hidden_data
= self
._hidden
_inputs
(last_bookend_page
)
1632 hidden_data
['history'] = 3
1634 mvpd_confirm_page_res
= self
._download
_webpage
_handle
(
1635 urlh
.geturl(), video_id
, 'Sending final bookend',
1638 post_form(mvpd_confirm_page_res
, 'Confirming Login')
1640 # Some providers (e.g. DIRECTV NOW) have another meta refresh
1641 # based redirect that should be followed.
1642 provider_redirect_page
, urlh
= provider_redirect_page_res
1643 provider_refresh_redirect_url
= extract_redirect_url(
1644 provider_redirect_page
, url
=urlh
.geturl())
1645 if provider_refresh_redirect_url
:
1646 provider_redirect_page_res
= self
._download
_webpage
_handle
(
1647 provider_refresh_redirect_url
, video_id
,
1648 'Downloading Provider Redirect Page (meta refresh)')
1649 provider_login_page_res
= post_form(
1650 provider_redirect_page_res
, self
._DOWNLOADING
_LOGIN
_PAGE
)
1652 mso_info
.get('username_field', 'username'): username
,
1653 mso_info
.get('password_field', 'password'): password
1655 if mso_id
== 'Cablevision':
1656 form_data
['_eventId_proceed'] = ''
1657 mvpd_confirm_page_res
= post_form(provider_login_page_res
, 'Logging in', form_data
)
1658 if mso_id
!= 'Rogers':
1659 post_form(mvpd_confirm_page_res
, 'Confirming Login')
1661 session
= self
._download
_webpage
(
1662 self
._SERVICE
_PROVIDER
_TEMPLATE
% 'session', video_id
,
1663 'Retrieving Session', data
=urlencode_postdata({
1665 'requestor_id': requestor_id
,
1666 }), headers
=mvpd_headers
)
1667 if '<pendingLogout' in session
:
1668 self
._downloader
.cache
.store(self
._MVPD
_CACHE
, requestor_id
, {})
1671 authn_token
= unescapeHTML(xml_text(session
, 'authnToken'))
1672 requestor_info
['authn_token'] = authn_token
1673 self
._downloader
.cache
.store(self
._MVPD
_CACHE
, requestor_id
, requestor_info
)
1675 authz_token
= requestor_info
.get(guid
)
1676 if authz_token
and is_expired(authz_token
, 'simpleTokenTTL'):
1679 authorize
= self
._download
_webpage
(
1680 self
._SERVICE
_PROVIDER
_TEMPLATE
% 'authorize', video_id
,
1681 'Retrieving Authorization Token', data
=urlencode_postdata({
1682 'resource_id': resource
,
1683 'requestor_id': requestor_id
,
1684 'authentication_token': authn_token
,
1685 'mso_id': xml_text(authn_token
, 'simpleTokenMsoID'),
1687 }), headers
=mvpd_headers
)
1688 if '<pendingLogout' in authorize
:
1689 self
._downloader
.cache
.store(self
._MVPD
_CACHE
, requestor_id
, {})
1692 if '<error' in authorize
:
1693 raise ExtractorError(xml_text(authorize
, 'details'), expected
=True)
1694 authz_token
= unescapeHTML(xml_text(authorize
, 'authzToken'))
1695 requestor_info
[guid
] = authz_token
1696 self
._downloader
.cache
.store(self
._MVPD
_CACHE
, requestor_id
, requestor_info
)
1698 mvpd_headers
.update({
1699 'ap_19': xml_text(authn_token
, 'simpleSamlNameID'),
1700 'ap_23': xml_text(authn_token
, 'simpleSamlSessionIndex'),
1703 short_authorize
= self
._download
_webpage
(
1704 self
._SERVICE
_PROVIDER
_TEMPLATE
% 'shortAuthorize',
1705 video_id
, 'Retrieving Media Token', data
=urlencode_postdata({
1706 'authz_token': authz_token
,
1707 'requestor_id': requestor_id
,
1708 'session_guid': xml_text(authn_token
, 'simpleTokenAuthenticationGuid'),
1709 'hashed_guid': 'false',
1710 }), headers
=mvpd_headers
)
1711 if '<pendingLogout' in short_authorize
:
1712 self
._downloader
.cache
.store(self
._MVPD
_CACHE
, requestor_id
, {})
1715 return short_authorize