mirror of
https://github.com/l1ving/youtube-dl
synced 2020-11-18 19:53:54 -08:00
Update facebook.py
This commit is contained in:
parent
772f93a75d
commit
09eed10644
@ -22,11 +22,12 @@ from ..utils import (
|
|||||||
int_or_none,
|
int_or_none,
|
||||||
js_to_json,
|
js_to_json,
|
||||||
limit_length,
|
limit_length,
|
||||||
|
merge_dicts,
|
||||||
parse_count,
|
parse_count,
|
||||||
sanitized_Request,
|
sanitized_Request,
|
||||||
try_get,
|
try_get,
|
||||||
urlencode_postdata,
|
urlencode_postdata,
|
||||||
merge_dicts,
|
urljoin,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -515,8 +516,14 @@ class FacebookPluginsVideoIE(InfoExtractor):
|
|||||||
|
|
||||||
|
|
||||||
class FacebookUserIE(InfoExtractor):
|
class FacebookUserIE(InfoExtractor):
|
||||||
_VALID_URL = r'(?P<url>https?://(?:[^/]+\.)?facebook\.com/(?:pg/)?(?P<id>[^/?#&]+))/videos(?!/[\w\.])'
|
_VALID_URL = r'https?://(?:[^/]+\.)?facebook\.com/(?:pg/)?(?P<id>[^/?#&]+)/videos'
|
||||||
IE_NAME = "facebook:user"
|
IE_NAME = 'facebook:user'
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def suitable(cls, url):
|
||||||
|
return (False
|
||||||
|
if FacebookIE.suitable(url)
|
||||||
|
else super(FacebookUserIE, cls).suitable(url))
|
||||||
|
|
||||||
_TESTS = [{
|
_TESTS = [{
|
||||||
# page
|
# page
|
||||||
@ -532,17 +539,17 @@ class FacebookUserIE(InfoExtractor):
|
|||||||
}]
|
}]
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
mobj = re.match(self._VALID_URL, url)
|
user_id = self._match_id(url)
|
||||||
user_id = mobj.group('id')
|
|
||||||
|
|
||||||
page = self._download_webpage(
|
page = self._download_webpage(
|
||||||
url, user_id, 'Downloading user webpage')
|
url, user_id, 'Downloading user webpage')
|
||||||
fb_url = self._html_search_meta(
|
fb_url = self._html_search_meta(
|
||||||
'al:android:url', page, default=None)
|
'al:android:url', page, default=None)
|
||||||
fb_url_mobj = re.match(r'fb://(?P<type>page|profile)/(?P<id>\d+)', fb_url)
|
fb_url_re = r'fb://(?P<type>page|profile)/(?P<id>\d+)'
|
||||||
if not fb_url_mobj:
|
page_type = self._search_regex(
|
||||||
raise ExtractorError('Could not extract page ID', expected=False)
|
fb_url_re, fb_url, 'page type', group='type')
|
||||||
page_id = fb_url_mobj.group('id')
|
page_id = self._search_regex(
|
||||||
|
fb_url_re, fb_url, 'page id', group='id')
|
||||||
fb_dtsg_ag = self._search_regex(
|
fb_dtsg_ag = self._search_regex(
|
||||||
r'"async_get_token":"([\w\-:]+)"',
|
r'"async_get_token":"([\w\-:]+)"',
|
||||||
page, 'fb_dtsg_ag', default=None)
|
page, 'fb_dtsg_ag', default=None)
|
||||||
@ -555,15 +562,15 @@ class FacebookUserIE(InfoExtractor):
|
|||||||
cursor = None
|
cursor = None
|
||||||
entries = []
|
entries = []
|
||||||
|
|
||||||
if fb_url_mobj.group('type') == 'page':
|
if page_type == 'page':
|
||||||
endpoint = 'PagesVideoHubVideoContainerPagelet'
|
endpoint = 'PagesVideoHubVideoContainerPagelet'
|
||||||
data = {
|
data = {
|
||||||
'page': page_id
|
'page': page_id
|
||||||
}
|
}
|
||||||
page_re = r'<td[^>]+>.+?<a href="(?P<url>[^"]+)".+?</td>'
|
page_re = r'<td[^>]+>.+?<a href="(?P<url>[^"]+)".+?</td>'
|
||||||
elif fb_url_mobj.group('type') == 'profile':
|
elif page_type == 'profile':
|
||||||
if not (fb_dtsg_ag and pagelet_token and collection_token):
|
if not (fb_dtsg_ag and pagelet_token and collection_token):
|
||||||
raise ExtractorError('You must be logged in to extract profile videos', expected=True)
|
raise ExtractorError('You must use cookies to extract profile videos', expected=True)
|
||||||
endpoint = 'VideosByUserAppCollectionPagelet'
|
endpoint = 'VideosByUserAppCollectionPagelet'
|
||||||
data = {
|
data = {
|
||||||
'collection_token': collection_token,
|
'collection_token': collection_token,
|
||||||
@ -592,17 +599,19 @@ class FacebookUserIE(InfoExtractor):
|
|||||||
self._search_regex(
|
self._search_regex(
|
||||||
r'({.+})', js_data_page,
|
r'({.+})', js_data_page,
|
||||||
'js data', default='{}'),
|
'js data', default='{}'),
|
||||||
user_id, fatal=True)
|
user_id)
|
||||||
|
|
||||||
for video in re.findall(
|
for video in re.findall(
|
||||||
page_re, js_data['payload']):
|
page_re, js_data['payload']):
|
||||||
|
video_url = urljoin('https://www.facebook.com', video)
|
||||||
|
if not FacebookIE.suitable(video_url):
|
||||||
|
continue
|
||||||
entries.append(
|
entries.append(
|
||||||
self.url_result(
|
self.url_result(
|
||||||
'https://www.facebook.com%s' % video,
|
video_url, FacebookIE.ie_key()))
|
||||||
FacebookIE.ie_key()))
|
|
||||||
|
|
||||||
cursor = None
|
cursor = None
|
||||||
if fb_url_mobj.group('type') == 'page':
|
if page_type == 'page':
|
||||||
if 'instances' not in js_data['jsmods']:
|
if 'instances' not in js_data['jsmods']:
|
||||||
break
|
break
|
||||||
for parent in js_data['jsmods']['instances']:
|
for parent in js_data['jsmods']['instances']:
|
||||||
@ -613,7 +622,7 @@ class FacebookUserIE(InfoExtractor):
|
|||||||
if type(subchild) is dict and 'cursor' in subchild:
|
if type(subchild) is dict and 'cursor' in subchild:
|
||||||
cursor = subchild['cursor']
|
cursor = subchild['cursor']
|
||||||
break
|
break
|
||||||
elif fb_url_mobj.group('type') == 'profile':
|
elif page_type == 'profile':
|
||||||
for parent in js_data['jsmods']['require']:
|
for parent in js_data['jsmods']['require']:
|
||||||
if type(parent) is list:
|
if type(parent) is list:
|
||||||
for child in parent:
|
for child in parent:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user