]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/googleplus.py
[vk] Add support for more URL formats (#3172)
[yt-dlp.git] / youtube_dl / extractor / googleplus.py
CommitLineData
0c56a3f7 1# coding: utf-8
3501423d 2from __future__ import unicode_literals
0c56a3f7 3
7aca14a1
PH
4import datetime
5import re
6
7from .common import InfoExtractor
8from ..utils import (
9 ExtractorError,
10)
11
12
13class GooglePlusIE(InfoExtractor):
3501423d
JMF
14 IE_DESC = 'Google Plus'
15 _VALID_URL = r'https://plus\.google\.com/(?:[^/]+/)*?posts/(?P<id>\w+)'
16 IE_NAME = 'plus.google'
0c56a3f7 17 _TEST = {
3501423d
JMF
18 'url': 'https://plus.google.com/u/0/108897254135232129896/posts/ZButuJc6CtH',
19 'info_dict': {
20 'id': 'ZButuJc6CtH',
21 'ext': 'flv',
22 'upload_date': '20120613',
23 'uploader': '井上ヨシマサ',
24 'title': '嘆きの天使 降臨',
0c56a3f7
PH
25 }
26 }
7aca14a1
PH
27
28 def _real_extract(self, url):
29 # Extract id from URL
30 mobj = re.match(self._VALID_URL, url)
7aca14a1 31
3501423d 32 video_id = mobj.group('id')
7aca14a1
PH
33
34 # Step 1, Retrieve post webpage to extract further information
3501423d 35 webpage = self._download_webpage(url, video_id, 'Downloading entry webpage')
7aca14a1
PH
36
37 self.report_extraction(video_id)
38
39 # Extract update date
fad84d50 40 upload_date = self._html_search_regex(
685a9cd2 41 r'''(?x)<a.+?class="o-U-s\s[^"]+"\s+style="display:\s*none"\s*>
e94b783c 42 ([0-9]{4}-[0-9]{2}-[0-9]{2})</a>''',
3501423d 43 webpage, 'upload date', fatal=False, flags=re.VERBOSE)
7aca14a1
PH
44 if upload_date:
45 # Convert timestring to a format suitable for filename
46 upload_date = datetime.datetime.strptime(upload_date, "%Y-%m-%d")
47 upload_date = upload_date.strftime('%Y%m%d')
48
49 # Extract uploader
50 uploader = self._html_search_regex(r'rel\="author".*?>(.*?)</a>',
3501423d 51 webpage, 'uploader', fatal=False)
7aca14a1
PH
52
53 # Extract title
54 # Get the first line for title
55 video_title = self._html_search_regex(r'<meta name\=\"Description\" content\=\"(.*?)[\n<"]',
3501423d 56 webpage, 'title', default='NA')
7aca14a1 57
d6628960 58 # Step 2, Simulate clicking the image box to launch video
7f3c4f4f
JS
59 DOMAIN = 'https://plus.google.com/'
60 video_page = self._search_regex(r'<a href="((?:%s)?photos/.*?)"' % re.escape(DOMAIN),
3501423d 61 webpage, 'video page URL')
d6628960
PH
62 if not video_page.startswith(DOMAIN):
63 video_page = DOMAIN + video_page
64
3501423d 65 webpage = self._download_webpage(video_page, video_id, 'Downloading video page')
7aca14a1 66
3501423d 67 # Extract video links all sizes
d6628960 68 pattern = r'\d+,\d+,(\d+),"(http\://redirector\.googlevideo\.com.*?)"'
7aca14a1
PH
69 mobj = re.findall(pattern, webpage)
70 if len(mobj) == 0:
3501423d 71 raise ExtractorError('Unable to extract video links')
7aca14a1
PH
72
73 # Sort in resolution
74 links = sorted(mobj)
75
76 # Choose the lowest of the sort, i.e. highest resolution
77 video_url = links[-1]
78 # Only get the url. The resolution part in the tuple has no use anymore
79 video_url = video_url[-1]
80 # Treat escaped \u0026 style hex
81 try:
82 video_url = video_url.decode("unicode_escape")
83 except AttributeError: # Python 3
84 video_url = bytes(video_url, 'ascii').decode('unicode-escape')
85
3501423d
JMF
86 return {
87 'id': video_id,
88 'url': video_url,
7aca14a1 89 'uploader': uploader,
3501423d
JMF
90 'upload_date': upload_date,
91 'title': video_title,
92 'ext': 'flv',
93 }