Merge pull request #10819 from raleeper/adobepass
[youtube-dl] / youtube_dl / extractor / adobepass.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5 import time
6 import xml.etree.ElementTree as etree
7
8 from .common import InfoExtractor
9 from ..compat import compat_urlparse
10 from ..utils import (
11     unescapeHTML,
12     urlencode_postdata,
13     unified_timestamp,
14     ExtractorError,
15 )
16
17
18 MSO_INFO = {
19     'DTV': {
20         'name': 'DIRECTV',
21         'username_field': 'username',
22         'password_field': 'password',
23     },
24     'Rogers': {
25         'name': 'Rogers',
26         'username_field': 'UserName',
27         'password_field': 'UserPassword',
28     },
29     'Comcast_SSO': {
30         'name': 'Comcast XFINITY',
31         'username_field': 'user',
32         'password_field': 'passwd',
33     },
34     'thr030': {
35         'name': '3 Rivers Communications'
36     },
37     'com140': {
38         'name': 'Access Montana'
39     },
40     'acecommunications': {
41         'name': 'AcenTek'
42     },
43     'acm010': {
44         'name': 'Acme Communications'
45     },
46     'ada020': {
47         'name': 'Adams Cable Service'
48     },
49     'alb020': {
50         'name': 'Albany Mutual Telephone'
51     },
52     'algona': {
53         'name': 'Algona Municipal Utilities'
54     },
55     'allwest': {
56         'name': 'All West Communications'
57     },
58     'all025': {
59         'name': 'Allen\'s Communications'
60     },
61     'spl010': {
62         'name': 'Alliance Communications'
63     },
64     'all070': {
65         'name': 'ALLO Communications'
66     },
67     'alpine': {
68         'name': 'Alpine Communications'
69     },
70     'hun015': {
71         'name': 'American Broadband'
72     },
73     'nwc010': {
74         'name': 'American Broadband Missouri'
75     },
76     'com130-02': {
77         'name': 'American Community Networks'
78     },
79     'com130-01': {
80         'name': 'American Warrior Networks'
81     },
82     'tom020': {
83         'name': 'Amherst Telephone/Tomorrow Valley'
84     },
85     'tvc020': {
86         'name': 'Andycable'
87     },
88     'arkwest': {
89         'name': 'Arkwest Communications'
90     },
91     'art030': {
92         'name': 'Arthur Mutual Telephone Company'
93     },
94     'arvig': {
95         'name': 'Arvig'
96     },
97     'nttcash010': {
98         'name': 'Ashland Home Net'
99     },
100     'astound': {
101         'name': 'Astound (now Wave)'
102     },
103     'dix030': {
104         'name': 'ATC Broadband'
105     },
106     'ara010': {
107         'name': 'ATC Communications'
108     },
109     'she030-02': {
110         'name': 'Ayersville Communications'
111     },
112     'baldwin': {
113         'name': 'Baldwin Lightstream'
114     },
115     'bal040': {
116         'name': 'Ballard TV'
117     },
118     'cit025': {
119         'name': 'Bardstown Cable TV'
120     },
121     'bay030': {
122         'name': 'Bay Country Communications'
123     },
124     'tel095': {
125         'name': 'Beaver Creek Cooperative Telephone'
126     },
127     'bea020': {
128         'name': 'Beaver Valley Cable'
129     },
130     'bee010': {
131         'name': 'Bee Line Cable'
132     },
133     'wir030': {
134         'name': 'Beehive Broadband'
135     },
136     'bra020': {
137         'name': 'BELD'
138     },
139     'bel020': {
140         'name': 'Bellevue Municipal Cable'
141     },
142     'vol040-01': {
143         'name': 'Ben Lomand Connect / BLTV'
144     },
145     'bev010': {
146         'name': 'BEVCOMM'
147     },
148     'big020': {
149         'name': 'Big Sandy Broadband'
150     },
151     'ble020': {
152         'name': 'Bledsoe Telephone Cooperative'
153     },
154     'bvt010': {
155         'name': 'Blue Valley Tele-Communications'
156     },
157     'bra050': {
158         'name': 'Brandenburg Telephone Co.'
159     },
160     'bte010': {
161         'name': 'Bristol Tennessee Essential Services'
162     },
163     'annearundel': {
164         'name': 'Broadstripe'
165     },
166     'btc010': {
167         'name': 'BTC Communications'
168     },
169     'btc040': {
170         'name': 'BTC Vision - Nahunta'
171     },
172     'bul010': {
173         'name': 'Bulloch Telephone Cooperative'
174     },
175     'but010': {
176         'name': 'Butler-Bremer Communications'
177     },
178     'tel160-csp': {
179         'name': 'C Spire SNAP'
180     },
181     'csicable': {
182         'name': 'Cable Services Inc.'
183     },
184     'cableamerica': {
185         'name': 'CableAmerica'
186     },
187     'cab038': {
188         'name': 'CableSouth Media 3'
189     },
190     'weh010-camtel': {
191         'name': 'Cam-Tel Company'
192     },
193     'car030': {
194         'name': 'Cameron Communications'
195     },
196     'canbytel': {
197         'name': 'Canby Telcom'
198     },
199     'crt020': {
200         'name': 'CapRock Tv'
201     },
202     'car050': {
203         'name': 'Carnegie Cable'
204     },
205     'cas': {
206         'name': 'CAS Cable'
207     },
208     'casscomm': {
209         'name': 'CASSCOMM'
210     },
211     'mid180-02': {
212         'name': 'Catalina Broadband Solutions'
213     },
214     'cccomm': {
215         'name': 'CC Communications'
216     },
217     'nttccde010': {
218         'name': 'CDE Lightband'
219     },
220     'cfunet': {
221         'name': 'Cedar Falls Utilities'
222     },
223     'dem010-01': {
224         'name': 'Celect-Bloomer Telephone Area'
225     },
226     'dem010-02': {
227         'name': 'Celect-Bruce Telephone Area'
228     },
229     'dem010-03': {
230         'name': 'Celect-Citizens Connected Area'
231     },
232     'dem010-04': {
233         'name': 'Celect-Elmwood/Spring Valley Area'
234     },
235     'dem010-06': {
236         'name': 'Celect-Mosaic Telecom'
237     },
238     'dem010-05': {
239         'name': 'Celect-West WI Telephone Area'
240     },
241     'net010-02': {
242         'name': 'Cellcom/Nsight Telservices'
243     },
244     'cen100': {
245         'name': 'CentraCom'
246     },
247     'nttccst010': {
248         'name': 'Central Scott / CSTV'
249     },
250     'cha035': {
251         'name': 'Chaparral CableVision'
252     },
253     'cha050': {
254         'name': 'Chariton Valley Communication Corporation, Inc.'
255     },
256     'cha060': {
257         'name': 'Chatmoss Cablevision'
258     },
259     'nttcche010': {
260         'name': 'Cherokee Communications'
261     },
262     'che050': {
263         'name': 'Chesapeake Bay Communications'
264     },
265     'cimtel': {
266         'name': 'Cim-Tel Cable, LLC.'
267     },
268     'cit180': {
269         'name': 'Citizens Cablevision - Floyd, VA'
270     },
271     'cit210': {
272         'name': 'Citizens Cablevision, Inc.'
273     },
274     'cit040': {
275         'name': 'Citizens Fiber'
276     },
277     'cit250': {
278         'name': 'Citizens Mutual'
279     },
280     'war040': {
281         'name': 'Citizens Telephone Corporation'
282     },
283     'wat025': {
284         'name': 'City Of Monroe'
285     },
286     'wadsworth': {
287         'name': 'CityLink'
288     },
289     'nor100': {
290         'name': 'CL Tel'
291     },
292     'cla010': {
293         'name': 'Clarence Telephone and Cedar Communications'
294     },
295     'ser060': {
296         'name': 'Clear Choice Communications'
297     },
298     'tac020': {
299         'name': 'Click! Cable TV'
300     },
301     'war020': {
302         'name': 'CLICK1.NET'
303     },
304     'cml010': {
305         'name': 'CML Telephone Cooperative Association'
306     },
307     'cns': {
308         'name': 'CNS'
309     },
310     'com160': {
311         'name': 'Co-Mo Connect'
312     },
313     'coa020': {
314         'name': 'Coast Communications'
315     },
316     'coa030': {
317         'name': 'Coaxial Cable TV'
318     },
319     'mid055': {
320         'name': 'Cobalt TV (Mid-State Community TV)'
321     },
322     'col070': {
323         'name': 'Columbia Power & Water Systems'
324     },
325     'col080': {
326         'name': 'Columbus Telephone'
327     },
328     'nor105': {
329         'name': 'Communications 1 Cablevision, Inc.'
330     },
331     'com150': {
332         'name': 'Community Cable & Broadband'
333     },
334     'com020': {
335         'name': 'Community Communications Company'
336     },
337     'coy010': {
338         'name': 'commZoom'
339     },
340     'com025': {
341         'name': 'Complete Communication Services'
342     },
343     'cat020': {
344         'name': 'Comporium'
345     },
346     'com071': {
347         'name': 'ComSouth Telesys'
348     },
349     'consolidatedcable': {
350         'name': 'Consolidated'
351     },
352     'conwaycorp': {
353         'name': 'Conway Corporation'
354     },
355     'coo050': {
356         'name': 'Coon Valley Telecommunications Inc'
357     },
358     'coo080': {
359         'name': 'Cooperative Telephone Company'
360     },
361     'cpt010': {
362         'name': 'CP-TEL'
363     },
364     'cra010': {
365         'name': 'Craw-Kan Telephone'
366     },
367     'crestview': {
368         'name': 'Crestview Cable Communications'
369     },
370     'cross': {
371         'name': 'Cross TV'
372     },
373     'cro030': {
374         'name': 'Crosslake Communications'
375     },
376     'ctc040': {
377         'name': 'CTC - Brainerd MN'
378     },
379     'phe030': {
380         'name': 'CTV-Beam - East Alabama'
381     },
382     'cun010': {
383         'name': 'Cunningham Telephone & Cable'
384     },
385     'dpc010': {
386         'name': 'D & P Communications'
387     },
388     'dak030': {
389         'name': 'Dakota Central Telecommunications'
390     },
391     'nttcdel010': {
392         'name': 'Delcambre Telephone LLC'
393     },
394     'tel160-del': {
395         'name': 'Delta Telephone Company'
396     },
397     'sal040': {
398         'name': 'DiamondNet'
399     },
400     'ind060-dc': {
401         'name': 'Direct Communications'
402     },
403     'doy010': {
404         'name': 'Doylestown Cable TV'
405     },
406     'dic010': {
407         'name': 'DRN'
408     },
409     'dtc020': {
410         'name': 'DTC'
411     },
412     'dtc010': {
413         'name': 'DTC Cable (Delhi)'
414     },
415     'dum010': {
416         'name': 'Dumont Telephone Company'
417     },
418     'dun010': {
419         'name': 'Dunkerton Telephone Cooperative'
420     },
421     'cci010': {
422         'name': 'Duo County Telecom'
423     },
424     'eagle': {
425         'name': 'Eagle Communications'
426     },
427     'weh010-east': {
428         'name': 'East Arkansas Cable TV'
429     },
430     'eatel': {
431         'name': 'EATEL Video, LLC'
432     },
433     'ell010': {
434         'name': 'ECTA'
435     },
436     'emerytelcom': {
437         'name': 'Emery Telcom Video LLC'
438     },
439     'nor200': {
440         'name': 'Empire Access'
441     },
442     'endeavor': {
443         'name': 'Endeavor Communications'
444     },
445     'sun045': {
446         'name': 'Enhanced Telecommunications Corporation'
447     },
448     'mid030': {
449         'name': 'enTouch'
450     },
451     'epb020': {
452         'name': 'EPB Smartnet'
453     },
454     'jea010': {
455         'name': 'EPlus Broadband'
456     },
457     'com065': {
458         'name': 'ETC'
459     },
460     'ete010': {
461         'name': 'Etex Communications'
462     },
463     'fbc-tele': {
464         'name': 'F&B Communications'
465     },
466     'fal010': {
467         'name': 'Falcon Broadband'
468     },
469     'fam010': {
470         'name': 'FamilyView CableVision'
471     },
472     'far020': {
473         'name': 'Farmers Mutual Telephone Company'
474     },
475     'fay010': {
476         'name': 'Fayetteville Public Utilities'
477     },
478     'sal060': {
479         'name': 'fibrant'
480     },
481     'fid010': {
482         'name': 'Fidelity Communications'
483     },
484     'for030': {
485         'name': 'FJ Communications'
486     },
487     'fli020': {
488         'name': 'Flint River Communications'
489     },
490     'far030': {
491         'name': 'FMT - Jesup'
492     },
493     'foo010': {
494         'name': 'Foothills Communications'
495     },
496     'for080': {
497         'name': 'Forsyth CableNet'
498     },
499     'fbcomm': {
500         'name': 'Frankfort Plant Board'
501     },
502     'tel160-fra': {
503         'name': 'Franklin Telephone Company'
504     },
505     'nttcftc010': {
506         'name': 'FTC'
507     },
508     'fullchannel': {
509         'name': 'Full Channel, Inc.'
510     },
511     'gar040': {
512         'name': 'Gardonville Cooperative Telephone Association'
513     },
514     'gbt010': {
515         'name': 'GBT Communications, Inc.'
516     },
517     'tec010': {
518         'name': 'Genuine Telecom'
519     },
520     'clr010': {
521         'name': 'Giant Communications'
522     },
523     'gla010': {
524         'name': 'Glasgow EPB'
525     },
526     'gle010': {
527         'name': 'Glenwood Telecommunications'
528     },
529     'gra060': {
530         'name': 'GLW Broadband Inc.'
531     },
532     'goldenwest': {
533         'name': 'Golden West Cablevision'
534     },
535     'vis030': {
536         'name': 'Grantsburg Telcom'
537     },
538     'gpcom': {
539         'name': 'Great Plains Communications'
540     },
541     'gri010': {
542         'name': 'Gridley Cable Inc'
543     },
544     'hbc010': {
545         'name': 'H&B Cable Services'
546     },
547     'hae010': {
548         'name': 'Haefele TV Inc.'
549     },
550     'htc010': {
551         'name': 'Halstad Telephone Company'
552     },
553     'har005': {
554         'name': 'Harlan Municipal Utilities'
555     },
556     'har020': {
557         'name': 'Hart Communications'
558     },
559     'ced010': {
560         'name': 'Hartelco TV'
561     },
562     'hea040': {
563         'name': 'Heart of Iowa Communications Cooperative'
564     },
565     'htc020': {
566         'name': 'Hickory Telephone Company'
567     },
568     'nttchig010': {
569         'name': 'Highland Communication Services'
570     },
571     'hig030': {
572         'name': 'Highland Media'
573     },
574     'spc010': {
575         'name': 'Hilliary Communications'
576     },
577     'hin020': {
578         'name': 'Hinton CATV Co.'
579     },
580     'hometel': {
581         'name': 'HomeTel Entertainment, Inc.'
582     },
583     'hoodcanal': {
584         'name': 'Hood Canal Communications'
585     },
586     'weh010-hope': {
587         'name': 'Hope - Prescott Cable TV'
588     },
589     'horizoncable': {
590         'name': 'Horizon Cable TV, Inc.'
591     },
592     'hor040': {
593         'name': 'Horizon Chillicothe Telephone'
594     },
595     'htc030': {
596         'name': 'HTC Communications Co. - IL'
597     },
598     'htccomm': {
599         'name': 'HTC Communications, Inc. - IA'
600     },
601     'wal005': {
602         'name': 'Huxley Communications'
603     },
604     'imon': {
605         'name': 'ImOn Communications'
606     },
607     'ind040': {
608         'name': 'Independence Telecommunications'
609     },
610     'rrc010': {
611         'name': 'Inland Networks'
612     },
613     'stc020': {
614         'name': 'Innovative Cable TV St Croix'
615     },
616     'car100': {
617         'name': 'Innovative Cable TV St Thomas-St John'
618     },
619     'icc010': {
620         'name': 'Inside Connect Cable'
621     },
622     'int100': {
623         'name': 'Integra Telecom'
624     },
625     'int050': {
626         'name': 'Interstate Telecommunications Coop'
627     },
628     'irv010': {
629         'name': 'Irvine Cable'
630     },
631     'k2c010': {
632         'name': 'K2 Communications'
633     },
634     'kal010': {
635         'name': 'Kalida Telephone Company, Inc.'
636     },
637     'kal030': {
638         'name': 'Kalona Cooperative Telephone Company'
639     },
640     'kmt010': {
641         'name': 'KMTelecom'
642     },
643     'kpu010': {
644         'name': 'KPU Telecommunications'
645     },
646     'kuh010': {
647         'name': 'Kuhn Communications, Inc.'
648     },
649     'lak130': {
650         'name': 'Lakeland Communications'
651     },
652     'lan010': {
653         'name': 'Langco'
654     },
655     'lau020': {
656         'name': 'Laurel Highland Total Communications, Inc.'
657     },
658     'leh010': {
659         'name': 'Lehigh Valley Cooperative Telephone'
660     },
661     'bra010': {
662         'name': 'Limestone Cable/Bracken Cable'
663     },
664     'loc020': {
665         'name': 'LISCO'
666     },
667     'lit020': {
668         'name': 'Litestream'
669     },
670     'tel140': {
671         'name': 'LivCom'
672     },
673     'loc010': {
674         'name': 'LocalTel Communications'
675     },
676     'weh010-longview': {
677         'name': 'Longview - Kilgore Cable TV'
678     },
679     'lon030': {
680         'name': 'Lonsdale Video Ventures, LLC'
681     },
682     'lns010': {
683         'name': 'Lost Nation-Elwood Telephone Co.'
684     },
685     'nttclpc010': {
686         'name': 'LPC Connect'
687     },
688     'lumos': {
689         'name': 'Lumos Networks'
690     },
691     'madison': {
692         'name': 'Madison Communications'
693     },
694     'mad030': {
695         'name': 'Madison County Cable Inc.'
696     },
697     'nttcmah010': {
698         'name': 'Mahaska Communication Group'
699     },
700     'mar010': {
701         'name': 'Marne & Elk Horn Telephone Company'
702     },
703     'mcc040': {
704         'name': 'McClure Telephone Co.'
705     },
706     'mctv': {
707         'name': 'MCTV'
708     },
709     'merrimac': {
710         'name': 'Merrimac Communications Ltd.'
711     },
712     'metronet': {
713         'name': 'Metronet'
714     },
715     'mhtc': {
716         'name': 'MHTC'
717     },
718     'midhudson': {
719         'name': 'Mid-Hudson Cable'
720     },
721     'midrivers': {
722         'name': 'Mid-Rivers Communications'
723     },
724     'mid045': {
725         'name': 'Midstate Communications'
726     },
727     'mil080': {
728         'name': 'Milford Communications'
729     },
730     'min030': {
731         'name': 'MINET'
732     },
733     'nttcmin010': {
734         'name': 'Minford TV'
735     },
736     'san040-02': {
737         'name': 'Mitchell Telecom'
738     },
739     'mlg010': {
740         'name': 'MLGC'
741     },
742     'mon060': {
743         'name': 'Mon-Cre TVE'
744     },
745     'mou110': {
746         'name': 'Mountain Telephone'
747     },
748     'mou050': {
749         'name': 'Mountain Village Cable'
750     },
751     'mtacomm': {
752         'name': 'MTA Communications, LLC'
753     },
754     'mtc010': {
755         'name': 'MTC Cable'
756     },
757     'med040': {
758         'name': 'MTC Technologies'
759     },
760     'man060': {
761         'name': 'MTCC'
762     },
763     'mtc030': {
764         'name': 'MTCO Communications'
765     },
766     'mul050': {
767         'name': 'Mulberry Telecommunications'
768     },
769     'mur010': {
770         'name': 'Murray Electric System'
771     },
772     'musfiber': {
773         'name': 'MUS FiberNET'
774     },
775     'mpw': {
776         'name': 'Muscatine Power & Water'
777     },
778     'nttcsli010': {
779         'name': 'myEVTV.com'
780     },
781     'nor115': {
782         'name': 'NCC'
783     },
784     'nor260': {
785         'name': 'NDTC'
786     },
787     'nctc': {
788         'name': 'Nebraska Central Telecom, Inc.'
789     },
790     'nel020': {
791         'name': 'Nelsonville TV Cable'
792     },
793     'nem010': {
794         'name': 'Nemont'
795     },
796     'new075': {
797         'name': 'New Hope Telephone Cooperative'
798     },
799     'nor240': {
800         'name': 'NICP'
801     },
802     'cic010': {
803         'name': 'NineStar Connect'
804     },
805     'nktelco': {
806         'name': 'NKTelco'
807     },
808     'nortex': {
809         'name': 'Nortex Communications'
810     },
811     'nor140': {
812         'name': 'North Central Telephone Cooperative'
813     },
814     'nor030': {
815         'name': 'Northland Communications'
816     },
817     'nor075': {
818         'name': 'Northwest Communications'
819     },
820     'nor125': {
821         'name': 'Norwood Light Broadband'
822     },
823     'net010': {
824         'name': 'Nsight Telservices'
825     },
826     'dur010': {
827         'name': 'Ntec'
828     },
829     'nts010': {
830         'name': 'NTS Communications'
831     },
832     'new045': {
833         'name': 'NU-Telecom'
834     },
835     'nulink': {
836         'name': 'NuLink'
837     },
838     'jam030': {
839         'name': 'NVC'
840     },
841     'far035': {
842         'name': 'OmniTel Communications'
843     },
844     'onesource': {
845         'name': 'OneSource Communications'
846     },
847     'cit230': {
848         'name': 'Opelika Power Services'
849     },
850     'daltonutilities': {
851         'name': 'OptiLink'
852     },
853     'mid140': {
854         'name': 'OPTURA'
855     },
856     'ote010': {
857         'name': 'OTEC Communication Company'
858     },
859     'cci020': {
860         'name': 'Packerland Broadband'
861     },
862     'pan010': {
863         'name': 'Panora Telco/Guthrie Center Communications'
864     },
865     'otter': {
866         'name': 'Park Region Telephone & Otter Tail Telcom'
867     },
868     'mid050': {
869         'name': 'Partner Communications Cooperative'
870     },
871     'fib010': {
872         'name': 'Pathway'
873     },
874     'paulbunyan': {
875         'name': 'Paul Bunyan Communications'
876     },
877     'pem020': {
878         'name': 'Pembroke Telephone Company'
879     },
880     'mck010': {
881         'name': 'Peoples Rural Telephone Cooperative'
882     },
883     'pul010': {
884         'name': 'PES Energize'
885     },
886     'phi010': {
887         'name': 'Philippi Communications System'
888     },
889     'phonoscope': {
890         'name': 'Phonoscope Cable'
891     },
892     'pin070': {
893         'name': 'Pine Belt Communications, Inc.'
894     },
895     'weh010-pine': {
896         'name': 'Pine Bluff Cable TV'
897     },
898     'pin060': {
899         'name': 'Pineland Telephone Cooperative'
900     },
901     'cam010': {
902         'name': 'Pinpoint Communications'
903     },
904     'pio060': {
905         'name': 'Pioneer Broadband'
906     },
907     'pioncomm': {
908         'name': 'Pioneer Communications'
909     },
910     'pioneer': {
911         'name': 'Pioneer DTV'
912     },
913     'pla020': {
914         'name': 'Plant TiftNet, Inc.'
915     },
916     'par010': {
917         'name': 'PLWC'
918     },
919     'pro035': {
920         'name': 'PMT'
921     },
922     'vik011': {
923         'name': 'Polar Cablevision'
924     },
925     'pottawatomie': {
926         'name': 'Pottawatomie Telephone Co.'
927     },
928     'premiercomm': {
929         'name': 'Premier Communications'
930     },
931     'psc010': {
932         'name': 'PSC'
933     },
934     'pan020': {
935         'name': 'PTCI'
936     },
937     'qco010': {
938         'name': 'QCOL'
939     },
940     'qua010': {
941         'name': 'Quality Cablevision'
942     },
943     'rad010': {
944         'name': 'Radcliffe Telephone Company'
945     },
946     'car040': {
947         'name': 'Rainbow Communications'
948     },
949     'rai030': {
950         'name': 'Rainier Connect'
951     },
952     'ral010': {
953         'name': 'Ralls Technologies'
954     },
955     'rct010': {
956         'name': 'RC Technologies'
957     },
958     'red040': {
959         'name': 'Red River Communications'
960     },
961     'ree010': {
962         'name': 'Reedsburg Utility Commission'
963     },
964     'mol010': {
965         'name': 'Reliance Connects- Oregon'
966     },
967     'res020': {
968         'name': 'Reserve Telecommunications'
969     },
970     'weh010-resort': {
971         'name': 'Resort TV Cable'
972     },
973     'rld010': {
974         'name': 'Richland Grant Telephone Cooperative, Inc.'
975     },
976     'riv030': {
977         'name': 'River Valley Telecommunications Coop'
978     },
979     'rockportcable': {
980         'name': 'Rock Port Cablevision'
981     },
982     'rsf010': {
983         'name': 'RS Fiber'
984     },
985     'rtc': {
986         'name': 'RTC Communication Corp'
987     },
988     'res040': {
989         'name': 'RTC-Reservation Telephone Coop.'
990     },
991     'rte010': {
992         'name': 'RTEC Communications'
993     },
994     'stc010': {
995         'name': 'S&T'
996     },
997     'san020': {
998         'name': 'San Bruno Cable TV'
999     },
1000     'san040-01': {
1001         'name': 'Santel'
1002     },
1003     'sav010': {
1004         'name': 'SCI Broadband-Savage Communications Inc.'
1005     },
1006     'sco050': {
1007         'name': 'Scottsboro Electric Power Board'
1008     },
1009     'scr010': {
1010         'name': 'Scranton Telephone Company'
1011     },
1012     'selco': {
1013         'name': 'SELCO'
1014     },
1015     'she010': {
1016         'name': 'Shentel'
1017     },
1018     'she030': {
1019         'name': 'Sherwood Mutual Telephone Association, Inc.'
1020     },
1021     'ind060-ssc': {
1022         'name': 'Silver Star Communications'
1023     },
1024     'sjoberg': {
1025         'name': 'Sjoberg\'s Inc.'
1026     },
1027     'sou025': {
1028         'name': 'SKT'
1029     },
1030     'sky050': {
1031         'name': 'SkyBest TV'
1032     },
1033     'nttcsmi010': {
1034         'name': 'Smithville Communications'
1035     },
1036     'woo010': {
1037         'name': 'Solarus'
1038     },
1039     'sou075': {
1040         'name': 'South Central Rural Telephone Cooperative'
1041     },
1042     'sou065': {
1043         'name': 'South Holt Cablevision, Inc.'
1044     },
1045     'sou035': {
1046         'name': 'South Slope Cooperative Communications'
1047     },
1048     'spa020': {
1049         'name': 'Spanish Fork Community Network'
1050     },
1051     'spe010': {
1052         'name': 'Spencer Municipal Utilities'
1053     },
1054     'spi005': {
1055         'name': 'Spillway Communications, Inc.'
1056     },
1057     'srt010': {
1058         'name': 'SRT'
1059     },
1060     'cccsmc010': {
1061         'name': 'St. Maarten Cable TV'
1062     },
1063     'sta025': {
1064         'name': 'Star Communications'
1065     },
1066     'sco020': {
1067         'name': 'STE'
1068     },
1069     'uin010': {
1070         'name': 'STRATA Networks'
1071     },
1072     'sum010': {
1073         'name': 'Sumner Cable TV'
1074     },
1075     'pie010': {
1076         'name': 'Surry TV/PCSI TV'
1077     },
1078     'swa010': {
1079         'name': 'Swayzee Communications'
1080     },
1081     'sweetwater': {
1082         'name': 'Sweetwater Cable Television Co'
1083     },
1084     'weh010-talequah': {
1085         'name': 'Tahlequah Cable TV'
1086     },
1087     'tct': {
1088         'name': 'TCT'
1089     },
1090     'tel050': {
1091         'name': 'Tele-Media Company'
1092     },
1093     'com050': {
1094         'name': 'The Community Agency'
1095     },
1096     'thr020': {
1097         'name': 'Three River'
1098     },
1099     'cab140': {
1100         'name': 'Town & Country Technologies'
1101     },
1102     'tra010': {
1103         'name': 'Trans-Video'
1104     },
1105     'tre010': {
1106         'name': 'Trenton TV Cable Company'
1107     },
1108     'tcc': {
1109         'name': 'Tri County Communications Cooperative'
1110     },
1111     'tri025': {
1112         'name': 'TriCounty Telecom'
1113     },
1114     'tri110': {
1115         'name': 'TrioTel Communications, Inc.'
1116     },
1117     'tro010': {
1118         'name': 'Troy Cablevision, Inc.'
1119     },
1120     'tsc': {
1121         'name': 'TSC'
1122     },
1123     'cit220': {
1124         'name': 'Tullahoma Utilities Board'
1125     },
1126     'tvc030': {
1127         'name': 'TV Cable of Rensselaer'
1128     },
1129     'tvc015': {
1130         'name': 'TVC Cable'
1131     },
1132     'cab180': {
1133         'name': 'TVision'
1134     },
1135     'twi040': {
1136         'name': 'Twin Lakes'
1137     },
1138     'tvtinc': {
1139         'name': 'Twin Valley'
1140     },
1141     'uis010': {
1142         'name': 'Union Telephone Company'
1143     },
1144     'uni110': {
1145         'name': 'United Communications - TN'
1146     },
1147     'uni120': {
1148         'name': 'United Services'
1149     },
1150     'uss020': {
1151         'name': 'US Sonet'
1152     },
1153     'cab060': {
1154         'name': 'USA Communications'
1155     },
1156     'she005': {
1157         'name': 'USA Communications/Shellsburg, IA'
1158     },
1159     'val040': {
1160         'name': 'Valley TeleCom Group'
1161     },
1162     'val025': {
1163         'name': 'Valley Telecommunications'
1164     },
1165     'val030': {
1166         'name': 'Valparaiso Broadband'
1167     },
1168     'cla050': {
1169         'name': 'Vast Broadband'
1170     },
1171     'sul015': {
1172         'name': 'Venture Communications Cooperative, Inc.'
1173     },
1174     'ver025': {
1175         'name': 'Vernon Communications Co-op'
1176     },
1177     'weh010-vicksburg': {
1178         'name': 'Vicksburg Video'
1179     },
1180     'vis070': {
1181         'name': 'Vision Communications'
1182     },
1183     'volcanotel': {
1184         'name': 'Volcano Vision, Inc.'
1185     },
1186     'vol040-02': {
1187         'name': 'VolFirst / BLTV'
1188     },
1189     'ver070': {
1190         'name': 'VTel'
1191     },
1192     'nttcvtx010': {
1193         'name': 'VTX1'
1194     },
1195     'bci010-02': {
1196         'name': 'Vyve Broadband'
1197     },
1198     'wab020': {
1199         'name': 'Wabash Mutual Telephone'
1200     },
1201     'waitsfield': {
1202         'name': 'Waitsfield Cable'
1203     },
1204     'wal010': {
1205         'name': 'Walnut Communications'
1206     },
1207     'wavebroadband': {
1208         'name': 'Wave'
1209     },
1210     'wav030': {
1211         'name': 'Waverly Communications Utility'
1212     },
1213     'wbi010': {
1214         'name': 'WBI'
1215     },
1216     'web020': {
1217         'name': 'Webster-Calhoun Cooperative Telephone Association'
1218     },
1219     'wes005': {
1220         'name': 'West Alabama TV Cable'
1221     },
1222     'carolinata': {
1223         'name': 'West Carolina Communications'
1224     },
1225     'wct010': {
1226         'name': 'West Central Telephone Association'
1227     },
1228     'wes110': {
1229         'name': 'West River Cooperative Telephone Company'
1230     },
1231     'ani030': {
1232         'name': 'WesTel Systems'
1233     },
1234     'westianet': {
1235         'name': 'Western Iowa Networks'
1236     },
1237     'nttcwhi010': {
1238         'name': 'Whidbey Telecom'
1239     },
1240     'weh010-white': {
1241         'name': 'White County Cable TV'
1242     },
1243     'wes130': {
1244         'name': 'Wiatel'
1245     },
1246     'wik010': {
1247         'name': 'Wiktel'
1248     },
1249     'wil070': {
1250         'name': 'Wilkes Communications, Inc./RiverStreet Networks'
1251     },
1252     'wil015': {
1253         'name': 'Wilson Communications'
1254     },
1255     'win010': {
1256         'name': 'Windomnet/SMBS'
1257     },
1258     'win090': {
1259         'name': 'Windstream Cable TV'
1260     },
1261     'wcta': {
1262         'name': 'Winnebago Cooperative Telecom Association'
1263     },
1264     'wtc010': {
1265         'name': 'WTC'
1266     },
1267     'wil040': {
1268         'name': 'WTC Communications, Inc.'
1269     },
1270     'wya010': {
1271         'name': 'Wyandotte Cable'
1272     },
1273     'hin020-02': {
1274         'name': 'X-Stream Services'
1275     },
1276     'xit010': {
1277         'name': 'XIT Communications'
1278     },
1279     'yel010': {
1280         'name': 'Yelcot Communications'
1281     },
1282     'mid180-01': {
1283         'name': 'yondoo'
1284     },
1285     'cou060': {
1286         'name': 'Zito Media'
1287     },
1288 }
1289
1290
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'
1295
1296     @staticmethod
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>'
1310
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)
1315
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())
1319
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',
1330                 })
1331
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)
1337
1338         mvpd_headers = {
1339             'ap_42': 'anonymous',
1340             'ap_11': 'Linux i686',
1341             'ap_z': self._USER_AGENT,
1342             'User-Agent': self._USER_AGENT,
1343         }
1344
1345         guid = xml_text(resource, 'guid') if '<' in resource else resource
1346         count = 0
1347         while count < 2:
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'):
1351                 authn_token = None
1352             if not authn_token:
1353                 # TODO add support for other TV Providers
1354                 mso_id = self._downloader.params.get('ap_mso')
1355                 if not mso_id:
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]
1361
1362                 provider_redirect_page_res = self._download_webpage_handle(
1363                     self._SERVICE_PROVIDER_TEMPLATE % 'authenticate/saml', video_id,
1364                     'Downloading Provider Redirect Page', query={
1365                         'noflash': 'true',
1366                         'mso_id': mso_id,
1367                         'requestor_id': requestor_id,
1368                         'no_iframe': 'false',
1369                         'domain_name': 'adobe.com',
1370                         'redirect_url': url,
1371                     })
1372
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(r'window\.location\s*=\s*[\'"]([^\'"]+)',
1380                             provider_redirect_page, 'oauth redirect')
1381                         # Just need to process the request. No useful data comes back
1382                         self._download_webpage(oauth_redirect_url, video_id, 'Confirming auto login')
1383                     else:
1384                         if '<form name="signin"' in provider_redirect_page:
1385                             # already have the form, just fill it
1386                             provider_login_page_res = provider_redirect_page_res
1387                         elif 'http-equiv="refresh"' in provider_redirect_page:
1388                             # redirects to the login page
1389                             oauth_redirect_url = self._html_search_regex(r'content="0;\s*url=([^\'"]+)',
1390                                 provider_redirect_page, 'meta refresh redirect')
1391                             provider_login_page_res = self._download_webpage_handle(oauth_redirect_url,
1392                                 video_id, 'Downloading Provider Login Page')
1393                         else:
1394                             provider_login_page_res = post_form(
1395                                 provider_redirect_page_res, 'Downloading Provider Login Page')
1396
1397                         mvpd_confirm_page_res = post_form(provider_login_page_res, 'Logging in', {
1398                             mso_info.get('username_field', 'username'): username,
1399                             mso_info.get('password_field', 'password'): password,
1400                         })
1401                         mvpd_confirm_page, urlh = mvpd_confirm_page_res
1402                         if '<button class="submit" value="Resume">Resume</button>' in mvpd_confirm_page:
1403                             post_form(mvpd_confirm_page_res, 'Confirming Login')
1404
1405                 else:
1406                     # Normal, non-Comcast flow
1407                     provider_login_page_res = post_form(
1408                         provider_redirect_page_res, 'Downloading Provider Login Page')
1409                     mvpd_confirm_page_res = post_form(provider_login_page_res, 'Logging in', {
1410                         mso_info.get('username_field', 'username'): username,
1411                         mso_info.get('password_field', 'password'): password,
1412                     })
1413                     if mso_id != 'Rogers':
1414                         post_form(mvpd_confirm_page_res, 'Confirming Login')
1415
1416                 session = self._download_webpage(
1417                     self._SERVICE_PROVIDER_TEMPLATE % 'session', video_id,
1418                     'Retrieving Session', data=urlencode_postdata({
1419                         '_method': 'GET',
1420                         'requestor_id': requestor_id,
1421                     }), headers=mvpd_headers)
1422                 if '<pendingLogout' in session:
1423                     self._downloader.cache.store(self._MVPD_CACHE, requestor_id, {})
1424                     count += 1
1425                     continue
1426                 authn_token = unescapeHTML(xml_text(session, 'authnToken'))
1427                 requestor_info['authn_token'] = authn_token
1428                 self._downloader.cache.store(self._MVPD_CACHE, requestor_id, requestor_info)
1429
1430             authz_token = requestor_info.get(guid)
1431             if authz_token and is_expired(authz_token, 'simpleTokenTTL'):
1432                 authz_token = None
1433             if not authz_token:
1434                 authorize = self._download_webpage(
1435                     self._SERVICE_PROVIDER_TEMPLATE % 'authorize', video_id,
1436                     'Retrieving Authorization Token', data=urlencode_postdata({
1437                         'resource_id': resource,
1438                         'requestor_id': requestor_id,
1439                         'authentication_token': authn_token,
1440                         'mso_id': xml_text(authn_token, 'simpleTokenMsoID'),
1441                         'userMeta': '1',
1442                     }), headers=mvpd_headers)
1443                 if '<pendingLogout' in authorize:
1444                     self._downloader.cache.store(self._MVPD_CACHE, requestor_id, {})
1445                     count += 1
1446                     continue
1447                 authz_token = unescapeHTML(xml_text(authorize, 'authzToken'))
1448                 requestor_info[guid] = authz_token
1449                 self._downloader.cache.store(self._MVPD_CACHE, requestor_id, requestor_info)
1450
1451             mvpd_headers.update({
1452                 'ap_19': xml_text(authn_token, 'simpleSamlNameID'),
1453                 'ap_23': xml_text(authn_token, 'simpleSamlSessionIndex'),
1454             })
1455
1456             short_authorize = self._download_webpage(
1457                 self._SERVICE_PROVIDER_TEMPLATE % 'shortAuthorize',
1458                 video_id, 'Retrieving Media Token', data=urlencode_postdata({
1459                     'authz_token': authz_token,
1460                     'requestor_id': requestor_id,
1461                     'session_guid': xml_text(authn_token, 'simpleTokenAuthenticationGuid'),
1462                     'hashed_guid': 'false',
1463                 }), headers=mvpd_headers)
1464             if '<pendingLogout' in short_authorize:
1465                 self._downloader.cache.store(self._MVPD_CACHE, requestor_id, {})
1466                 count += 1
1467                 continue
1468             return short_authorize