generic.py 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199
  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. 'title': 'Unity 8 desktop-mode windows on Mir! - Ubuntu Discourse',
  472. },
  473. 'playlist_mincount': 2,
  474. },
  475. # Direct link with incorrect MIME type
  476. {
  477. 'url': 'http://ftp.nluug.nl/video/nluug/2014-11-20_nj14/zaal-2/5_Lennart_Poettering_-_Systemd.webm',
  478. 'md5': '4ccbebe5f36706d85221f204d7eb5913',
  479. 'info_dict': {
  480. 'url': 'http://ftp.nluug.nl/video/nluug/2014-11-20_nj14/zaal-2/5_Lennart_Poettering_-_Systemd.webm',
  481. 'id': '5_Lennart_Poettering_-_Systemd',
  482. 'ext': 'webm',
  483. 'title': '5_Lennart_Poettering_-_Systemd',
  484. 'upload_date': '20141120',
  485. },
  486. 'expected_warnings': [
  487. 'URL could be a direct video link, returning it as such.'
  488. ]
  489. },
  490. # Cinchcast embed
  491. {
  492. 'url': 'http://undergroundwellness.com/podcasts/306-5-steps-to-permanent-gut-healing/',
  493. 'info_dict': {
  494. 'id': '7141703',
  495. 'ext': 'mp3',
  496. 'upload_date': '20141126',
  497. 'title': 'Jack Tips: 5 Steps to Permanent Gut Healing',
  498. }
  499. },
  500. # Cinerama player
  501. {
  502. 'url': 'http://www.abc.net.au/7.30/content/2015/s4164797.htm',
  503. 'info_dict': {
  504. 'id': '730m_DandD_1901_512k',
  505. 'ext': 'mp4',
  506. 'uploader': 'www.abc.net.au',
  507. 'title': 'Game of Thrones with dice - Dungeons and Dragons fantasy role-playing game gets new life - 19/01/2015',
  508. }
  509. },
  510. # embedded viddler video
  511. {
  512. 'url': 'http://deadspin.com/i-cant-stop-watching-john-wall-chop-the-nuggets-with-th-1681801597',
  513. 'info_dict': {
  514. 'id': '4d03aad9',
  515. 'ext': 'mp4',
  516. 'uploader': 'deadspin',
  517. 'title': 'WALL-TO-GORTAT',
  518. 'timestamp': 1422285291,
  519. 'upload_date': '20150126',
  520. },
  521. 'add_ie': ['Viddler'],
  522. },
  523. # jwplayer YouTube
  524. {
  525. 'url': 'http://media.nationalarchives.gov.uk/index.php/webinar-using-discovery-national-archives-online-catalogue/',
  526. 'info_dict': {
  527. 'id': 'Mrj4DVp2zeA',
  528. 'ext': 'mp4',
  529. 'upload_date': '20150204',
  530. 'uploader': 'The National Archives UK',
  531. 'description': 'md5:a236581cd2449dd2df4f93412f3f01c6',
  532. 'uploader_id': 'NationalArchives08',
  533. 'title': 'Webinar: Using Discovery, The National Archives’ online catalogue',
  534. },
  535. },
  536. # rtl.nl embed
  537. {
  538. 'url': 'http://www.rtlnieuws.nl/nieuws/buitenland/aanslagen-kopenhagen',
  539. 'playlist_mincount': 5,
  540. 'info_dict': {
  541. 'id': 'aanslagen-kopenhagen',
  542. 'title': 'Aanslagen Kopenhagen | RTL Nieuws',
  543. }
  544. }
  545. ]
  546. def report_following_redirect(self, new_url):
  547. """Report information extraction."""
  548. self._downloader.to_screen('[redirect] Following redirect to %s' % new_url)
  549. def _extract_rss(self, url, video_id, doc):
  550. playlist_title = doc.find('./channel/title').text
  551. playlist_desc_el = doc.find('./channel/description')
  552. playlist_desc = None if playlist_desc_el is None else playlist_desc_el.text
  553. entries = [{
  554. '_type': 'url',
  555. 'url': e.find('link').text,
  556. 'title': e.find('title').text,
  557. } for e in doc.findall('./channel/item')]
  558. return {
  559. '_type': 'playlist',
  560. 'id': url,
  561. 'title': playlist_title,
  562. 'description': playlist_desc,
  563. 'entries': entries,
  564. }
  565. def _extract_camtasia(self, url, video_id, webpage):
  566. """ Returns None if no camtasia video can be found. """
  567. camtasia_cfg = self._search_regex(
  568. r'fo\.addVariable\(\s*"csConfigFile",\s*"([^"]+)"\s*\);',
  569. webpage, 'camtasia configuration file', default=None)
  570. if camtasia_cfg is None:
  571. return None
  572. title = self._html_search_meta('DC.title', webpage, fatal=True)
  573. camtasia_url = compat_urlparse.urljoin(url, camtasia_cfg)
  574. camtasia_cfg = self._download_xml(
  575. camtasia_url, video_id,
  576. note='Downloading camtasia configuration',
  577. errnote='Failed to download camtasia configuration')
  578. fileset_node = camtasia_cfg.find('./playlist/array/fileset')
  579. entries = []
  580. for n in fileset_node.getchildren():
  581. url_n = n.find('./uri')
  582. if url_n is None:
  583. continue
  584. entries.append({
  585. 'id': os.path.splitext(url_n.text.rpartition('/')[2])[0],
  586. 'title': '%s - %s' % (title, n.tag),
  587. 'url': compat_urlparse.urljoin(url, url_n.text),
  588. 'duration': float_or_none(n.find('./duration').text),
  589. })
  590. return {
  591. '_type': 'playlist',
  592. 'entries': entries,
  593. 'title': title,
  594. }
  595. def _real_extract(self, url):
  596. if url.startswith('//'):
  597. return {
  598. '_type': 'url',
  599. 'url': self.http_scheme() + url,
  600. }
  601. parsed_url = compat_urlparse.urlparse(url)
  602. if not parsed_url.scheme:
  603. default_search = self._downloader.params.get('default_search')
  604. if default_search is None:
  605. default_search = 'fixup_error'
  606. if default_search in ('auto', 'auto_warning', 'fixup_error'):
  607. if '/' in url:
  608. self._downloader.report_warning('The url doesn\'t specify the protocol, trying with http')
  609. return self.url_result('http://' + url)
  610. elif default_search != 'fixup_error':
  611. if default_search == 'auto_warning':
  612. if re.match(r'^(?:url|URL)$', url):
  613. raise ExtractorError(
  614. 'Invalid URL: %r . Call youtube-dl like this: youtube-dl -v "https://www.youtube.com/watch?v=BaW_jenozKc" ' % url,
  615. expected=True)
  616. else:
  617. self._downloader.report_warning(
  618. 'Falling back to youtube search for %s . Set --default-search "auto" to suppress this warning.' % url)
  619. return self.url_result('ytsearch:' + url)
  620. if default_search in ('error', 'fixup_error'):
  621. raise ExtractorError(
  622. '%r is not a valid URL. '
  623. 'Set --default-search "ytsearch" (or run youtube-dl "ytsearch:%s" ) to search YouTube'
  624. % (url, url), expected=True)
  625. else:
  626. if ':' not in default_search:
  627. default_search += ':'
  628. return self.url_result(default_search + url)
  629. url, smuggled_data = unsmuggle_url(url)
  630. force_videoid = None
  631. is_intentional = smuggled_data and smuggled_data.get('to_generic')
  632. if smuggled_data and 'force_videoid' in smuggled_data:
  633. force_videoid = smuggled_data['force_videoid']
  634. video_id = force_videoid
  635. else:
  636. video_id = os.path.splitext(url.rstrip('/').split('/')[-1])[0]
  637. self.to_screen('%s: Requesting header' % video_id)
  638. head_req = HEADRequest(url)
  639. head_response = self._request_webpage(
  640. head_req, video_id,
  641. note=False, errnote='Could not send HEAD request to %s' % url,
  642. fatal=False)
  643. if head_response is not False:
  644. # Check for redirect
  645. new_url = head_response.geturl()
  646. if url != new_url:
  647. self.report_following_redirect(new_url)
  648. if force_videoid:
  649. new_url = smuggle_url(
  650. new_url, {'force_videoid': force_videoid})
  651. return self.url_result(new_url)
  652. full_response = None
  653. if head_response is False:
  654. full_response = self._request_webpage(url, video_id)
  655. head_response = full_response
  656. # Check for direct link to a video
  657. content_type = head_response.headers.get('Content-Type', '')
  658. m = re.match(r'^(?P<type>audio|video|application(?=/ogg$))/(?P<format_id>.+)$', content_type)
  659. if m:
  660. upload_date = unified_strdate(
  661. head_response.headers.get('Last-Modified'))
  662. return {
  663. 'id': video_id,
  664. 'title': os.path.splitext(url_basename(url))[0],
  665. 'direct': True,
  666. 'formats': [{
  667. 'format_id': m.group('format_id'),
  668. 'url': url,
  669. 'vcodec': 'none' if m.group('type') == 'audio' else None
  670. }],
  671. 'upload_date': upload_date,
  672. }
  673. if not self._downloader.params.get('test', False) and not is_intentional:
  674. self._downloader.report_warning('Falling back on generic information extractor.')
  675. if not full_response:
  676. full_response = self._request_webpage(url, video_id)
  677. # Maybe it's a direct link to a video?
  678. # Be careful not to download the whole thing!
  679. first_bytes = full_response.read(512)
  680. if not is_html(first_bytes):
  681. self._downloader.report_warning(
  682. 'URL could be a direct video link, returning it as such.')
  683. upload_date = unified_strdate(
  684. head_response.headers.get('Last-Modified'))
  685. return {
  686. 'id': video_id,
  687. 'title': os.path.splitext(url_basename(url))[0],
  688. 'direct': True,
  689. 'url': url,
  690. 'upload_date': upload_date,
  691. }
  692. webpage = self._webpage_read_content(
  693. full_response, url, video_id, prefix=first_bytes)
  694. self.report_extraction(video_id)
  695. # Is it an RSS feed?
  696. try:
  697. doc = parse_xml(webpage)
  698. if doc.tag == 'rss':
  699. return self._extract_rss(url, video_id, doc)
  700. except compat_xml_parse_error:
  701. pass
  702. # Is it a Camtasia project?
  703. camtasia_res = self._extract_camtasia(url, video_id, webpage)
  704. if camtasia_res is not None:
  705. return camtasia_res
  706. # Sometimes embedded video player is hidden behind percent encoding
  707. # (e.g. https://github.com/rg3/youtube-dl/issues/2448)
  708. # Unescaping the whole page allows to handle those cases in a generic way
  709. webpage = compat_urllib_parse.unquote(webpage)
  710. # it's tempting to parse this further, but you would
  711. # have to take into account all the variations like
  712. # Video Title - Site Name
  713. # Site Name | Video Title
  714. # Video Title - Tagline | Site Name
  715. # and so on and so forth; it's just not practical
  716. video_title = self._html_search_regex(
  717. r'(?s)<title>(.*?)</title>', webpage, 'video title',
  718. default='video')
  719. # Try to detect age limit automatically
  720. age_limit = self._rta_search(webpage)
  721. # And then there are the jokers who advertise that they use RTA,
  722. # but actually don't.
  723. AGE_LIMIT_MARKERS = [
  724. r'Proudly Labeled <a href="http://www.rtalabel.org/" title="Restricted to Adults">RTA</a>',
  725. ]
  726. if any(re.search(marker, webpage) for marker in AGE_LIMIT_MARKERS):
  727. age_limit = 18
  728. # video uploader is domain name
  729. video_uploader = self._search_regex(
  730. r'^(?:https?://)?([^/]*)/.*', url, 'video uploader')
  731. # Helper method
  732. def _playlist_from_matches(matches, getter=None, ie=None):
  733. urlrs = orderedSet(
  734. self.url_result(self._proto_relative_url(getter(m) if getter else m), ie)
  735. for m in matches)
  736. return self.playlist_result(
  737. urlrs, playlist_id=video_id, playlist_title=video_title)
  738. # Look for BrightCove:
  739. bc_urls = BrightcoveIE._extract_brightcove_urls(webpage)
  740. if bc_urls:
  741. self.to_screen('Brightcove video detected.')
  742. entries = [{
  743. '_type': 'url',
  744. 'url': smuggle_url(bc_url, {'Referer': url}),
  745. 'ie_key': 'Brightcove'
  746. } for bc_url in bc_urls]
  747. return {
  748. '_type': 'playlist',
  749. 'title': video_title,
  750. 'id': video_id,
  751. 'entries': entries,
  752. }
  753. # Look for embedded rtl.nl player
  754. matches = re.findall(
  755. r'<iframe\s+(?:[a-zA-Z-]+="[^"]+"\s+)*?src="((?:https?:)?//(?:www\.)?rtl\.nl/system/videoplayer/[^"]+video_embed[^"]+)"',
  756. webpage)
  757. if matches:
  758. return _playlist_from_matches(matches, ie='RtlNl')
  759. # Look for embedded (iframe) Vimeo player
  760. mobj = re.search(
  761. r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//player\.vimeo\.com/video/.+?)\1', webpage)
  762. if mobj:
  763. player_url = unescapeHTML(mobj.group('url'))
  764. surl = smuggle_url(player_url, {'Referer': url})
  765. return self.url_result(surl)
  766. # Look for embedded (swf embed) Vimeo player
  767. mobj = re.search(
  768. r'<embed[^>]+?src="((?:https?:)?//(?:www\.)?vimeo\.com/moogaloop\.swf.+?)"', webpage)
  769. if mobj:
  770. return self.url_result(mobj.group(1))
  771. # Look for embedded YouTube player
  772. matches = re.findall(r'''(?x)
  773. (?:
  774. <iframe[^>]+?src=|
  775. data-video-url=|
  776. <embed[^>]+?src=|
  777. embedSWF\(?:\s*|
  778. new\s+SWFObject\(
  779. )
  780. (["\'])
  781. (?P<url>(?:https?:)?//(?:www\.)?youtube(?:-nocookie)?\.com/
  782. (?:embed|v|p)/.+?)
  783. \1''', webpage)
  784. if matches:
  785. return _playlist_from_matches(
  786. matches, lambda m: unescapeHTML(m[1]))
  787. # Look for lazyYT YouTube embed
  788. matches = re.findall(
  789. r'class="lazyYT" data-youtube-id="([^"]+)"', webpage)
  790. if matches:
  791. return _playlist_from_matches(matches, lambda m: unescapeHTML(m))
  792. # Look for embedded Dailymotion player
  793. matches = re.findall(
  794. r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:www\.)?dailymotion\.com/embed/video/.+?)\1', webpage)
  795. if matches:
  796. return _playlist_from_matches(
  797. matches, lambda m: unescapeHTML(m[1]))
  798. # Look for embedded Dailymotion playlist player (#3822)
  799. m = re.search(
  800. r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:www\.)?dailymotion\.[a-z]{2,3}/widget/jukebox\?.+?)\1', webpage)
  801. if m:
  802. playlists = re.findall(
  803. r'list\[\]=/playlist/([^/]+)/', unescapeHTML(m.group('url')))
  804. if playlists:
  805. return _playlist_from_matches(
  806. playlists, lambda p: '//dailymotion.com/playlist/%s' % p)
  807. # Look for embedded Wistia player
  808. match = re.search(
  809. r'<(?:meta[^>]+?content|iframe[^>]+?src)=(["\'])(?P<url>(?:https?:)?//(?:fast\.)?wistia\.net/embed/iframe/.+?)\1', webpage)
  810. if match:
  811. embed_url = self._proto_relative_url(
  812. unescapeHTML(match.group('url')))
  813. return {
  814. '_type': 'url_transparent',
  815. 'url': embed_url,
  816. 'ie_key': 'Wistia',
  817. 'uploader': video_uploader,
  818. 'title': video_title,
  819. 'id': video_id,
  820. }
  821. match = re.search(r'(?:id=["\']wistia_|data-wistia-?id=["\']|Wistia\.embed\(["\'])(?P<id>[^"\']+)', webpage)
  822. if match:
  823. return {
  824. '_type': 'url_transparent',
  825. 'url': 'http://fast.wistia.net/embed/iframe/{0:}'.format(match.group('id')),
  826. 'ie_key': 'Wistia',
  827. 'uploader': video_uploader,
  828. 'title': video_title,
  829. 'id': match.group('id')
  830. }
  831. # Look for embedded blip.tv player
  832. mobj = re.search(r'<meta\s[^>]*https?://api\.blip\.tv/\w+/redirect/\w+/(\d+)', webpage)
  833. if mobj:
  834. return self.url_result('http://blip.tv/a/a-' + mobj.group(1), 'BlipTV')
  835. mobj = re.search(r'<(?:iframe|embed|object)\s[^>]*(https?://(?:\w+\.)?blip\.tv/(?:play/|api\.swf#)[a-zA-Z0-9_]+)', webpage)
  836. if mobj:
  837. return self.url_result(mobj.group(1), 'BlipTV')
  838. # Look for embedded condenast player
  839. matches = re.findall(
  840. r'<iframe\s+(?:[a-zA-Z-]+="[^"]+"\s+)*?src="(https?://player\.cnevids\.com/embed/[^"]+")',
  841. webpage)
  842. if matches:
  843. return {
  844. '_type': 'playlist',
  845. 'entries': [{
  846. '_type': 'url',
  847. 'ie_key': 'CondeNast',
  848. 'url': ma,
  849. } for ma in matches],
  850. 'title': video_title,
  851. 'id': video_id,
  852. }
  853. # Look for Bandcamp pages with custom domain
  854. mobj = re.search(r'<meta property="og:url"[^>]*?content="(.*?bandcamp\.com.*?)"', webpage)
  855. if mobj is not None:
  856. burl = unescapeHTML(mobj.group(1))
  857. # Don't set the extractor because it can be a track url or an album
  858. return self.url_result(burl)
  859. # Look for embedded Vevo player
  860. mobj = re.search(
  861. r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:cache\.)?vevo\.com/.+?)\1', webpage)
  862. if mobj is not None:
  863. return self.url_result(mobj.group('url'))
  864. # Look for embedded Viddler player
  865. mobj = re.search(
  866. r'<(?:iframe[^>]+?src|param[^>]+?value)=(["\'])(?P<url>(?:https?:)?//(?:www\.)?viddler\.com/(?:embed|player)/.+?)\1',
  867. webpage)
  868. if mobj is not None:
  869. return self.url_result(mobj.group('url'))
  870. # Look for Ooyala videos
  871. mobj = (re.search(r'player\.ooyala\.com/[^"?]+\?[^"]*?(?:embedCode|ec)=(?P<ec>[^"&]+)', webpage) or
  872. re.search(r'OO\.Player\.create\([\'"].*?[\'"],\s*[\'"](?P<ec>.{32})[\'"]', webpage) or
  873. re.search(r'SBN\.VideoLinkset\.ooyala\([\'"](?P<ec>.{32})[\'"]\)', webpage))
  874. if mobj is not None:
  875. return OoyalaIE._build_url_result(mobj.group('ec'))
  876. # Look for multiple Ooyala embeds on SBN network websites
  877. mobj = re.search(r'SBN\.VideoLinkset\.entryGroup\((\[.*?\])', webpage)
  878. if mobj is not None:
  879. embeds = self._parse_json(mobj.group(1), video_id, fatal=False)
  880. if embeds:
  881. return _playlist_from_matches(
  882. embeds, getter=lambda v: OoyalaIE._url_for_embed_code(v['provider_video_id']), ie='Ooyala')
  883. # Look for Aparat videos
  884. mobj = re.search(r'<iframe .*?src="(http://www\.aparat\.com/video/[^"]+)"', webpage)
  885. if mobj is not None:
  886. return self.url_result(mobj.group(1), 'Aparat')
  887. # Look for MPORA videos
  888. mobj = re.search(r'<iframe .*?src="(http://mpora\.(?:com|de)/videos/[^"]+)"', webpage)
  889. if mobj is not None:
  890. return self.url_result(mobj.group(1), 'Mpora')
  891. # Look for embedded NovaMov-based player
  892. mobj = re.search(
  893. r'''(?x)<(?:pagespeed_)?iframe[^>]+?src=(["\'])
  894. (?P<url>http://(?:(?:embed|www)\.)?
  895. (?:novamov\.com|
  896. nowvideo\.(?:ch|sx|eu|at|ag|co)|
  897. videoweed\.(?:es|com)|
  898. movshare\.(?:net|sx|ag)|
  899. divxstage\.(?:eu|net|ch|co|at|ag))
  900. /embed\.php.+?)\1''', webpage)
  901. if mobj is not None:
  902. return self.url_result(mobj.group('url'))
  903. # Look for embedded Facebook player
  904. mobj = re.search(
  905. r'<iframe[^>]+?src=(["\'])(?P<url>https://www\.facebook\.com/video/embed.+?)\1', webpage)
  906. if mobj is not None:
  907. return self.url_result(mobj.group('url'), 'Facebook')
  908. # Look for embedded VK player
  909. mobj = re.search(r'<iframe[^>]+?src=(["\'])(?P<url>https?://vk\.com/video_ext\.php.+?)\1', webpage)
  910. if mobj is not None:
  911. return self.url_result(mobj.group('url'), 'VK')
  912. # Look for embedded ivi player
  913. mobj = re.search(r'<embed[^>]+?src=(["\'])(?P<url>https?://(?:www\.)?ivi\.ru/video/player.+?)\1', webpage)
  914. if mobj is not None:
  915. return self.url_result(mobj.group('url'), 'Ivi')
  916. # Look for embedded Huffington Post player
  917. mobj = re.search(
  918. r'<iframe[^>]+?src=(["\'])(?P<url>https?://embed\.live\.huffingtonpost\.com/.+?)\1', webpage)
  919. if mobj is not None:
  920. return self.url_result(mobj.group('url'), 'HuffPost')
  921. # Look for embed.ly
  922. mobj = re.search(r'class=["\']embedly-card["\'][^>]href=["\'](?P<url>[^"\']+)', webpage)
  923. if mobj is not None:
  924. return self.url_result(mobj.group('url'))
  925. mobj = re.search(r'class=["\']embedly-embed["\'][^>]src=["\'][^"\']*url=(?P<url>[^&]+)', webpage)
  926. if mobj is not None:
  927. return self.url_result(compat_urllib_parse.unquote(mobj.group('url')))
  928. # Look for funnyordie embed
  929. matches = re.findall(r'<iframe[^>]+?src="(https?://(?:www\.)?funnyordie\.com/embed/[^"]+)"', webpage)
  930. if matches:
  931. return _playlist_from_matches(
  932. matches, getter=unescapeHTML, ie='FunnyOrDie')
  933. # Look for BBC iPlayer embed
  934. matches = re.findall(r'setPlaylist\("(https?://www\.bbc\.co\.uk/iplayer/[^/]+/[\da-z]{8})"\)', webpage)
  935. if matches:
  936. return _playlist_from_matches(matches, ie='BBCCoUk')
  937. # Look for embedded RUTV player
  938. rutv_url = RUTVIE._extract_url(webpage)
  939. if rutv_url:
  940. return self.url_result(rutv_url, 'RUTV')
  941. # Look for embedded TED player
  942. mobj = re.search(
  943. r'<iframe[^>]+?src=(["\'])(?P<url>https?://embed(?:-ssl)?\.ted\.com/.+?)\1', webpage)
  944. if mobj is not None:
  945. return self.url_result(mobj.group('url'), 'TED')
  946. # Look for embedded Ustream videos
  947. mobj = re.search(
  948. r'<iframe[^>]+?src=(["\'])(?P<url>http://www\.ustream\.tv/embed/.+?)\1', webpage)
  949. if mobj is not None:
  950. return self.url_result(mobj.group('url'), 'Ustream')
  951. # Look for embedded arte.tv player
  952. mobj = re.search(
  953. r'<script [^>]*?src="(?P<url>http://www\.arte\.tv/playerv2/embed[^"]+)"',
  954. webpage)
  955. if mobj is not None:
  956. return self.url_result(mobj.group('url'), 'ArteTVEmbed')
  957. # Look for embedded smotri.com player
  958. smotri_url = SmotriIE._extract_url(webpage)
  959. if smotri_url:
  960. return self.url_result(smotri_url, 'Smotri')
  961. # Look for embeded soundcloud player
  962. mobj = re.search(
  963. r'<iframe\s+(?:[a-zA-Z0-9_-]+="[^"]+"\s+)*src="(?P<url>https?://(?:w\.)?soundcloud\.com/player[^"]+)"',
  964. webpage)
  965. if mobj is not None:
  966. url = unescapeHTML(mobj.group('url'))
  967. return self.url_result(url)
  968. # Look for embedded vulture.com player
  969. mobj = re.search(
  970. r'<iframe src="(?P<url>https?://video\.vulture\.com/[^"]+)"',
  971. webpage)
  972. if mobj is not None:
  973. url = unescapeHTML(mobj.group('url'))
  974. return self.url_result(url, ie='Vulture')
  975. # Look for embedded mtvservices player
  976. mobj = re.search(
  977. r'<iframe src="(?P<url>https?://media\.mtvnservices\.com/embed/[^"]+)"',
  978. webpage)
  979. if mobj is not None:
  980. url = unescapeHTML(mobj.group('url'))
  981. return self.url_result(url, ie='MTVServicesEmbedded')
  982. # Look for embedded yahoo player
  983. mobj = re.search(
  984. r'<iframe[^>]+?src=(["\'])(?P<url>https?://(?:screen|movies)\.yahoo\.com/.+?\.html\?format=embed)\1',
  985. webpage)
  986. if mobj is not None:
  987. return self.url_result(mobj.group('url'), 'Yahoo')
  988. # Look for embedded sbs.com.au player
  989. mobj = re.search(
  990. r'''(?x)
  991. (?:
  992. <meta\s+property="og:video"\s+content=|
  993. <iframe[^>]+?src=
  994. )
  995. (["\'])(?P<url>https?://(?:www\.)?sbs\.com\.au/ondemand/video/.+?)\1''',
  996. webpage)
  997. if mobj is not None:
  998. return self.url_result(mobj.group('url'), 'SBS')
  999. # Look for embedded Cinchcast player
  1000. mobj = re.search(
  1001. r'<iframe[^>]+?src=(["\'])(?P<url>https?://player\.cinchcast\.com/.+?)\1',
  1002. webpage)
  1003. if mobj is not None:
  1004. return self.url_result(mobj.group('url'), 'Cinchcast')
  1005. mobj = re.search(
  1006. r'<iframe[^>]+?src=(["\'])(?P<url>https?://m(?:lb)?\.mlb\.com/shared/video/embed/embed\.html\?.+?)\1',
  1007. webpage)
  1008. if mobj is not None:
  1009. return self.url_result(mobj.group('url'), 'MLB')
  1010. mobj = re.search(
  1011. r'<iframe[^>]+?src=(["\'])(?P<url>%s)\1' % CondeNastIE.EMBED_URL,
  1012. webpage)
  1013. if mobj is not None:
  1014. return self.url_result(self._proto_relative_url(mobj.group('url'), scheme='http:'), 'CondeNast')
  1015. mobj = re.search(
  1016. r'<iframe[^>]+src="(?P<url>https?://new\.livestream\.com/[^"]+/player[^"]+)"',
  1017. webpage)
  1018. if mobj is not None:
  1019. return self.url_result(mobj.group('url'), 'Livestream')
  1020. def check_video(vurl):
  1021. if YoutubeIE.suitable(vurl):
  1022. return True
  1023. vpath = compat_urlparse.urlparse(vurl).path
  1024. vext = determine_ext(vpath)
  1025. return '.' in vpath and vext not in ('swf', 'png', 'jpg', 'srt', 'sbv', 'sub', 'vtt', 'ttml')
  1026. def filter_video(urls):
  1027. return list(filter(check_video, urls))
  1028. # Start with something easy: JW Player in SWFObject
  1029. found = filter_video(re.findall(r'flashvars: [\'"](?:.*&)?file=(http[^\'"&]*)', webpage))
  1030. if not found:
  1031. # Look for gorilla-vid style embedding
  1032. found = filter_video(re.findall(r'''(?sx)
  1033. (?:
  1034. jw_plugins|
  1035. JWPlayerOptions|
  1036. jwplayer\s*\(\s*["'][^'"]+["']\s*\)\s*\.setup
  1037. )
  1038. .*?
  1039. ['"]?file['"]?\s*:\s*["\'](.*?)["\']''', webpage))
  1040. if not found:
  1041. # Broaden the search a little bit
  1042. found = filter_video(re.findall(r'[^A-Za-z0-9]?(?:file|source)=(http[^\'"&]*)', webpage))
  1043. if not found:
  1044. # Broaden the findall a little bit: JWPlayer JS loader
  1045. found = filter_video(re.findall(
  1046. r'[^A-Za-z0-9]?file["\']?:\s*["\'](http(?![^\'"]+\.[0-9]+[\'"])[^\'"]+)["\']', webpage))
  1047. if not found:
  1048. # Flow player
  1049. found = filter_video(re.findall(r'''(?xs)
  1050. flowplayer\("[^"]+",\s*
  1051. \{[^}]+?\}\s*,
  1052. \s*\{[^}]+? ["']?clip["']?\s*:\s*\{\s*
  1053. ["']?url["']?\s*:\s*["']([^"']+)["']
  1054. ''', webpage))
  1055. if not found:
  1056. # Cinerama player
  1057. found = re.findall(
  1058. r"cinerama\.embedPlayer\(\s*\'[^']+\',\s*'([^']+)'", webpage)
  1059. if not found:
  1060. # Try to find twitter cards info
  1061. found = filter_video(re.findall(
  1062. r'<meta (?:property|name)="twitter:player:stream" (?:content|value)="(.+?)"', webpage))
  1063. if not found:
  1064. # We look for Open Graph info:
  1065. # We have to match any number spaces between elements, some sites try to align them (eg.: statigr.am)
  1066. m_video_type = re.findall(r'<meta.*?property="og:video:type".*?content="video/(.*?)"', webpage)
  1067. # We only look in og:video if the MIME type is a video, don't try if it's a Flash player:
  1068. if m_video_type is not None:
  1069. found = filter_video(re.findall(r'<meta.*?property="og:video".*?content="(.*?)"', webpage))
  1070. if not found:
  1071. # HTML5 video
  1072. found = re.findall(r'(?s)<video[^<]*(?:>.*?<source[^>]*)?\s+src=["\'](.*?)["\']', webpage)
  1073. if not found:
  1074. found = re.search(
  1075. r'(?i)<meta\s+(?=(?:[a-z-]+="[^"]+"\s+)*http-equiv="refresh")'
  1076. r'(?:[a-z-]+="[^"]+"\s+)*?content="[0-9]{,2};url=\'?([^\'"]+)',
  1077. webpage)
  1078. if found:
  1079. new_url = found.group(1)
  1080. self.report_following_redirect(new_url)
  1081. return {
  1082. '_type': 'url',
  1083. 'url': new_url,
  1084. }
  1085. if not found:
  1086. raise UnsupportedError(url)
  1087. entries = []
  1088. for video_url in found:
  1089. video_url = compat_urlparse.urljoin(url, video_url)
  1090. video_id = compat_urllib_parse.unquote(os.path.basename(video_url))
  1091. # Sometimes, jwplayer extraction will result in a YouTube URL
  1092. if YoutubeIE.suitable(video_url):
  1093. entries.append(self.url_result(video_url, 'Youtube'))
  1094. continue
  1095. # here's a fun little line of code for you:
  1096. video_id = os.path.splitext(video_id)[0]
  1097. entries.append({
  1098. 'id': video_id,
  1099. 'url': video_url,
  1100. 'uploader': video_uploader,
  1101. 'title': video_title,
  1102. 'age_limit': age_limit,
  1103. })
  1104. if len(entries) == 1:
  1105. return entries[0]
  1106. else:
  1107. for num, e in enumerate(entries, start=1):
  1108. e['title'] = '%s (%d)' % (e['title'], num)
  1109. return {
  1110. '_type': 'playlist',
  1111. 'entries': entries,
  1112. }