2015-06-29 07:53:21 +01:00
|
|
|
import re
|
2025-11-04 13:26:21 +13:00
|
|
|
import urllib.parse
|
2015-06-29 07:53:21 +01:00
|
|
|
|
2015-06-24 01:13:23 +01:00
|
|
|
from .common import InfoExtractor
|
2024-08-17 23:49:00 +12:00
|
|
|
from ..networking.exceptions import HTTPError
|
2015-07-18 23:31:14 +01:00
|
|
|
from ..utils import (
|
|
|
|
|
ExtractorError,
|
2023-02-28 23:09:20 +05:30
|
|
|
determine_ext,
|
2023-07-05 09:17:13 +07:00
|
|
|
extract_attributes,
|
2025-10-28 16:17:16 +01:00
|
|
|
filter_dict,
|
2021-02-04 13:26:01 +05:30
|
|
|
get_element_by_class,
|
2023-07-05 09:17:13 +07:00
|
|
|
get_element_html_by_id,
|
2015-12-21 03:05:34 +01:00
|
|
|
int_or_none,
|
2025-11-04 20:39:35 +13:00
|
|
|
js_to_json,
|
2025-10-24 22:54:08 +02:00
|
|
|
mimetype2ext,
|
|
|
|
|
parse_duration,
|
|
|
|
|
str_or_none,
|
2017-08-22 11:48:59 -05:00
|
|
|
update_url_query,
|
2025-10-24 22:54:08 +02:00
|
|
|
url_or_none,
|
2015-07-18 23:31:14 +01:00
|
|
|
)
|
2025-10-24 22:54:08 +02:00
|
|
|
from ..utils.traversal import traverse_obj, value
|
2015-06-24 01:13:23 +01:00
|
|
|
|
2015-12-21 03:05:34 +01:00
|
|
|
|
|
|
|
|
class GoogleDriveIE(InfoExtractor):
|
2017-08-28 00:50:41 +07:00
|
|
|
_VALID_URL = r'''(?x)
|
|
|
|
|
https?://
|
|
|
|
|
(?:
|
2024-01-19 06:24:34 +07:00
|
|
|
(?:docs|drive|drive\.usercontent)\.google\.com/
|
2017-08-28 00:50:41 +07:00
|
|
|
(?:
|
2024-01-19 06:24:34 +07:00
|
|
|
(?:uc|open|download)\?.*?id=|
|
2017-08-28 00:50:41 +07:00
|
|
|
file/d/
|
|
|
|
|
)|
|
|
|
|
|
video\.google\.com/get_player\?.*?docid=
|
|
|
|
|
)
|
|
|
|
|
(?P<id>[a-zA-Z0-9_-]{28,})
|
|
|
|
|
'''
|
2016-03-12 00:36:39 +06:00
|
|
|
_TESTS = [{
|
2015-12-21 03:05:34 +01:00
|
|
|
'url': 'https://drive.google.com/file/d/0ByeS4oOUV-49Zzh4R1J6R09zazQ/edit?pli=1',
|
2017-08-28 00:39:22 +07:00
|
|
|
'md5': '5c602afbbf2c1db91831f5d82f678554',
|
2015-06-29 07:53:21 +01:00
|
|
|
'info_dict': {
|
2015-12-21 03:05:34 +01:00
|
|
|
'id': '0ByeS4oOUV-49Zzh4R1J6R09zazQ',
|
2015-06-29 07:53:21 +01:00
|
|
|
'ext': 'mp4',
|
2015-12-21 03:05:34 +01:00
|
|
|
'title': 'Big Buck Bunny.mp4',
|
2025-10-24 22:54:08 +02:00
|
|
|
'duration': 45.069,
|
|
|
|
|
'thumbnail': r're:https://lh3\.googleusercontent\.com/drive-storage/',
|
2024-06-12 01:09:58 +02:00
|
|
|
},
|
2024-05-13 01:05:47 +02:00
|
|
|
}, {
|
|
|
|
|
'url': 'https://drive.google.com/uc?id=1IP0o8dHcQrIHGgVyp0Ofvx2cGfLzyO1x',
|
|
|
|
|
'md5': '322db8d63dd19788c04050a4bba67073',
|
|
|
|
|
'info_dict': {
|
|
|
|
|
'id': '1IP0o8dHcQrIHGgVyp0Ofvx2cGfLzyO1x',
|
|
|
|
|
'ext': 'mp3',
|
|
|
|
|
'title': 'My Buddy - Henry Burr - Gus Kahn - Walter Donaldson.mp3',
|
2025-10-24 22:54:08 +02:00
|
|
|
'duration': 184.68,
|
|
|
|
|
},
|
|
|
|
|
}, {
|
|
|
|
|
# Has subtitle track
|
|
|
|
|
'url': 'https://drive.google.com/file/d/1RAGWRgzn85TXCaCk4gxnwF6TGUaZatzE/view',
|
|
|
|
|
'md5': '05488c528da6ef737ec8c962bfa9724e',
|
|
|
|
|
'info_dict': {
|
|
|
|
|
'id': '1RAGWRgzn85TXCaCk4gxnwF6TGUaZatzE',
|
|
|
|
|
'ext': 'mp4',
|
|
|
|
|
'title': 'test.mp4',
|
|
|
|
|
'duration': 9.999,
|
|
|
|
|
'thumbnail': r're:https://lh3\.googleusercontent\.com/drive-storage/',
|
2024-05-13 01:05:47 +02:00
|
|
|
},
|
2025-10-28 16:17:16 +01:00
|
|
|
}, {
|
|
|
|
|
# Has subtitle track with kind 'asr'
|
|
|
|
|
'url': 'https://drive.google.com/file/d/1Prvv9-mtDDfN_gkJgtt1OFvIULK8c3Ev/view',
|
|
|
|
|
'md5': 'ccae12d07f18b5988900b2c8b92801fc',
|
|
|
|
|
'info_dict': {
|
|
|
|
|
'id': '1Prvv9-mtDDfN_gkJgtt1OFvIULK8c3Ev',
|
|
|
|
|
'ext': 'mp4',
|
|
|
|
|
'title': 'LEE NA GYUNG-3410-VOICE_MESSAGE.mp4',
|
|
|
|
|
'duration': 8.766,
|
|
|
|
|
'thumbnail': r're:https://lh3\.googleusercontent\.com/drive-storage/',
|
2024-05-13 01:05:47 +02:00
|
|
|
},
|
2024-09-29 00:24:50 +12:00
|
|
|
}, {
|
|
|
|
|
# shortcut url
|
|
|
|
|
'url': 'https://drive.google.com/file/d/1_n3-8ZwEUV4OniMsLAJ_C1JEjuT2u5Pk/view?usp=drivesdk',
|
|
|
|
|
'md5': '43d34f7be1acc0262f337a039d1ad12d',
|
|
|
|
|
'info_dict': {
|
|
|
|
|
'id': '1J1RCw2jcgUngrZRdpza-IHXYkardZ-4l',
|
|
|
|
|
'ext': 'webm',
|
|
|
|
|
'title': 'Forrest walk with Best Mind Refresh Music Mithran [tEvJKrE4cS0].webm',
|
|
|
|
|
'duration': 512,
|
|
|
|
|
'thumbnail': 'https://drive.google.com/thumbnail?id=1J1RCw2jcgUngrZRdpza-IHXYkardZ-4l',
|
|
|
|
|
},
|
2017-08-28 00:39:22 +07:00
|
|
|
}, {
|
|
|
|
|
# video can't be watched anonymously due to view count limit reached,
|
2019-03-09 19:14:41 +07:00
|
|
|
# but can be downloaded (see https://github.com/ytdl-org/youtube-dl/issues/14046)
|
2017-08-28 00:39:22 +07:00
|
|
|
'url': 'https://drive.google.com/file/d/0B-vUyvmDLdWDcEt4WjBqcmI2XzQ/view',
|
2020-11-21 20:20:42 +05:30
|
|
|
'only_matching': True,
|
2016-03-12 00:36:39 +06:00
|
|
|
}, {
|
|
|
|
|
# video id is longer than 28 characters
|
|
|
|
|
'url': 'https://drive.google.com/file/d/1ENcQ_jeCuj7y19s66_Ou9dRP4GKGsodiDQ/edit',
|
2017-08-28 00:50:41 +07:00
|
|
|
'only_matching': True,
|
|
|
|
|
}, {
|
|
|
|
|
'url': 'https://drive.google.com/open?id=0B2fjwgkl1A_CX083Tkowdmt6d28',
|
|
|
|
|
'only_matching': True,
|
|
|
|
|
}, {
|
|
|
|
|
'url': 'https://drive.google.com/uc?id=0B2fjwgkl1A_CX083Tkowdmt6d28',
|
|
|
|
|
'only_matching': True,
|
2024-01-19 06:24:34 +07:00
|
|
|
}, {
|
|
|
|
|
'url': 'https://drive.usercontent.google.com/download?id=0ByeS4oOUV-49Zzh4R1J6R09zazQ',
|
|
|
|
|
'only_matching': True,
|
2016-03-12 00:36:39 +06:00
|
|
|
}]
|
2015-06-29 07:53:21 +01:00
|
|
|
|
2022-08-01 06:53:25 +05:30
|
|
|
@classmethod
|
|
|
|
|
def _extract_embed_urls(cls, url, webpage):
|
2015-06-29 07:53:21 +01:00
|
|
|
mobj = re.search(
|
2016-03-12 00:36:39 +06:00
|
|
|
r'<iframe[^>]+src="https?://(?:video\.google\.com/get_player\?.*?docid=|(?:docs|drive)\.google\.com/file/d/)(?P<id>[a-zA-Z0-9_-]{28,})',
|
2015-06-29 07:53:21 +01:00
|
|
|
webpage)
|
|
|
|
|
if mobj:
|
2024-06-12 01:09:58 +02:00
|
|
|
yield 'https://drive.google.com/file/d/{}'.format(mobj.group('id'))
|
2015-06-29 07:53:21 +01:00
|
|
|
|
2025-10-24 22:54:08 +02:00
|
|
|
@staticmethod
|
2025-10-28 16:17:16 +01:00
|
|
|
def _construct_subtitle_url(base_url, video_id, language, fmt, kind):
|
2025-10-24 22:54:08 +02:00
|
|
|
return update_url_query(
|
2025-10-28 16:17:16 +01:00
|
|
|
base_url, filter_dict({
|
2025-10-24 22:54:08 +02:00
|
|
|
'hl': 'en-US',
|
2017-08-22 11:48:59 -05:00
|
|
|
'v': video_id,
|
2025-10-24 22:54:08 +02:00
|
|
|
'type': 'track',
|
|
|
|
|
'lang': language,
|
|
|
|
|
'fmt': fmt,
|
2025-10-28 16:17:16 +01:00
|
|
|
'kind': kind,
|
|
|
|
|
}))
|
2017-08-22 11:48:59 -05:00
|
|
|
|
2025-10-24 22:54:08 +02:00
|
|
|
def _get_subtitles(self, video_id, video_info):
|
|
|
|
|
subtitles = {}
|
|
|
|
|
timed_text_base_url = traverse_obj(video_info, ('timedTextDetails', 'timedTextBaseUrl', {url_or_none}))
|
|
|
|
|
if not timed_text_base_url:
|
|
|
|
|
return subtitles
|
|
|
|
|
subtitle_data = self._download_xml(
|
|
|
|
|
timed_text_base_url, video_id, 'Downloading subtitles XML', fatal=False, query={
|
|
|
|
|
'hl': 'en-US',
|
|
|
|
|
'type': 'list',
|
|
|
|
|
'tlangs': 1,
|
|
|
|
|
'v': video_id,
|
|
|
|
|
'vssids': 1,
|
|
|
|
|
})
|
|
|
|
|
subtitle_formats = traverse_obj(subtitle_data, (lambda _, v: v.tag == 'format', {lambda x: x.get('fmt_code')}, {str}))
|
|
|
|
|
for track in traverse_obj(subtitle_data, (lambda _, v: v.tag == 'track' and v.get('lang_code'))):
|
|
|
|
|
language = track.get('lang_code')
|
|
|
|
|
subtitles.setdefault(language, []).extend([{
|
2025-10-28 16:17:16 +01:00
|
|
|
'url': self._construct_subtitle_url(
|
|
|
|
|
timed_text_base_url, video_id, language, sub_fmt, track.get('kind')),
|
2025-10-24 22:54:08 +02:00
|
|
|
'name': track.get('lang_original'),
|
|
|
|
|
'ext': sub_fmt,
|
|
|
|
|
} for sub_fmt in subtitle_formats])
|
|
|
|
|
return subtitles
|
2017-08-22 11:48:59 -05:00
|
|
|
|
2015-06-29 07:53:21 +01:00
|
|
|
def _real_extract(self, url):
|
|
|
|
|
video_id = self._match_id(url)
|
2024-10-01 23:51:00 +13:00
|
|
|
try:
|
|
|
|
|
_, webpage_urlh = self._download_webpage_handle(url, video_id)
|
|
|
|
|
except ExtractorError as e:
|
|
|
|
|
if isinstance(e.cause, HTTPError):
|
|
|
|
|
if e.cause.status in (401, 403):
|
|
|
|
|
self.raise_login_required('Access Denied')
|
|
|
|
|
raise
|
2024-07-28 03:36:55 +12:00
|
|
|
if webpage_urlh.url != url:
|
2024-10-01 23:51:00 +13:00
|
|
|
url = webpage_urlh.url
|
|
|
|
|
video_id = self._match_id(url)
|
2024-07-28 03:36:55 +12:00
|
|
|
|
2025-10-24 22:54:08 +02:00
|
|
|
video_info = self._download_json(
|
|
|
|
|
f'https://content-workspacevideo-pa.googleapis.com/v1/drive/media/{video_id}/playback',
|
|
|
|
|
video_id, 'Downloading video webpage', query={'key': 'AIzaSyDVQw45DwoYh632gvsP5vPDqEKvb-Ywnb8'},
|
|
|
|
|
headers={'Referer': 'https://drive.google.com/'})
|
2017-08-28 00:39:22 +07:00
|
|
|
|
|
|
|
|
formats = []
|
2025-10-24 22:54:08 +02:00
|
|
|
for fmt in traverse_obj(video_info, (
|
|
|
|
|
'mediaStreamingData', 'formatStreamingData', ('adaptiveTranscodes', 'progressiveTranscodes'),
|
|
|
|
|
lambda _, v: url_or_none(v['url']))):
|
|
|
|
|
formats.append({
|
|
|
|
|
**traverse_obj(fmt, {
|
|
|
|
|
'url': 'url',
|
|
|
|
|
'format_id': ('itag', {int}, {str_or_none}),
|
|
|
|
|
}),
|
|
|
|
|
**traverse_obj(fmt, ('transcodeMetadata', {
|
|
|
|
|
'ext': ('mimeType', {mimetype2ext}),
|
|
|
|
|
'width': ('width', {int_or_none}),
|
|
|
|
|
'height': ('height', {int_or_none}),
|
|
|
|
|
'fps': ('videoFps', {int_or_none}),
|
|
|
|
|
'filesize': ('contentLength', {int_or_none}),
|
|
|
|
|
'vcodec': ((('videoCodecString', {str}), {value('none')}), any),
|
|
|
|
|
'acodec': ((('audioCodecString', {str}), {value('none')}), any),
|
|
|
|
|
})),
|
|
|
|
|
'downloader_options': {
|
|
|
|
|
'http_chunk_size': 10 << 20,
|
|
|
|
|
},
|
|
|
|
|
})
|
2015-06-24 01:13:23 +01:00
|
|
|
|
2025-10-24 22:54:08 +02:00
|
|
|
title = traverse_obj(video_info, ('mediaMetadata', 'title', {str}))
|
2017-06-20 22:58:33 +07:00
|
|
|
|
2017-08-28 00:39:22 +07:00
|
|
|
source_url = update_url_query(
|
2024-01-19 06:24:34 +07:00
|
|
|
'https://drive.usercontent.google.com/download', {
|
2017-08-28 00:39:22 +07:00
|
|
|
'id': video_id,
|
|
|
|
|
'export': 'download',
|
2024-01-19 06:24:34 +07:00
|
|
|
'confirm': 't',
|
2017-08-28 00:39:22 +07:00
|
|
|
})
|
2020-09-13 20:43:50 +07:00
|
|
|
|
2023-07-05 09:17:13 +07:00
|
|
|
def request_source_file(source_url, kind, data=None):
|
2020-09-13 20:43:50 +07:00
|
|
|
return self._request_webpage(
|
2024-06-12 01:09:58 +02:00
|
|
|
source_url, video_id, note=f'Requesting {kind} file',
|
|
|
|
|
errnote=f'Unable to request {kind} file', fatal=False, data=data)
|
2020-09-13 20:43:50 +07:00
|
|
|
urlh = request_source_file(source_url, 'source')
|
2017-08-28 00:39:22 +07:00
|
|
|
if urlh:
|
2020-09-13 20:43:50 +07:00
|
|
|
def add_source_format(urlh):
|
2023-02-28 23:09:20 +05:30
|
|
|
nonlocal title
|
|
|
|
|
if not title:
|
|
|
|
|
title = self._search_regex(
|
|
|
|
|
r'\bfilename="([^"]+)"', urlh.headers.get('Content-Disposition'),
|
|
|
|
|
'title', default=None)
|
2017-08-28 00:39:22 +07:00
|
|
|
formats.append({
|
2020-09-13 20:43:50 +07:00
|
|
|
# Use redirect URLs as download URLs in order to calculate
|
|
|
|
|
# correct cookies in _calc_cookies.
|
|
|
|
|
# Using original URLs may result in redirect loop due to
|
|
|
|
|
# google.com's cookies mistakenly used for googleusercontent.com
|
|
|
|
|
# redirect URLs (see #23919).
|
2023-07-09 13:23:02 +05:30
|
|
|
'url': urlh.url,
|
2017-08-28 00:39:22 +07:00
|
|
|
'ext': determine_ext(title, 'mp4').lower(),
|
|
|
|
|
'format_id': 'source',
|
|
|
|
|
'quality': 1,
|
2017-06-20 22:58:33 +07:00
|
|
|
})
|
2017-08-28 00:39:22 +07:00
|
|
|
if urlh.headers.get('Content-Disposition'):
|
2020-09-13 20:43:50 +07:00
|
|
|
add_source_format(urlh)
|
2017-08-28 00:39:22 +07:00
|
|
|
else:
|
|
|
|
|
confirmation_webpage = self._webpage_read_content(
|
|
|
|
|
urlh, url, video_id, note='Downloading confirmation page',
|
|
|
|
|
errnote='Unable to confirm download', fatal=False)
|
|
|
|
|
if confirmation_webpage:
|
2023-07-05 09:17:13 +07:00
|
|
|
confirmed_source_url = extract_attributes(
|
|
|
|
|
get_element_html_by_id('download-form', confirmation_webpage) or '').get('action')
|
|
|
|
|
if confirmed_source_url:
|
|
|
|
|
urlh = request_source_file(confirmed_source_url, 'confirmed source', data=b'')
|
2020-09-13 20:43:50 +07:00
|
|
|
if urlh and urlh.headers.get('Content-Disposition'):
|
|
|
|
|
add_source_format(urlh)
|
2021-02-04 13:26:01 +05:30
|
|
|
else:
|
|
|
|
|
self.report_warning(
|
|
|
|
|
get_element_by_class('uc-error-subcaption', confirmation_webpage)
|
|
|
|
|
or get_element_by_class('uc-error-caption', confirmation_webpage)
|
|
|
|
|
or 'unable to extract confirmation code')
|
2017-08-28 00:39:22 +07:00
|
|
|
|
2015-06-24 01:13:23 +01:00
|
|
|
return {
|
|
|
|
|
'id': video_id,
|
|
|
|
|
'title': title,
|
2025-10-24 22:54:08 +02:00
|
|
|
**traverse_obj(video_info, {
|
|
|
|
|
'duration': ('mediaMetadata', 'duration', {parse_duration}),
|
|
|
|
|
'thumbnails': ('thumbnails', lambda _, v: url_or_none(v['url']), {
|
|
|
|
|
'url': 'url',
|
|
|
|
|
'ext': ('mimeType', {mimetype2ext}),
|
|
|
|
|
'width': ('width', {int}),
|
|
|
|
|
'height': ('height', {int}),
|
|
|
|
|
}),
|
|
|
|
|
}),
|
2015-12-21 03:05:34 +01:00
|
|
|
'formats': formats,
|
2025-10-24 22:54:08 +02:00
|
|
|
'subtitles': self.extract_subtitles(video_id, video_info),
|
2015-06-24 01:13:23 +01:00
|
|
|
}
|
2022-06-14 09:33:29 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class GoogleDriveFolderIE(InfoExtractor):
|
|
|
|
|
IE_NAME = 'GoogleDrive:Folder'
|
2024-09-30 06:35:33 +13:00
|
|
|
_VALID_URL = r'https?://(?:docs|drive)\.google\.com/drive/(?:folders/(?P<id>[\w-]{19,})|my-drive)'
|
2022-06-14 09:33:29 -04:00
|
|
|
_TESTS = [{
|
|
|
|
|
'url': 'https://drive.google.com/drive/folders/1dQ4sx0-__Nvg65rxTSgQrl7VyW_FZ9QI',
|
|
|
|
|
'info_dict': {
|
|
|
|
|
'id': '1dQ4sx0-__Nvg65rxTSgQrl7VyW_FZ9QI',
|
2024-06-12 01:09:58 +02:00
|
|
|
'title': 'Forrest',
|
2022-06-14 09:33:29 -04:00
|
|
|
},
|
|
|
|
|
'playlist_count': 3,
|
2024-07-19 16:31:08 +12:00
|
|
|
}, {
|
2024-08-17 23:49:00 +12:00
|
|
|
'note': 'Contains various formats and a subfolder, folder name was formerly mismatched.'
|
|
|
|
|
'also contains loop shortcut, shortcut to non-downloadable files, etc.',
|
2024-09-29 00:24:50 +12:00
|
|
|
'url': 'https://docs.google.com/drive/folders/1jjrhqi94d8TSHSVMSdBjD49MOiHYpHfF',
|
2024-07-19 16:31:08 +12:00
|
|
|
'info_dict': {
|
2024-08-17 23:49:00 +12:00
|
|
|
'id': '1jjrhqi94d8TSHSVMSdBjD49MOiHYpHfF',
|
|
|
|
|
'title': '], sideChannel: {}});',
|
2024-07-19 16:31:08 +12:00
|
|
|
},
|
2024-08-17 23:49:00 +12:00
|
|
|
'playlist_count': 8,
|
2022-06-14 09:33:29 -04:00
|
|
|
}]
|
|
|
|
|
|
2024-08-17 20:21:02 +12:00
|
|
|
def _extract_json_meta(self, webpage, video_id, dsval=None, hashval=None, name=None, **kwargs):
|
2024-07-19 16:31:08 +12:00
|
|
|
"""
|
2024-08-17 20:21:02 +12:00
|
|
|
Uses regex to search for json metadata with 'ds' value(0-5) or 'hash' value(1-6)
|
|
|
|
|
from the webpage.
|
2025-11-04 20:39:35 +13:00
|
|
|
logged out folder info:ds0hash1; items (old):ds4hash6
|
|
|
|
|
logged in folder info:ds0hash1; items (old):ds5hash6
|
|
|
|
|
my-drive folder info:ds0hash1/ds0hash4; items (old):ds5hash6
|
2024-07-19 16:31:08 +12:00
|
|
|
For example, if the webpage contains the line below, the empty data array
|
2024-08-17 20:21:02 +12:00
|
|
|
can be got by passing dsval=3 or hashval=2 to this method.
|
2024-07-19 16:31:08 +12:00
|
|
|
AF_initDataCallback({key: 'ds:3', hash: '2', data:[], sideChannel: {}});
|
|
|
|
|
"""
|
2024-08-17 20:21:02 +12:00
|
|
|
_ARRAY_RE = r'\[(?s:.+)\]'
|
|
|
|
|
_META_END_RE = r', sideChannel: \{\}\}\);' # greedy match to deal with the 2nd test case
|
2024-09-30 06:35:33 +13:00
|
|
|
if dsval is not None:
|
2024-08-17 20:21:02 +12:00
|
|
|
if not name:
|
|
|
|
|
name = f'webpage JSON metadata ds:{dsval}'
|
|
|
|
|
return self._search_json(
|
|
|
|
|
rf'''key\s*?:\s*?(['"])ds:\s*?{dsval}\1,[^\[]*?data:''', webpage, name, video_id,
|
|
|
|
|
end_pattern=_META_END_RE, contains_pattern=_ARRAY_RE, **kwargs)
|
2024-09-30 06:35:33 +13:00
|
|
|
elif hashval is not None:
|
2024-08-17 20:21:02 +12:00
|
|
|
if not name:
|
|
|
|
|
name = f'webpage JSON metadata hash:{hashval}'
|
|
|
|
|
return self._search_json(
|
|
|
|
|
rf'''hash\s*?:\s*?(['"]){hashval}\1,[^\[]*?data:''', webpage, name, video_id,
|
|
|
|
|
end_pattern=_META_END_RE, contains_pattern=_ARRAY_RE, **kwargs)
|
2022-06-14 09:33:29 -04:00
|
|
|
|
|
|
|
|
def _real_extract(self, url):
|
2024-07-22 16:51:04 +12:00
|
|
|
def item_url_getter(item, video_id):
|
2024-08-18 03:08:45 +12:00
|
|
|
if not isinstance(item, list):
|
|
|
|
|
return None
|
2024-09-30 06:35:33 +13:00
|
|
|
available_IEs = (GoogleDriveFolderIE, GoogleDriveIE) # subfolder or item
|
2024-08-17 20:21:02 +12:00
|
|
|
if 'application/vnd.google-apps.shortcut' in item: # extract real link
|
2024-07-28 03:18:17 +12:00
|
|
|
entry_url = traverse_obj(
|
2024-08-17 20:21:02 +12:00
|
|
|
item,
|
|
|
|
|
(..., ..., lambda _, v: any(ie.suitable(v) for ie in available_IEs), any))
|
2024-07-28 03:18:17 +12:00
|
|
|
else:
|
|
|
|
|
entry_url = traverse_obj(
|
2024-08-17 20:21:02 +12:00
|
|
|
item,
|
|
|
|
|
(lambda _, v: any(ie.suitable(v) for ie in available_IEs), any))
|
2024-07-28 03:18:17 +12:00
|
|
|
if not entry_url:
|
|
|
|
|
return None
|
2025-11-04 20:49:28 +13:00
|
|
|
return self.url_result(entry_url, video_id=video_id, video_title=traverse_obj(item, 2))
|
2022-06-14 09:33:29 -04:00
|
|
|
|
2024-08-18 03:08:45 +12:00
|
|
|
folder_id = self._match_id(url) or 'my-drive'
|
2024-07-19 16:31:08 +12:00
|
|
|
headers = self.geo_verification_headers()
|
2022-06-14 09:33:29 -04:00
|
|
|
|
2024-08-17 23:49:00 +12:00
|
|
|
try:
|
|
|
|
|
webpage, urlh = self._download_webpage_handle(url, folder_id, headers=headers)
|
|
|
|
|
except ExtractorError as e:
|
2024-08-18 00:01:03 +12:00
|
|
|
if isinstance(e.cause, HTTPError):
|
|
|
|
|
if e.cause.status == 404:
|
2024-10-01 23:51:00 +13:00
|
|
|
self.raise_no_formats(e.cause.msg, expected=True)
|
2024-08-18 00:01:03 +12:00
|
|
|
elif e.cause.status == 403:
|
2024-09-30 06:35:33 +13:00
|
|
|
# logged in with an account without access
|
|
|
|
|
self.raise_login_required('Access Denied')
|
2024-08-17 23:49:56 +12:00
|
|
|
raise
|
2024-08-17 23:49:00 +12:00
|
|
|
if urllib.parse.urlparse(urlh.url).netloc == 'accounts.google.com':
|
2024-09-30 06:35:33 +13:00
|
|
|
# not logged in when visiting a private folder
|
|
|
|
|
self.raise_login_required('Access Denied')
|
2024-08-17 23:49:00 +12:00
|
|
|
|
2024-09-30 06:35:33 +13:00
|
|
|
title = self._extract_json_meta(webpage, folder_id, dsval=0, name='folder info')[1][2]
|
2025-11-04 20:39:35 +13:00
|
|
|
items = (
|
|
|
|
|
self._extract_json_meta(webpage, folder_id, hashval=6, name='folder items', default=[None])[-1] or
|
|
|
|
|
self._parse_json(self._search_json(
|
|
|
|
|
r'''window\['_DRIVE_ivd'\]\s*=''', webpage, 'folder items', folder_id,
|
|
|
|
|
contains_pattern="'[^']+'", transform_source=js_to_json), folder_id)[0])
|
2024-07-24 23:16:44 +12:00
|
|
|
|
2025-11-04 20:39:35 +13:00
|
|
|
if not items: # empty folder, False or None
|
2024-07-22 17:28:45 +12:00
|
|
|
return self.playlist_result([], folder_id, title)
|
2022-06-14 09:33:29 -04:00
|
|
|
|
2024-07-24 23:16:44 +12:00
|
|
|
return self.playlist_result(
|
|
|
|
|
(entry for item in items if (entry := item_url_getter(item, folder_id))),
|
|
|
|
|
folder_id, title)
|