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

279 lines
11 KiB

Switch codebase to use sanitized_Request instead of compat_urllib_request.Request [downloader/dash] Use sanitized_Request [downloader/http] Use sanitized_Request [atresplayer] Use sanitized_Request [bambuser] Use sanitized_Request [bliptv] Use sanitized_Request [brightcove] Use sanitized_Request [cbs] Use sanitized_Request [ceskatelevize] Use sanitized_Request [collegerama] Use sanitized_Request [extractor/common] Use sanitized_Request [crunchyroll] Use sanitized_Request [dailymotion] Use sanitized_Request [dcn] Use sanitized_Request [dramafever] Use sanitized_Request [dumpert] Use sanitized_Request [eitb] Use sanitized_Request [escapist] Use sanitized_Request [everyonesmixtape] Use sanitized_Request [extremetube] Use sanitized_Request [facebook] Use sanitized_Request [fc2] Use sanitized_Request [flickr] Use sanitized_Request [4tube] Use sanitized_Request [gdcvault] Use sanitized_Request [extractor/generic] Use sanitized_Request [hearthisat] Use sanitized_Request [hotnewhiphop] Use sanitized_Request [hypem] Use sanitized_Request [iprima] Use sanitized_Request [ivi] Use sanitized_Request [keezmovies] Use sanitized_Request [letv] Use sanitized_Request [lynda] Use sanitized_Request [metacafe] Use sanitized_Request [minhateca] Use sanitized_Request [miomio] Use sanitized_Request [meovideo] Use sanitized_Request [mofosex] Use sanitized_Request [moniker] Use sanitized_Request [mooshare] Use sanitized_Request [movieclips] Use sanitized_Request [mtv] Use sanitized_Request [myvideo] Use sanitized_Request [neteasemusic] Use sanitized_Request [nfb] Use sanitized_Request [niconico] Use sanitized_Request [noco] Use sanitized_Request [nosvideo] Use sanitized_Request [novamov] Use sanitized_Request [nowness] Use sanitized_Request [nuvid] Use sanitized_Request [played] Use sanitized_Request [pluralsight] Use sanitized_Request [pornhub] Use sanitized_Request [pornotube] Use sanitized_Request [primesharetv] Use sanitized_Request [promptfile] Use sanitized_Request [qqmusic] Use sanitized_Request [rtve] Use sanitized_Request [safari] Use sanitized_Request [sandia] Use sanitized_Request [shared] Use sanitized_Request [sharesix] Use sanitized_Request [sina] Use sanitized_Request [smotri] Use sanitized_Request [sohu] Use sanitized_Request [spankwire] Use sanitized_Request [sportdeutschland] Use sanitized_Request [streamcloud] Use sanitized_Request [streamcz] Use sanitized_Request [tapely] Use sanitized_Request [tube8] Use sanitized_Request [tubitv] Use sanitized_Request [twitch] Use sanitized_Request [twitter] Use sanitized_Request [udemy] Use sanitized_Request [vbox7] Use sanitized_Request [veoh] Use sanitized_Request [vessel] Use sanitized_Request [vevo] Use sanitized_Request [viddler] Use sanitized_Request [videomega] Use sanitized_Request [viewvster] Use sanitized_Request [viki] Use sanitized_Request [vk] Use sanitized_Request [vodlocker] Use sanitized_Request [voicerepublic] Use sanitized_Request [wistia] Use sanitized_Request [xfileshare] Use sanitized_Request [xtube] Use sanitized_Request [xvideos] Use sanitized_Request [yandexmusic] Use sanitized_Request [youku] Use sanitized_Request [youporn] Use sanitized_Request [youtube] Use sanitized_Request [patreon] Use sanitized_Request [extractor/common] Remove unused import [nfb] PEP 8
9 years ago
Switch codebase to use sanitized_Request instead of compat_urllib_request.Request [downloader/dash] Use sanitized_Request [downloader/http] Use sanitized_Request [atresplayer] Use sanitized_Request [bambuser] Use sanitized_Request [bliptv] Use sanitized_Request [brightcove] Use sanitized_Request [cbs] Use sanitized_Request [ceskatelevize] Use sanitized_Request [collegerama] Use sanitized_Request [extractor/common] Use sanitized_Request [crunchyroll] Use sanitized_Request [dailymotion] Use sanitized_Request [dcn] Use sanitized_Request [dramafever] Use sanitized_Request [dumpert] Use sanitized_Request [eitb] Use sanitized_Request [escapist] Use sanitized_Request [everyonesmixtape] Use sanitized_Request [extremetube] Use sanitized_Request [facebook] Use sanitized_Request [fc2] Use sanitized_Request [flickr] Use sanitized_Request [4tube] Use sanitized_Request [gdcvault] Use sanitized_Request [extractor/generic] Use sanitized_Request [hearthisat] Use sanitized_Request [hotnewhiphop] Use sanitized_Request [hypem] Use sanitized_Request [iprima] Use sanitized_Request [ivi] Use sanitized_Request [keezmovies] Use sanitized_Request [letv] Use sanitized_Request [lynda] Use sanitized_Request [metacafe] Use sanitized_Request [minhateca] Use sanitized_Request [miomio] Use sanitized_Request [meovideo] Use sanitized_Request [mofosex] Use sanitized_Request [moniker] Use sanitized_Request [mooshare] Use sanitized_Request [movieclips] Use sanitized_Request [mtv] Use sanitized_Request [myvideo] Use sanitized_Request [neteasemusic] Use sanitized_Request [nfb] Use sanitized_Request [niconico] Use sanitized_Request [noco] Use sanitized_Request [nosvideo] Use sanitized_Request [novamov] Use sanitized_Request [nowness] Use sanitized_Request [nuvid] Use sanitized_Request [played] Use sanitized_Request [pluralsight] Use sanitized_Request [pornhub] Use sanitized_Request [pornotube] Use sanitized_Request [primesharetv] Use sanitized_Request [promptfile] Use sanitized_Request [qqmusic] Use sanitized_Request [rtve] Use sanitized_Request [safari] Use sanitized_Request [sandia] Use sanitized_Request [shared] Use sanitized_Request [sharesix] Use sanitized_Request [sina] Use sanitized_Request [smotri] Use sanitized_Request [sohu] Use sanitized_Request [spankwire] Use sanitized_Request [sportdeutschland] Use sanitized_Request [streamcloud] Use sanitized_Request [streamcz] Use sanitized_Request [tapely] Use sanitized_Request [tube8] Use sanitized_Request [tubitv] Use sanitized_Request [twitch] Use sanitized_Request [twitter] Use sanitized_Request [udemy] Use sanitized_Request [vbox7] Use sanitized_Request [veoh] Use sanitized_Request [vessel] Use sanitized_Request [vevo] Use sanitized_Request [viddler] Use sanitized_Request [videomega] Use sanitized_Request [viewvster] Use sanitized_Request [viki] Use sanitized_Request [vk] Use sanitized_Request [vodlocker] Use sanitized_Request [voicerepublic] Use sanitized_Request [wistia] Use sanitized_Request [xfileshare] Use sanitized_Request [xtube] Use sanitized_Request [xvideos] Use sanitized_Request [yandexmusic] Use sanitized_Request [youku] Use sanitized_Request [youporn] Use sanitized_Request [youtube] Use sanitized_Request [patreon] Use sanitized_Request [extractor/common] Remove unused import [nfb] PEP 8
9 years ago
Switch codebase to use sanitized_Request instead of compat_urllib_request.Request [downloader/dash] Use sanitized_Request [downloader/http] Use sanitized_Request [atresplayer] Use sanitized_Request [bambuser] Use sanitized_Request [bliptv] Use sanitized_Request [brightcove] Use sanitized_Request [cbs] Use sanitized_Request [ceskatelevize] Use sanitized_Request [collegerama] Use sanitized_Request [extractor/common] Use sanitized_Request [crunchyroll] Use sanitized_Request [dailymotion] Use sanitized_Request [dcn] Use sanitized_Request [dramafever] Use sanitized_Request [dumpert] Use sanitized_Request [eitb] Use sanitized_Request [escapist] Use sanitized_Request [everyonesmixtape] Use sanitized_Request [extremetube] Use sanitized_Request [facebook] Use sanitized_Request [fc2] Use sanitized_Request [flickr] Use sanitized_Request [4tube] Use sanitized_Request [gdcvault] Use sanitized_Request [extractor/generic] Use sanitized_Request [hearthisat] Use sanitized_Request [hotnewhiphop] Use sanitized_Request [hypem] Use sanitized_Request [iprima] Use sanitized_Request [ivi] Use sanitized_Request [keezmovies] Use sanitized_Request [letv] Use sanitized_Request [lynda] Use sanitized_Request [metacafe] Use sanitized_Request [minhateca] Use sanitized_Request [miomio] Use sanitized_Request [meovideo] Use sanitized_Request [mofosex] Use sanitized_Request [moniker] Use sanitized_Request [mooshare] Use sanitized_Request [movieclips] Use sanitized_Request [mtv] Use sanitized_Request [myvideo] Use sanitized_Request [neteasemusic] Use sanitized_Request [nfb] Use sanitized_Request [niconico] Use sanitized_Request [noco] Use sanitized_Request [nosvideo] Use sanitized_Request [novamov] Use sanitized_Request [nowness] Use sanitized_Request [nuvid] Use sanitized_Request [played] Use sanitized_Request [pluralsight] Use sanitized_Request [pornhub] Use sanitized_Request [pornotube] Use sanitized_Request [primesharetv] Use sanitized_Request [promptfile] Use sanitized_Request [qqmusic] Use sanitized_Request [rtve] Use sanitized_Request [safari] Use sanitized_Request [sandia] Use sanitized_Request [shared] Use sanitized_Request [sharesix] Use sanitized_Request [sina] Use sanitized_Request [smotri] Use sanitized_Request [sohu] Use sanitized_Request [spankwire] Use sanitized_Request [sportdeutschland] Use sanitized_Request [streamcloud] Use sanitized_Request [streamcz] Use sanitized_Request [tapely] Use sanitized_Request [tube8] Use sanitized_Request [tubitv] Use sanitized_Request [twitch] Use sanitized_Request [twitter] Use sanitized_Request [udemy] Use sanitized_Request [vbox7] Use sanitized_Request [veoh] Use sanitized_Request [vessel] Use sanitized_Request [vevo] Use sanitized_Request [viddler] Use sanitized_Request [videomega] Use sanitized_Request [viewvster] Use sanitized_Request [viki] Use sanitized_Request [vk] Use sanitized_Request [vodlocker] Use sanitized_Request [voicerepublic] Use sanitized_Request [wistia] Use sanitized_Request [xfileshare] Use sanitized_Request [xtube] Use sanitized_Request [xvideos] Use sanitized_Request [yandexmusic] Use sanitized_Request [youku] Use sanitized_Request [youporn] Use sanitized_Request [youtube] Use sanitized_Request [patreon] Use sanitized_Request [extractor/common] Remove unused import [nfb] PEP 8
9 years ago
Switch codebase to use sanitized_Request instead of compat_urllib_request.Request [downloader/dash] Use sanitized_Request [downloader/http] Use sanitized_Request [atresplayer] Use sanitized_Request [bambuser] Use sanitized_Request [bliptv] Use sanitized_Request [brightcove] Use sanitized_Request [cbs] Use sanitized_Request [ceskatelevize] Use sanitized_Request [collegerama] Use sanitized_Request [extractor/common] Use sanitized_Request [crunchyroll] Use sanitized_Request [dailymotion] Use sanitized_Request [dcn] Use sanitized_Request [dramafever] Use sanitized_Request [dumpert] Use sanitized_Request [eitb] Use sanitized_Request [escapist] Use sanitized_Request [everyonesmixtape] Use sanitized_Request [extremetube] Use sanitized_Request [facebook] Use sanitized_Request [fc2] Use sanitized_Request [flickr] Use sanitized_Request [4tube] Use sanitized_Request [gdcvault] Use sanitized_Request [extractor/generic] Use sanitized_Request [hearthisat] Use sanitized_Request [hotnewhiphop] Use sanitized_Request [hypem] Use sanitized_Request [iprima] Use sanitized_Request [ivi] Use sanitized_Request [keezmovies] Use sanitized_Request [letv] Use sanitized_Request [lynda] Use sanitized_Request [metacafe] Use sanitized_Request [minhateca] Use sanitized_Request [miomio] Use sanitized_Request [meovideo] Use sanitized_Request [mofosex] Use sanitized_Request [moniker] Use sanitized_Request [mooshare] Use sanitized_Request [movieclips] Use sanitized_Request [mtv] Use sanitized_Request [myvideo] Use sanitized_Request [neteasemusic] Use sanitized_Request [nfb] Use sanitized_Request [niconico] Use sanitized_Request [noco] Use sanitized_Request [nosvideo] Use sanitized_Request [novamov] Use sanitized_Request [nowness] Use sanitized_Request [nuvid] Use sanitized_Request [played] Use sanitized_Request [pluralsight] Use sanitized_Request [pornhub] Use sanitized_Request [pornotube] Use sanitized_Request [primesharetv] Use sanitized_Request [promptfile] Use sanitized_Request [qqmusic] Use sanitized_Request [rtve] Use sanitized_Request [safari] Use sanitized_Request [sandia] Use sanitized_Request [shared] Use sanitized_Request [sharesix] Use sanitized_Request [sina] Use sanitized_Request [smotri] Use sanitized_Request [sohu] Use sanitized_Request [spankwire] Use sanitized_Request [sportdeutschland] Use sanitized_Request [streamcloud] Use sanitized_Request [streamcz] Use sanitized_Request [tapely] Use sanitized_Request [tube8] Use sanitized_Request [tubitv] Use sanitized_Request [twitch] Use sanitized_Request [twitter] Use sanitized_Request [udemy] Use sanitized_Request [vbox7] Use sanitized_Request [veoh] Use sanitized_Request [vessel] Use sanitized_Request [vevo] Use sanitized_Request [viddler] Use sanitized_Request [videomega] Use sanitized_Request [viewvster] Use sanitized_Request [viki] Use sanitized_Request [vk] Use sanitized_Request [vodlocker] Use sanitized_Request [voicerepublic] Use sanitized_Request [wistia] Use sanitized_Request [xfileshare] Use sanitized_Request [xtube] Use sanitized_Request [xvideos] Use sanitized_Request [yandexmusic] Use sanitized_Request [youku] Use sanitized_Request [youporn] Use sanitized_Request [youtube] Use sanitized_Request [patreon] Use sanitized_Request [extractor/common] Remove unused import [nfb] PEP 8
9 years ago
  1. from __future__ import unicode_literals
  2. import json
  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. error_to_compat_str,
  15. ExtractorError,
  16. limit_length,
  17. sanitized_Request,
  18. urlencode_postdata,
  19. get_element_by_id,
  20. clean_html,
  21. )
  22. class FacebookIE(InfoExtractor):
  23. _VALID_URL = r'''(?x)
  24. (?:
  25. https?://
  26. (?:\w+\.)?facebook\.com/
  27. (?:[^#]*?\#!/)?
  28. (?:
  29. (?:
  30. video/video\.php|
  31. photo\.php|
  32. video\.php|
  33. video/embed|
  34. story\.php
  35. )\?(?:.*?)(?:v|video_id|story_fbid)=|
  36. [^/]+/videos/(?:[^/]+/)?
  37. )|
  38. facebook:
  39. )
  40. (?P<id>[0-9]+)
  41. '''
  42. _LOGIN_URL = 'https://www.facebook.com/login.php?next=http%3A%2F%2Ffacebook.com%2Fhome.php&login_attempt=1'
  43. _CHECKPOINT_URL = 'https://www.facebook.com/checkpoint/?next=http%3A%2F%2Ffacebook.com%2Fhome.php&_fb_noscript=1'
  44. _NETRC_MACHINE = 'facebook'
  45. IE_NAME = 'facebook'
  46. _CHROME_USER_AGENT = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.97 Safari/537.36'
  47. _TESTS = [{
  48. 'url': 'https://www.facebook.com/video.php?v=637842556329505&fref=nf',
  49. 'md5': '6a40d33c0eccbb1af76cf0485a052659',
  50. 'info_dict': {
  51. 'id': '637842556329505',
  52. 'ext': 'mp4',
  53. 'title': 're:Did you know Kei Nishikori is the first Asian man to ever reach a Grand Slam',
  54. 'uploader': 'Tennis on Facebook',
  55. }
  56. }, {
  57. 'note': 'Video without discernible title',
  58. 'url': 'https://www.facebook.com/video.php?v=274175099429670',
  59. 'info_dict': {
  60. 'id': '274175099429670',
  61. 'ext': 'mp4',
  62. 'title': 'Facebook video #274175099429670',
  63. 'uploader': 'Asif Nawab Butt',
  64. },
  65. 'expected_warnings': [
  66. 'title'
  67. ]
  68. }, {
  69. 'note': 'Video with DASH manifest',
  70. 'url': 'https://www.facebook.com/video.php?v=957955867617029',
  71. 'md5': '54706e4db4f5ad58fbad82dde1f1213f',
  72. 'info_dict': {
  73. 'id': '957955867617029',
  74. 'ext': 'mp4',
  75. 'title': 'When you post epic content on instagram.com/433 8 million followers, this is ...',
  76. 'uploader': 'Demy de Zeeuw',
  77. },
  78. }, {
  79. 'url': 'https://www.facebook.com/video.php?v=10204634152394104',
  80. 'only_matching': True,
  81. }, {
  82. 'url': 'https://www.facebook.com/amogood/videos/1618742068337349/?fref=nf',
  83. 'only_matching': True,
  84. }, {
  85. 'url': 'https://www.facebook.com/ChristyClarkForBC/videos/vb.22819070941/10153870694020942/?type=2&theater',
  86. 'only_matching': True,
  87. }, {
  88. 'url': 'facebook:544765982287235',
  89. 'only_matching': True,
  90. }, {
  91. 'url': 'https://m.facebook.com/story.php?story_fbid=1035862816472149&id=116132035111903',
  92. 'only_matching': True,
  93. }]
  94. def _login(self):
  95. (useremail, password) = self._get_login_info()
  96. if useremail is None:
  97. return
  98. login_page_req = sanitized_Request(self._LOGIN_URL)
  99. self._set_cookie('facebook.com', 'locale', 'en_US')
  100. login_page = self._download_webpage(login_page_req, None,
  101. note='Downloading login page',
  102. errnote='Unable to download login page')
  103. lsd = self._search_regex(
  104. r'<input type="hidden" name="lsd" value="([^"]*)"',
  105. login_page, 'lsd')
  106. lgnrnd = self._search_regex(r'name="lgnrnd" value="([^"]*?)"', login_page, 'lgnrnd')
  107. login_form = {
  108. 'email': useremail,
  109. 'pass': password,
  110. 'lsd': lsd,
  111. 'lgnrnd': lgnrnd,
  112. 'next': 'http://facebook.com/home.php',
  113. 'default_persistent': '0',
  114. 'legacy_return': '1',
  115. 'timezone': '-60',
  116. 'trynum': '1',
  117. }
  118. request = sanitized_Request(self._LOGIN_URL, urlencode_postdata(login_form))
  119. request.add_header('Content-Type', 'application/x-www-form-urlencoded')
  120. try:
  121. login_results = self._download_webpage(request, None,
  122. note='Logging in', errnote='unable to fetch login page')
  123. if re.search(r'<form(.*)name="login"(.*)</form>', login_results) is not None:
  124. error = self._html_search_regex(
  125. r'(?s)<div[^>]+class=(["\']).*?login_error_box.*?\1[^>]*><div[^>]*>.*?</div><div[^>]*>(?P<error>.+?)</div>',
  126. login_results, 'login error', default=None, group='error')
  127. if error:
  128. raise ExtractorError('Unable to login: %s' % error, expected=True)
  129. self._downloader.report_warning('unable to log in: bad username/password, or exceeded login rate limit (~3/min). Check credentials or wait.')
  130. return
  131. fb_dtsg = self._search_regex(
  132. r'name="fb_dtsg" value="(.+?)"', login_results, 'fb_dtsg', default=None)
  133. h = self._search_regex(
  134. r'name="h"\s+(?:\w+="[^"]+"\s+)*?value="([^"]+)"', login_results, 'h', default=None)
  135. if not fb_dtsg or not h:
  136. return
  137. check_form = {
  138. 'fb_dtsg': fb_dtsg,
  139. 'h': h,
  140. 'name_action_selected': 'dont_save',
  141. }
  142. check_req = sanitized_Request(self._CHECKPOINT_URL, urlencode_postdata(check_form))
  143. check_req.add_header('Content-Type', 'application/x-www-form-urlencoded')
  144. check_response = self._download_webpage(check_req, None,
  145. note='Confirming login')
  146. if re.search(r'id="checkpointSubmitButton"', check_response) is not None:
  147. self._downloader.report_warning('Unable to confirm login, you have to login in your browser and authorize the login.')
  148. except (compat_urllib_error.URLError, compat_http_client.HTTPException, socket.error) as err:
  149. self._downloader.report_warning('unable to log in: %s' % error_to_compat_str(err))
  150. return
  151. def _real_initialize(self):
  152. self._login()
  153. def _real_extract(self, url):
  154. video_id = self._match_id(url)
  155. req = sanitized_Request('https://www.facebook.com/video/video.php?v=%s' % video_id)
  156. req.add_header('User-Agent', self._CHROME_USER_AGENT)
  157. webpage = self._download_webpage(req, video_id)
  158. video_data = None
  159. BEFORE = '{swf.addParam(param[0], param[1]);});\n'
  160. AFTER = '.forEach(function(variable) {swf.addVariable(variable[0], variable[1]);});'
  161. m = re.search(re.escape(BEFORE) + '(.*?)' + re.escape(AFTER), webpage)
  162. if m:
  163. data = dict(json.loads(m.group(1)))
  164. params_raw = compat_urllib_parse_unquote(data['params'])
  165. video_data = json.loads(params_raw)['video_data']
  166. def video_data_list2dict(video_data):
  167. ret = {}
  168. for item in video_data:
  169. format_id = item['stream_type']
  170. ret.setdefault(format_id, []).append(item)
  171. return ret
  172. if not video_data:
  173. server_js_data = self._parse_json(self._search_regex(
  174. r'handleServerJS\(({.+})\);', webpage, 'server js data'), video_id)
  175. for item in server_js_data.get('instances', []):
  176. if item[1][0] == 'VideoConfig':
  177. video_data = video_data_list2dict(item[2][0]['videoData'])
  178. break
  179. if not video_data:
  180. m_msg = re.search(r'class="[^"]*uiInterstitialContent[^"]*"><div>(.*?)</div>', webpage)
  181. if m_msg is not None:
  182. raise ExtractorError(
  183. 'The video is not available, Facebook said: "%s"' % m_msg.group(1),
  184. expected=True)
  185. else:
  186. raise ExtractorError('Cannot parse data')
  187. formats = []
  188. for format_id, f in video_data.items():
  189. if not f or not isinstance(f, list):
  190. continue
  191. for quality in ('sd', 'hd'):
  192. for src_type in ('src', 'src_no_ratelimit'):
  193. src = f[0].get('%s_%s' % (quality, src_type))
  194. if src:
  195. preference = -10 if format_id == 'progressive' else 0
  196. if quality == 'hd':
  197. preference += 5
  198. formats.append({
  199. 'format_id': '%s_%s_%s' % (format_id, quality, src_type),
  200. 'url': src,
  201. 'preference': preference,
  202. })
  203. dash_manifest = f[0].get('dash_manifest')
  204. if dash_manifest:
  205. formats.extend(self._parse_mpd_formats(
  206. compat_etree_fromstring(compat_urllib_parse_unquote_plus(dash_manifest))))
  207. if not formats:
  208. raise ExtractorError('Cannot find video formats')
  209. self._sort_formats(formats)
  210. video_title = self._html_search_regex(
  211. r'<h2\s+[^>]*class="uiHeaderTitle"[^>]*>([^<]*)</h2>', webpage, 'title',
  212. default=None)
  213. if not video_title:
  214. video_title = self._html_search_regex(
  215. r'(?s)<span class="fbPhotosPhotoCaption".*?id="fbPhotoPageCaption"><span class="hasCaption">(.*?)</span>',
  216. webpage, 'alternative title', default=None)
  217. video_title = limit_length(video_title, 80)
  218. if not video_title:
  219. video_title = 'Facebook video #%s' % video_id
  220. uploader = clean_html(get_element_by_id('fbPhotoPageAuthorName', webpage))
  221. return {
  222. 'id': video_id,
  223. 'title': video_title,
  224. 'formats': formats,
  225. 'uploader': uploader,
  226. }
  227. class FacebookPostIE(InfoExtractor):
  228. IE_NAME = 'facebook:post'
  229. _VALID_URL = r'https?://(?:\w+\.)?facebook\.com/[^/]+/posts/(?P<id>\d+)'
  230. _TEST = {
  231. 'url': 'https://www.facebook.com/maxlayn/posts/10153807558977570',
  232. 'md5': '037b1fa7f3c2d02b7a0d7bc16031ecc6',
  233. 'info_dict': {
  234. 'id': '544765982287235',
  235. 'ext': 'mp4',
  236. 'title': '"What are you doing running in the snow?"',
  237. 'uploader': 'FailArmy',
  238. }
  239. }
  240. def _real_extract(self, url):
  241. post_id = self._match_id(url)
  242. webpage = self._download_webpage(url, post_id)
  243. entries = [
  244. self.url_result('facebook:%s' % video_id, FacebookIE.ie_key())
  245. for video_id in self._parse_json(
  246. self._search_regex(
  247. r'(["\'])video_ids\1\s*:\s*(?P<ids>\[.+?\])',
  248. webpage, 'video ids', group='ids'),
  249. post_id)]
  250. return self.playlist_result(entries, post_id)