generic.py 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200
  1. # encoding: utf-8
  2. from __future__ import unicode_literals
  3. import os
  4. import re
  5. from .common import InfoExtractor
  6. from .youtube import YoutubeIE
  7. from ..compat import (
  8. compat_urllib_parse,
  9. compat_urlparse,
  10. compat_xml_parse_error,
  11. )
  12. from ..utils import (
  13. determine_ext,
  14. ExtractorError,
  15. float_or_none,
  16. HEADRequest,
  17. is_html,
  18. orderedSet,
  19. parse_xml,
  20. smuggle_url,
  21. unescapeHTML,
  22. unified_strdate,
  23. unsmuggle_url,
  24. UnsupportedError,
  25. url_basename,
  26. )
  27. from .brightcove import BrightcoveIE
  28. from .ooyala import OoyalaIE
  29. from .rutv import RUTVIE
  30. from .smotri import SmotriIE
  31. from .condenast import CondeNastIE
  32. class GenericIE(InfoExtractor):
  33. IE_DESC = 'Generic downloader that works on some sites'
  34. _VALID_URL = r'.*'
  35. IE_NAME = 'generic'
  36. _TESTS = [
  37. {
  38. 'url': 'http://www.hodiho.fr/2013/02/regis-plante-sa-jeep.html',
  39. 'md5': '85b90ccc9d73b4acd9138d3af4c27f89',
  40. 'info_dict': {
  41. 'id': '13601338388002',
  42. 'ext': 'mp4',
  43. 'uploader': 'www.hodiho.fr',
  44. 'title': 'R\u00e9gis plante sa Jeep',
  45. }
  46. },
  47. # bandcamp page with custom domain
  48. {
  49. 'add_ie': ['Bandcamp'],
  50. 'url': 'http://bronyrock.com/track/the-pony-mash',
  51. 'info_dict': {
  52. 'id': '3235767654',
  53. 'ext': 'mp3',
  54. 'title': 'The Pony Mash',
  55. 'uploader': 'M_Pallante',
  56. },
  57. 'skip': 'There is a limit of 200 free downloads / month for the test song',
  58. },
  59. # embedded brightcove video
  60. # it also tests brightcove videos that need to set the 'Referer' in the
  61. # http requests
  62. {
  63. 'add_ie': ['Brightcove'],
  64. 'url': 'http://www.bfmtv.com/video/bfmbusiness/cours-bourse/cours-bourse-l-analyse-technique-154522/',
  65. 'info_dict': {
  66. 'id': '2765128793001',
  67. 'ext': 'mp4',
  68. 'title': 'Le cours de bourse : l’analyse technique',
  69. 'description': 'md5:7e9ad046e968cb2d1114004aba466fd9',
  70. 'uploader': 'BFM BUSINESS',
  71. },
  72. 'params': {
  73. 'skip_download': True,
  74. },
  75. },
  76. {
  77. # https://github.com/rg3/youtube-dl/issues/2253
  78. 'url': 'http://bcove.me/i6nfkrc3',
  79. 'md5': '0ba9446db037002366bab3b3eb30c88c',
  80. 'info_dict': {
  81. 'id': '3101154703001',
  82. 'ext': 'mp4',
  83. 'title': 'Still no power',
  84. 'uploader': 'thestar.com',
  85. 'description': 'Mississauga resident David Farmer is still out of power as a result of the ice storm a month ago. To keep the house warm, Farmer cuts wood from his property for a wood burning stove downstairs.',
  86. },
  87. 'add_ie': ['Brightcove'],
  88. },
  89. {
  90. 'url': 'http://www.championat.com/video/football/v/87/87499.html',
  91. 'md5': 'fb973ecf6e4a78a67453647444222983',
  92. 'info_dict': {
  93. 'id': '3414141473001',
  94. 'ext': 'mp4',
  95. 'title': 'Видео. Удаление Дзагоева (ЦСКА)',
  96. 'description': 'Онлайн-трансляция матча ЦСКА - "Волга"',
  97. 'uploader': 'Championat',
  98. },
  99. },
  100. {
  101. # https://github.com/rg3/youtube-dl/issues/3541
  102. 'add_ie': ['Brightcove'],
  103. 'url': 'http://www.kijk.nl/sbs6/leermijvrouwenkennen/videos/jqMiXKAYan2S/aflevering-1',
  104. 'info_dict': {
  105. 'id': '3866516442001',
  106. 'ext': 'mp4',
  107. 'title': 'Leer mij vrouwen kennen: Aflevering 1',
  108. 'description': 'Leer mij vrouwen kennen: Aflevering 1',
  109. 'uploader': 'SBS Broadcasting',
  110. },
  111. 'skip': 'Restricted to Netherlands',
  112. 'params': {
  113. 'skip_download': True, # m3u8 download
  114. },
  115. },
  116. # Direct link to a video
  117. {
  118. 'url': 'http://media.w3.org/2010/05/sintel/trailer.mp4',
  119. 'md5': '67d406c2bcb6af27fa886f31aa934bbe',
  120. 'info_dict': {
  121. 'id': 'trailer',
  122. 'ext': 'mp4',
  123. 'title': 'trailer',
  124. 'upload_date': '20100513',
  125. }
  126. },
  127. # ooyala video
  128. {
  129. 'url': 'http://www.rollingstone.com/music/videos/norwegian-dj-cashmere-cat-goes-spartan-on-with-me-premiere-20131219',
  130. 'md5': '166dd577b433b4d4ebfee10b0824d8ff',
  131. 'info_dict': {
  132. 'id': 'BwY2RxaTrTkslxOfcan0UCf0YqyvWysJ',
  133. 'ext': 'mp4',
  134. 'title': '2cc213299525360.mov', # that's what we get
  135. },
  136. 'add_ie': ['Ooyala'],
  137. },
  138. # multiple ooyala embeds on SBN network websites
  139. {
  140. 'url': 'http://www.sbnation.com/college-football-recruiting/2015/2/3/7970291/national-signing-day-rationalizations-itll-be-ok-itll-be-ok',
  141. 'info_dict': {
  142. 'id': 'national-signing-day-rationalizations-itll-be-ok-itll-be-ok',
  143. 'title': '25 lies you will tell yourself on National Signing Day - SBNation.com',
  144. },
  145. 'playlist_mincount': 3,
  146. 'params': {
  147. 'skip_download': True,
  148. },
  149. 'add_ie': ['Ooyala'],
  150. },
  151. # google redirect
  152. {
  153. 'url': 'http://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&ved=0CCUQtwIwAA&url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DcmQHVoWB5FY&ei=F-sNU-LLCaXk4QT52ICQBQ&usg=AFQjCNEw4hL29zgOohLXvpJ-Bdh2bils1Q&bvm=bv.61965928,d.bGE',
  154. 'info_dict': {
  155. 'id': 'cmQHVoWB5FY',
  156. 'ext': 'mp4',
  157. 'upload_date': '20130224',
  158. 'uploader_id': 'TheVerge',
  159. 'description': 're:^Chris Ziegler takes a look at the\.*',
  160. 'uploader': 'The Verge',
  161. 'title': 'First Firefox OS phones side-by-side',
  162. },
  163. 'params': {
  164. 'skip_download': False,
  165. }
  166. },
  167. # embed.ly video
  168. {
  169. 'url': 'http://www.tested.com/science/weird/460206-tested-grinding-coffee-2000-frames-second/',
  170. 'info_dict': {
  171. 'id': '9ODmcdjQcHQ',
  172. 'ext': 'mp4',
  173. 'title': 'Tested: Grinding Coffee at 2000 Frames Per Second',
  174. 'upload_date': '20140225',
  175. 'description': 'md5:06a40fbf30b220468f1e0957c0f558ff',
  176. 'uploader': 'Tested',
  177. 'uploader_id': 'testedcom',
  178. },
  179. # No need to test YoutubeIE here
  180. 'params': {
  181. 'skip_download': True,
  182. },
  183. },
  184. # funnyordie embed
  185. {
  186. 'url': 'http://www.theguardian.com/world/2014/mar/11/obama-zach-galifianakis-between-two-ferns',
  187. 'info_dict': {
  188. 'id': '18e820ec3f',
  189. 'ext': 'mp4',
  190. 'title': 'Between Two Ferns with Zach Galifianakis: President Barack Obama',
  191. 'description': 'Episode 18: President Barack Obama sits down with Zach Galifianakis for his most memorable interview yet.',
  192. },
  193. },
  194. # BBC iPlayer embeds
  195. {
  196. 'url': 'http://www.bbc.co.uk/blogs/adamcurtis/posts/BUGGER',
  197. 'info_dict': {
  198. 'title': 'BBC - Blogs - Adam Curtis - BUGGER',
  199. },
  200. 'playlist_mincount': 18,
  201. },
  202. # RUTV embed
  203. {
  204. 'url': 'http://www.rg.ru/2014/03/15/reg-dfo/anklav-anons.html',
  205. 'info_dict': {
  206. 'id': '776940',
  207. 'ext': 'mp4',
  208. 'title': 'Охотское море стало целиком российским',
  209. 'description': 'md5:5ed62483b14663e2a95ebbe115eb8f43',
  210. },
  211. 'params': {
  212. # m3u8 download
  213. 'skip_download': True,
  214. },
  215. },
  216. # Embedded TED video
  217. {
  218. 'url': 'http://en.support.wordpress.com/videos/ted-talks/',
  219. 'md5': '65fdff94098e4a607385a60c5177c638',
  220. 'info_dict': {
  221. 'id': '1969',
  222. 'ext': 'mp4',
  223. 'title': 'Hidden miracles of the natural world',
  224. 'uploader': 'Louie Schwartzberg',
  225. 'description': 'md5:8145d19d320ff3e52f28401f4c4283b9',
  226. }
  227. },
  228. # Embeded Ustream video
  229. {
  230. 'url': 'http://www.american.edu/spa/pti/nsa-privacy-janus-2014.cfm',
  231. 'md5': '27b99cdb639c9b12a79bca876a073417',
  232. 'info_dict': {
  233. 'id': '45734260',
  234. 'ext': 'flv',
  235. 'uploader': 'AU SPA: The NSA and Privacy',
  236. 'title': 'NSA and Privacy Forum Debate featuring General Hayden and Barton Gellman'
  237. }
  238. },
  239. # nowvideo embed hidden behind percent encoding
  240. {
  241. 'url': 'http://www.waoanime.tv/the-super-dimension-fortress-macross-episode-1/',
  242. 'md5': '2baf4ddd70f697d94b1c18cf796d5107',
  243. 'info_dict': {
  244. 'id': '06e53103ca9aa',
  245. 'ext': 'flv',
  246. 'title': 'Macross Episode 001 Watch Macross Episode 001 onl',
  247. 'description': 'No description',
  248. },
  249. },
  250. # arte embed
  251. {
  252. 'url': 'http://www.tv-replay.fr/redirection/20-03-14/x-enius-arte-10753389.html',
  253. 'md5': '7653032cbb25bf6c80d80f217055fa43',
  254. 'info_dict': {
  255. 'id': '048195-004_PLUS7-F',
  256. 'ext': 'flv',
  257. 'title': 'X:enius',
  258. 'description': 'md5:d5fdf32ef6613cdbfd516ae658abf168',
  259. 'upload_date': '20140320',
  260. },
  261. 'params': {
  262. 'skip_download': 'Requires rtmpdump'
  263. }
  264. },
  265. # Condé Nast embed
  266. {
  267. 'url': 'http://www.wired.com/2014/04/honda-asimo/',
  268. 'md5': 'ba0dfe966fa007657bd1443ee672db0f',
  269. 'info_dict': {
  270. 'id': '53501be369702d3275860000',
  271. 'ext': 'mp4',
  272. 'title': 'Honda’s New Asimo Robot Is More Human Than Ever',
  273. }
  274. },
  275. # Dailymotion embed
  276. {
  277. 'url': 'http://www.spi0n.com/zap-spi0n-com-n216/',
  278. 'md5': '441aeeb82eb72c422c7f14ec533999cd',
  279. 'info_dict': {
  280. 'id': 'k2mm4bCdJ6CQ2i7c8o2',
  281. 'ext': 'mp4',
  282. 'title': 'Le Zap de Spi0n n°216 - Zapping du Web',
  283. 'uploader': 'Spi0n',
  284. },
  285. 'add_ie': ['Dailymotion'],
  286. },
  287. # YouTube embed
  288. {
  289. 'url': 'http://www.badzine.de/ansicht/datum/2014/06/09/so-funktioniert-die-neue-englische-badminton-liga.html',
  290. 'info_dict': {
  291. 'id': 'FXRb4ykk4S0',
  292. 'ext': 'mp4',
  293. 'title': 'The NBL Auction 2014',
  294. 'uploader': 'BADMINTON England',
  295. 'uploader_id': 'BADMINTONEvents',
  296. 'upload_date': '20140603',
  297. 'description': 'md5:9ef128a69f1e262a700ed83edb163a73',
  298. },
  299. 'add_ie': ['Youtube'],
  300. 'params': {
  301. 'skip_download': True,
  302. }
  303. },
  304. # MTVSercices embed
  305. {
  306. 'url': 'http://www.gametrailers.com/news-post/76093/north-america-europe-is-getting-that-mario-kart-8-mercedes-dlc-too',
  307. 'md5': '35727f82f58c76d996fc188f9755b0d5',
  308. 'info_dict': {
  309. 'id': '0306a69b-8adf-4fb5-aace-75f8e8cbfca9',
  310. 'ext': 'mp4',
  311. 'title': 'Review',
  312. 'description': 'Mario\'s life in the fast lane has never looked so good.',
  313. },
  314. },
  315. # YouTube embed via <data-embed-url="">
  316. {
  317. 'url': 'https://play.google.com/store/apps/details?id=com.gameloft.android.ANMP.GloftA8HM',
  318. 'info_dict': {
  319. 'id': '4vAffPZIT44',
  320. 'ext': 'mp4',
  321. 'title': 'Asphalt 8: Airborne - Update - Welcome to Dubai!',
  322. 'uploader': 'Gameloft',
  323. 'uploader_id': 'gameloft',
  324. 'upload_date': '20140828',
  325. 'description': 'md5:c80da9ed3d83ae6d1876c834de03e1c4',
  326. },
  327. 'params': {
  328. 'skip_download': True,
  329. }
  330. },
  331. # Camtasia studio
  332. {
  333. 'url': 'http://www.ll.mit.edu/workshops/education/videocourses/antennas/lecture1/video/',
  334. 'playlist': [{
  335. 'md5': '0c5e352edabf715d762b0ad4e6d9ee67',
  336. 'info_dict': {
  337. 'id': 'Fenn-AA_PA_Radar_Course_Lecture_1c_Final',
  338. 'title': 'Fenn-AA_PA_Radar_Course_Lecture_1c_Final - video1',
  339. 'ext': 'flv',
  340. 'duration': 2235.90,
  341. }
  342. }, {
  343. 'md5': '10e4bb3aaca9fd630e273ff92d9f3c63',
  344. 'info_dict': {
  345. 'id': 'Fenn-AA_PA_Radar_Course_Lecture_1c_Final_PIP',
  346. 'title': 'Fenn-AA_PA_Radar_Course_Lecture_1c_Final - pip',
  347. 'ext': 'flv',
  348. 'duration': 2235.93,
  349. }
  350. }],
  351. 'info_dict': {
  352. 'title': 'Fenn-AA_PA_Radar_Course_Lecture_1c_Final',
  353. }
  354. },
  355. # Flowplayer
  356. {
  357. 'url': 'http://www.handjobhub.com/video/busty-blonde-siri-tit-fuck-while-wank-6313.html',
  358. 'md5': '9d65602bf31c6e20014319c7d07fba27',
  359. 'info_dict': {
  360. 'id': '5123ea6d5e5a7',
  361. 'ext': 'mp4',
  362. 'age_limit': 18,
  363. 'uploader': 'www.handjobhub.com',
  364. 'title': 'Busty Blonde Siri Tit Fuck While Wank at HandjobHub.com',
  365. }
  366. },
  367. # RSS feed
  368. {
  369. 'url': 'http://phihag.de/2014/youtube-dl/rss2.xml',
  370. 'info_dict': {
  371. 'id': 'http://phihag.de/2014/youtube-dl/rss2.xml',
  372. 'title': 'Zero Punctuation',
  373. 'description': 're:.*groundbreaking video review series.*'
  374. },
  375. 'playlist_mincount': 11,
  376. },
  377. # Multiple brightcove videos
  378. # https://github.com/rg3/youtube-dl/issues/2283
  379. {
  380. 'url': 'http://www.newyorker.com/online/blogs/newsdesk/2014/01/always-never-nuclear-command-and-control.html',
  381. 'info_dict': {
  382. 'id': 'always-never',
  383. 'title': 'Always / Never - The New Yorker',
  384. },
  385. 'playlist_count': 3,
  386. 'params': {
  387. 'extract_flat': False,
  388. 'skip_download': True,
  389. }
  390. },
  391. # MLB embed
  392. {
  393. 'url': 'http://umpire-empire.com/index.php/topic/58125-laz-decides-no-thats-low/',
  394. 'md5': '96f09a37e44da40dd083e12d9a683327',
  395. 'info_dict': {
  396. 'id': '33322633',
  397. 'ext': 'mp4',
  398. 'title': 'Ump changes call to ball',
  399. 'description': 'md5:71c11215384298a172a6dcb4c2e20685',
  400. 'duration': 48,
  401. 'timestamp': 1401537900,
  402. 'upload_date': '20140531',
  403. 'thumbnail': 're:^https?://.*\.jpg$',
  404. },
  405. },
  406. # Wistia embed
  407. {
  408. 'url': 'http://education-portal.com/academy/lesson/north-american-exploration-failed-colonies-of-spain-france-england.html#lesson',
  409. 'md5': '8788b683c777a5cf25621eaf286d0c23',
  410. 'info_dict': {
  411. 'id': '1cfaf6b7ea',
  412. 'ext': 'mov',
  413. 'title': 'md5:51364a8d3d009997ba99656004b5e20d',
  414. 'duration': 643.0,
  415. 'filesize': 182808282,
  416. 'uploader': 'education-portal.com',
  417. },
  418. },
  419. {
  420. 'url': 'http://thoughtworks.wistia.com/medias/uxjb0lwrcz',
  421. 'md5': 'baf49c2baa8a7de5f3fc145a8506dcd4',
  422. 'info_dict': {
  423. 'id': 'uxjb0lwrcz',
  424. 'ext': 'mp4',
  425. 'title': 'Conversation about Hexagonal Rails Part 1 - ThoughtWorks',
  426. 'duration': 1715.0,
  427. 'uploader': 'thoughtworks.wistia.com',
  428. },
  429. },
  430. # Direct download with broken HEAD
  431. {
  432. 'url': 'http://ai-radio.org:8000/radio.opus',
  433. 'info_dict': {
  434. 'id': 'radio',
  435. 'ext': 'opus',
  436. 'title': 'radio',
  437. },
  438. 'params': {
  439. 'skip_download': True, # infinite live stream
  440. },
  441. 'expected_warnings': [
  442. r'501.*Not Implemented'
  443. ],
  444. },
  445. # Soundcloud embed
  446. {
  447. 'url': 'http://nakedsecurity.sophos.com/2014/10/29/sscc-171-are-you-sure-that-1234-is-a-bad-password-podcast/',
  448. 'info_dict': {
  449. 'id': '174391317',
  450. 'ext': 'mp3',
  451. 'description': 'md5:ff867d6b555488ad3c52572bb33d432c',
  452. 'uploader': 'Sophos Security',
  453. 'title': 'Chet Chat 171 - Oct 29, 2014',
  454. 'upload_date': '20141029',
  455. }
  456. },
  457. # Livestream embed
  458. {
  459. 'url': 'http://www.esa.int/Our_Activities/Space_Science/Rosetta/Philae_comet_touch-down_webcast',
  460. 'info_dict': {
  461. 'id': '67864563',
  462. 'ext': 'flv',
  463. 'upload_date': '20141112',
  464. 'title': 'Rosetta #CometLanding webcast HL 10',
  465. }
  466. },
  467. # LazyYT
  468. {
  469. 'url': 'http://discourse.ubuntu.com/t/unity-8-desktop-mode-windows-on-mir/1986',
  470. 'info_dict': {
  471. 'id': '1986',
  472. 'title': 'Unity 8 desktop-mode windows on Mir! - Ubuntu Discourse',
  473. },
  474. 'playlist_mincount': 2,
  475. },
  476. # Direct link with incorrect MIME type
  477. {
  478. 'url': 'http://ftp.nluug.nl/video/nluug/2014-11-20_nj14/zaal-2/5_Lennart_Poettering_-_Systemd.webm',
  479. 'md5': '4ccbebe5f36706d85221f204d7eb5913',
  480. 'info_dict': {
  481. 'url': 'http://ftp.nluug.nl/video/nluug/2014-11-20_nj14/zaal-2/5_Lennart_Poettering_-_Systemd.webm',
  482. 'id': '5_Lennart_Poettering_-_Systemd',
  483. 'ext': 'webm',
  484. 'title': '5_Lennart_Poettering_-_Systemd',
  485. 'upload_date': '20141120',
  486. },
  487. 'expected_warnings': [
  488. 'URL could be a direct video link, returning it as such.'
  489. ]
  490. },
  491. # Cinchcast embed
  492. {
  493. 'url': 'http://undergroundwellness.com/podcasts/306-5-steps-to-permanent-gut-healing/',
  494. 'info_dict': {
  495. 'id': '7141703',
  496. 'ext': 'mp3',
  497. 'upload_date': '20141126',
  498. 'title': 'Jack Tips: 5 Steps to Permanent Gut Healing',
  499. }
  500. },
  501. # Cinerama player
  502. {
  503. 'url': 'http://www.abc.net.au/7.30/content/2015/s4164797.htm',
  504. 'info_dict': {
  505. 'id': '730m_DandD_1901_512k',
  506. 'ext': 'mp4',
  507. 'uploader': 'www.abc.net.au',
  508. 'title': 'Game of Thrones with dice - Dungeons and Dragons fantasy role-playing game gets new life - 19/01/2015',
  509. }
  510. },
  511. # embedded viddler video
  512. {
  513. 'url': 'http://deadspin.com/i-cant-stop-watching-john-wall-chop-the-nuggets-with-th-1681801597',
  514. 'info_dict': {
  515. 'id': '4d03aad9',
  516. 'ext': 'mp4',
  517. 'uploader': 'deadspin',
  518. 'title': 'WALL-TO-GORTAT',
  519. 'timestamp': 1422285291,
  520. 'upload_date': '20150126',
  521. },
  522. 'add_ie': ['Viddler'],
  523. },
  524. # jwplayer YouTube
  525. {
  526. 'url': 'http://media.nationalarchives.gov.uk/index.php/webinar-using-discovery-national-archives-online-catalogue/',
  527. 'info_dict': {
  528. 'id': 'Mrj4DVp2zeA',
  529. 'ext': 'mp4',
  530. 'upload_date': '20150204',
  531. 'uploader': 'The National Archives UK',
  532. 'description': 'md5:a236581cd2449dd2df4f93412f3f01c6',
  533. 'uploader_id': 'NationalArchives08',
  534. 'title': 'Webinar: Using Discovery, The National Archives’ online catalogue',
  535. },
  536. },
  537. # rtl.nl embed
  538. {
  539. 'url': 'http://www.rtlnieuws.nl/nieuws/buitenland/aanslagen-kopenhagen',
  540. 'playlist_mincount': 5,
  541. 'info_dict': {
  542. 'id': 'aanslagen-kopenhagen',
  543. 'title': 'Aanslagen Kopenhagen | RTL Nieuws',
  544. }
  545. }
  546. ]
  547. def report_following_redirect(self, new_url):
  548. """Report information extraction."""
  549. self._downloader.to_screen('[redirect] Following redirect to %s' % new_url)
  550. def _extract_rss(self, url, video_id, doc):
  551. playlist_title = doc.find('./channel/title').text
  552. playlist_desc_el = doc.find('./channel/description')
  553. playlist_desc = None if playlist_desc_el is None else playlist_desc_el.text
  554. entries = [{
  555. '_type': 'url',
  556. 'url': e.find('link').text,
  557. 'title': e.find('title').text,
  558. } for e in doc.findall('./channel/item')]
  559. return {
  560. '_type': 'playlist',
  561. 'id': url,
  562. 'title': playlist_title,
  563. 'description': playlist_desc,
  564. 'entries': entries,
  565. }
  566. def _extract_camtasia(self, url, video_id, webpage):
  567. """ Returns None if no camtasia video can be found. """
  568. camtasia_cfg = self._search_regex(
  569. r'fo\.addVariable\(\s*"csConfigFile",\s*"([^"]+)"\s*\);',
  570. webpage, 'camtasia configuration file', default=None)
  571. if camtasia_cfg is None:
  572. return None
  573. title = self._html_search_meta('DC.title', webpage, fatal=True)
  574. camtasia_url = compat_urlparse.urljoin(url, camtasia_cfg)
  575. camtasia_cfg = self._download_xml(
  576. camtasia_url, video_id,
  577. note='Downloading camtasia configuration',
  578. errnote='Failed to download camtasia configuration')
  579. fileset_node = camtasia_cfg.find('./playlist/array/fileset')
  580. entries = []
  581. for n in fileset_node.getchildren():
  582. url_n = n.find('./uri')
  583. if url_n is None:
  584. continue
  585. entries.append({
  586. 'id': os.path.splitext(url_n.text.rpartition('/')[2])[0],
  587. 'title': '%s - %s' % (title, n.tag),
  588. 'url': compat_urlparse.urljoin(url, url_n.text),
  589. 'duration': float_or_none(n.find('./duration').text),
  590. })
  591. return {
  592. '_type': 'playlist',
  593. 'entries': entries,
  594. 'title': title,
  595. }
  596. def _real_extract(self, url):
  597. if url.startswith('//'):
  598. return {
  599. '_type': 'url',
  600. 'url': self.http_scheme() + url,
  601. }
  602. parsed_url = compat_urlparse.urlparse(url)
  603. if not parsed_url.scheme:
  604. default_search = self._downloader.params.get('default_search')
  605. if default_search is None:
  606. default_search = 'fixup_error'
  607. if default_search in ('auto', 'auto_warning', 'fixup_error'):
  608. if '/' in url:
  609. self._downloader.report_warning('The url doesn\'t specify the protocol, trying with http')
  610. return self.url_result('http://' + url)
  611. elif default_search != 'fixup_error':
  612. if default_search == 'auto_warning':
  613. if re.match(r'^(?:url|URL)$', url):
  614. raise ExtractorError(
  615. 'Invalid URL: %r . Call youtube-dl like this: youtube-dl -v "https://www.youtube.com/watch?v=BaW_jenozKc" ' % url,
  616. expected=True)
  617. else:
  618. self._downloader.report_warning(
  619. 'Falling back to youtube search for %s . Set --default-search "auto" to suppress this warning.' % url)
  620. return self.url_result('ytsearch:' + url)
  621. if default_search in ('error', 'fixup_error'):
  622. raise ExtractorError(
  623. '%r is not a valid URL. '
  624. 'Set --default-search "ytsearch" (or run youtube-dl "ytsearch:%s" ) to search YouTube'
  625. % (url, url), expected=True)
  626. else:
  627. if ':' not in default_search:
  628. default_search += ':'
  629. return self.url_result(default_search + url)
  630. url, smuggled_data = unsmuggle_url(url)
  631. force_videoid = None
  632. is_intentional = smuggled_data and smuggled_data.get('to_generic')
  633. if smuggled_data and 'force_videoid' in smuggled_data:
  634. force_videoid = smuggled_data['force_videoid']
  635. video_id = force_videoid
  636. else:
  637. video_id = os.path.splitext(url.rstrip('/').split('/')[-1])[0]
  638. self.to_screen('%s: Requesting header' % video_id)
  639. head_req = HEADRequest(url)
  640. head_response = self._request_webpage(
  641. head_req, video_id,
  642. note=False, errnote='Could not send HEAD request to %s' % url,
  643. fatal=False)
  644. if head_response is not False:
  645. # Check for redirect
  646. new_url = head_response.geturl()
  647. if url != new_url:
  648. self.report_following_redirect(new_url)
  649. if force_videoid:
  650. new_url = smuggle_url(
  651. new_url, {'force_videoid': force_videoid})
  652. return self.url_result(new_url)
  653. full_response = None
  654. if head_response is False:
  655. full_response = self._request_webpage(url, video_id)
  656. head_response = full_response
  657. # Check for direct link to a video
  658. content_type = head_response.headers.get('Content-Type', '')
  659. m = re.match(r'^(?P<type>audio|video|application(?=/ogg$))/(?P<format_id>.+)$', content_type)
  660. if m:
  661. upload_date = unified_strdate(
  662. head_response.headers.get('Last-Modified'))
  663. return {
  664. 'id': video_id,
  665. 'title': os.path.splitext(url_basename(url))[0],
  666. 'direct': True,
  667. 'formats': [{
  668. 'format_id': m.group('format_id'),
  669. 'url': url,
  670. 'vcodec': 'none' if m.group('type') == 'audio' else None
  671. }],
  672. 'upload_date': upload_date,
  673. }
  674. if not self._downloader.params.get('test', False) and not is_intentional:
  675. self._downloader.report_warning('Falling back on generic information extractor.')
  676. if not full_response:
  677. full_response = self._request_webpage(url, video_id)
  678. # Maybe it's a direct link to a video?
  679. # Be careful not to download the whole thing!
  680. first_bytes = full_response.read(512)
  681. if not is_html(first_bytes):
  682. self._downloader.report_warning(
  683. 'URL could be a direct video link, returning it as such.')
  684. upload_date = unified_strdate(
  685. head_response.headers.get('Last-Modified'))
  686. return {
  687. 'id': video_id,
  688. 'title': os.path.splitext(url_basename(url))[0],
  689. 'direct': True,
  690. 'url': url,
  691. 'upload_date': upload_date,
  692. }
  693. webpage = self._webpage_read_content(
  694. full_response, url, video_id, prefix=first_bytes)
  695. self.report_extraction(video_id)
  696. # Is it an RSS feed?
  697. try:
  698. doc = parse_xml(webpage)
  699. if doc.tag == 'rss':
  700. return self._extract_rss(url, video_id, doc)
  701. except compat_xml_parse_error:
  702. pass
  703. # Is it a Camtasia project?
  704. camtasia_res = self._extract_camtasia(url, video_id, webpage)
  705. if camtasia_res is not None:
  706. return camtasia_res
  707. # Sometimes embedded video player is hidden behind percent encoding
  708. # (e.g. https://github.com/rg3/youtube-dl/issues/2448)
  709. # Unescaping the whole page allows to handle those cases in a generic way
  710. webpage = compat_urllib_parse.unquote(webpage)
  711. # it's tempting to parse this further, but you would
  712. # have to take into account all the variations like
  713. # Video Title - Site Name
  714. # Site Name | Video Title
  715. # Video Title - Tagline | Site Name
  716. # and so on and so forth; it's just not practical
  717. video_title = self._html_search_regex(
  718. r'(?s)<title>(.*?)</title>', webpage, 'video title',
  719. default='video')
  720. # Try to detect age limit automatically
  721. age_limit = self._rta_search(webpage)
  722. # And then there are the jokers who advertise that they use RTA,
  723. # but actually don't.
  724. AGE_LIMIT_MARKERS = [
  725. r'Proudly Labeled <a href="http://www.rtalabel.org/" title="Restricted to Adults">RTA</a>',
  726. ]
  727. if any(re.search(marker, webpage) for marker in AGE_LIMIT_MARKERS):
  728. age_limit = 18
  729. # video uploader is domain name
  730. video_uploader = self._search_regex(
  731. r'^(?:https?://)?([^/]*)/.*', url, 'video uploader')
  732. # Helper method
  733. def _playlist_from_matches(matches, getter=None, ie=None):
  734. urlrs = orderedSet(
  735. self.url_result(self._proto_relative_url(getter(m) if getter else m), ie)
  736. for m in matches)
  737. return self.playlist_result(
  738. urlrs, playlist_id=video_id, playlist_title=video_title)
  739. # Look for BrightCove:
  740. bc_urls = BrightcoveIE._extract_brightcove_urls(webpage)
  741. if bc_urls:
  742. self.to_screen('Brightcove video detected.')
  743. entries = [{
  744. '_type': 'url',
  745. 'url': smuggle_url(bc_url, {'Referer': url}),
  746. 'ie_key': 'Brightcove'
  747. } for bc_url in bc_urls]
  748. return {
  749. '_type': 'playlist',
  750. 'title': video_title,
  751. 'id': video_id,
  752. 'entries': entries,
  753. }
  754. # Look for embedded rtl.nl player
  755. matches = re.findall(
  756. r'<iframe\s+(?:[a-zA-Z-]+="[^"]+"\s+)*?src="((?:https?:)?//(?:www\.)?rtl\.nl/system/videoplayer/[^"]+video_embed[^"]+)"',
  757. webpage)
  758. if matches:
  759. return _playlist_from_matches(matches, ie='RtlNl')
  760. # Look for embedded (iframe) Vimeo player
  761. mobj = re.search(
  762. r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//player\.vimeo\.com/video/.+?)\1', webpage)
  763. if mobj:
  764. player_url = unescapeHTML(mobj.group('url'))
  765. surl = smuggle_url(player_url, {'Referer': url})
  766. return self.url_result(surl)
  767. # Look for embedded (swf embed) Vimeo player
  768. mobj = re.search(
  769. r'<embed[^>]+?src="((?:https?:)?//(?:www\.)?vimeo\.com/moogaloop\.swf.+?)"', webpage)
  770. if mobj:
  771. return self.url_result(mobj.group(1))
  772. # Look for embedded YouTube player
  773. matches = re.findall(r'''(?x)
  774. (?:
  775. <iframe[^>]+?src=|
  776. data-video-url=|
  777. <embed[^>]+?src=|
  778. embedSWF\(?:\s*|
  779. new\s+SWFObject\(
  780. )
  781. (["\'])
  782. (?P<url>(?:https?:)?//(?:www\.)?youtube(?:-nocookie)?\.com/
  783. (?:embed|v|p)/.+?)
  784. \1''', webpage)
  785. if matches:
  786. return _playlist_from_matches(
  787. matches, lambda m: unescapeHTML(m[1]))
  788. # Look for lazyYT YouTube embed
  789. matches = re.findall(
  790. r'class="lazyYT" data-youtube-id="([^"]+)"', webpage)
  791. if matches:
  792. return _playlist_from_matches(matches, lambda m: unescapeHTML(m))
  793. # Look for embedded Dailymotion player
  794. matches = re.findall(
  795. r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:www\.)?dailymotion\.com/embed/video/.+?)\1', webpage)
  796. if matches:
  797. return _playlist_from_matches(
  798. matches, lambda m: unescapeHTML(m[1]))
  799. # Look for embedded Dailymotion playlist player (#3822)
  800. m = re.search(
  801. r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:www\.)?dailymotion\.[a-z]{2,3}/widget/jukebox\?.+?)\1', webpage)
  802. if m:
  803. playlists = re.findall(
  804. r'list\[\]=/playlist/([^/]+)/', unescapeHTML(m.group('url')))
  805. if playlists:
  806. return _playlist_from_matches(
  807. playlists, lambda p: '//dailymotion.com/playlist/%s' % p)
  808. # Look for embedded Wistia player
  809. match = re.search(
  810. r'<(?:meta[^>]+?content|iframe[^>]+?src)=(["\'])(?P<url>(?:https?:)?//(?:fast\.)?wistia\.net/embed/iframe/.+?)\1', webpage)
  811. if match:
  812. embed_url = self._proto_relative_url(
  813. unescapeHTML(match.group('url')))
  814. return {
  815. '_type': 'url_transparent',
  816. 'url': embed_url,
  817. 'ie_key': 'Wistia',
  818. 'uploader': video_uploader,
  819. 'title': video_title,
  820. 'id': video_id,
  821. }
  822. match = re.search(r'(?:id=["\']wistia_|data-wistia-?id=["\']|Wistia\.embed\(["\'])(?P<id>[^"\']+)', webpage)
  823. if match:
  824. return {
  825. '_type': 'url_transparent',
  826. 'url': 'http://fast.wistia.net/embed/iframe/{0:}'.format(match.group('id')),
  827. 'ie_key': 'Wistia',
  828. 'uploader': video_uploader,
  829. 'title': video_title,
  830. 'id': match.group('id')
  831. }
  832. # Look for embedded blip.tv player
  833. mobj = re.search(r'<meta\s[^>]*https?://api\.blip\.tv/\w+/redirect/\w+/(\d+)', webpage)
  834. if mobj:
  835. return self.url_result('http://blip.tv/a/a-' + mobj.group(1), 'BlipTV')
  836. mobj = re.search(r'<(?:iframe|embed|object)\s[^>]*(https?://(?:\w+\.)?blip\.tv/(?:play/|api\.swf#)[a-zA-Z0-9_]+)', webpage)
  837. if mobj:
  838. return self.url_result(mobj.group(1), 'BlipTV')
  839. # Look for embedded condenast player
  840. matches = re.findall(
  841. r'<iframe\s+(?:[a-zA-Z-]+="[^"]+"\s+)*?src="(https?://player\.cnevids\.com/embed/[^"]+")',
  842. webpage)
  843. if matches:
  844. return {
  845. '_type': 'playlist',
  846. 'entries': [{
  847. '_type': 'url',
  848. 'ie_key': 'CondeNast',
  849. 'url': ma,
  850. } for ma in matches],
  851. 'title': video_title,
  852. 'id': video_id,
  853. }
  854. # Look for Bandcamp pages with custom domain
  855. mobj = re.search(r'<meta property="og:url"[^>]*?content="(.*?bandcamp\.com.*?)"', webpage)
  856. if mobj is not None:
  857. burl = unescapeHTML(mobj.group(1))
  858. # Don't set the extractor because it can be a track url or an album
  859. return self.url_result(burl)
  860. # Look for embedded Vevo player
  861. mobj = re.search(
  862. r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:cache\.)?vevo\.com/.+?)\1', webpage)
  863. if mobj is not None:
  864. return self.url_result(mobj.group('url'))
  865. # Look for embedded Viddler player
  866. mobj = re.search(
  867. r'<(?:iframe[^>]+?src|param[^>]+?value)=(["\'])(?P<url>(?:https?:)?//(?:www\.)?viddler\.com/(?:embed|player)/.+?)\1',
  868. webpage)
  869. if mobj is not None:
  870. return self.url_result(mobj.group('url'))
  871. # Look for Ooyala videos
  872. mobj = (re.search(r'player\.ooyala\.com/[^"?]+\?[^"]*?(?:embedCode|ec)=(?P<ec>[^"&]+)', webpage) or
  873. re.search(r'OO\.Player\.create\([\'"].*?[\'"],\s*[\'"](?P<ec>.{32})[\'"]', webpage) or
  874. re.search(r'SBN\.VideoLinkset\.ooyala\([\'"](?P<ec>.{32})[\'"]\)', webpage))
  875. if mobj is not None:
  876. return OoyalaIE._build_url_result(mobj.group('ec'))
  877. # Look for multiple Ooyala embeds on SBN network websites
  878. mobj = re.search(r'SBN\.VideoLinkset\.entryGroup\((\[.*?\])', webpage)
  879. if mobj is not None:
  880. embeds = self._parse_json(mobj.group(1), video_id, fatal=False)
  881. if embeds:
  882. return _playlist_from_matches(
  883. embeds, getter=lambda v: OoyalaIE._url_for_embed_code(v['provider_video_id']), ie='Ooyala')
  884. # Look for Aparat videos
  885. mobj = re.search(r'<iframe .*?src="(http://www\.aparat\.com/video/[^"]+)"', webpage)
  886. if mobj is not None:
  887. return self.url_result(mobj.group(1), 'Aparat')
  888. # Look for MPORA videos
  889. mobj = re.search(r'<iframe .*?src="(http://mpora\.(?:com|de)/videos/[^"]+)"', webpage)
  890. if mobj is not None:
  891. return self.url_result(mobj.group(1), 'Mpora')
  892. # Look for embedded NovaMov-based player
  893. mobj = re.search(
  894. r'''(?x)<(?:pagespeed_)?iframe[^>]+?src=(["\'])
  895. (?P<url>http://(?:(?:embed|www)\.)?
  896. (?:novamov\.com|
  897. nowvideo\.(?:ch|sx|eu|at|ag|co)|
  898. videoweed\.(?:es|com)|
  899. movshare\.(?:net|sx|ag)|
  900. divxstage\.(?:eu|net|ch|co|at|ag))
  901. /embed\.php.+?)\1''', webpage)
  902. if mobj is not None:
  903. return self.url_result(mobj.group('url'))
  904. # Look for embedded Facebook player
  905. mobj = re.search(
  906. r'<iframe[^>]+?src=(["\'])(?P<url>https://www\.facebook\.com/video/embed.+?)\1', webpage)
  907. if mobj is not None:
  908. return self.url_result(mobj.group('url'), 'Facebook')
  909. # Look for embedded VK player
  910. mobj = re.search(r'<iframe[^>]+?src=(["\'])(?P<url>https?://vk\.com/video_ext\.php.+?)\1', webpage)
  911. if mobj is not None:
  912. return self.url_result(mobj.group('url'), 'VK')
  913. # Look for embedded ivi player
  914. mobj = re.search(r'<embed[^>]+?src=(["\'])(?P<url>https?://(?:www\.)?ivi\.ru/video/player.+?)\1', webpage)
  915. if mobj is not None:
  916. return self.url_result(mobj.group('url'), 'Ivi')
  917. # Look for embedded Huffington Post player
  918. mobj = re.search(
  919. r'<iframe[^>]+?src=(["\'])(?P<url>https?://embed\.live\.huffingtonpost\.com/.+?)\1', webpage)
  920. if mobj is not None:
  921. return self.url_result(mobj.group('url'), 'HuffPost')
  922. # Look for embed.ly
  923. mobj = re.search(r'class=["\']embedly-card["\'][^>]href=["\'](?P<url>[^"\']+)', webpage)
  924. if mobj is not None:
  925. return self.url_result(mobj.group('url'))
  926. mobj = re.search(r'class=["\']embedly-embed["\'][^>]src=["\'][^"\']*url=(?P<url>[^&]+)', webpage)
  927. if mobj is not None:
  928. return self.url_result(compat_urllib_parse.unquote(mobj.group('url')))
  929. # Look for funnyordie embed
  930. matches = re.findall(r'<iframe[^>]+?src="(https?://(?:www\.)?funnyordie\.com/embed/[^"]+)"', webpage)
  931. if matches:
  932. return _playlist_from_matches(
  933. matches, getter=unescapeHTML, ie='FunnyOrDie')
  934. # Look for BBC iPlayer embed
  935. matches = re.findall(r'setPlaylist\("(https?://www\.bbc\.co\.uk/iplayer/[^/]+/[\da-z]{8})"\)', webpage)
  936. if matches:
  937. return _playlist_from_matches(matches, ie='BBCCoUk')
  938. # Look for embedded RUTV player
  939. rutv_url = RUTVIE._extract_url(webpage)
  940. if rutv_url:
  941. return self.url_result(rutv_url, 'RUTV')
  942. # Look for embedded TED player
  943. mobj = re.search(
  944. r'<iframe[^>]+?src=(["\'])(?P<url>https?://embed(?:-ssl)?\.ted\.com/.+?)\1', webpage)
  945. if mobj is not None:
  946. return self.url_result(mobj.group('url'), 'TED')
  947. # Look for embedded Ustream videos
  948. mobj = re.search(
  949. r'<iframe[^>]+?src=(["\'])(?P<url>http://www\.ustream\.tv/embed/.+?)\1', webpage)
  950. if mobj is not None:
  951. return self.url_result(mobj.group('url'), 'Ustream')
  952. # Look for embedded arte.tv player
  953. mobj = re.search(
  954. r'<script [^>]*?src="(?P<url>http://www\.arte\.tv/playerv2/embed[^"]+)"',
  955. webpage)
  956. if mobj is not None:
  957. return self.url_result(mobj.group('url'), 'ArteTVEmbed')
  958. # Look for embedded smotri.com player
  959. smotri_url = SmotriIE._extract_url(webpage)
  960. if smotri_url:
  961. return self.url_result(smotri_url, 'Smotri')
  962. # Look for embeded soundcloud player
  963. mobj = re.search(
  964. r'<iframe\s+(?:[a-zA-Z0-9_-]+="[^"]+"\s+)*src="(?P<url>https?://(?:w\.)?soundcloud\.com/player[^"]+)"',
  965. webpage)
  966. if mobj is not None:
  967. url = unescapeHTML(mobj.group('url'))
  968. return self.url_result(url)
  969. # Look for embedded vulture.com player
  970. mobj = re.search(
  971. r'<iframe src="(?P<url>https?://video\.vulture\.com/[^"]+)"',
  972. webpage)
  973. if mobj is not None:
  974. url = unescapeHTML(mobj.group('url'))
  975. return self.url_result(url, ie='Vulture')
  976. # Look for embedded mtvservices player
  977. mobj = re.search(
  978. r'<iframe src="(?P<url>https?://media\.mtvnservices\.com/embed/[^"]+)"',
  979. webpage)
  980. if mobj is not None:
  981. url = unescapeHTML(mobj.group('url'))
  982. return self.url_result(url, ie='MTVServicesEmbedded')
  983. # Look for embedded yahoo player
  984. mobj = re.search(
  985. r'<iframe[^>]+?src=(["\'])(?P<url>https?://(?:screen|movies)\.yahoo\.com/.+?\.html\?format=embed)\1',
  986. webpage)
  987. if mobj is not None:
  988. return self.url_result(mobj.group('url'), 'Yahoo')
  989. # Look for embedded sbs.com.au player
  990. mobj = re.search(
  991. r'''(?x)
  992. (?:
  993. <meta\s+property="og:video"\s+content=|
  994. <iframe[^>]+?src=
  995. )
  996. (["\'])(?P<url>https?://(?:www\.)?sbs\.com\.au/ondemand/video/.+?)\1''',
  997. webpage)
  998. if mobj is not None:
  999. return self.url_result(mobj.group('url'), 'SBS')
  1000. # Look for embedded Cinchcast player
  1001. mobj = re.search(
  1002. r'<iframe[^>]+?src=(["\'])(?P<url>https?://player\.cinchcast\.com/.+?)\1',
  1003. webpage)
  1004. if mobj is not None:
  1005. return self.url_result(mobj.group('url'), 'Cinchcast')
  1006. mobj = re.search(
  1007. r'<iframe[^>]+?src=(["\'])(?P<url>https?://m(?:lb)?\.mlb\.com/shared/video/embed/embed\.html\?.+?)\1',
  1008. webpage)
  1009. if mobj is not None:
  1010. return self.url_result(mobj.group('url'), 'MLB')
  1011. mobj = re.search(
  1012. r'<iframe[^>]+?src=(["\'])(?P<url>%s)\1' % CondeNastIE.EMBED_URL,
  1013. webpage)
  1014. if mobj is not None:
  1015. return self.url_result(self._proto_relative_url(mobj.group('url'), scheme='http:'), 'CondeNast')
  1016. mobj = re.search(
  1017. r'<iframe[^>]+src="(?P<url>https?://new\.livestream\.com/[^"]+/player[^"]+)"',
  1018. webpage)
  1019. if mobj is not None:
  1020. return self.url_result(mobj.group('url'), 'Livestream')
  1021. def check_video(vurl):
  1022. if YoutubeIE.suitable(vurl):
  1023. return True
  1024. vpath = compat_urlparse.urlparse(vurl).path
  1025. vext = determine_ext(vpath)
  1026. return '.' in vpath and vext not in ('swf', 'png', 'jpg', 'srt', 'sbv', 'sub', 'vtt', 'ttml')
  1027. def filter_video(urls):
  1028. return list(filter(check_video, urls))
  1029. # Start with something easy: JW Player in SWFObject
  1030. found = filter_video(re.findall(r'flashvars: [\'"](?:.*&)?file=(http[^\'"&]*)', webpage))
  1031. if not found:
  1032. # Look for gorilla-vid style embedding
  1033. found = filter_video(re.findall(r'''(?sx)
  1034. (?:
  1035. jw_plugins|
  1036. JWPlayerOptions|
  1037. jwplayer\s*\(\s*["'][^'"]+["']\s*\)\s*\.setup
  1038. )
  1039. .*?
  1040. ['"]?file['"]?\s*:\s*["\'](.*?)["\']''', webpage))
  1041. if not found:
  1042. # Broaden the search a little bit
  1043. found = filter_video(re.findall(r'[^A-Za-z0-9]?(?:file|source)=(http[^\'"&]*)', webpage))
  1044. if not found:
  1045. # Broaden the findall a little bit: JWPlayer JS loader
  1046. found = filter_video(re.findall(
  1047. r'[^A-Za-z0-9]?file["\']?:\s*["\'](http(?![^\'"]+\.[0-9]+[\'"])[^\'"]+)["\']', webpage))
  1048. if not found:
  1049. # Flow player
  1050. found = filter_video(re.findall(r'''(?xs)
  1051. flowplayer\("[^"]+",\s*
  1052. \{[^}]+?\}\s*,
  1053. \s*\{[^}]+? ["']?clip["']?\s*:\s*\{\s*
  1054. ["']?url["']?\s*:\s*["']([^"']+)["']
  1055. ''', webpage))
  1056. if not found:
  1057. # Cinerama player
  1058. found = re.findall(
  1059. r"cinerama\.embedPlayer\(\s*\'[^']+\',\s*'([^']+)'", webpage)
  1060. if not found:
  1061. # Try to find twitter cards info
  1062. found = filter_video(re.findall(
  1063. r'<meta (?:property|name)="twitter:player:stream" (?:content|value)="(.+?)"', webpage))
  1064. if not found:
  1065. # We look for Open Graph info:
  1066. # We have to match any number spaces between elements, some sites try to align them (eg.: statigr.am)
  1067. m_video_type = re.findall(r'<meta.*?property="og:video:type".*?content="video/(.*?)"', webpage)
  1068. # We only look in og:video if the MIME type is a video, don't try if it's a Flash player:
  1069. if m_video_type is not None:
  1070. found = filter_video(re.findall(r'<meta.*?property="og:video".*?content="(.*?)"', webpage))
  1071. if not found:
  1072. # HTML5 video
  1073. found = re.findall(r'(?s)<video[^<]*(?:>.*?<source[^>]*)?\s+src=["\'](.*?)["\']', webpage)
  1074. if not found:
  1075. found = re.search(
  1076. r'(?i)<meta\s+(?=(?:[a-z-]+="[^"]+"\s+)*http-equiv="refresh")'
  1077. r'(?:[a-z-]+="[^"]+"\s+)*?content="[0-9]{,2};url=\'?([^\'"]+)',
  1078. webpage)
  1079. if found:
  1080. new_url = found.group(1)
  1081. self.report_following_redirect(new_url)
  1082. return {
  1083. '_type': 'url',
  1084. 'url': new_url,
  1085. }
  1086. if not found:
  1087. raise UnsupportedError(url)
  1088. entries = []
  1089. for video_url in found:
  1090. video_url = compat_urlparse.urljoin(url, video_url)
  1091. video_id = compat_urllib_parse.unquote(os.path.basename(video_url))
  1092. # Sometimes, jwplayer extraction will result in a YouTube URL
  1093. if YoutubeIE.suitable(video_url):
  1094. entries.append(self.url_result(video_url, 'Youtube'))
  1095. continue
  1096. # here's a fun little line of code for you:
  1097. video_id = os.path.splitext(video_id)[0]
  1098. entries.append({
  1099. 'id': video_id,
  1100. 'url': video_url,
  1101. 'uploader': video_uploader,
  1102. 'title': video_title,
  1103. 'age_limit': age_limit,
  1104. })
  1105. if len(entries) == 1:
  1106. return entries[0]
  1107. else:
  1108. for num, e in enumerate(entries, start=1):
  1109. e['title'] = '%s (%d)' % (e['title'], num)
  1110. return {
  1111. '_type': 'playlist',
  1112. 'entries': entries,
  1113. }