Skip to content

Commit

Permalink
[facebook] Fix invalid video being extracted (Closes #9851)
Browse files Browse the repository at this point in the history
  • Loading branch information
dstftw committed Jul 8, 2016
1 parent 07d7689 commit cedc70b
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions youtube_dl/extractor/facebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,23 @@ def _extract_from_url(self, url, video_id, fatal_if_no_video=True):

BEFORE = '{swf.addParam(param[0], param[1]);});'
AFTER = '.forEach(function(variable) {swf.addVariable(variable[0], variable[1]);});'
m = re.search(re.escape(BEFORE) + '(?:\n|\\\\n)(.*?)' + re.escape(AFTER), webpage)
if m:
swf_params = m.group(1).replace('\\\\', '\\').replace('\\"', '"')
PATTERN = re.escape(BEFORE) + '(?:\n|\\\\n)(.*?)' + re.escape(AFTER)

for m in re.findall(PATTERN, webpage):
swf_params = m.replace('\\\\', '\\').replace('\\"', '"')
data = dict(json.loads(swf_params))
params_raw = compat_urllib_parse_unquote(data['params'])
video_data = json.loads(params_raw)['video_data']
video_data_candidate = json.loads(params_raw)['video_data']
for _, f in video_data_candidate.items():
if not f:
continue
if isinstance(f, dict):
f = [f]
if isinstance(f, list):
continue
if f[0].get('video_id') == video_id:
video_data = video_data_candidate
break

def video_data_list2dict(video_data):
ret = {}
Expand Down

0 comments on commit cedc70b

Please sign in to comment.