]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/googleplus.py
debian/changelog: Start new release.
[youtubedl] / youtube_dl / extractor / googleplus.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import datetime
5 import re
6
7 from .common import InfoExtractor
8 from ..utils import (
9 ExtractorError,
10 )
11
12
13 class GooglePlusIE(InfoExtractor):
14 IE_DESC = 'Google Plus'
15 _VALID_URL = r'https://plus\.google\.com/(?:[^/]+/)*?posts/(?P<id>\w+)'
16 IE_NAME = 'plus.google'
17 _TEST = {
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': '嘆きの天使 降臨',
25 }
26 }
27
28 def _real_extract(self, url):
29 # Extract id from URL
30 mobj = re.match(self._VALID_URL, url)
31
32 video_id = mobj.group('id')
33
34 # Step 1, Retrieve post webpage to extract further information
35 webpage = self._download_webpage(url, video_id, 'Downloading entry webpage')
36
37 self.report_extraction(video_id)
38
39 # Extract update date
40 upload_date = self._html_search_regex(
41 r'''(?x)<a.+?class="o-U-s\s[^"]+"\s+style="display:\s*none"\s*>
42 ([0-9]{4}-[0-9]{2}-[0-9]{2})</a>''',
43 webpage, 'upload date', fatal=False, flags=re.VERBOSE)
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>',
51 webpage, 'uploader', fatal=False)
52
53 # Extract title
54 # Get the first line for title
55 video_title = self._og_search_description(webpage).splitlines()[0]
56
57 # Step 2, Simulate clicking the image box to launch video
58 DOMAIN = 'https://plus.google.com/'
59 video_page = self._search_regex(r'<a href="((?:%s)?photos/.*?)"' % re.escape(DOMAIN),
60 webpage, 'video page URL')
61 if not video_page.startswith(DOMAIN):
62 video_page = DOMAIN + video_page
63
64 webpage = self._download_webpage(video_page, video_id, 'Downloading video page')
65
66 # Extract video links all sizes
67 pattern = r'\d+,\d+,(\d+),"(http\://redirector\.googlevideo\.com.*?)"'
68 mobj = re.findall(pattern, webpage)
69 if len(mobj) == 0:
70 raise ExtractorError('Unable to extract video links')
71
72 # Sort in resolution
73 links = sorted(mobj)
74
75 # Choose the lowest of the sort, i.e. highest resolution
76 video_url = links[-1]
77 # Only get the url. The resolution part in the tuple has no use anymore
78 video_url = video_url[-1]
79 # Treat escaped \u0026 style hex
80 try:
81 video_url = video_url.decode("unicode_escape")
82 except AttributeError: # Python 3
83 video_url = bytes(video_url, 'ascii').decode('unicode-escape')
84
85 return {
86 'id': video_id,
87 'url': video_url,
88 'uploader': uploader,
89 'upload_date': upload_date,
90 'title': video_title,
91 'ext': 'flv',
92 }