logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

pbs.py (36627B)


  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..compat import compat_str
  6. from ..utils import (
  7. ExtractorError,
  8. determine_ext,
  9. int_or_none,
  10. float_or_none,
  11. js_to_json,
  12. orderedSet,
  13. strip_jsonp,
  14. strip_or_none,
  15. unified_strdate,
  16. url_or_none,
  17. US_RATINGS,
  18. )
  19. class PBSIE(InfoExtractor):
  20. _STATIONS = (
  21. (r'(?:video|www|player)\.pbs\.org', 'PBS: Public Broadcasting Service'), # http://www.pbs.org/
  22. (r'video\.aptv\.org', 'APT - Alabama Public Television (WBIQ)'), # http://aptv.org/
  23. (r'video\.gpb\.org', 'GPB/Georgia Public Broadcasting (WGTV)'), # http://www.gpb.org/
  24. (r'video\.mpbonline\.org', 'Mississippi Public Broadcasting (WMPN)'), # http://www.mpbonline.org
  25. (r'video\.wnpt\.org', 'Nashville Public Television (WNPT)'), # http://www.wnpt.org
  26. (r'video\.wfsu\.org', 'WFSU-TV (WFSU)'), # http://wfsu.org/
  27. (r'video\.wsre\.org', 'WSRE (WSRE)'), # http://www.wsre.org
  28. (r'video\.wtcitv\.org', 'WTCI (WTCI)'), # http://www.wtcitv.org
  29. (r'video\.pba\.org', 'WPBA/Channel 30 (WPBA)'), # http://pba.org/
  30. (r'video\.alaskapublic\.org', 'Alaska Public Media (KAKM)'), # http://alaskapublic.org/kakm
  31. # (r'kuac\.org', 'KUAC (KUAC)'), # http://kuac.org/kuac-tv/
  32. # (r'ktoo\.org', '360 North (KTOO)'), # http://www.ktoo.org/
  33. # (r'azpm\.org', 'KUAT 6 (KUAT)'), # http://www.azpm.org/
  34. (r'video\.azpbs\.org', 'Arizona PBS (KAET)'), # http://www.azpbs.org
  35. (r'portal\.knme\.org', 'KNME-TV/Channel 5 (KNME)'), # http://www.newmexicopbs.org/
  36. (r'video\.vegaspbs\.org', 'Vegas PBS (KLVX)'), # http://vegaspbs.org/
  37. (r'watch\.aetn\.org', 'AETN/ARKANSAS ETV NETWORK (KETS)'), # http://www.aetn.org/
  38. (r'video\.ket\.org', 'KET (WKLE)'), # http://www.ket.org/
  39. (r'video\.wkno\.org', 'WKNO/Channel 10 (WKNO)'), # http://www.wkno.org/
  40. (r'video\.lpb\.org', 'LPB/LOUISIANA PUBLIC BROADCASTING (WLPB)'), # http://www.lpb.org/
  41. (r'videos\.oeta\.tv', 'OETA (KETA)'), # http://www.oeta.tv
  42. (r'video\.optv\.org', 'Ozarks Public Television (KOZK)'), # http://www.optv.org/
  43. (r'watch\.wsiu\.org', 'WSIU Public Broadcasting (WSIU)'), # http://www.wsiu.org/
  44. (r'video\.keet\.org', 'KEET TV (KEET)'), # http://www.keet.org
  45. (r'pbs\.kixe\.org', 'KIXE/Channel 9 (KIXE)'), # http://kixe.org/
  46. (r'video\.kpbs\.org', 'KPBS San Diego (KPBS)'), # http://www.kpbs.org/
  47. (r'video\.kqed\.org', 'KQED (KQED)'), # http://www.kqed.org
  48. (r'vids\.kvie\.org', 'KVIE Public Television (KVIE)'), # http://www.kvie.org
  49. (r'video\.pbssocal\.org', 'PBS SoCal/KOCE (KOCE)'), # http://www.pbssocal.org/
  50. (r'video\.valleypbs\.org', 'ValleyPBS (KVPT)'), # http://www.valleypbs.org/
  51. (r'video\.cptv\.org', 'CONNECTICUT PUBLIC TELEVISION (WEDH)'), # http://cptv.org
  52. (r'watch\.knpb\.org', 'KNPB Channel 5 (KNPB)'), # http://www.knpb.org/
  53. (r'video\.soptv\.org', 'SOPTV (KSYS)'), # http://www.soptv.org
  54. # (r'klcs\.org', 'KLCS/Channel 58 (KLCS)'), # http://www.klcs.org
  55. # (r'krcb\.org', 'KRCB Television & Radio (KRCB)'), # http://www.krcb.org
  56. # (r'kvcr\.org', 'KVCR TV/DT/FM :: Vision for the Future (KVCR)'), # http://kvcr.org
  57. (r'video\.rmpbs\.org', 'Rocky Mountain PBS (KRMA)'), # http://www.rmpbs.org
  58. (r'video\.kenw\.org', 'KENW-TV3 (KENW)'), # http://www.kenw.org
  59. (r'video\.kued\.org', 'KUED Channel 7 (KUED)'), # http://www.kued.org
  60. (r'video\.wyomingpbs\.org', 'Wyoming PBS (KCWC)'), # http://www.wyomingpbs.org
  61. (r'video\.cpt12\.org', 'Colorado Public Television / KBDI 12 (KBDI)'), # http://www.cpt12.org/
  62. (r'video\.kbyueleven\.org', 'KBYU-TV (KBYU)'), # http://www.kbyutv.org/
  63. (r'video\.thirteen\.org', 'Thirteen/WNET New York (WNET)'), # http://www.thirteen.org
  64. (r'video\.wgbh\.org', 'WGBH/Channel 2 (WGBH)'), # http://wgbh.org
  65. (r'video\.wgby\.org', 'WGBY (WGBY)'), # http://www.wgby.org
  66. (r'watch\.njtvonline\.org', 'NJTV Public Media NJ (WNJT)'), # http://www.njtvonline.org/
  67. # (r'ripbs\.org', 'Rhode Island PBS (WSBE)'), # http://www.ripbs.org/home/
  68. (r'watch\.wliw\.org', 'WLIW21 (WLIW)'), # http://www.wliw.org/
  69. (r'video\.mpt\.tv', 'mpt/Maryland Public Television (WMPB)'), # http://www.mpt.org
  70. (r'watch\.weta\.org', 'WETA Television and Radio (WETA)'), # http://www.weta.org
  71. (r'video\.whyy\.org', 'WHYY (WHYY)'), # http://www.whyy.org
  72. (r'video\.wlvt\.org', 'PBS 39 (WLVT)'), # http://www.wlvt.org/
  73. (r'video\.wvpt\.net', 'WVPT - Your Source for PBS and More! (WVPT)'), # http://www.wvpt.net
  74. (r'video\.whut\.org', 'Howard University Television (WHUT)'), # http://www.whut.org
  75. (r'video\.wedu\.org', 'WEDU PBS (WEDU)'), # http://www.wedu.org
  76. (r'video\.wgcu\.org', 'WGCU Public Media (WGCU)'), # http://www.wgcu.org/
  77. # (r'wjct\.org', 'WJCT Public Broadcasting (WJCT)'), # http://www.wjct.org
  78. (r'video\.wpbt2\.org', 'WPBT2 (WPBT)'), # http://www.wpbt2.org
  79. (r'video\.wucftv\.org', 'WUCF TV (WUCF)'), # http://wucftv.org
  80. (r'video\.wuft\.org', 'WUFT/Channel 5 (WUFT)'), # http://www.wuft.org
  81. (r'watch\.wxel\.org', 'WXEL/Channel 42 (WXEL)'), # http://www.wxel.org/home/
  82. (r'video\.wlrn\.org', 'WLRN/Channel 17 (WLRN)'), # http://www.wlrn.org/
  83. (r'video\.wusf\.usf\.edu', 'WUSF Public Broadcasting (WUSF)'), # http://wusf.org/
  84. (r'video\.scetv\.org', 'ETV (WRLK)'), # http://www.scetv.org
  85. (r'video\.unctv\.org', 'UNC-TV (WUNC)'), # http://www.unctv.org/
  86. # (r'pbsguam\.org', 'PBS Guam (KGTF)'), # http://www.pbsguam.org/
  87. (r'video\.pbshawaii\.org', 'PBS Hawaii - Oceanic Cable Channel 10 (KHET)'), # http://www.pbshawaii.org/
  88. (r'video\.idahoptv\.org', 'Idaho Public Television (KAID)'), # http://idahoptv.org
  89. (r'video\.ksps\.org', 'KSPS (KSPS)'), # http://www.ksps.org/home/
  90. (r'watch\.opb\.org', 'OPB (KOPB)'), # http://www.opb.org
  91. (r'watch\.nwptv\.org', 'KWSU/Channel 10 & KTNW/Channel 31 (KWSU)'), # http://www.kwsu.org
  92. (r'video\.will\.illinois\.edu', 'WILL-TV (WILL)'), # http://will.illinois.edu/
  93. (r'video\.networkknowledge\.tv', 'Network Knowledge - WSEC/Springfield (WSEC)'), # http://www.wsec.tv
  94. (r'video\.wttw\.com', 'WTTW11 (WTTW)'), # http://www.wttw.com/
  95. # (r'wtvp\.org', 'WTVP & WTVP.org, Public Media for Central Illinois (WTVP)'), # http://www.wtvp.org/
  96. (r'video\.iptv\.org', 'Iowa Public Television/IPTV (KDIN)'), # http://www.iptv.org/
  97. (r'video\.ninenet\.org', 'Nine Network (KETC)'), # http://www.ninenet.org
  98. (r'video\.wfwa\.org', 'PBS39 Fort Wayne (WFWA)'), # http://wfwa.org/
  99. (r'video\.wfyi\.org', 'WFYI Indianapolis (WFYI)'), # http://www.wfyi.org
  100. (r'video\.mptv\.org', 'Milwaukee Public Television (WMVS)'), # http://www.mptv.org
  101. (r'video\.wnin\.org', 'WNIN (WNIN)'), # http://www.wnin.org/
  102. (r'video\.wnit\.org', 'WNIT Public Television (WNIT)'), # http://www.wnit.org/
  103. (r'video\.wpt\.org', 'WPT (WPNE)'), # http://www.wpt.org/
  104. (r'video\.wvut\.org', 'WVUT/Channel 22 (WVUT)'), # http://wvut.org/
  105. (r'video\.weiu\.net', 'WEIU/Channel 51 (WEIU)'), # http://www.weiu.net
  106. (r'video\.wqpt\.org', 'WQPT-TV (WQPT)'), # http://www.wqpt.org
  107. (r'video\.wycc\.org', 'WYCC PBS Chicago (WYCC)'), # http://www.wycc.org
  108. # (r'lakeshorepublicmedia\.org', 'Lakeshore Public Television (WYIN)'), # http://lakeshorepublicmedia.org/
  109. (r'video\.wipb\.org', 'WIPB-TV (WIPB)'), # http://wipb.org
  110. (r'video\.indianapublicmedia\.org', 'WTIU (WTIU)'), # http://indianapublicmedia.org/tv/
  111. (r'watch\.cetconnect\.org', 'CET (WCET)'), # http://www.cetconnect.org
  112. (r'video\.thinktv\.org', 'ThinkTVNetwork (WPTD)'), # http://www.thinktv.org
  113. (r'video\.wbgu\.org', 'WBGU-TV (WBGU)'), # http://wbgu.org
  114. (r'video\.wgvu\.org', 'WGVU TV (WGVU)'), # http://www.wgvu.org/
  115. (r'video\.netnebraska\.org', 'NET1 (KUON)'), # http://netnebraska.org
  116. (r'video\.pioneer\.org', 'Pioneer Public Television (KWCM)'), # http://www.pioneer.org
  117. (r'watch\.sdpb\.org', 'SDPB Television (KUSD)'), # http://www.sdpb.org
  118. (r'video\.tpt\.org', 'TPT (KTCA)'), # http://www.tpt.org
  119. (r'watch\.ksmq\.org', 'KSMQ (KSMQ)'), # http://www.ksmq.org/
  120. (r'watch\.kpts\.org', 'KPTS/Channel 8 (KPTS)'), # http://www.kpts.org/
  121. (r'watch\.ktwu\.org', 'KTWU/Channel 11 (KTWU)'), # http://ktwu.org
  122. # (r'shptv\.org', 'Smoky Hills Public Television (KOOD)'), # http://www.shptv.org
  123. # (r'kcpt\.org', 'KCPT Kansas City Public Television (KCPT)'), # http://kcpt.org/
  124. # (r'blueridgepbs\.org', 'Blue Ridge PBS (WBRA)'), # http://www.blueridgepbs.org/
  125. (r'watch\.easttennesseepbs\.org', 'East Tennessee PBS (WSJK)'), # http://easttennesseepbs.org
  126. (r'video\.wcte\.tv', 'WCTE-TV (WCTE)'), # http://www.wcte.org
  127. (r'video\.wljt\.org', 'WLJT, Channel 11 (WLJT)'), # http://wljt.org/
  128. (r'video\.wosu\.org', 'WOSU TV (WOSU)'), # http://wosu.org/
  129. (r'video\.woub\.org', 'WOUB/WOUC (WOUB)'), # http://woub.org/tv/index.php?section=5
  130. (r'video\.wvpublic\.org', 'WVPB (WVPB)'), # http://wvpublic.org/
  131. (r'video\.wkyupbs\.org', 'WKYU-PBS (WKYU)'), # http://www.wkyupbs.org
  132. # (r'wyes\.org', 'WYES-TV/New Orleans (WYES)'), # http://www.wyes.org
  133. (r'video\.kera\.org', 'KERA 13 (KERA)'), # http://www.kera.org/
  134. (r'video\.mpbn\.net', 'MPBN (WCBB)'), # http://www.mpbn.net/
  135. (r'video\.mountainlake\.org', 'Mountain Lake PBS (WCFE)'), # http://www.mountainlake.org/
  136. (r'video\.nhptv\.org', 'NHPTV (WENH)'), # http://nhptv.org/
  137. (r'video\.vpt\.org', 'Vermont PBS (WETK)'), # http://www.vpt.org
  138. (r'video\.witf\.org', 'witf (WITF)'), # http://www.witf.org
  139. (r'watch\.wqed\.org', 'WQED Multimedia (WQED)'), # http://www.wqed.org/
  140. (r'video\.wmht\.org', 'WMHT Educational Telecommunications (WMHT)'), # http://www.wmht.org/home/
  141. (r'video\.deltabroadcasting\.org', 'Q-TV (WDCQ)'), # http://www.deltabroadcasting.org
  142. (r'video\.dptv\.org', 'WTVS Detroit Public TV (WTVS)'), # http://www.dptv.org/
  143. (r'video\.wcmu\.org', 'CMU Public Television (WCMU)'), # http://www.wcmu.org
  144. (r'video\.wkar\.org', 'WKAR-TV (WKAR)'), # http://wkar.org/
  145. (r'wnmuvideo\.nmu\.edu', 'WNMU-TV Public TV 13 (WNMU)'), # http://wnmutv.nmu.edu
  146. (r'video\.wdse\.org', 'WDSE - WRPT (WDSE)'), # http://www.wdse.org/
  147. (r'video\.wgte\.org', 'WGTE TV (WGTE)'), # http://www.wgte.org
  148. (r'video\.lptv\.org', 'Lakeland Public Television (KAWE)'), # http://www.lakelandptv.org
  149. # (r'prairiepublic\.org', 'PRAIRIE PUBLIC (KFME)'), # http://www.prairiepublic.org/
  150. (r'video\.kmos\.org', 'KMOS-TV - Channels 6.1, 6.2 and 6.3 (KMOS)'), # http://www.kmos.org/
  151. (r'watch\.montanapbs\.org', 'MontanaPBS (KUSM)'), # http://montanapbs.org
  152. (r'video\.krwg\.org', 'KRWG/Channel 22 (KRWG)'), # http://www.krwg.org
  153. (r'video\.kacvtv\.org', 'KACV (KACV)'), # http://www.panhandlepbs.org/home/
  154. (r'video\.kcostv\.org', 'KCOS/Channel 13 (KCOS)'), # www.kcostv.org
  155. (r'video\.wcny\.org', 'WCNY/Channel 24 (WCNY)'), # http://www.wcny.org
  156. (r'video\.wned\.org', 'WNED (WNED)'), # http://www.wned.org/
  157. (r'watch\.wpbstv\.org', 'WPBS (WPBS)'), # http://www.wpbstv.org
  158. (r'video\.wskg\.org', 'WSKG Public TV (WSKG)'), # http://wskg.org
  159. (r'video\.wxxi\.org', 'WXXI (WXXI)'), # http://wxxi.org
  160. (r'video\.wpsu\.org', 'WPSU (WPSU)'), # http://www.wpsu.org
  161. # (r'wqln\.org', 'WQLN/Channel 54 (WQLN)'), # http://www.wqln.org
  162. (r'on-demand\.wvia\.org', 'WVIA Public Media Studios (WVIA)'), # http://www.wvia.org/
  163. (r'video\.wtvi\.org', 'WTVI (WTVI)'), # http://www.wtvi.org/
  164. # (r'whro\.org', 'WHRO (WHRO)'), # http://whro.org
  165. (r'video\.westernreservepublicmedia\.org', 'Western Reserve PBS (WNEO)'), # http://www.WesternReservePublicMedia.org/
  166. (r'video\.ideastream\.org', 'WVIZ/PBS ideastream (WVIZ)'), # http://www.wviz.org/
  167. (r'video\.kcts9\.org', 'KCTS 9 (KCTS)'), # http://kcts9.org/
  168. (r'video\.basinpbs\.org', 'Basin PBS (KPBT)'), # http://www.basinpbs.org
  169. (r'video\.houstonpbs\.org', 'KUHT / Channel 8 (KUHT)'), # http://www.houstonpublicmedia.org/
  170. # (r'tamu\.edu', 'KAMU - TV (KAMU)'), # http://KAMU.tamu.edu
  171. # (r'kedt\.org', 'KEDT/Channel 16 (KEDT)'), # http://www.kedt.org
  172. (r'video\.klrn\.org', 'KLRN (KLRN)'), # http://www.klrn.org
  173. (r'video\.klru\.tv', 'KLRU (KLRU)'), # http://www.klru.org
  174. # (r'kmbh\.org', 'KMBH-TV (KMBH)'), # http://www.kmbh.org
  175. # (r'knct\.org', 'KNCT (KNCT)'), # http://www.knct.org
  176. # (r'ktxt\.org', 'KTTZ-TV (KTXT)'), # http://www.ktxt.org
  177. (r'video\.wtjx\.org', 'WTJX Channel 12 (WTJX)'), # http://www.wtjx.org/
  178. (r'video\.ideastations\.org', 'WCVE PBS (WCVE)'), # http://ideastations.org/
  179. (r'video\.kbtc\.org', 'KBTC Public Television (KBTC)'), # http://kbtc.org
  180. )
  181. IE_NAME = 'pbs'
  182. IE_DESC = 'Public Broadcasting Service (PBS) and member stations: %s' % ', '.join(list(zip(*_STATIONS))[1])
  183. _VALID_URL = r'''(?x)https?://
  184. (?:
  185. # Direct video URL
  186. (?:%s)/(?:(?:vir|port)alplayer|video)/(?P<id>[0-9]+)(?:[?/]|$) |
  187. # Article with embedded player (or direct video)
  188. (?:www\.)?pbs\.org/(?:[^/]+/){1,5}(?P<presumptive_id>[^/]+?)(?:\.html)?/?(?:$|[?\#]) |
  189. # Player
  190. (?:video|player)\.pbs\.org/(?:widget/)?partnerplayer/(?P<player_id>[^/]+)/
  191. )
  192. ''' % '|'.join(list(zip(*_STATIONS))[0])
  193. _GEO_COUNTRIES = ['US']
  194. _TESTS = [
  195. {
  196. 'url': 'http://www.pbs.org/tpt/constitution-usa-peter-sagal/watch/a-more-perfect-union/',
  197. 'md5': '173dc391afd361fa72eab5d3d918968d',
  198. 'info_dict': {
  199. 'id': '2365006249',
  200. 'ext': 'mp4',
  201. 'title': 'Constitution USA with Peter Sagal - A More Perfect Union',
  202. 'description': 'md5:31b664af3c65fd07fa460d306b837d00',
  203. 'duration': 3190,
  204. },
  205. },
  206. {
  207. 'url': 'http://www.pbs.org/wgbh/pages/frontline/losing-iraq/',
  208. 'md5': '6f722cb3c3982186d34b0f13374499c7',
  209. 'info_dict': {
  210. 'id': '2365297690',
  211. 'ext': 'mp4',
  212. 'title': 'FRONTLINE - Losing Iraq',
  213. 'description': 'md5:5979a4d069b157f622d02bff62fbe654',
  214. 'duration': 5050,
  215. },
  216. },
  217. {
  218. 'url': 'http://www.pbs.org/newshour/bb/education-jan-june12-cyberschools_02-23/',
  219. 'md5': 'b19856d7f5351b17a5ab1dc6a64be633',
  220. 'info_dict': {
  221. 'id': '2201174722',
  222. 'ext': 'mp4',
  223. 'title': 'PBS NewsHour - Cyber Schools Gain Popularity, but Quality Questions Persist',
  224. 'description': 'md5:86ab9a3d04458b876147b355788b8781',
  225. 'duration': 801,
  226. },
  227. },
  228. {
  229. 'url': 'http://www.pbs.org/wnet/gperf/dudamel-conducts-verdi-requiem-hollywood-bowl-full-episode/3374/',
  230. 'md5': 'c62859342be2a0358d6c9eb306595978',
  231. 'info_dict': {
  232. 'id': '2365297708',
  233. 'ext': 'mp4',
  234. 'title': 'Great Performances - Dudamel Conducts Verdi Requiem at the Hollywood Bowl - Full',
  235. 'description': 'md5:657897370e09e2bc6bf0f8d2cd313c6b',
  236. 'duration': 6559,
  237. 'thumbnail': r're:^https?://.*\.jpg$',
  238. },
  239. },
  240. {
  241. 'url': 'http://www.pbs.org/wgbh/nova/earth/killer-typhoon.html',
  242. 'md5': '908f3e5473a693b266b84e25e1cf9703',
  243. 'info_dict': {
  244. 'id': '2365160389',
  245. 'display_id': 'killer-typhoon',
  246. 'ext': 'mp4',
  247. 'description': 'md5:c741d14e979fc53228c575894094f157',
  248. 'title': 'NOVA - Killer Typhoon',
  249. 'duration': 3172,
  250. 'thumbnail': r're:^https?://.*\.jpg$',
  251. 'upload_date': '20140122',
  252. 'age_limit': 10,
  253. },
  254. },
  255. {
  256. 'url': 'http://www.pbs.org/wgbh/pages/frontline/united-states-of-secrets/',
  257. 'info_dict': {
  258. 'id': 'united-states-of-secrets',
  259. },
  260. 'playlist_count': 2,
  261. },
  262. {
  263. 'url': 'http://www.pbs.org/wgbh/americanexperience/films/great-war/',
  264. 'info_dict': {
  265. 'id': 'great-war',
  266. },
  267. 'playlist_count': 3,
  268. },
  269. {
  270. 'url': 'http://www.pbs.org/wgbh/americanexperience/films/death/player/',
  271. 'info_dict': {
  272. 'id': '2276541483',
  273. 'display_id': 'player',
  274. 'ext': 'mp4',
  275. 'title': 'American Experience - Death and the Civil War, Chapter 1',
  276. 'description': 'md5:67fa89a9402e2ee7d08f53b920674c18',
  277. 'duration': 682,
  278. 'thumbnail': r're:^https?://.*\.jpg$',
  279. },
  280. 'params': {
  281. 'skip_download': True, # requires ffmpeg
  282. },
  283. },
  284. {
  285. 'url': 'http://www.pbs.org/video/2365245528/',
  286. 'md5': '115223d41bd55cda8ae5cd5ed4e11497',
  287. 'info_dict': {
  288. 'id': '2365245528',
  289. 'display_id': '2365245528',
  290. 'ext': 'mp4',
  291. 'title': 'FRONTLINE - United States of Secrets (Part One)',
  292. 'description': 'md5:55756bd5c551519cc4b7703e373e217e',
  293. 'duration': 6851,
  294. 'thumbnail': r're:^https?://.*\.jpg$',
  295. },
  296. },
  297. {
  298. # Video embedded in iframe containing angle brackets as attribute's value (e.g.
  299. # "<iframe style='position: absolute;<br />\ntop: 0; left: 0;' ...", see
  300. # https://github.com/ytdl-org/youtube-dl/issues/7059)
  301. 'url': 'http://www.pbs.org/food/features/a-chefs-life-season-3-episode-5-prickly-business/',
  302. 'md5': '59b0ef5009f9ac8a319cc5efebcd865e',
  303. 'info_dict': {
  304. 'id': '2365546844',
  305. 'display_id': 'a-chefs-life-season-3-episode-5-prickly-business',
  306. 'ext': 'mp4',
  307. 'title': "A Chef's Life - Season 3, Ep. 5: Prickly Business",
  308. 'description': 'md5:c0ff7475a4b70261c7e58f493c2792a5',
  309. 'duration': 1480,
  310. 'thumbnail': r're:^https?://.*\.jpg$',
  311. },
  312. },
  313. {
  314. # Frontline video embedded via flp2012.js
  315. 'url': 'http://www.pbs.org/wgbh/pages/frontline/the-atomic-artists',
  316. 'info_dict': {
  317. 'id': '2070868960',
  318. 'display_id': 'the-atomic-artists',
  319. 'ext': 'mp4',
  320. 'title': 'FRONTLINE - The Atomic Artists',
  321. 'description': 'md5:f677e4520cfacb4a5ce1471e31b57800',
  322. 'duration': 723,
  323. 'thumbnail': r're:^https?://.*\.jpg$',
  324. },
  325. 'params': {
  326. 'skip_download': True, # requires ffmpeg
  327. },
  328. },
  329. {
  330. # Serves hd only via wigget/partnerplayer page
  331. 'url': 'http://www.pbs.org/video/2365641075/',
  332. 'md5': 'fdf907851eab57211dd589cf12006666',
  333. 'info_dict': {
  334. 'id': '2365641075',
  335. 'ext': 'mp4',
  336. 'title': 'FRONTLINE - Netanyahu at War',
  337. 'duration': 6852,
  338. 'thumbnail': r're:^https?://.*\.jpg$',
  339. 'formats': 'mincount:8',
  340. },
  341. },
  342. {
  343. # https://github.com/ytdl-org/youtube-dl/issues/13801
  344. 'url': 'https://www.pbs.org/video/pbs-newshour-full-episode-july-31-2017-1501539057/',
  345. 'info_dict': {
  346. 'id': '3003333873',
  347. 'ext': 'mp4',
  348. 'title': 'PBS NewsHour - full episode July 31, 2017',
  349. 'description': 'md5:d41d8cd98f00b204e9800998ecf8427e',
  350. 'duration': 3265,
  351. 'thumbnail': r're:^https?://.*\.jpg$',
  352. },
  353. 'params': {
  354. 'skip_download': True,
  355. },
  356. },
  357. {
  358. 'url': 'http://www.pbs.org/wgbh/roadshow/watch/episode/2105-indianapolis-hour-2/',
  359. 'info_dict': {
  360. 'id': '2365936247',
  361. 'ext': 'mp4',
  362. 'title': 'Antiques Roadshow - Indianapolis, Hour 2',
  363. 'description': 'md5:524b32249db55663e7231b6b8d1671a2',
  364. 'duration': 3180,
  365. 'thumbnail': r're:^https?://.*\.jpg$',
  366. },
  367. 'params': {
  368. 'skip_download': True,
  369. },
  370. 'expected_warnings': ['HTTP Error 403: Forbidden'],
  371. },
  372. {
  373. 'url': 'https://www.pbs.org/wgbh/masterpiece/episodes/victoria-s2-e1/',
  374. 'info_dict': {
  375. 'id': '3007193718',
  376. 'ext': 'mp4',
  377. 'title': "Victoria - A Soldier's Daughter / The Green-Eyed Monster",
  378. 'description': 'md5:37efbac85e0c09b009586523ec143652',
  379. 'duration': 6292,
  380. 'thumbnail': r're:^https?://.*\.(?:jpg|JPG)$',
  381. },
  382. 'params': {
  383. 'skip_download': True,
  384. },
  385. 'expected_warnings': ['HTTP Error 403: Forbidden'],
  386. },
  387. {
  388. 'url': 'https://player.pbs.org/partnerplayer/tOz9tM5ljOXQqIIWke53UA==/',
  389. 'info_dict': {
  390. 'id': '3011407934',
  391. 'ext': 'mp4',
  392. 'title': 'Stories from the Stage - Road Trip',
  393. 'duration': 1619,
  394. 'thumbnail': r're:^https?://.*\.(?:jpg|JPG)$',
  395. },
  396. 'params': {
  397. 'skip_download': True,
  398. },
  399. 'expected_warnings': ['HTTP Error 403: Forbidden'],
  400. },
  401. {
  402. 'url': 'http://player.pbs.org/widget/partnerplayer/2365297708/?start=0&end=0&chapterbar=false&endscreen=false&topbar=true',
  403. 'only_matching': True,
  404. },
  405. {
  406. 'url': 'http://watch.knpb.org/video/2365616055/',
  407. 'only_matching': True,
  408. },
  409. {
  410. 'url': 'https://player.pbs.org/portalplayer/3004638221/?uid=',
  411. 'only_matching': True,
  412. }
  413. ]
  414. _ERRORS = {
  415. 101: 'We\'re sorry, but this video is not yet available.',
  416. 403: 'We\'re sorry, but this video is not available in your region due to right restrictions.',
  417. 404: 'We are experiencing technical difficulties that are preventing us from playing the video at this time. Please check back again soon.',
  418. 410: 'This video has expired and is no longer available for online streaming.',
  419. }
  420. def _real_initialize(self):
  421. cookie = (self._download_json(
  422. 'http://localization.services.pbs.org/localize/auto/cookie/',
  423. None, headers=self.geo_verification_headers(), fatal=False) or {}).get('cookie')
  424. if cookie:
  425. station = self._search_regex(r'#?s=\["([^"]+)"', cookie, 'station')
  426. if station:
  427. self._set_cookie('.pbs.org', 'pbsol.station', station)
  428. def _extract_webpage(self, url):
  429. mobj = re.match(self._VALID_URL, url)
  430. description = None
  431. presumptive_id = mobj.group('presumptive_id')
  432. display_id = presumptive_id
  433. if presumptive_id:
  434. webpage = self._download_webpage(url, display_id)
  435. description = strip_or_none(self._og_search_description(
  436. webpage, default=None) or self._html_search_meta(
  437. 'description', webpage, default=None))
  438. upload_date = unified_strdate(self._search_regex(
  439. r'<input type="hidden" id="air_date_[0-9]+" value="([^"]+)"',
  440. webpage, 'upload date', default=None))
  441. # tabbed frontline videos
  442. MULTI_PART_REGEXES = (
  443. r'<div[^>]+class="videotab[^"]*"[^>]+vid="(\d+)"',
  444. r'<a[^>]+href=["\']#(?:video-|part)\d+["\'][^>]+data-cove[Ii]d=["\'](\d+)',
  445. )
  446. for p in MULTI_PART_REGEXES:
  447. tabbed_videos = orderedSet(re.findall(p, webpage))
  448. if tabbed_videos:
  449. return tabbed_videos, presumptive_id, upload_date, description
  450. MEDIA_ID_REGEXES = [
  451. r"div\s*:\s*'videoembed'\s*,\s*mediaid\s*:\s*'(\d+)'", # frontline video embed
  452. r'class="coveplayerid">([^<]+)<', # coveplayer
  453. r'<section[^>]+data-coveid="(\d+)"', # coveplayer from http://www.pbs.org/wgbh/frontline/film/real-csi/
  454. r'<input type="hidden" id="pbs_video_id_[0-9]+" value="([0-9]+)"/>', # jwplayer
  455. r"(?s)window\.PBS\.playerConfig\s*=\s*{.*?id\s*:\s*'([0-9]+)',",
  456. r'<div[^>]+\bdata-cove-id=["\'](\d+)"', # http://www.pbs.org/wgbh/roadshow/watch/episode/2105-indianapolis-hour-2/
  457. r'<iframe[^>]+\bsrc=["\'](?:https?:)?//video\.pbs\.org/widget/partnerplayer/(\d+)', # https://www.pbs.org/wgbh/masterpiece/episodes/victoria-s2-e1/
  458. ]
  459. media_id = self._search_regex(
  460. MEDIA_ID_REGEXES, webpage, 'media ID', fatal=False, default=None)
  461. if media_id:
  462. return media_id, presumptive_id, upload_date, description
  463. # Frontline video embedded via flp
  464. video_id = self._search_regex(
  465. r'videoid\s*:\s*"([\d+a-z]{7,})"', webpage, 'videoid', default=None)
  466. if video_id:
  467. # pkg_id calculation is reverse engineered from
  468. # http://www.pbs.org/wgbh/pages/frontline/js/flp2012.js
  469. prg_id = self._search_regex(
  470. r'videoid\s*:\s*"([\d+a-z]{7,})"', webpage, 'videoid')[7:]
  471. if 'q' in prg_id:
  472. prg_id = prg_id.split('q')[1]
  473. prg_id = int(prg_id, 16)
  474. getdir = self._download_json(
  475. 'http://www.pbs.org/wgbh/pages/frontline/.json/getdir/getdir%d.json' % prg_id,
  476. presumptive_id, 'Downloading getdir JSON',
  477. transform_source=strip_jsonp)
  478. return getdir['mid'], presumptive_id, upload_date, description
  479. for iframe in re.findall(r'(?s)<iframe(.+?)></iframe>', webpage):
  480. url = self._search_regex(
  481. r'src=(["\'])(?P<url>.+?partnerplayer.+?)\1', iframe,
  482. 'player URL', default=None, group='url')
  483. if url:
  484. break
  485. if not url:
  486. url = self._og_search_url(webpage)
  487. mobj = re.match(
  488. self._VALID_URL, self._proto_relative_url(url.strip()))
  489. player_id = mobj.group('player_id')
  490. if not display_id:
  491. display_id = player_id
  492. if player_id:
  493. player_page = self._download_webpage(
  494. url, display_id, note='Downloading player page',
  495. errnote='Could not download player page')
  496. video_id = self._search_regex(
  497. r'<div\s+id=["\']video_(\d+)', player_page, 'video ID',
  498. default=None)
  499. if not video_id:
  500. video_info = self._extract_video_data(
  501. player_page, 'video data', display_id)
  502. video_id = compat_str(
  503. video_info.get('id') or video_info['contentID'])
  504. else:
  505. video_id = mobj.group('id')
  506. display_id = video_id
  507. return video_id, display_id, None, description
  508. def _extract_video_data(self, string, name, video_id, fatal=True):
  509. return self._parse_json(
  510. self._search_regex(
  511. [r'(?s)PBS\.videoData\s*=\s*({.+?});\n',
  512. r'window\.videoBridge\s*=\s*({.+?});'],
  513. string, name, default='{}'),
  514. video_id, transform_source=js_to_json, fatal=fatal)
  515. def _real_extract(self, url):
  516. video_id, display_id, upload_date, description = self._extract_webpage(url)
  517. if isinstance(video_id, list):
  518. entries = [self.url_result(
  519. 'http://video.pbs.org/video/%s' % vid_id, 'PBS', vid_id)
  520. for vid_id in video_id]
  521. return self.playlist_result(entries, display_id)
  522. info = None
  523. redirects = []
  524. redirect_urls = set()
  525. def extract_redirect_urls(info):
  526. for encoding_name in ('recommended_encoding', 'alternate_encoding'):
  527. redirect = info.get(encoding_name)
  528. if not redirect:
  529. continue
  530. redirect_url = redirect.get('url')
  531. if redirect_url and redirect_url not in redirect_urls:
  532. redirects.append(redirect)
  533. redirect_urls.add(redirect_url)
  534. encodings = info.get('encodings')
  535. if isinstance(encodings, list):
  536. for encoding in encodings:
  537. encoding_url = url_or_none(encoding)
  538. if encoding_url and encoding_url not in redirect_urls:
  539. redirects.append({'url': encoding_url})
  540. redirect_urls.add(encoding_url)
  541. chapters = []
  542. # Player pages may also serve different qualities
  543. for page in ('widget/partnerplayer', 'portalplayer'):
  544. player = self._download_webpage(
  545. 'http://player.pbs.org/%s/%s' % (page, video_id),
  546. display_id, 'Downloading %s page' % page, fatal=False)
  547. if player:
  548. video_info = self._extract_video_data(
  549. player, '%s video data' % page, display_id, fatal=False)
  550. if video_info:
  551. extract_redirect_urls(video_info)
  552. if not info:
  553. info = video_info
  554. if not chapters:
  555. raw_chapters = video_info.get('chapters') or []
  556. if not raw_chapters:
  557. for chapter_data in re.findall(r'(?s)chapters\.push\(({.*?})\)', player):
  558. chapter = self._parse_json(chapter_data, video_id, js_to_json, fatal=False)
  559. if not chapter:
  560. continue
  561. raw_chapters.append(chapter)
  562. for chapter in raw_chapters:
  563. start_time = float_or_none(chapter.get('start_time'), 1000)
  564. duration = float_or_none(chapter.get('duration'), 1000)
  565. if start_time is None or duration is None:
  566. continue
  567. chapters.append({
  568. 'start_time': start_time,
  569. 'end_time': start_time + duration,
  570. 'title': chapter.get('title'),
  571. })
  572. formats = []
  573. http_url = None
  574. for num, redirect in enumerate(redirects):
  575. redirect_id = redirect.get('eeid')
  576. redirect_info = self._download_json(
  577. '%s?format=json' % redirect['url'], display_id,
  578. 'Downloading %s video url info' % (redirect_id or num),
  579. headers=self.geo_verification_headers())
  580. if redirect_info['status'] == 'error':
  581. message = self._ERRORS.get(
  582. redirect_info['http_code'], redirect_info['message'])
  583. if redirect_info['http_code'] == 403:
  584. self.raise_geo_restricted(
  585. msg=message, countries=self._GEO_COUNTRIES)
  586. raise ExtractorError(
  587. '%s said: %s' % (self.IE_NAME, message), expected=True)
  588. format_url = redirect_info.get('url')
  589. if not format_url:
  590. continue
  591. if determine_ext(format_url) == 'm3u8':
  592. formats.extend(self._extract_m3u8_formats(
  593. format_url, display_id, 'mp4', m3u8_id='hls', fatal=False))
  594. else:
  595. formats.append({
  596. 'url': format_url,
  597. 'format_id': redirect_id,
  598. })
  599. if re.search(r'^https?://.*(?:\d+k|baseline)', format_url):
  600. http_url = format_url
  601. self._remove_duplicate_formats(formats)
  602. m3u8_formats = list(filter(
  603. lambda f: f.get('protocol') == 'm3u8' and f.get('vcodec') != 'none',
  604. formats))
  605. if http_url:
  606. for m3u8_format in m3u8_formats:
  607. bitrate = self._search_regex(r'(\d+)k', m3u8_format['url'], 'bitrate', default=None)
  608. # Lower qualities (150k and 192k) are not available as HTTP formats (see [1]),
  609. # we won't try extracting them.
  610. # Since summer 2016 higher quality formats (4500k and 6500k) are also available
  611. # albeit they are not documented in [2].
  612. # 1. https://github.com/ytdl-org/youtube-dl/commit/cbc032c8b70a038a69259378c92b4ba97b42d491#commitcomment-17313656
  613. # 2. https://projects.pbs.org/confluence/display/coveapi/COVE+Video+Specifications
  614. if not bitrate or int(bitrate) < 400:
  615. continue
  616. f_url = re.sub(r'\d+k|baseline', bitrate + 'k', http_url)
  617. # This may produce invalid links sometimes (e.g.
  618. # http://www.pbs.org/wgbh/frontline/film/suicide-plan)
  619. if not self._is_valid_url(f_url, display_id, 'http-%sk video' % bitrate):
  620. continue
  621. f = m3u8_format.copy()
  622. f.update({
  623. 'url': f_url,
  624. 'format_id': m3u8_format['format_id'].replace('hls', 'http'),
  625. 'protocol': 'http',
  626. })
  627. formats.append(f)
  628. self._sort_formats(formats)
  629. rating_str = info.get('rating')
  630. if rating_str is not None:
  631. rating_str = rating_str.rpartition('-')[2]
  632. age_limit = US_RATINGS.get(rating_str)
  633. subtitles = {}
  634. closed_captions_url = info.get('closed_captions_url')
  635. if closed_captions_url:
  636. subtitles['en'] = [{
  637. 'ext': 'ttml',
  638. 'url': closed_captions_url,
  639. }]
  640. mobj = re.search(r'/(\d+)_Encoded\.dfxp', closed_captions_url)
  641. if mobj:
  642. ttml_caption_suffix, ttml_caption_id = mobj.group(0, 1)
  643. ttml_caption_id = int(ttml_caption_id)
  644. subtitles['en'].extend([{
  645. 'url': closed_captions_url.replace(
  646. ttml_caption_suffix, '/%d_Encoded.srt' % (ttml_caption_id + 1)),
  647. 'ext': 'srt',
  648. }, {
  649. 'url': closed_captions_url.replace(
  650. ttml_caption_suffix, '/%d_Encoded.vtt' % (ttml_caption_id + 2)),
  651. 'ext': 'vtt',
  652. }])
  653. # info['title'] is often incomplete (e.g. 'Full Episode', 'Episode 5', etc)
  654. # Try turning it to 'program - title' naming scheme if possible
  655. alt_title = info.get('program', {}).get('title')
  656. if alt_title:
  657. info['title'] = alt_title + ' - ' + re.sub(r'^' + alt_title + r'[\s\-:]+', '', info['title'])
  658. description = info.get('description') or info.get(
  659. 'program', {}).get('description') or description
  660. return {
  661. 'id': video_id,
  662. 'display_id': display_id,
  663. 'title': info['title'],
  664. 'description': description,
  665. 'thumbnail': info.get('image_url'),
  666. 'duration': int_or_none(info.get('duration')),
  667. 'age_limit': age_limit,
  668. 'upload_date': upload_date,
  669. 'formats': formats,
  670. 'subtitles': subtitles,
  671. 'chapters': chapters,
  672. }