]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/googleplus.py
Prepare to upload
[youtubedl] / youtube_dl / extractor / googleplus.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5 import codecs
6
7 from .common import InfoExtractor
8 from ..utils import unified_strdate
9
10
11 class GooglePlusIE(InfoExtractor):
12 IE_DESC = 'Google Plus'
13 _VALID_URL = r'https?://plus\.google\.com/(?:[^/]+/)*?posts/(?P<id>\w+)'
14 IE_NAME = 'plus.google'
15 _TEST = {
16 'url': 'https://plus.google.com/u/0/108897254135232129896/posts/ZButuJc6CtH',
17 'info_dict': {
18 'id': 'ZButuJc6CtH',
19 'ext': 'flv',
20 'title': '嘆きの天使 降臨',
21 'upload_date': '20120613',
22 'uploader': '井上ヨシマサ',
23 }
24 }
25
26 def _real_extract(self, url):
27 video_id = self._match_id(url)
28
29 # Step 1, Retrieve post webpage to extract further information
30 webpage = self._download_webpage(url, video_id, 'Downloading entry webpage')
31
32 title = self._og_search_description(webpage).splitlines()[0]
33 upload_date = unified_strdate(self._html_search_regex(
34 r'''(?x)<a.+?class="o-U-s\s[^"]+"\s+style="display:\s*none"\s*>
35 ([0-9]{4}-[0-9]{2}-[0-9]{2})</a>''',
36 webpage, 'upload date', fatal=False, flags=re.VERBOSE))
37 uploader = self._html_search_regex(
38 r'rel="author".*?>(.*?)</a>', webpage, 'uploader', fatal=False)
39
40 # Step 2, Simulate clicking the image box to launch video
41 DOMAIN = 'https://plus.google.com/'
42 video_page = self._search_regex(
43 r'<a href="((?:%s)?photos/.*?)"' % re.escape(DOMAIN),
44 webpage, 'video page URL')
45 if not video_page.startswith(DOMAIN):
46 video_page = DOMAIN + video_page
47
48 webpage = self._download_webpage(video_page, video_id, 'Downloading video page')
49
50 def unicode_escape(s):
51 decoder = codecs.getdecoder('unicode_escape')
52 return re.sub(
53 r'\\u[0-9a-fA-F]{4,}',
54 lambda m: decoder(m.group(0))[0],
55 s)
56
57 # Extract video links all sizes
58 formats = [{
59 'url': unicode_escape(video_url),
60 'ext': 'flv',
61 'width': int(width),
62 'height': int(height),
63 } for width, height, video_url in re.findall(
64 r'\d+,(\d+),(\d+),"(https?://[^.]+\.googleusercontent\.com.*?)"', webpage)]
65 self._sort_formats(formats)
66
67 return {
68 'id': video_id,
69 'title': title,
70 'uploader': uploader,
71 'upload_date': upload_date,
72 'formats': formats,
73 }