1 from __future__ import unicode_literals
5 from .common import InfoExtractor
13 class GoogleDriveIE(InfoExtractor):
14 _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,})'
16 'url': 'https://drive.google.com/file/d/0ByeS4oOUV-49Zzh4R1J6R09zazQ/edit?pli=1',
17 'md5': 'd109872761f7e7ecf353fa108c0dbe1e',
19 'id': '0ByeS4oOUV-49Zzh4R1J6R09zazQ',
21 'title': 'Big Buck Bunny.mp4',
25 # video id is longer than 28 characters
26 'url': 'https://drive.google.com/file/d/1ENcQ_jeCuj7y19s66_Ou9dRP4GKGsodiDQ/edit',
27 'only_matching': True,
49 def _extract_url(webpage):
51 r'<iframe[^>]+src="https?://(?:video\.google\.com/get_player\?.*?docid=|(?:docs|drive)\.google\.com/file/d/)(?P<id>[a-zA-Z0-9_-]{28,})',
54 return 'https://drive.google.com/file/d/%s' % mobj.group('id')
56 def _real_extract(self, url):
57 video_id = self._match_id(url)
58 webpage = self._download_webpage(
59 'http://docs.google.com/file/d/%s' % video_id, video_id)
61 reason = self._search_regex(r'"reason"\s*,\s*"([^"]+)', webpage, 'reason', default=None)
63 raise ExtractorError(reason)
65 title = self._search_regex(r'"title"\s*,\s*"([^"]+)', webpage, 'title')
66 duration = int_or_none(self._search_regex(
67 r'"length_seconds"\s*,\s*"([^"]+)', webpage, 'length seconds', default=None))
68 fmt_stream_map = self._search_regex(
69 r'"fmt_stream_map"\s*,\s*"([^"]+)', webpage, 'fmt stream map').split(',')
70 fmt_list = self._search_regex(r'"fmt_list"\s*,\s*"([^"]+)', webpage, 'fmt_list').split(',')
75 r'^(?P<format_id>\d+)/(?P<width>\d+)[xX](?P<height>\d+)', fmt)
77 resolutions[mobj.group('format_id')] = (
78 int(mobj.group('width')), int(mobj.group('height')))
81 for fmt_stream in fmt_stream_map:
82 fmt_stream_split = fmt_stream.split('|')
83 if len(fmt_stream_split) < 2:
85 format_id, format_url = fmt_stream_split[:2]
87 'url': lowercase_escape(format_url),
88 'format_id': format_id,
89 'ext': self._FORMATS_EXT[format_id],
91 resolution = resolutions.get(format_id)
94 'width': resolution[0],
95 'height': resolution[1],
98 self._sort_formats(formats)
103 'thumbnail': self._og_search_thumbnail(webpage, default=None),
104 'duration': duration,