You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

503 lines
26 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. ExtractorError,
  7. determine_ext,
  8. int_or_none,
  9. strip_jsonp,
  10. unified_strdate,
  11. US_RATINGS,
  12. )
  13. class PBSIE(InfoExtractor):
  14. _STATIONS = (
  15. (r'(?:video|www|player)\.pbs\.org', 'PBS: Public Broadcasting Service'), # http://www.pbs.org/
  16. (r'video\.aptv\.org', 'APT - Alabama Public Television (WBIQ)'), # http://aptv.org/
  17. (r'video\.gpb\.org', 'GPB/Georgia Public Broadcasting (WGTV)'), # http://www.gpb.org/
  18. (r'video\.mpbonline\.org', 'Mississippi Public Broadcasting (WMPN)'), # http://www.mpbonline.org
  19. (r'video\.wnpt\.org', 'Nashville Public Television (WNPT)'), # http://www.wnpt.org
  20. (r'video\.wfsu\.org', 'WFSU-TV (WFSU)'), # http://wfsu.org/
  21. (r'video\.wsre\.org', 'WSRE (WSRE)'), # http://www.wsre.org
  22. (r'video\.wtcitv\.org', 'WTCI (WTCI)'), # http://www.wtcitv.org
  23. (r'video\.pba\.org', 'WPBA/Channel 30 (WPBA)'), # http://pba.org/
  24. (r'video\.alaskapublic\.org', 'Alaska Public Media (KAKM)'), # http://alaskapublic.org/kakm
  25. # (r'kuac\.org', 'KUAC (KUAC)'), # http://kuac.org/kuac-tv/
  26. # (r'ktoo\.org', '360 North (KTOO)'), # http://www.ktoo.org/
  27. # (r'azpm\.org', 'KUAT 6 (KUAT)'), # http://www.azpm.org/
  28. (r'video\.azpbs\.org', 'Arizona PBS (KAET)'), # http://www.azpbs.org
  29. (r'portal\.knme\.org', 'KNME-TV/Channel 5 (KNME)'), # http://www.newmexicopbs.org/
  30. (r'video\.vegaspbs\.org', 'Vegas PBS (KLVX)'), # http://vegaspbs.org/
  31. (r'watch\.aetn\.org', 'AETN/ARKANSAS ETV NETWORK (KETS)'), # http://www.aetn.org/
  32. (r'video\.ket\.org', 'KET (WKLE)'), # http://www.ket.org/
  33. (r'video\.wkno\.org', 'WKNO/Channel 10 (WKNO)'), # http://www.wkno.org/
  34. (r'video\.lpb\.org', 'LPB/LOUISIANA PUBLIC BROADCASTING (WLPB)'), # http://www.lpb.org/
  35. (r'videos\.oeta\.tv', 'OETA (KETA)'), # http://www.oeta.tv
  36. (r'video\.optv\.org', 'Ozarks Public Television (KOZK)'), # http://www.optv.org/
  37. (r'watch\.wsiu\.org', 'WSIU Public Broadcasting (WSIU)'), # http://www.wsiu.org/
  38. (r'video\.keet\.org', 'KEET TV (KEET)'), # http://www.keet.org
  39. (r'pbs\.kixe\.org', 'KIXE/Channel 9 (KIXE)'), # http://kixe.org/
  40. (r'video\.kpbs\.org', 'KPBS San Diego (KPBS)'), # http://www.kpbs.org/
  41. (r'video\.kqed\.org', 'KQED (KQED)'), # http://www.kqed.org
  42. (r'vids\.kvie\.org', 'KVIE Public Television (KVIE)'), # http://www.kvie.org
  43. (r'video\.pbssocal\.org', 'PBS SoCal/KOCE (KOCE)'), # http://www.pbssocal.org/
  44. (r'video\.valleypbs\.org', 'ValleyPBS (KVPT)'), # http://www.valleypbs.org/
  45. (r'video\.cptv\.org', 'CONNECTICUT PUBLIC TELEVISION (WEDH)'), # http://cptv.org
  46. (r'watch\.knpb\.org', 'KNPB Channel 5 (KNPB)'), # http://www.knpb.org/
  47. (r'video\.soptv\.org', 'SOPTV (KSYS)'), # http://www.soptv.org
  48. # (r'klcs\.org', 'KLCS/Channel 58 (KLCS)'), # http://www.klcs.org
  49. # (r'krcb\.org', 'KRCB Television & Radio (KRCB)'), # http://www.krcb.org
  50. # (r'kvcr\.org', 'KVCR TV/DT/FM :: Vision for the Future (KVCR)'), # http://kvcr.org
  51. (r'video\.rmpbs\.org', 'Rocky Mountain PBS (KRMA)'), # http://www.rmpbs.org
  52. (r'video\.kenw\.org', 'KENW-TV3 (KENW)'), # http://www.kenw.org
  53. (r'video\.kued\.org', 'KUED Channel 7 (KUED)'), # http://www.kued.org
  54. (r'video\.wyomingpbs\.org', 'Wyoming PBS (KCWC)'), # http://www.wyomingpbs.org
  55. (r'video\.cpt12\.org', 'Colorado Public Television / KBDI 12 (KBDI)'), # http://www.cpt12.org/
  56. (r'video\.kbyueleven\.org', 'KBYU-TV (KBYU)'), # http://www.kbyutv.org/
  57. (r'video\.thirteen\.org', 'Thirteen/WNET New York (WNET)'), # http://www.thirteen.org
  58. (r'video\.wgbh\.org', 'WGBH/Channel 2 (WGBH)'), # http://wgbh.org
  59. (r'video\.wgby\.org', 'WGBY (WGBY)'), # http://www.wgby.org
  60. (r'watch\.njtvonline\.org', 'NJTV Public Media NJ (WNJT)'), # http://www.njtvonline.org/
  61. # (r'ripbs\.org', 'Rhode Island PBS (WSBE)'), # http://www.ripbs.org/home/
  62. (r'watch\.wliw\.org', 'WLIW21 (WLIW)'), # http://www.wliw.org/
  63. (r'video\.mpt\.tv', 'mpt/Maryland Public Television (WMPB)'), # http://www.mpt.org
  64. (r'watch\.weta\.org', 'WETA Television and Radio (WETA)'), # http://www.weta.org
  65. (r'video\.whyy\.org', 'WHYY (WHYY)'), # http://www.whyy.org
  66. (r'video\.wlvt\.org', 'PBS 39 (WLVT)'), # http://www.wlvt.org/
  67. (r'video\.wvpt\.net', 'WVPT - Your Source for PBS and More! (WVPT)'), # http://www.wvpt.net
  68. (r'video\.whut\.org', 'Howard University Television (WHUT)'), # http://www.whut.org
  69. (r'video\.wedu\.org', 'WEDU PBS (WEDU)'), # http://www.wedu.org
  70. (r'video\.wgcu\.org', 'WGCU Public Media (WGCU)'), # http://www.wgcu.org/
  71. # (r'wjct\.org', 'WJCT Public Broadcasting (WJCT)'), # http://www.wjct.org
  72. (r'video\.wpbt2\.org', 'WPBT2 (WPBT)'), # http://www.wpbt2.org
  73. (r'video\.wucftv\.org', 'WUCF TV (WUCF)'), # http://wucftv.org
  74. (r'video\.wuft\.org', 'WUFT/Channel 5 (WUFT)'), # http://www.wuft.org
  75. (r'watch\.wxel\.org', 'WXEL/Channel 42 (WXEL)'), # http://www.wxel.org/home/
  76. (r'video\.wlrn\.org', 'WLRN/Channel 17 (WLRN)'), # http://www.wlrn.org/
  77. (r'video\.wusf\.usf\.edu', 'WUSF Public Broadcasting (WUSF)'), # http://wusf.org/
  78. (r'video\.scetv\.org', 'ETV (WRLK)'), # http://www.scetv.org
  79. (r'video\.unctv\.org', 'UNC-TV (WUNC)'), # http://www.unctv.org/
  80. # (r'pbsguam\.org', 'PBS Guam (KGTF)'), # http://www.pbsguam.org/
  81. (r'video\.pbshawaii\.org', 'PBS Hawaii - Oceanic Cable Channel 10 (KHET)'), # http://www.pbshawaii.org/
  82. (r'video\.idahoptv\.org', 'Idaho Public Television (KAID)'), # http://idahoptv.org
  83. (r'video\.ksps\.org', 'KSPS (KSPS)'), # http://www.ksps.org/home/
  84. (r'watch\.opb\.org', 'OPB (KOPB)'), # http://www.opb.org
  85. (r'watch\.nwptv\.org', 'KWSU/Channel 10 & KTNW/Channel 31 (KWSU)'), # http://www.kwsu.org
  86. (r'video\.will\.illinois\.edu', 'WILL-TV (WILL)'), # http://will.illinois.edu/
  87. (r'video\.networkknowledge\.tv', 'Network Knowledge - WSEC/Springfield (WSEC)'), # http://www.wsec.tv
  88. (r'video\.wttw\.com', 'WTTW11 (WTTW)'), # http://www.wttw.com/
  89. # (r'wtvp\.org', 'WTVP & WTVP.org, Public Media for Central Illinois (WTVP)'), # http://www.wtvp.org/
  90. (r'video\.iptv\.org', 'Iowa Public Television/IPTV (KDIN)'), # http://www.iptv.org/
  91. (r'video\.ninenet\.org', 'Nine Network (KETC)'), # http://www.ninenet.org
  92. (r'video\.wfwa\.org', 'PBS39 Fort Wayne (WFWA)'), # http://wfwa.org/
  93. (r'video\.wfyi\.org', 'WFYI Indianapolis (WFYI)'), # http://www.wfyi.org
  94. (r'video\.mptv\.org', 'Milwaukee Public Television (WMVS)'), # http://www.mptv.org
  95. (r'video\.wnin\.org', 'WNIN (WNIN)'), # http://www.wnin.org/
  96. (r'video\.wnit\.org', 'WNIT Public Television (WNIT)'), # http://www.wnit.org/
  97. (r'video\.wpt\.org', 'WPT (WPNE)'), # http://www.wpt.org/
  98. (r'video\.wvut\.org', 'WVUT/Channel 22 (WVUT)'), # http://wvut.org/
  99. (r'video\.weiu\.net', 'WEIU/Channel 51 (WEIU)'), # http://www.weiu.net
  100. (r'video\.wqpt\.org', 'WQPT-TV (WQPT)'), # http://www.wqpt.org
  101. (r'video\.wycc\.org', 'WYCC PBS Chicago (WYCC)'), # http://www.wycc.org
  102. # (r'lakeshorepublicmedia\.org', 'Lakeshore Public Television (WYIN)'), # http://lakeshorepublicmedia.org/
  103. (r'video\.wipb\.org', 'WIPB-TV (WIPB)'), # http://wipb.org
  104. (r'video\.indianapublicmedia\.org', 'WTIU (WTIU)'), # http://indianapublicmedia.org/tv/
  105. (r'watch\.cetconnect\.org', 'CET (WCET)'), # http://www.cetconnect.org
  106. (r'video\.thinktv\.org', 'ThinkTVNetwork (WPTD)'), # http://www.thinktv.org
  107. (r'video\.wbgu\.org', 'WBGU-TV (WBGU)'), # http://wbgu.org
  108. (r'video\.wgvu\.org', 'WGVU TV (WGVU)'), # http://www.wgvu.org/
  109. (r'video\.netnebraska\.org', 'NET1 (KUON)'), # http://netnebraska.org
  110. (r'video\.pioneer\.org', 'Pioneer Public Television (KWCM)'), # http://www.pioneer.org
  111. (r'watch\.sdpb\.org', 'SDPB Television (KUSD)'), # http://www.sdpb.org
  112. (r'video\.tpt\.org', 'TPT (KTCA)'), # http://www.tpt.org
  113. (r'watch\.ksmq\.org', 'KSMQ (KSMQ)'), # http://www.ksmq.org/
  114. (r'watch\.kpts\.org', 'KPTS/Channel 8 (KPTS)'), # http://www.kpts.org/
  115. (r'watch\.ktwu\.org', 'KTWU/Channel 11 (KTWU)'), # http://ktwu.org
  116. # (r'shptv\.org', 'Smoky Hills Public Television (KOOD)'), # http://www.shptv.org
  117. # (r'kcpt\.org', 'KCPT Kansas City Public Television (KCPT)'), # http://kcpt.org/
  118. # (r'blueridgepbs\.org', 'Blue Ridge PBS (WBRA)'), # http://www.blueridgepbs.org/
  119. (r'watch\.easttennesseepbs\.org', 'East Tennessee PBS (WSJK)'), # http://easttennesseepbs.org
  120. (r'video\.wcte\.tv', 'WCTE-TV (WCTE)'), # http://www.wcte.org
  121. (r'video\.wljt\.org', 'WLJT, Channel 11 (WLJT)'), # http://wljt.org/
  122. (r'video\.wosu\.org', 'WOSU TV (WOSU)'), # http://wosu.org/
  123. (r'video\.woub\.org', 'WOUB/WOUC (WOUB)'), # http://woub.org/tv/index.php?section=5
  124. (r'video\.wvpublic\.org', 'WVPB (WVPB)'), # http://wvpublic.org/
  125. (r'video\.wkyupbs\.org', 'WKYU-PBS (WKYU)'), # http://www.wkyupbs.org
  126. # (r'wyes\.org', 'WYES-TV/New Orleans (WYES)'), # http://www.wyes.org
  127. (r'video\.kera\.org', 'KERA 13 (KERA)'), # http://www.kera.org/
  128. (r'video\.mpbn\.net', 'MPBN (WCBB)'), # http://www.mpbn.net/
  129. (r'video\.mountainlake\.org', 'Mountain Lake PBS (WCFE)'), # http://www.mountainlake.org/
  130. (r'video\.nhptv\.org', 'NHPTV (WENH)'), # http://nhptv.org/
  131. (r'video\.vpt\.org', 'Vermont PBS (WETK)'), # http://www.vpt.org
  132. (r'video\.witf\.org', 'witf (WITF)'), # http://www.witf.org
  133. (r'watch\.wqed\.org', 'WQED Multimedia (WQED)'), # http://www.wqed.org/
  134. (r'video\.wmht\.org', 'WMHT Educational Telecommunications (WMHT)'), # http://www.wmht.org/home/
  135. (r'video\.deltabroadcasting\.org', 'Q-TV (WDCQ)'), # http://www.deltabroadcasting.org
  136. (r'video\.dptv\.org', 'WTVS Detroit Public TV (WTVS)'), # http://www.dptv.org/
  137. (r'video\.wcmu\.org', 'CMU Public Television (WCMU)'), # http://www.wcmu.org
  138. (r'video\.wkar\.org', 'WKAR-TV (WKAR)'), # http://wkar.org/
  139. (r'wnmuvideo\.nmu\.edu', 'WNMU-TV Public TV 13 (WNMU)'), # http://wnmutv.nmu.edu
  140. (r'video\.wdse\.org', 'WDSE - WRPT (WDSE)'), # http://www.wdse.org/
  141. (r'video\.wgte\.org', 'WGTE TV (WGTE)'), # http://www.wgte.org
  142. (r'video\.lptv\.org', 'Lakeland Public Television (KAWE)'), # http://www.lakelandptv.org
  143. # (r'prairiepublic\.org', 'PRAIRIE PUBLIC (KFME)'), # http://www.prairiepublic.org/
  144. (r'video\.kmos\.org', 'KMOS-TV - Channels 6.1, 6.2 and 6.3 (KMOS)'), # http://www.kmos.org/
  145. (r'watch\.montanapbs\.org', 'MontanaPBS (KUSM)'), # http://montanapbs.org
  146. (r'video\.krwg\.org', 'KRWG/Channel 22 (KRWG)'), # http://www.krwg.org
  147. (r'video\.kacvtv\.org', 'KACV (KACV)'), # http://www.panhandlepbs.org/home/
  148. (r'video\.kcostv\.org', 'KCOS/Channel 13 (KCOS)'), # www.kcostv.org
  149. (r'video\.wcny\.org', 'WCNY/Channel 24 (WCNY)'), # http://www.wcny.org
  150. (r'video\.wned\.org', 'WNED (WNED)'), # http://www.wned.org/
  151. (r'watch\.wpbstv\.org', 'WPBS (WPBS)'), # http://www.wpbstv.org
  152. (r'video\.wskg\.org', 'WSKG Public TV (WSKG)'), # http://wskg.org
  153. (r'video\.wxxi\.org', 'WXXI (WXXI)'), # http://wxxi.org
  154. (r'video\.wpsu\.org', 'WPSU (WPSU)'), # http://www.wpsu.org
  155. # (r'wqln\.org', 'WQLN/Channel 54 (WQLN)'), # http://www.wqln.org
  156. (r'on-demand\.wvia\.org', 'WVIA Public Media Studios (WVIA)'), # http://www.wvia.org/
  157. (r'video\.wtvi\.org', 'WTVI (WTVI)'), # http://www.wtvi.org/
  158. # (r'whro\.org', 'WHRO (WHRO)'), # http://whro.org
  159. (r'video\.westernreservepublicmedia\.org', 'Western Reserve PBS (WNEO)'), # http://www.WesternReservePublicMedia.org/
  160. (r'video\.ideastream\.org', 'WVIZ/PBS ideastream (WVIZ)'), # http://www.wviz.org/
  161. (r'video\.kcts9\.org', 'KCTS 9 (KCTS)'), # http://kcts9.org/
  162. (r'video\.basinpbs\.org', 'Basin PBS (KPBT)'), # http://www.basinpbs.org
  163. (r'video\.houstonpbs\.org', 'KUHT / Channel 8 (KUHT)'), # http://www.houstonpublicmedia.org/
  164. # (r'tamu\.edu', 'KAMU - TV (KAMU)'), # http://KAMU.tamu.edu
  165. # (r'kedt\.org', 'KEDT/Channel 16 (KEDT)'), # http://www.kedt.org
  166. (r'video\.klrn\.org', 'KLRN (KLRN)'), # http://www.klrn.org
  167. (r'video\.klru\.tv', 'KLRU (KLRU)'), # http://www.klru.org
  168. # (r'kmbh\.org', 'KMBH-TV (KMBH)'), # http://www.kmbh.org
  169. # (r'knct\.org', 'KNCT (KNCT)'), # http://www.knct.org
  170. # (r'ktxt\.org', 'KTTZ-TV (KTXT)'), # http://www.ktxt.org
  171. (r'video\.wtjx\.org', 'WTJX Channel 12 (WTJX)'), # http://www.wtjx.org/
  172. (r'video\.ideastations\.org', 'WCVE PBS (WCVE)'), # http://ideastations.org/
  173. (r'video\.kbtc\.org', 'KBTC Public Television (KBTC)'), # http://kbtc.org
  174. )
  175. IE_NAME = 'pbs'
  176. IE_DESC = 'Public Broadcasting Service (PBS) and member stations: %s' % ', '.join(list(zip(*_STATIONS))[1])
  177. _VALID_URL = r'''(?x)https?://
  178. (?:
  179. # Direct video URL
  180. (?:%s)/(?:viralplayer|video)/(?P<id>[0-9]+)/? |
  181. # Article with embedded player (or direct video)
  182. (?:www\.)?pbs\.org/(?:[^/]+/){2,5}(?P<presumptive_id>[^/]+?)(?:\.html)?/?(?:$|[?\#]) |
  183. # Player
  184. (?:video|player)\.pbs\.org/(?:widget/)?partnerplayer/(?P<player_id>[^/]+)/
  185. )
  186. ''' % '|'.join(list(zip(*_STATIONS))[0])
  187. _TESTS = [
  188. {
  189. 'url': 'http://www.pbs.org/tpt/constitution-usa-peter-sagal/watch/a-more-perfect-union/',
  190. 'md5': 'ce1888486f0908d555a8093cac9a7362',
  191. 'info_dict': {
  192. 'id': '2365006249',
  193. 'ext': 'mp4',
  194. 'title': 'Constitution USA with Peter Sagal - A More Perfect Union',
  195. 'description': 'md5:ba0c207295339c8d6eced00b7c363c6a',
  196. 'duration': 3190,
  197. },
  198. 'params': {
  199. 'skip_download': True, # requires ffmpeg
  200. },
  201. },
  202. {
  203. 'url': 'http://www.pbs.org/wgbh/pages/frontline/losing-iraq/',
  204. 'md5': '143c98aa54a346738a3d78f54c925321',
  205. 'info_dict': {
  206. 'id': '2365297690',
  207. 'ext': 'mp4',
  208. 'title': 'FRONTLINE - Losing Iraq',
  209. 'description': 'md5:f5bfbefadf421e8bb8647602011caf8e',
  210. 'duration': 5050,
  211. },
  212. 'params': {
  213. 'skip_download': True, # requires ffmpeg
  214. }
  215. },
  216. {
  217. 'url': 'http://www.pbs.org/newshour/bb/education-jan-june12-cyberschools_02-23/',
  218. 'md5': 'b19856d7f5351b17a5ab1dc6a64be633',
  219. 'info_dict': {
  220. 'id': '2201174722',
  221. 'ext': 'mp4',
  222. 'title': 'PBS NewsHour - Cyber Schools Gain Popularity, but Quality Questions Persist',
  223. 'description': 'md5:5871c15cba347c1b3d28ac47a73c7c28',
  224. 'duration': 801,
  225. },
  226. },
  227. {
  228. 'url': 'http://www.pbs.org/wnet/gperf/dudamel-conducts-verdi-requiem-hollywood-bowl-full-episode/3374/',
  229. 'md5': 'c62859342be2a0358d6c9eb306595978',
  230. 'info_dict': {
  231. 'id': '2365297708',
  232. 'ext': 'mp4',
  233. 'description': 'md5:68d87ef760660eb564455eb30ca464fe',
  234. 'title': 'Great Performances - Dudamel Conducts Verdi Requiem at the Hollywood Bowl - Full',
  235. 'duration': 6559,
  236. 'thumbnail': 're:^https?://.*\.jpg$',
  237. },
  238. 'params': {
  239. 'skip_download': True, # requires ffmpeg
  240. },
  241. },
  242. {
  243. 'url': 'http://www.pbs.org/wgbh/nova/earth/killer-typhoon.html',
  244. 'md5': '908f3e5473a693b266b84e25e1cf9703',
  245. 'info_dict': {
  246. 'id': '2365160389',
  247. 'display_id': 'killer-typhoon',
  248. 'ext': 'mp4',
  249. 'description': 'md5:c741d14e979fc53228c575894094f157',
  250. 'title': 'NOVA - Killer Typhoon',
  251. 'duration': 3172,
  252. 'thumbnail': 're:^https?://.*\.jpg$',
  253. 'upload_date': '20140122',
  254. 'age_limit': 10,
  255. },
  256. 'params': {
  257. 'skip_download': True, # requires ffmpeg
  258. },
  259. },
  260. {
  261. 'url': 'http://www.pbs.org/wgbh/pages/frontline/united-states-of-secrets/',
  262. 'info_dict': {
  263. 'id': 'united-states-of-secrets',
  264. },
  265. 'playlist_count': 2,
  266. },
  267. {
  268. 'url': 'http://www.pbs.org/wgbh/americanexperience/films/death/player/',
  269. 'info_dict': {
  270. 'id': '2276541483',
  271. 'display_id': 'player',
  272. 'ext': 'mp4',
  273. 'title': 'American Experience - Death and the Civil War, Chapter 1',
  274. 'description': 'American Experience, TV’s most-watched history series, brings to life the compelling stories from our past that inform our understanding of the world today.',
  275. 'duration': 682,
  276. 'thumbnail': 're:^https?://.*\.jpg$',
  277. },
  278. 'params': {
  279. 'skip_download': True, # requires ffmpeg
  280. },
  281. },
  282. {
  283. 'url': 'http://video.pbs.org/video/2365367186/',
  284. 'info_dict': {
  285. 'id': '2365367186',
  286. 'display_id': '2365367186',
  287. 'ext': 'mp4',
  288. 'title': 'To Catch A Comet - Full Episode',
  289. 'description': 'On November 12, 2014, billions of kilometers from Earth, spacecraft orbiter Rosetta and lander Philae did what no other had dared to attempt \u2014 land on the volatile surface of a comet as it zooms around the sun at 67,000 km/hr. The European Space Agency hopes this mission can help peer into our past and unlock secrets of our origins.',
  290. 'duration': 3342,
  291. 'thumbnail': 're:^https?://.*\.jpg$',
  292. },
  293. 'params': {
  294. 'skip_download': True, # requires ffmpeg
  295. },
  296. 'skip': 'Expired',
  297. },
  298. {
  299. # Video embedded in iframe containing angle brackets as attribute's value (e.g.
  300. # "<iframe style='position: absolute;<br />\ntop: 0; left: 0;' ...", see
  301. # https://github.com/rg3/youtube-dl/issues/7059)
  302. 'url': 'http://www.pbs.org/food/features/a-chefs-life-season-3-episode-5-prickly-business/',
  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:61db2ddf27c9912f09c241014b118ed1',
  309. 'duration': 1480,
  310. 'thumbnail': 're:^https?://.*\.jpg$',
  311. },
  312. 'params': {
  313. 'skip_download': True, # requires ffmpeg
  314. },
  315. },
  316. {
  317. # Frontline video embedded via flp2012.js
  318. 'url': 'http://www.pbs.org/wgbh/pages/frontline/the-atomic-artists',
  319. 'info_dict': {
  320. 'id': '2070868960',
  321. 'display_id': 'the-atomic-artists',
  322. 'ext': 'mp4',
  323. 'title': 'FRONTLINE - The Atomic Artists',
  324. 'description': 'md5:f5bfbefadf421e8bb8647602011caf8e',
  325. 'duration': 723,
  326. 'thumbnail': 're:^https?://.*\.jpg$',
  327. },
  328. 'params': {
  329. 'skip_download': True, # requires ffmpeg
  330. },
  331. },
  332. {
  333. 'url': 'http://player.pbs.org/widget/partnerplayer/2365297708/?start=0&end=0&chapterbar=false&endscreen=false&topbar=true',
  334. 'only_matching': True,
  335. },
  336. {
  337. 'url': 'http://watch.knpb.org/video/2365616055/',
  338. 'only_matching': True,
  339. }
  340. ]
  341. _ERRORS = {
  342. 101: 'We\'re sorry, but this video is not yet available.',
  343. 403: 'We\'re sorry, but this video is not available in your region due to right restrictions.',
  344. 404: 'We are experiencing technical difficulties that are preventing us from playing the video at this time. Please check back again soon.',
  345. 410: 'This video has expired and is no longer available for online streaming.',
  346. }
  347. def _extract_webpage(self, url):
  348. mobj = re.match(self._VALID_URL, url)
  349. presumptive_id = mobj.group('presumptive_id')
  350. display_id = presumptive_id
  351. if presumptive_id:
  352. webpage = self._download_webpage(url, display_id)
  353. upload_date = unified_strdate(self._search_regex(
  354. r'<input type="hidden" id="air_date_[0-9]+" value="([^"]+)"',
  355. webpage, 'upload date', default=None))
  356. # tabbed frontline videos
  357. tabbed_videos = re.findall(
  358. r'<div[^>]+class="videotab[^"]*"[^>]+vid="(\d+)"', webpage)
  359. if tabbed_videos:
  360. return tabbed_videos, presumptive_id, upload_date
  361. MEDIA_ID_REGEXES = [
  362. r"div\s*:\s*'videoembed'\s*,\s*mediaid\s*:\s*'(\d+)'", # frontline video embed
  363. r'class="coveplayerid">([^<]+)<', # coveplayer
  364. r'<section[^>]+data-coveid="(\d+)"', # coveplayer from http://www.pbs.org/wgbh/frontline/film/real-csi/
  365. r'<input type="hidden" id="pbs_video_id_[0-9]+" value="([0-9]+)"/>', # jwplayer
  366. ]
  367. media_id = self._search_regex(
  368. MEDIA_ID_REGEXES, webpage, 'media ID', fatal=False, default=None)
  369. if media_id:
  370. return media_id, presumptive_id, upload_date
  371. # Fronline video embedded via flp
  372. video_id = self._search_regex(
  373. r'videoid\s*:\s*"([\d+a-z]{7,})"', webpage, 'videoid', default=None)
  374. if video_id:
  375. # pkg_id calculation is reverse engineered from
  376. # http://www.pbs.org/wgbh/pages/frontline/js/flp2012.js
  377. prg_id = self._search_regex(
  378. r'videoid\s*:\s*"([\d+a-z]{7,})"', webpage, 'videoid')[7:]
  379. if 'q' in prg_id:
  380. prg_id = prg_id.split('q')[1]
  381. prg_id = int(prg_id, 16)
  382. getdir = self._download_json(
  383. 'http://www.pbs.org/wgbh/pages/frontline/.json/getdir/getdir%d.json' % prg_id,
  384. presumptive_id, 'Downloading getdir JSON',
  385. transform_source=strip_jsonp)
  386. return getdir['mid'], presumptive_id, upload_date
  387. for iframe in re.findall(r'(?s)<iframe(.+?)></iframe>', webpage):
  388. url = self._search_regex(
  389. r'src=(["\'])(?P<url>.+?partnerplayer.+?)\1', iframe,
  390. 'player URL', default=None, group='url')
  391. if url:
  392. break
  393. mobj = re.match(self._VALID_URL, url)
  394. player_id = mobj.group('player_id')
  395. if not display_id:
  396. display_id = player_id
  397. if player_id:
  398. player_page = self._download_webpage(
  399. url, display_id, note='Downloading player page',
  400. errnote='Could not download player page')
  401. video_id = self._search_regex(
  402. r'<div\s+id="video_([0-9]+)"', player_page, 'video ID')
  403. else:
  404. video_id = mobj.group('id')
  405. display_id = video_id
  406. return video_id, display_id, None
  407. def _real_extract(self, url):
  408. video_id, display_id, upload_date = self._extract_webpage(url)
  409. if isinstance(video_id, list):
  410. entries = [self.url_result(
  411. 'http://video.pbs.org/video/%s' % vid_id, 'PBS', vid_id)
  412. for vid_id in video_id]
  413. return self.playlist_result(entries, display_id)
  414. info = self._download_json(
  415. 'http://player.pbs.org/videoInfo/%s?format=json&type=partner' % video_id,
  416. display_id)
  417. formats = []
  418. for encoding_name in ('recommended_encoding', 'alternate_encoding'):
  419. redirect = info.get(encoding_name)
  420. if not redirect:
  421. continue
  422. redirect_url = redirect.get('url')
  423. if not redirect_url:
  424. continue
  425. redirect_info = self._download_json(
  426. redirect_url + '?format=json', display_id,
  427. 'Downloading %s video url info' % encoding_name)
  428. if redirect_info['status'] == 'error':
  429. raise ExtractorError(
  430. '%s said: %s' % (
  431. self.IE_NAME,
  432. self._ERRORS.get(redirect_info['http_code'], redirect_info['message'])),
  433. expected=True)
  434. format_url = redirect_info.get('url')
  435. if not format_url:
  436. continue
  437. if determine_ext(format_url) == 'm3u8':
  438. formats.extend(self._extract_m3u8_formats(
  439. format_url, display_id, 'mp4', preference=1, m3u8_id='hls'))
  440. else:
  441. formats.append({
  442. 'url': format_url,
  443. 'format_id': redirect.get('eeid'),
  444. })
  445. self._sort_formats(formats)
  446. rating_str = info.get('rating')
  447. if rating_str is not None:
  448. rating_str = rating_str.rpartition('-')[2]
  449. age_limit = US_RATINGS.get(rating_str)
  450. subtitles = {}
  451. closed_captions_url = info.get('closed_captions_url')
  452. if closed_captions_url:
  453. subtitles['en'] = [{
  454. 'ext': 'ttml',
  455. 'url': closed_captions_url,
  456. }]
  457. # info['title'] is often incomplete (e.g. 'Full Episode', 'Episode 5', etc)
  458. # Try turning it to 'program - title' naming scheme if possible
  459. alt_title = info.get('program', {}).get('title')
  460. if alt_title:
  461. info['title'] = alt_title + ' - ' + re.sub(r'^' + alt_title + '[\s\-:]+', '', info['title'])
  462. return {
  463. 'id': video_id,
  464. 'display_id': display_id,
  465. 'title': info['title'],
  466. 'description': info['program'].get('description'),
  467. 'thumbnail': info.get('image_url'),
  468. 'duration': int_or_none(info.get('duration')),
  469. 'age_limit': age_limit,
  470. 'upload_date': upload_date,
  471. 'formats': formats,
  472. 'subtitles': subtitles,
  473. }