generic.py 53 KB

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