Fix facebook extractor

Previously would throw error if there is no hd_src
Modified to use json parser and check if hd_src is None
This commit is contained in:
D Low 2015-04-12 14:55:36 +01:00
parent e22fb5269d
commit 90fb2f4842

View File

@ -3,22 +3,26 @@
__all__ = ['facebook_download']
from ..common import *
import json
def facebook_download(url, output_dir = '.', merge = True, info_only = False):
def facebook_download(url, output_dir='.', merge=True, info_only=False):
html = get_html(url)
title = r1(r'<title id="pageTitle">(.+) \| Facebook</title>', html)
s2 = parse.unquote(unicodize(r1(r'\["params","([^"]*)"\]', html)))
data = json.loads(s2)
video_data = data["video_data"][0]
for fmt in ["hd_src", "sd_src"]:
src= re.sub(r'\\/', r'/', r1(r'"' + fmt + '":"([^"]*)"', parse.unquote(unicodize(r1(r'\["params","([^"]*)"\]', html)))))
src = video_data[fmt]
if src:
break
type, ext, size = url_info(src)
type, ext, size = url_info(src, True)
print_info(site_info, title, type, size)
if not info_only:
download_urls([src], title, ext, size, output_dir, merge = merge)
download_urls([src], title, ext, size, output_dir, merge=merge)
site_info = "Facebook.com"
download = facebook_download