]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/googledrive.py
   1 from __future__ 
import unicode_literals
 
   5 from .common 
import InfoExtractor
 
  12 class GoogleDriveIE(InfoExtractor
): 
  13     _VALID_URL 
= r
'https?://(?:(?:docs|drive)\.google\.com/(?:uc\?.*?id=|file/d/)|video\.google\.com/get_player\?.*?docid=)(?P<id>[a-zA-Z0-9_-]{28,})' 
  15         'url': 'https://drive.google.com/file/d/0ByeS4oOUV-49Zzh4R1J6R09zazQ/edit?pli=1', 
  16         'md5': '881f7700aec4f538571fa1e0eed4a7b6', 
  18             'id': '0ByeS4oOUV-49Zzh4R1J6R09zazQ', 
  20             'title': 'Big Buck Bunny.mp4', 
  24         # video id is longer than 28 characters 
  25         'url': 'https://drive.google.com/file/d/1ENcQ_jeCuj7y19s66_Ou9dRP4GKGsodiDQ/edit', 
  26         'only_matching': True, 
  48     def _extract_url(webpage
): 
  50             r
'<iframe[^>]+src="https?://(?:video\.google\.com/get_player\?.*?docid=|(?:docs|drive)\.google\.com/file/d/)(?P<id>[a-zA-Z0-9_-]{28,})', 
  53             return 'https://drive.google.com/file/d/%s' % mobj
.group('id') 
  55     def _real_extract(self
, url
): 
  56         video_id 
= self
._match
_id
(url
) 
  57         webpage 
= self
._download
_webpage
( 
  58             'http://docs.google.com/file/d/%s' % video_id
, video_id
, encoding
='unicode_escape') 
  60         reason 
= self
._search
_regex
(r
'"reason"\s*,\s*"([^"]+)', webpage
, 'reason', default
=None) 
  62             raise ExtractorError(reason
) 
  64         title 
= self
._search
_regex
(r
'"title"\s*,\s*"([^"]+)', webpage
, 'title') 
  65         duration 
= int_or_none(self
._search
_regex
( 
  66             r
'"length_seconds"\s*,\s*"([^"]+)', webpage
, 'length seconds', default
=None)) 
  67         fmt_stream_map 
= self
._search
_regex
( 
  68             r
'"fmt_stream_map"\s*,\s*"([^"]+)', webpage
, 'fmt stream map').split(',') 
  69         fmt_list 
= self
._search
_regex
(r
'"fmt_list"\s*,\s*"([^"]+)', webpage
, 'fmt_list').split(',') 
  72         for fmt
, fmt_stream 
in zip(fmt_list
, fmt_stream_map
): 
  73             fmt_id
, fmt_url 
= fmt_stream
.split('|') 
  74             resolution 
= fmt
.split('/')[1] 
  75             width
, height 
= resolution
.split('x') 
  79                 'resolution': resolution
, 
  80                 'width': int_or_none(width
), 
  81                 'height': int_or_none(height
), 
  82                 'ext': self
._FORMATS
_EXT
[fmt_id
], 
  84         self
._sort
_formats
(formats
) 
  89             'thumbnail': self
._og
_search
_thumbnail
(webpage
, default
=None),