]>
Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/googleplus.py
   2 from __future__ 
import unicode_literals
 
   7 from .common 
import InfoExtractor
 
  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' 
  18         'url': 'https://plus.google.com/u/0/108897254135232129896/posts/ZButuJc6CtH', 
  22             'upload_date': '20120613', 
  28     def _real_extract(self
, url
): 
  30         mobj 
= re
.match(self
._VALID
_URL
, url
) 
  32         video_id 
= mobj
.group('id') 
  34         # Step 1, Retrieve post webpage to extract further information 
  35         webpage 
= self
._download
_webpage
(url
, video_id
, 'Downloading entry webpage') 
  37         self
.report_extraction(video_id
) 
  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
) 
  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') 
  50         uploader 
= self
._html
_search
_regex
(r
'rel\="author".*?>(.*?)</a>', 
  51             webpage
, 'uploader', fatal
=False) 
  54         # Get the first line for title 
  55         video_title 
= self
._html
_search
_regex
(r
'<meta name\=\"Description\" content\=\"(.*?)[\n<"]', 
  56             webpage
, 'title', default
='NA') 
  58         # Step 2, Simulate clicking the image box to launch video 
  59         DOMAIN 
= 'https://plus.google.com/' 
  60         video_page 
= self
._search
_regex
(r
'<a href="((?:%s)?photos/.*?)"' % re
.escape(DOMAIN
), 
  61             webpage
, 'video page URL') 
  62         if not video_page
.startswith(DOMAIN
): 
  63             video_page 
= DOMAIN 
+ video_page
 
  65         webpage 
= self
._download
_webpage
(video_page
, video_id
, 'Downloading video page') 
  67         # Extract video links all sizes 
  68         pattern 
= r
'\d+,\d+,(\d+),"(http\://redirector\.googlevideo\.com.*?)"' 
  69         mobj 
= re
.findall(pattern
, webpage
) 
  71             raise ExtractorError('Unable to extract video links') 
  76         # Choose the lowest of the sort, i.e. highest resolution 
  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 
  82             video_url 
= video_url
.decode("unicode_escape") 
  83         except AttributeError: # Python 3 
  84             video_url 
= bytes(video_url
, 'ascii').decode('unicode-escape') 
  90             'upload_date': upload_date
,