]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/googleplus.py
Merge branch 'atomicdryad-pr-bbcnews'
[yt-dlp.git] / youtube_dl / extractor / googleplus.py
CommitLineData
0c56a3f7 1# coding: utf-8
3501423d 2from __future__ import unicode_literals
0c56a3f7 3
7aca14a1 4import re
4828703f 5import codecs
7aca14a1
PH
6
7from .common import InfoExtractor
4828703f 8from ..utils import unified_strdate
7aca14a1
PH
9
10
11class GooglePlusIE(InfoExtractor):
3501423d
JMF
12 IE_DESC = 'Google Plus'
13 _VALID_URL = r'https://plus\.google\.com/(?:[^/]+/)*?posts/(?P<id>\w+)'
14 IE_NAME = 'plus.google'
0c56a3f7 15 _TEST = {
3501423d
JMF
16 'url': 'https://plus.google.com/u/0/108897254135232129896/posts/ZButuJc6CtH',
17 'info_dict': {
18 'id': 'ZButuJc6CtH',
19 'ext': 'flv',
4828703f 20 'title': '嘆きの天使 降臨',
3501423d
JMF
21 'upload_date': '20120613',
22 'uploader': '井上ヨシマサ',
0c56a3f7
PH
23 }
24 }
7aca14a1
PH
25
26 def _real_extract(self, url):
4828703f 27 video_id = self._match_id(url)
7aca14a1
PH
28
29 # Step 1, Retrieve post webpage to extract further information
3501423d 30 webpage = self._download_webpage(url, video_id, 'Downloading entry webpage')
7aca14a1 31
4828703f
S
32 title = self._og_search_description(webpage).splitlines()[0]
33 upload_date = unified_strdate(self._html_search_regex(
685a9cd2 34 r'''(?x)<a.+?class="o-U-s\s[^"]+"\s+style="display:\s*none"\s*>
e94b783c 35 ([0-9]{4}-[0-9]{2}-[0-9]{2})</a>''',
4828703f
S
36 webpage, 'upload date', fatal=False, flags=re.VERBOSE))
37 uploader = self._html_search_regex(
38 r'rel="author".*?>(.*?)</a>', webpage, 'uploader', fatal=False)
7aca14a1 39
d6628960 40 # Step 2, Simulate clicking the image box to launch video
7f3c4f4f 41 DOMAIN = 'https://plus.google.com/'
4828703f
S
42 video_page = self._search_regex(
43 r'<a href="((?:%s)?photos/.*?)"' % re.escape(DOMAIN),
3501423d 44 webpage, 'video page URL')
d6628960
PH
45 if not video_page.startswith(DOMAIN):
46 video_page = DOMAIN + video_page
47
3501423d 48 webpage = self._download_webpage(video_page, video_id, 'Downloading video page')
7aca14a1 49
4828703f
S
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)
7aca14a1 56
4828703f
S
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?://redirector\.googlevideo\.com.*?)"', webpage)]
65 self._sort_formats(formats)
7aca14a1 66
3501423d
JMF
67 return {
68 'id': video_id,
4828703f 69 'title': title,
7aca14a1 70 'uploader': uploader,
3501423d 71 'upload_date': upload_date,
4828703f 72 'formats': formats,
3501423d 73 }