2 from __future__ 
import unicode_literals
 
   6 import xml
.etree
.ElementTree 
as etree
 
   8 from .common 
import InfoExtractor
 
   9 from ..compat 
import compat_urlparse
 
  21         'username_field': 'username', 
  22         'password_field': 'password', 
  26         'username_field': 'UserName', 
  27         'password_field': 'UserPassword', 
  30         'name': 'Comcast XFINITY', 
  31         'username_field': 'user', 
  32         'password_field': 'passwd', 
  35         'name': '3 Rivers Communications' 
  38         'name': 'Access Montana' 
  40     'acecommunications': { 
  44         'name': 'Acme Communications' 
  47         'name': 'Adams Cable Service' 
  50         'name': 'Albany Mutual Telephone' 
  53         'name': 'Algona Municipal Utilities' 
  56         'name': 'All West Communications' 
  59         'name': 'Allen\'s Communications' 
  62         'name': 'Alliance Communications' 
  65         'name': 'ALLO Communications' 
  68         'name': 'Alpine Communications' 
  71         'name': 'American Broadband' 
  74         'name': 'American Broadband Missouri' 
  77         'name': 'American Community Networks' 
  80         'name': 'American Warrior Networks' 
  83         'name': 'Amherst Telephone/Tomorrow Valley' 
  89         'name': 'Arkwest Communications' 
  92         'name': 'Arthur Mutual Telephone Company' 
  98         'name': 'Ashland Home Net' 
 101         'name': 'Astound (now Wave)' 
 104         'name': 'ATC Broadband' 
 107         'name': 'ATC Communications' 
 110         'name': 'Ayersville Communications' 
 113         'name': 'Baldwin Lightstream' 
 119         'name': 'Bardstown Cable TV' 
 122         'name': 'Bay Country Communications' 
 125         'name': 'Beaver Creek Cooperative Telephone' 
 128         'name': 'Beaver Valley Cable' 
 131         'name': 'Bee Line Cable' 
 134         'name': 'Beehive Broadband' 
 140         'name': 'Bellevue Municipal Cable' 
 143         'name': 'Ben Lomand Connect / BLTV' 
 149         'name': 'Big Sandy Broadband' 
 152         'name': 'Bledsoe Telephone Cooperative' 
 155         'name': 'Blue Valley Tele-Communications' 
 158         'name': 'Brandenburg Telephone Co.' 
 161         'name': 'Bristol Tennessee Essential Services' 
 164         'name': 'Broadstripe' 
 167         'name': 'BTC Communications' 
 170         'name': 'BTC Vision - Nahunta' 
 173         'name': 'Bulloch Telephone Cooperative' 
 176         'name': 'Butler-Bremer Communications' 
 179         'name': 'C Spire SNAP' 
 182         'name': 'Cable Services Inc.' 
 185         'name': 'CableAmerica' 
 188         'name': 'CableSouth Media 3' 
 191         'name': 'Cam-Tel Company' 
 194         'name': 'Cameron Communications' 
 197         'name': 'Canby Telcom' 
 203         'name': 'Carnegie Cable' 
 212         'name': 'Catalina Broadband Solutions' 
 215         'name': 'CC Communications' 
 218         'name': 'CDE Lightband' 
 221         'name': 'Cedar Falls Utilities' 
 224         'name': 'Celect-Bloomer Telephone Area' 
 227         'name': 'Celect-Bruce Telephone Area' 
 230         'name': 'Celect-Citizens Connected Area' 
 233         'name': 'Celect-Elmwood/Spring Valley Area' 
 236         'name': 'Celect-Mosaic Telecom' 
 239         'name': 'Celect-West WI Telephone Area' 
 242         'name': 'Cellcom/Nsight Telservices' 
 248         'name': 'Central Scott / CSTV' 
 251         'name': 'Chaparral CableVision' 
 254         'name': 'Chariton Valley Communication Corporation, Inc.' 
 257         'name': 'Chatmoss Cablevision' 
 260         'name': 'Cherokee Communications' 
 263         'name': 'Chesapeake Bay Communications' 
 266         'name': 'Cim-Tel Cable, LLC.' 
 269         'name': 'Citizens Cablevision - Floyd, VA' 
 272         'name': 'Citizens Cablevision, Inc.' 
 275         'name': 'Citizens Fiber' 
 278         'name': 'Citizens Mutual' 
 281         'name': 'Citizens Telephone Corporation' 
 284         'name': 'City Of Monroe' 
 293         'name': 'Clarence Telephone and Cedar Communications' 
 296         'name': 'Clear Choice Communications' 
 299         'name': 'Click! Cable TV' 
 305         'name': 'CML Telephone Cooperative Association' 
 311         'name': 'Co-Mo Connect' 
 314         'name': 'Coast Communications' 
 317         'name': 'Coaxial Cable TV' 
 320         'name': 'Cobalt TV (Mid-State Community TV)' 
 323         'name': 'Columbia Power & Water Systems' 
 326         'name': 'Columbus Telephone' 
 329         'name': 'Communications 1 Cablevision, Inc.' 
 332         'name': 'Community Cable & Broadband' 
 335         'name': 'Community Communications Company' 
 341         'name': 'Complete Communication Services' 
 347         'name': 'ComSouth Telesys' 
 349     'consolidatedcable': { 
 350         'name': 'Consolidated' 
 353         'name': 'Conway Corporation' 
 356         'name': 'Coon Valley Telecommunications Inc' 
 359         'name': 'Cooperative Telephone Company' 
 365         'name': 'Craw-Kan Telephone' 
 368         'name': 'Crestview Cable Communications' 
 374         'name': 'Crosslake Communications' 
 377         'name': 'CTC - Brainerd MN' 
 380         'name': 'CTV-Beam - East Alabama' 
 383         'name': 'Cunningham Telephone & Cable' 
 386         'name': 'D & P Communications' 
 389         'name': 'Dakota Central Telecommunications' 
 392         'name': 'Delcambre Telephone LLC' 
 395         'name': 'Delta Telephone Company' 
 401         'name': 'Direct Communications' 
 404         'name': 'Doylestown Cable TV' 
 413         'name': 'DTC Cable (Delhi)' 
 416         'name': 'Dumont Telephone Company' 
 419         'name': 'Dunkerton Telephone Cooperative' 
 422         'name': 'Duo County Telecom' 
 425         'name': 'Eagle Communications' 
 428         'name': 'East Arkansas Cable TV' 
 431         'name': 'EATEL Video, LLC' 
 437         'name': 'Emery Telcom Video LLC' 
 440         'name': 'Empire Access' 
 443         'name': 'Endeavor Communications' 
 446         'name': 'Enhanced Telecommunications Corporation' 
 452         'name': 'EPB Smartnet' 
 455         'name': 'EPlus Broadband' 
 461         'name': 'Etex Communications' 
 464         'name': 'F&B Communications' 
 467         'name': 'Falcon Broadband' 
 470         'name': 'FamilyView CableVision' 
 473         'name': 'Farmers Mutual Telephone Company' 
 476         'name': 'Fayetteville Public Utilities' 
 482         'name': 'Fidelity Communications' 
 485         'name': 'FJ Communications' 
 488         'name': 'Flint River Communications' 
 491         'name': 'FMT - Jesup' 
 494         'name': 'Foothills Communications' 
 497         'name': 'Forsyth CableNet' 
 500         'name': 'Frankfort Plant Board' 
 503         'name': 'Franklin Telephone Company' 
 509         'name': 'Full Channel, Inc.' 
 512         'name': 'Gardonville Cooperative Telephone Association' 
 515         'name': 'GBT Communications, Inc.' 
 518         'name': 'Genuine Telecom' 
 521         'name': 'Giant Communications' 
 524         'name': 'Glasgow EPB' 
 527         'name': 'Glenwood Telecommunications' 
 530         'name': 'GLW Broadband Inc.' 
 533         'name': 'Golden West Cablevision' 
 536         'name': 'Grantsburg Telcom' 
 539         'name': 'Great Plains Communications' 
 542         'name': 'Gridley Cable Inc' 
 545         'name': 'H&B Cable Services' 
 548         'name': 'Haefele TV Inc.' 
 551         'name': 'Halstad Telephone Company' 
 554         'name': 'Harlan Municipal Utilities' 
 557         'name': 'Hart Communications' 
 560         'name': 'Hartelco TV' 
 563         'name': 'Heart of Iowa Communications Cooperative' 
 566         'name': 'Hickory Telephone Company' 
 569         'name': 'Highland Communication Services' 
 572         'name': 'Highland Media' 
 575         'name': 'Hilliary Communications' 
 578         'name': 'Hinton CATV Co.' 
 581         'name': 'HomeTel Entertainment, Inc.' 
 584         'name': 'Hood Canal Communications' 
 587         'name': 'Hope - Prescott Cable TV' 
 590         'name': 'Horizon Cable TV, Inc.' 
 593         'name': 'Horizon Chillicothe Telephone' 
 596         'name': 'HTC Communications Co. - IL' 
 599         'name': 'HTC Communications, Inc. - IA' 
 602         'name': 'Huxley Communications' 
 605         'name': 'ImOn Communications' 
 608         'name': 'Independence Telecommunications' 
 611         'name': 'Inland Networks' 
 614         'name': 'Innovative Cable TV St Croix' 
 617         'name': 'Innovative Cable TV St Thomas-St John' 
 620         'name': 'Inside Connect Cable' 
 623         'name': 'Integra Telecom' 
 626         'name': 'Interstate Telecommunications Coop' 
 629         'name': 'Irvine Cable' 
 632         'name': 'K2 Communications' 
 635         'name': 'Kalida Telephone Company, Inc.' 
 638         'name': 'Kalona Cooperative Telephone Company' 
 644         'name': 'KPU Telecommunications' 
 647         'name': 'Kuhn Communications, Inc.' 
 650         'name': 'Lakeland Communications' 
 656         'name': 'Laurel Highland Total Communications, Inc.' 
 659         'name': 'Lehigh Valley Cooperative Telephone' 
 662         'name': 'Limestone Cable/Bracken Cable' 
 674         'name': 'LocalTel Communications' 
 677         'name': 'Longview - Kilgore Cable TV' 
 680         'name': 'Lonsdale Video Ventures, LLC' 
 683         'name': 'Lost Nation-Elwood Telephone Co.' 
 686         'name': 'LPC Connect' 
 689         'name': 'Lumos Networks' 
 692         'name': 'Madison Communications' 
 695         'name': 'Madison County Cable Inc.' 
 698         'name': 'Mahaska Communication Group' 
 701         'name': 'Marne & Elk Horn Telephone Company' 
 704         'name': 'McClure Telephone Co.' 
 710         'name': 'Merrimac Communications Ltd.' 
 719         'name': 'Mid-Hudson Cable' 
 722         'name': 'Mid-Rivers Communications' 
 725         'name': 'Midstate Communications' 
 728         'name': 'Milford Communications' 
 737         'name': 'Mitchell Telecom' 
 743         'name': 'Mon-Cre TVE' 
 746         'name': 'Mountain Telephone' 
 749         'name': 'Mountain Village Cable' 
 752         'name': 'MTA Communications, LLC' 
 758         'name': 'MTC Technologies' 
 764         'name': 'MTCO Communications' 
 767         'name': 'Mulberry Telecommunications' 
 770         'name': 'Murray Electric System' 
 773         'name': 'MUS FiberNET' 
 776         'name': 'Muscatine Power & Water' 
 788         'name': 'Nebraska Central Telecom, Inc.' 
 791         'name': 'Nelsonville TV Cable' 
 797         'name': 'New Hope Telephone Cooperative' 
 803         'name': 'NineStar Connect' 
 809         'name': 'Nortex Communications' 
 812         'name': 'North Central Telephone Cooperative' 
 815         'name': 'Northland Communications' 
 818         'name': 'Northwest Communications' 
 821         'name': 'Norwood Light Broadband' 
 824         'name': 'Nsight Telservices' 
 830         'name': 'NTS Communications' 
 842         'name': 'OmniTel Communications' 
 845         'name': 'OneSource Communications' 
 848         'name': 'Opelika Power Services' 
 857         'name': 'OTEC Communication Company' 
 860         'name': 'Packerland Broadband' 
 863         'name': 'Panora Telco/Guthrie Center Communications' 
 866         'name': 'Park Region Telephone & Otter Tail Telcom' 
 869         'name': 'Partner Communications Cooperative' 
 875         'name': 'Paul Bunyan Communications' 
 878         'name': 'Pembroke Telephone Company' 
 881         'name': 'Peoples Rural Telephone Cooperative' 
 884         'name': 'PES Energize' 
 887         'name': 'Philippi Communications System' 
 890         'name': 'Phonoscope Cable' 
 893         'name': 'Pine Belt Communications, Inc.' 
 896         'name': 'Pine Bluff Cable TV' 
 899         'name': 'Pineland Telephone Cooperative' 
 902         'name': 'Pinpoint Communications' 
 905         'name': 'Pioneer Broadband' 
 908         'name': 'Pioneer Communications' 
 911         'name': 'Pioneer DTV' 
 914         'name': 'Plant TiftNet, Inc.' 
 923         'name': 'Polar Cablevision' 
 926         'name': 'Pottawatomie Telephone Co.' 
 929         'name': 'Premier Communications' 
 941         'name': 'Quality Cablevision' 
 944         'name': 'Radcliffe Telephone Company' 
 947         'name': 'Rainbow Communications' 
 950         'name': 'Rainier Connect' 
 953         'name': 'Ralls Technologies' 
 956         'name': 'RC Technologies' 
 959         'name': 'Red River Communications' 
 962         'name': 'Reedsburg Utility Commission' 
 965         'name': 'Reliance Connects- Oregon' 
 968         'name': 'Reserve Telecommunications' 
 971         'name': 'Resort TV Cable' 
 974         'name': 'Richland Grant Telephone Cooperative, Inc.' 
 977         'name': 'River Valley Telecommunications Coop' 
 980         'name': 'Rock Port Cablevision' 
 986         'name': 'RTC Communication Corp' 
 989         'name': 'RTC-Reservation Telephone Coop.' 
 992         'name': 'RTEC Communications' 
 998         'name': 'San Bruno Cable TV' 
1004         'name': 'SCI Broadband-Savage Communications Inc.' 
1007         'name': 'Scottsboro Electric Power Board' 
1010         'name': 'Scranton Telephone Company' 
1019         'name': 'Sherwood Mutual Telephone Association, Inc.' 
1022         'name': 'Silver Star Communications' 
1025         'name': 'Sjoberg\'s Inc.' 
1031         'name': 'SkyBest TV' 
1034         'name': 'Smithville Communications' 
1040         'name': 'South Central Rural Telephone Cooperative' 
1043         'name': 'South Holt Cablevision, Inc.' 
1046         'name': 'South Slope Cooperative Communications' 
1049         'name': 'Spanish Fork Community Network' 
1052         'name': 'Spencer Municipal Utilities' 
1055         'name': 'Spillway Communications, Inc.' 
1061         'name': 'St. Maarten Cable TV' 
1064         'name': 'Star Communications' 
1070         'name': 'STRATA Networks' 
1073         'name': 'Sumner Cable TV' 
1076         'name': 'Surry TV/PCSI TV' 
1079         'name': 'Swayzee Communications' 
1082         'name': 'Sweetwater Cable Television Co' 
1084     'weh010-talequah': { 
1085         'name': 'Tahlequah Cable TV' 
1091         'name': 'Tele-Media Company' 
1094         'name': 'The Community Agency' 
1097         'name': 'Three River' 
1100         'name': 'Town & Country Technologies' 
1103         'name': 'Trans-Video' 
1106         'name': 'Trenton TV Cable Company' 
1109         'name': 'Tri County Communications Cooperative' 
1112         'name': 'TriCounty Telecom' 
1115         'name': 'TrioTel Communications, Inc.' 
1118         'name': 'Troy Cablevision, Inc.' 
1124         'name': 'Tullahoma Utilities Board' 
1127         'name': 'TV Cable of Rensselaer' 
1136         'name': 'Twin Lakes' 
1139         'name': 'Twin Valley' 
1142         'name': 'Union Telephone Company' 
1145         'name': 'United Communications - TN' 
1148         'name': 'United Services' 
1154         'name': 'USA Communications' 
1157         'name': 'USA Communications/Shellsburg, IA' 
1160         'name': 'Valley TeleCom Group' 
1163         'name': 'Valley Telecommunications' 
1166         'name': 'Valparaiso Broadband' 
1169         'name': 'Vast Broadband' 
1172         'name': 'Venture Communications Cooperative, Inc.' 
1175         'name': 'Vernon Communications Co-op' 
1177     'weh010-vicksburg': { 
1178         'name': 'Vicksburg Video' 
1181         'name': 'Vision Communications' 
1184         'name': 'Volcano Vision, Inc.' 
1187         'name': 'VolFirst / BLTV' 
1196         'name': 'Vyve Broadband' 
1199         'name': 'Wabash Mutual Telephone' 
1202         'name': 'Waitsfield Cable' 
1205         'name': 'Walnut Communications' 
1211         'name': 'Waverly Communications Utility' 
1217         'name': 'Webster-Calhoun Cooperative Telephone Association' 
1220         'name': 'West Alabama TV Cable' 
1223         'name': 'West Carolina Communications' 
1226         'name': 'West Central Telephone Association' 
1229         'name': 'West River Cooperative Telephone Company' 
1232         'name': 'WesTel Systems' 
1235         'name': 'Western Iowa Networks' 
1238         'name': 'Whidbey Telecom' 
1241         'name': 'White County Cable TV' 
1250         'name': 'Wilkes Communications, Inc./RiverStreet Networks' 
1253         'name': 'Wilson Communications' 
1256         'name': 'Windomnet/SMBS' 
1259         'name': 'Windstream Cable TV' 
1262         'name': 'Winnebago Cooperative Telecom Association' 
1268         'name': 'WTC Communications, Inc.' 
1271         'name': 'Wyandotte Cable' 
1274         'name': 'X-Stream Services' 
1277         'name': 'XIT Communications' 
1280         'name': 'Yelcot Communications' 
1286         'name': 'Zito Media' 
1291 class AdobePassIE(InfoExtractor
): 
1292     _SERVICE_PROVIDER_TEMPLATE 
= 'https://sp.auth.adobe.com/adobe-services/%s' 
1293     _USER_AGENT 
= 'Mozilla/5.0 (X11; Linux i686; rv:47.0) Gecko/20100101 Firefox/47.0' 
1294     _MVPD_CACHE 
= 'ap-mvpd' 
1297     def _get_mvpd_resource(provider_id
, title
, guid
, rating
): 
1298         channel 
= etree
.Element('channel') 
1299         channel_title 
= etree
.SubElement(channel
, 'title') 
1300         channel_title
.text 
= provider_id
 
1301         item 
= etree
.SubElement(channel
, 'item') 
1302         resource_title 
= etree
.SubElement(item
, 'title') 
1303         resource_title
.text 
= title
 
1304         resource_guid 
= etree
.SubElement(item
, 'guid') 
1305         resource_guid
.text 
= guid
 
1306         resource_rating 
= etree
.SubElement(item
, 'media:rating') 
1307         resource_rating
.attrib 
= {'scheme': 'urn:v-chip'} 
1308         resource_rating
.text 
= rating
 
1309         return '<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/">' + etree
.tostring(channel
).decode() + '</rss>' 
1311     def _extract_mvpd_auth(self
, url
, video_id
, requestor_id
, resource
): 
1312         def xml_text(xml_str
, tag
): 
1313             return self
._search
_regex
( 
1314                 '<%s>(.+?)</%s>' % (tag
, tag
), xml_str
, tag
) 
1316         def is_expired(token
, date_ele
): 
1317             token_expires 
= unified_timestamp(re
.sub(r
'[_ ]GMT', '', xml_text(token
, date_ele
))) 
1318             return token_expires 
and token_expires 
<= int(time
.time()) 
1320         def post_form(form_page_res
, note
, data
={}): 
1321             form_page
, urlh 
= form_page_res
 
1322             post_url 
= self
._html
_search
_regex
(r
'<form[^>]+action=(["\'])(?P
<url
>.+?
)\
1', form_page, 'post url
', group='url
') 
1323             if not re.match(r'https?
://', post_url): 
1324                 post_url = compat_urlparse.urljoin(urlh.geturl(), post_url) 
1325             form_data = self._hidden_inputs(form_page) 
1326             form_data.update(data) 
1327             return self._download_webpage_handle( 
1328                 post_url, video_id, note, data=urlencode_postdata(form_data), headers={ 
1329                     'Content
-Type
': 'application
/x
-www
-form
-urlencoded
', 
1332         def raise_mvpd_required(): 
1333             raise ExtractorError( 
1334                 'This video 
is only available 
for users of participating TV providers
. ' 
1335                 'Use 
--ap
-mso to specify Adobe Pass Multiple
-system operator Identifier 
' 
1336                 'and --ap
-username 
and --ap
-password 
or --netrc to provide account credentials
.', expected=True) 
1339             'ap_42
': 'anonymous
', 
1340             'ap_11
': 'Linux i686
', 
1341             'ap_z
': self._USER_AGENT, 
1342             'User
-Agent
': self._USER_AGENT, 
1345         guid = xml_text(resource, 'guid
') if '<' in resource else resource 
1348             requestor_info = self._downloader.cache.load(self._MVPD_CACHE, requestor_id) or {} 
1349             authn_token = requestor_info.get('authn_token
') 
1350             if authn_token and is_expired(authn_token, 'simpleTokenExpires
'): 
1353                 # TODO add support for other TV Providers 
1354                 mso_id = self._downloader.params.get('ap_mso
') 
1356                     raise_mvpd_required() 
1357                 username, password = self._get_login_info('ap_username
', 'ap_password
', mso_id) 
1358                 if not username or not password: 
1359                     raise_mvpd_required() 
1360                 mso_info = MSO_INFO[mso_id] 
1362                 provider_redirect_page_res = self._download_webpage_handle( 
1363                     self._SERVICE_PROVIDER_TEMPLATE % 'authenticate
/saml
', video_id, 
1364                     'Downloading Provider Redirect Page
', query={ 
1367                         'requestor_id
': requestor_id, 
1368                         'no_iframe
': 'false
', 
1369                         'domain_name
': 'adobe
.com
', 
1370                         'redirect_url
': url, 
1373                 if mso_id == 'Comcast_SSO
': 
1374                     # Comcast page flow varies by video site and whether you 
1375                     # are on Comcast's network
. 
1376                     provider_redirect_page
, urlh 
= provider_redirect_page_res
 
1377                     # Check for Comcast auto login 
1378                     if 'automatically signing you in' in provider_redirect_page
: 
1379                         oauth_redirect_url 
= self
._html
_search
_regex
( 
1380                             r
'window\.location\s*=\s*[\'"]([^\'"]+)', 
1381                             provider_redirect_page, 'oauth redirect
') 
1382                         # Just need to process the request. No useful data comes back 
1383                         self._download_webpage( 
1384                             oauth_redirect_url, video_id, 'Confirming auto login
') 
1386                         if '<form name
="signin"' in provider_redirect_page: 
1387                             # already have the form, just fill it 
1388                             provider_login_page_res = provider_redirect_page_res 
1389                         elif 'http
-equiv
="refresh"' in provider_redirect_page: 
1390                             # redirects to the login page 
1391                             oauth_redirect_url = self._html_search_regex( 
1392                                 r'content
="0;\s*url=([^\'"]+)', 
1393                                 provider_redirect_page, 'meta refresh redirect
') 
1394                             provider_login_page_res = self._download_webpage_handle( 
1396                                 video_id, 'Downloading Provider Login Page
') 
1398                             provider_login_page_res = post_form( 
1399                                 provider_redirect_page_res, 'Downloading Provider Login Page
') 
1401                         mvpd_confirm_page_res = post_form(provider_login_page_res, 'Logging 
in', { 
1402                             mso_info.get('username_field
', 'username
'): username, 
1403                             mso_info.get('password_field
', 'password
'): password, 
1405                         mvpd_confirm_page, urlh = mvpd_confirm_page_res 
1406                         if '<button 
class="submit" value
="Resume">Resume
</button
>' in mvpd_confirm_page: 
1407                             post_form(mvpd_confirm_page_res, 'Confirming Login
') 
1410                     # Normal, non-Comcast flow 
1411                     provider_login_page_res = post_form( 
1412                         provider_redirect_page_res, 'Downloading Provider Login Page
') 
1413                     mvpd_confirm_page_res = post_form(provider_login_page_res, 'Logging 
in', { 
1414                         mso_info.get('username_field
', 'username
'): username, 
1415                         mso_info.get('password_field
', 'password
'): password, 
1417                     if mso_id != 'Rogers
': 
1418                         post_form(mvpd_confirm_page_res, 'Confirming Login
') 
1420                 session = self._download_webpage( 
1421                     self._SERVICE_PROVIDER_TEMPLATE % 'session
', video_id, 
1422                     'Retrieving Session
', data=urlencode_postdata({ 
1424                         'requestor_id
': requestor_id, 
1425                     }), headers=mvpd_headers) 
1426                 if '<pendingLogout
' in session: 
1427                     self._downloader.cache.store(self._MVPD_CACHE, requestor_id, {}) 
1430                 authn_token = unescapeHTML(xml_text(session, 'authnToken
')) 
1431                 requestor_info['authn_token
'] = authn_token 
1432                 self._downloader.cache.store(self._MVPD_CACHE, requestor_id, requestor_info) 
1434             authz_token = requestor_info.get(guid) 
1435             if authz_token and is_expired(authz_token, 'simpleTokenTTL
'): 
1438                 authorize = self._download_webpage( 
1439                     self._SERVICE_PROVIDER_TEMPLATE % 'authorize
', video_id, 
1440                     'Retrieving Authorization Token
', data=urlencode_postdata({ 
1441                         'resource_id
': resource, 
1442                         'requestor_id
': requestor_id, 
1443                         'authentication_token
': authn_token, 
1444                         'mso_id
': xml_text(authn_token, 'simpleTokenMsoID
'), 
1446                     }), headers=mvpd_headers) 
1447                 if '<pendingLogout
' in authorize: 
1448                     self._downloader.cache.store(self._MVPD_CACHE, requestor_id, {}) 
1451                 authz_token = unescapeHTML(xml_text(authorize, 'authzToken
')) 
1452                 requestor_info[guid] = authz_token 
1453                 self._downloader.cache.store(self._MVPD_CACHE, requestor_id, requestor_info) 
1455             mvpd_headers.update({ 
1456                 'ap_19
': xml_text(authn_token, 'simpleSamlNameID
'), 
1457                 'ap_23
': xml_text(authn_token, 'simpleSamlSessionIndex
'), 
1460             short_authorize = self._download_webpage( 
1461                 self._SERVICE_PROVIDER_TEMPLATE % 'shortAuthorize
', 
1462                 video_id, 'Retrieving Media Token
', data=urlencode_postdata({ 
1463                     'authz_token
': authz_token, 
1464                     'requestor_id
': requestor_id, 
1465                     'session_guid
': xml_text(authn_token, 'simpleTokenAuthenticationGuid
'), 
1466                     'hashed_guid
': 'false
', 
1467                 }), headers=mvpd_headers) 
1468             if '<pendingLogout
' in short_authorize: 
1469                 self._downloader.cache.store(self._MVPD_CACHE, requestor_id, {}) 
1472             return short_authorize