Google+: fixed

This commit is contained in:
Mort Yao 2014-05-17 19:28:52 +02:00
parent 5df8b25e5a
commit 86ab2d9a8c

View File

@ -43,54 +43,54 @@ fmt_level = dict(
def google_download(url, output_dir = '.', merge = True, info_only = False):
# Percent-encoding Unicode URL
url = parse.quote(url, safe = ':/+%')
service = url.split('/')[2].split('.')[0]
if service == 'plus': # Google Plus
if not re.search(r'plus.google.com/photos/[^/]*/albums/\d+/\d+', url):
html = get_html(url)
url = "https://plus.google.com/" + r1(r'"(photos/\d+/albums/\d+/\d+)', html)
title = r1(r'<title>([^<\n]+)', html)
else:
title = None
html = get_html(url)
real_urls = re.findall(r'\[(\d+),\d+,\d+,"([^"]+)"\]', html)
real_url = unicodize(sorted(real_urls, key = lambda x : fmt_level[x[0]])[0][1])
if title is None:
post_url = r1(r'"(https://plus.google.com/\d+/posts/[^"]*)"', html)
post_html = get_html(post_url)
title = r1(r'<title>([^<\n]+)', post_html)
title = r1(r'<title[^>]*>([^<\n]+)', post_html)
if title is None:
response = request.urlopen(request.Request(real_url))
if response.headers['content-disposition']:
filename = parse.unquote(r1(r'filename="?(.+)"?', response.headers['content-disposition'])).split('.')
title = ''.join(filename[:-1])
type, ext, size = url_info(real_url)
if ext is None:
ext = 'mp4'
elif service in ['docs', 'drive'] : # Google Docs
html = get_html(url)
title = r1(r'"title":"([^"]*)"', html) or r1(r'<meta itemprop="name" content="([^"]*)"', html)
if len(title.split('.')) > 1:
title = ".".join(title.split('.')[:-1])
docid = r1(r'"docid":"([^"]*)"', html)
request.install_opener(request.build_opener(request.HTTPCookieProcessor()))
request.urlopen(request.Request("https://docs.google.com/uc?id=%s&export=download" % docid))
real_url ="https://docs.google.com/uc?export=download&confirm=no_antivirus&id=%s" % docid
type, ext, size = url_info(real_url)
print_info(site_info, title, ext, size)
if not info_only:
download_urls([real_url], title, ext, size, output_dir, merge = merge)