facebook.py 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. import socket
  5. from .common import InfoExtractor
  6. from ..compat import (
  7. compat_etree_fromstring,
  8. compat_http_client,
  9. compat_urllib_error,
  10. compat_urllib_parse_unquote,
  11. compat_urllib_parse_unquote_plus,
  12. )
  13. from ..utils import (
  14. clean_html,
  15. error_to_compat_str,
  16. ExtractorError,
  17. float_or_none,
  18. get_element_by_id,
  19. int_or_none,
  20. js_to_json,
  21. limit_length,
  22. parse_count,
  23. qualities,
  24. sanitized_Request,
  25. try_get,
  26. urlencode_postdata,
  27. )
  28. class FacebookIE(InfoExtractor):
  29. _VALID_URL = r'''(?x)
  30. (?:
  31. https?://
  32. (?:[\w-]+\.)?(?:facebook\.com|facebookcorewwwi\.onion)/
  33. (?:[^#]*?\#!/)?
  34. (?:
  35. (?:
  36. video/video\.php|
  37. photo\.php|
  38. video\.php|
  39. video/embed|
  40. story\.php
  41. )\?(?:.*?)(?:v|video_id|story_fbid)=|
  42. [^/]+/videos/(?:[^/]+/)?|
  43. [^/]+/posts/|
  44. groups/[^/]+/permalink/
  45. )|
  46. facebook:
  47. )
  48. (?P<id>[0-9]+)
  49. '''
  50. _LOGIN_URL = 'https://www.facebook.com/login.php?next=http%3A%2F%2Ffacebook.com%2Fhome.php&login_attempt=1'
  51. _CHECKPOINT_URL = 'https://www.facebook.com/checkpoint/?next=http%3A%2F%2Ffacebook.com%2Fhome.php&_fb_noscript=1'
  52. _NETRC_MACHINE = 'facebook'
  53. IE_NAME = 'facebook'
  54. _VIDEO_PAGE_TEMPLATE = 'https://www.facebook.com/video/video.php?v=%s'
  55. _VIDEO_PAGE_TAHOE_TEMPLATE = 'https://www.facebook.com/video/tahoe/async/%s/?chain=true&isvideo=true&payloadtype=primary'
  56. _TESTS = [{
  57. 'url': 'https://www.facebook.com/video.php?v=637842556329505&fref=nf',
  58. 'md5': '6a40d33c0eccbb1af76cf0485a052659',
  59. 'info_dict': {
  60. 'id': '637842556329505',
  61. 'ext': 'mp4',
  62. 'title': 're:Did you know Kei Nishikori is the first Asian man to ever reach a Grand Slam',
  63. 'uploader': 'Tennis on Facebook',
  64. 'upload_date': '20140908',
  65. 'timestamp': 1410199200,
  66. },
  67. 'skip': 'Requires logging in',
  68. }, {
  69. 'url': 'https://www.facebook.com/video.php?v=274175099429670',
  70. 'info_dict': {
  71. 'id': '274175099429670',
  72. 'ext': 'mp4',
  73. 'title': 're:^Asif Nawab Butt posted a video',
  74. 'uploader': 'Asif Nawab Butt',
  75. 'upload_date': '20140506',
  76. 'timestamp': 1399398998,
  77. 'thumbnail': r're:^https?://.*',
  78. },
  79. 'expected_warnings': [
  80. 'title'
  81. ]
  82. }, {
  83. 'note': 'Video with DASH manifest',
  84. 'url': 'https://www.facebook.com/video.php?v=957955867617029',
  85. 'md5': 'b2c28d528273b323abe5c6ab59f0f030',
  86. 'info_dict': {
  87. 'id': '957955867617029',
  88. 'ext': 'mp4',
  89. 'title': 'When you post epic content on instagram.com/433 8 million followers, this is ...',
  90. 'uploader': 'Demy de Zeeuw',
  91. 'upload_date': '20160110',
  92. 'timestamp': 1452431627,
  93. },
  94. 'skip': 'Requires logging in',
  95. }, {
  96. 'url': 'https://www.facebook.com/maxlayn/posts/10153807558977570',
  97. 'md5': '037b1fa7f3c2d02b7a0d7bc16031ecc6',
  98. 'info_dict': {
  99. 'id': '544765982287235',
  100. 'ext': 'mp4',
  101. 'title': '"What are you doing running in the snow?"',
  102. 'uploader': 'FailArmy',
  103. },
  104. 'skip': 'Video gone',
  105. }, {
  106. 'url': 'https://m.facebook.com/story.php?story_fbid=1035862816472149&id=116132035111903',
  107. 'md5': '1deb90b6ac27f7efcf6d747c8a27f5e3',
  108. 'info_dict': {
  109. 'id': '1035862816472149',
  110. 'ext': 'mp4',
  111. 'title': 'What the Flock Is Going On In New Zealand Credit: ViralHog',
  112. 'uploader': 'S. Saint',
  113. },
  114. 'skip': 'Video gone',
  115. }, {
  116. 'note': 'swf params escaped',
  117. 'url': 'https://www.facebook.com/barackobama/posts/10153664894881749',
  118. 'md5': '97ba073838964d12c70566e0085c2b91',
  119. 'info_dict': {
  120. 'id': '10153664894881749',
  121. 'ext': 'mp4',
  122. 'title': 'Average time to confirm recent Supreme Court nominees: 67 days Longest it\'s t...',
  123. 'thumbnail': r're:^https?://.*',
  124. 'timestamp': 1456259628,
  125. 'upload_date': '20160223',
  126. 'uploader': 'Barack Obama',
  127. },
  128. }, {
  129. # have 1080P, but only up to 720p in swf params
  130. 'url': 'https://www.facebook.com/cnn/videos/10155529876156509/',
  131. 'md5': '9571fae53d4165bbbadb17a94651dcdc',
  132. 'info_dict': {
  133. 'id': '10155529876156509',
  134. 'ext': 'mp4',
  135. 'title': 'She survived the holocaust — and years later, she’s getting her citizenship s...',
  136. 'timestamp': 1477818095,
  137. 'upload_date': '20161030',
  138. 'uploader': 'CNN',
  139. 'thumbnail': r're:^https?://.*',
  140. 'view_count': int,
  141. },
  142. }, {
  143. # bigPipe.onPageletArrive ... onPageletArrive pagelet_group_mall
  144. 'url': 'https://www.facebook.com/yaroslav.korpan/videos/1417995061575415/',
  145. 'info_dict': {
  146. 'id': '1417995061575415',
  147. 'ext': 'mp4',
  148. 'title': 'md5:1db063d6a8c13faa8da727817339c857',
  149. 'timestamp': 1486648217,
  150. 'upload_date': '20170209',
  151. 'uploader': 'Yaroslav Korpan',
  152. },
  153. 'params': {
  154. 'skip_download': True,
  155. },
  156. }, {
  157. 'url': 'https://www.facebook.com/LaGuiaDelVaron/posts/1072691702860471',
  158. 'info_dict': {
  159. 'id': '1072691702860471',
  160. 'ext': 'mp4',
  161. 'title': 'md5:ae2d22a93fbb12dad20dc393a869739d',
  162. 'timestamp': 1477305000,
  163. 'upload_date': '20161024',
  164. 'uploader': 'La Guía Del Varón',
  165. 'thumbnail': r're:^https?://.*',
  166. },
  167. 'params': {
  168. 'skip_download': True,
  169. },
  170. }, {
  171. 'url': 'https://www.facebook.com/groups/1024490957622648/permalink/1396382447100162/',
  172. 'info_dict': {
  173. 'id': '1396382447100162',
  174. 'ext': 'mp4',
  175. 'title': 'md5:19a428bbde91364e3de815383b54a235',
  176. 'timestamp': 1486035494,
  177. 'upload_date': '20170202',
  178. 'uploader': 'Elisabeth Ahtn',
  179. },
  180. 'params': {
  181. 'skip_download': True,
  182. },
  183. }, {
  184. 'url': 'https://www.facebook.com/video.php?v=10204634152394104',
  185. 'only_matching': True,
  186. }, {
  187. 'url': 'https://www.facebook.com/amogood/videos/1618742068337349/?fref=nf',
  188. 'only_matching': True,
  189. }, {
  190. 'url': 'https://www.facebook.com/ChristyClarkForBC/videos/vb.22819070941/10153870694020942/?type=2&theater',
  191. 'only_matching': True,
  192. }, {
  193. 'url': 'facebook:544765982287235',
  194. 'only_matching': True,
  195. }, {
  196. 'url': 'https://www.facebook.com/groups/164828000315060/permalink/764967300301124/',
  197. 'only_matching': True,
  198. }, {
  199. 'url': 'https://zh-hk.facebook.com/peoplespower/videos/1135894589806027/',
  200. 'only_matching': True,
  201. }, {
  202. 'url': 'https://www.facebookcorewwwi.onion/video.php?v=274175099429670',
  203. 'only_matching': True,
  204. }, {
  205. # no title
  206. 'url': 'https://www.facebook.com/onlycleverentertainment/videos/1947995502095005/',
  207. 'only_matching': True,
  208. }, {
  209. 'url': 'https://www.facebook.com/WatchESLOne/videos/359649331226507/',
  210. 'info_dict': {
  211. 'id': '359649331226507',
  212. 'ext': 'mp4',
  213. 'title': '#ESLOne VoD - Birmingham Finals Day#1 Fnatic vs. @Evil Geniuses',
  214. 'uploader': 'ESL One Dota 2',
  215. },
  216. 'params': {
  217. 'skip_download': True,
  218. },
  219. }]
  220. @staticmethod
  221. def _extract_urls(webpage):
  222. urls = []
  223. for mobj in re.finditer(
  224. r'<iframe[^>]+?src=(["\'])(?P<url>https?://www\.facebook\.com/(?:video/embed|plugins/video\.php).+?)\1',
  225. webpage):
  226. urls.append(mobj.group('url'))
  227. # Facebook API embed
  228. # see https://developers.facebook.com/docs/plugins/embedded-video-player
  229. for mobj in re.finditer(r'''(?x)<div[^>]+
  230. class=(?P<q1>[\'"])[^\'"]*\bfb-(?:video|post)\b[^\'"]*(?P=q1)[^>]+
  231. data-href=(?P<q2>[\'"])(?P<url>(?:https?:)?//(?:www\.)?facebook.com/.+?)(?P=q2)''', webpage):
  232. urls.append(mobj.group('url'))
  233. return urls
  234. def _login(self):
  235. useremail, password = self._get_login_info()
  236. if useremail is None:
  237. return
  238. login_page_req = sanitized_Request(self._LOGIN_URL)
  239. self._set_cookie('facebook.com', 'locale', 'en_US')
  240. login_page = self._download_webpage(login_page_req, None,
  241. note='Downloading login page',
  242. errnote='Unable to download login page')
  243. lsd = self._search_regex(
  244. r'<input type="hidden" name="lsd" value="([^"]*)"',
  245. login_page, 'lsd')
  246. lgnrnd = self._search_regex(r'name="lgnrnd" value="([^"]*?)"', login_page, 'lgnrnd')
  247. login_form = {
  248. 'email': useremail,
  249. 'pass': password,
  250. 'lsd': lsd,
  251. 'lgnrnd': lgnrnd,
  252. 'next': 'http://facebook.com/home.php',
  253. 'default_persistent': '0',
  254. 'legacy_return': '1',
  255. 'timezone': '-60',
  256. 'trynum': '1',
  257. }
  258. request = sanitized_Request(self._LOGIN_URL, urlencode_postdata(login_form))
  259. request.add_header('Content-Type', 'application/x-www-form-urlencoded')
  260. try:
  261. login_results = self._download_webpage(request, None,
  262. note='Logging in', errnote='unable to fetch login page')
  263. if re.search(r'<form(.*)name="login"(.*)</form>', login_results) is not None:
  264. error = self._html_search_regex(
  265. r'(?s)<div[^>]+class=(["\']).*?login_error_box.*?\1[^>]*><div[^>]*>.*?</div><div[^>]*>(?P<error>.+?)</div>',
  266. login_results, 'login error', default=None, group='error')
  267. if error:
  268. raise ExtractorError('Unable to login: %s' % error, expected=True)
  269. self._downloader.report_warning('unable to log in: bad username/password, or exceeded login rate limit (~3/min). Check credentials or wait.')
  270. return
  271. fb_dtsg = self._search_regex(
  272. r'name="fb_dtsg" value="(.+?)"', login_results, 'fb_dtsg', default=None)
  273. h = self._search_regex(
  274. r'name="h"\s+(?:\w+="[^"]+"\s+)*?value="([^"]+)"', login_results, 'h', default=None)
  275. if not fb_dtsg or not h:
  276. return
  277. check_form = {
  278. 'fb_dtsg': fb_dtsg,
  279. 'h': h,
  280. 'name_action_selected': 'dont_save',
  281. }
  282. check_req = sanitized_Request(self._CHECKPOINT_URL, urlencode_postdata(check_form))
  283. check_req.add_header('Content-Type', 'application/x-www-form-urlencoded')
  284. check_response = self._download_webpage(check_req, None,
  285. note='Confirming login')
  286. if re.search(r'id="checkpointSubmitButton"', check_response) is not None:
  287. self._downloader.report_warning('Unable to confirm login, you have to login in your browser and authorize the login.')
  288. except (compat_urllib_error.URLError, compat_http_client.HTTPException, socket.error) as err:
  289. self._downloader.report_warning('unable to log in: %s' % error_to_compat_str(err))
  290. return
  291. def _real_initialize(self):
  292. self._login()
  293. def _extract_from_url(self, url, video_id, fatal_if_no_video=True):
  294. webpage = self._download_webpage(
  295. url.replace('://m.facebook.com/', '://www.facebook.com/'), video_id)
  296. video_data = None
  297. def extract_video_data(instances):
  298. for item in instances:
  299. if item[1][0] == 'VideoConfig':
  300. video_item = item[2][0]
  301. if video_item.get('video_id'):
  302. return video_item['videoData']
  303. server_js_data = self._parse_json(self._search_regex(
  304. r'handleServerJS\(({.+})(?:\);|,")', webpage,
  305. 'server js data', default='{}'), video_id, fatal=False)
  306. if server_js_data:
  307. video_data = extract_video_data(server_js_data.get('instances', []))
  308. def extract_from_jsmods_instances(js_data):
  309. if js_data:
  310. return extract_video_data(try_get(
  311. js_data, lambda x: x['jsmods']['instances'], list) or [])
  312. formats = []
  313. def extract_dash_manifest(video):
  314. dash_manifest = video.get('dash_manifest')
  315. if dash_manifest:
  316. formats.extend(self._parse_mpd_formats(
  317. compat_etree_fromstring(compat_urllib_parse_unquote_plus(dash_manifest))))
  318. if not video_data:
  319. server_js_data = self._parse_json(self._search_regex([
  320. r'bigPipe\.onPageletArrive\(({.+?})\)\s*;\s*}\s*\)\s*,\s*["\']onPageletArrive\s+(?:pagelet_group_mall|permalink_video_pagelet|hyperfeed_story_id_\d+)',
  321. r'bigPipe\.onPageletArrive\(({.*?id\s*:\s*"permalink_video_pagelet".*?})\);'
  322. ], webpage, 'js data', default='{}'), video_id, js_to_json, False)
  323. video_data = extract_from_jsmods_instances(server_js_data)
  324. if not video_data:
  325. graphql_data = self._parse_json(self._search_regex(
  326. r'handleWithCustomApplyEach\([^,]+,\s*({.*?"(?:dash_manifest|playable_url(?:_quality_hd)?)"\s*:\s*"[^"]+".*?})\);',
  327. webpage, 'graphql data', default='{}'), video_id, fatal=False) or {}
  328. for require in (graphql_data.get('require') or []):
  329. if require[0] == 'RelayPrefetchedStreamCache':
  330. def parse_graphql_video(video):
  331. q = qualities(['sd', 'hd'])
  332. for (suffix, format_id) in [('', 'sd'), ('_quality_hd', 'hd')]:
  333. playable_url = video.get('playable_url' + suffix)
  334. if not playable_url:
  335. continue
  336. formats.append({
  337. 'format_id': format_id,
  338. 'quality': q(format_id),
  339. 'url': playable_url,
  340. })
  341. extract_dash_manifest(video)
  342. self._sort_formats(formats)
  343. v_id = video.get('videoId') or video.get('id') or video_id
  344. info = {
  345. 'id': v_id,
  346. 'formats': formats,
  347. 'thumbnail': try_get(video, lambda x: x['thumbnailImage']['uri']),
  348. 'uploader_id': try_get(video, lambda x: x['owner']['id']),
  349. 'timestamp': int_or_none(video.get('publish_time')),
  350. 'duration': float_or_none(video.get('playable_duration_in_ms'), 1000),
  351. }
  352. description = try_get(video, lambda x: x['savable_description']['text'])
  353. title = video.get('name')
  354. if title:
  355. info.update({
  356. 'title': title,
  357. 'description': description,
  358. })
  359. else:
  360. info['title'] = description or 'Facebook video #%s' % v_id
  361. return webpage, info
  362. data = try_get(require, lambda x: x[3][1]['__bbox']['result']['data'], dict) or {}
  363. attachments = try_get(data, [
  364. lambda x: x['video']['story']['attachments'],
  365. lambda x: x['video']['creation_story']['attachments'],
  366. lambda x: x['node']['comet_sections']['content']['story']['attachments']
  367. ], list) or []
  368. for attachment in attachments:
  369. media = attachment.get('media') or try_get(attachment, lambda x: x['style_type_renderer']['attachment']['media'], dict) or {}
  370. if media.get('__typename') == 'Video':
  371. return parse_graphql_video(media)
  372. video = data.get('video') or {}
  373. if video:
  374. return parse_graphql_video(video)
  375. if not video_data:
  376. if not fatal_if_no_video:
  377. return webpage, False
  378. m_msg = re.search(r'class="[^"]*uiInterstitialContent[^"]*"><div>(.*?)</div>', webpage)
  379. if m_msg is not None:
  380. raise ExtractorError(
  381. 'The video is not available, Facebook said: "%s"' % m_msg.group(1),
  382. expected=True)
  383. elif '>You must log in to continue' in webpage:
  384. self.raise_login_required()
  385. # Video info not in first request, do a secondary request using
  386. # tahoe player specific URL
  387. tahoe_data = self._download_webpage(
  388. self._VIDEO_PAGE_TAHOE_TEMPLATE % video_id, video_id,
  389. data=urlencode_postdata({
  390. '__a': 1,
  391. '__pc': self._search_regex(
  392. r'pkg_cohort["\']\s*:\s*["\'](.+?)["\']', webpage,
  393. 'pkg cohort', default='PHASED:DEFAULT'),
  394. '__rev': self._search_regex(
  395. r'client_revision["\']\s*:\s*(\d+),', webpage,
  396. 'client revision', default='3944515'),
  397. 'fb_dtsg': self._search_regex(
  398. r'"DTSGInitialData"\s*,\s*\[\]\s*,\s*{\s*"token"\s*:\s*"([^"]+)"',
  399. webpage, 'dtsg token', default=''),
  400. }),
  401. headers={
  402. 'Content-Type': 'application/x-www-form-urlencoded',
  403. })
  404. tahoe_js_data = self._parse_json(
  405. self._search_regex(
  406. r'for\s+\(\s*;\s*;\s*\)\s*;(.+)', tahoe_data,
  407. 'tahoe js data', default='{}'),
  408. video_id, fatal=False)
  409. video_data = extract_from_jsmods_instances(tahoe_js_data)
  410. if not video_data:
  411. raise ExtractorError('Cannot parse data')
  412. subtitles = {}
  413. for f in video_data:
  414. format_id = f['stream_type']
  415. if f and isinstance(f, dict):
  416. f = [f]
  417. if not f or not isinstance(f, list):
  418. continue
  419. for quality in ('sd', 'hd'):
  420. for src_type in ('src', 'src_no_ratelimit'):
  421. src = f[0].get('%s_%s' % (quality, src_type))
  422. if src:
  423. preference = -10 if format_id == 'progressive' else 0
  424. if quality == 'hd':
  425. preference += 5
  426. formats.append({
  427. 'format_id': '%s_%s_%s' % (format_id, quality, src_type),
  428. 'url': src,
  429. 'preference': preference,
  430. })
  431. extract_dash_manifest(f[0])
  432. subtitles_src = f[0].get('subtitles_src')
  433. if subtitles_src:
  434. subtitles.setdefault('en', []).append({'url': subtitles_src})
  435. if not formats:
  436. raise ExtractorError('Cannot find video formats')
  437. # Downloads with browser's User-Agent are rate limited. Working around
  438. # with non-browser User-Agent.
  439. for f in formats:
  440. f.setdefault('http_headers', {})['User-Agent'] = 'facebookexternalhit/1.1'
  441. self._sort_formats(formats)
  442. video_title = self._html_search_regex(
  443. r'<h2\s+[^>]*class="uiHeaderTitle"[^>]*>([^<]*)</h2>', webpage,
  444. 'title', default=None)
  445. if not video_title:
  446. video_title = self._html_search_regex(
  447. r'(?s)<span class="fbPhotosPhotoCaption".*?id="fbPhotoPageCaption"><span class="hasCaption">(.*?)</span>',
  448. webpage, 'alternative title', default=None)
  449. if not video_title:
  450. video_title = self._html_search_meta(
  451. 'description', webpage, 'title', default=None)
  452. if video_title:
  453. video_title = limit_length(video_title, 80)
  454. else:
  455. video_title = 'Facebook video #%s' % video_id
  456. uploader = clean_html(get_element_by_id(
  457. 'fbPhotoPageAuthorName', webpage)) or self._search_regex(
  458. r'ownerName\s*:\s*"([^"]+)"', webpage, 'uploader',
  459. default=None) or self._og_search_title(webpage, fatal=False)
  460. timestamp = int_or_none(self._search_regex(
  461. r'<abbr[^>]+data-utime=["\'](\d+)', webpage,
  462. 'timestamp', default=None))
  463. thumbnail = self._html_search_meta(['og:image', 'twitter:image'], webpage)
  464. view_count = parse_count(self._search_regex(
  465. r'\bviewCount\s*:\s*["\']([\d,.]+)', webpage, 'view count',
  466. default=None))
  467. info_dict = {
  468. 'id': video_id,
  469. 'title': video_title,
  470. 'formats': formats,
  471. 'uploader': uploader,
  472. 'timestamp': timestamp,
  473. 'thumbnail': thumbnail,
  474. 'view_count': view_count,
  475. 'subtitles': subtitles,
  476. }
  477. return webpage, info_dict
  478. def _real_extract(self, url):
  479. video_id = self._match_id(url)
  480. real_url = self._VIDEO_PAGE_TEMPLATE % video_id if url.startswith('facebook:') else url
  481. webpage, info_dict = self._extract_from_url(real_url, video_id, fatal_if_no_video=False)
  482. if info_dict:
  483. return info_dict
  484. if '/posts/' in url:
  485. video_id_json = self._search_regex(
  486. r'(["\'])video_ids\1\s*:\s*(?P<ids>\[.+?\])', webpage, 'video ids', group='ids',
  487. default='')
  488. if video_id_json:
  489. entries = [
  490. self.url_result('facebook:%s' % vid, FacebookIE.ie_key())
  491. for vid in self._parse_json(video_id_json, video_id)]
  492. return self.playlist_result(entries, video_id)
  493. # Single Video?
  494. video_id = self._search_regex(r'video_id:\s*"([0-9]+)"', webpage, 'single video id')
  495. return self.url_result('facebook:%s' % video_id, FacebookIE.ie_key())
  496. else:
  497. _, info_dict = self._extract_from_url(
  498. self._VIDEO_PAGE_TEMPLATE % video_id,
  499. video_id, fatal_if_no_video=True)
  500. return info_dict
  501. class FacebookPluginsVideoIE(InfoExtractor):
  502. _VALID_URL = r'https?://(?:[\w-]+\.)?facebook\.com/plugins/video\.php\?.*?\bhref=(?P<id>https.+)'
  503. _TESTS = [{
  504. 'url': 'https://www.facebook.com/plugins/video.php?href=https%3A%2F%2Fwww.facebook.com%2Fgov.sg%2Fvideos%2F10154383743583686%2F&show_text=0&width=560',
  505. 'md5': '5954e92cdfe51fe5782ae9bda7058a07',
  506. 'info_dict': {
  507. 'id': '10154383743583686',
  508. 'ext': 'mp4',
  509. 'title': 'What to do during the haze?',
  510. 'uploader': 'Gov.sg',
  511. 'upload_date': '20160826',
  512. 'timestamp': 1472184808,
  513. },
  514. 'add_ie': [FacebookIE.ie_key()],
  515. }, {
  516. 'url': 'https://www.facebook.com/plugins/video.php?href=https%3A%2F%2Fwww.facebook.com%2Fvideo.php%3Fv%3D10204634152394104',
  517. 'only_matching': True,
  518. }, {
  519. 'url': 'https://www.facebook.com/plugins/video.php?href=https://www.facebook.com/gov.sg/videos/10154383743583686/&show_text=0&width=560',
  520. 'only_matching': True,
  521. }]
  522. def _real_extract(self, url):
  523. return self.url_result(
  524. compat_urllib_parse_unquote(self._match_id(url)),
  525. FacebookIE.ie_key())