add support for subfolders(recursive)

This commit is contained in:
grqx_wsl 2024-07-22 16:51:04 +12:00
parent a917af960c
commit 64d4e93516

View file

@ -298,13 +298,13 @@ class GoogleDriveFolderIE(InfoExtractor):
}, },
'playlist_count': 3, 'playlist_count': 3,
}, { }, {
# Contains various formats # Contains various formats and a subfolder
'url': 'https://drive.google.com/drive/folders/1CkqRsNlzZ0o3IL083j17s6sH5Q83DcGo', 'url': 'https://drive.google.com/drive/folders/1CkqRsNlzZ0o3IL083j17s6sH5Q83DcGo',
'info_dict': { 'info_dict': {
'id': '1CkqRsNlzZ0o3IL083j17s6sH5Q83DcGo', 'id': '1CkqRsNlzZ0o3IL083j17s6sH5Q83DcGo',
'title': r'], sideChannel: {}});', 'title': r'], sideChannel: {}});',
}, },
'playlist_count': 4, 'playlist_count': 5,
}] }]
_JSON_DS_RE = r'key\s*?:\s*?([\'"])ds:\s*?%d\1,[^}]*data:' _JSON_DS_RE = r'key\s*?:\s*?([\'"])ds:\s*?%d\1,[^}]*data:'
_JSON_HASH_RE = r'hash\s*?:\s*?([\'"])%d\1,[^}]*data:' _JSON_HASH_RE = r'hash\s*?:\s*?([\'"])%d\1,[^}]*data:'
@ -335,17 +335,24 @@ class GoogleDriveFolderIE(InfoExtractor):
contains_pattern=self._ARRAY_RE, **kwargs) contains_pattern=self._ARRAY_RE, **kwargs)
def _real_extract(self, url): def _real_extract(self, url):
def item_url_getter(item): def item_url_getter(item, video_id):
url_from_0 = f'https://drive.google.com/file/d/{item[0]}' available_IEs = [GoogleDriveFolderIE, GoogleDriveIE]
if GoogleDriveIE.suitable(url_from_0): for attr in item:
return url_from_0 if isinstance(attr, str):
else: for available_IE in available_IEs:
for attr in item: if available_IE.suitable(attr):
if isinstance(attr, str) and GoogleDriveIE.suitable(attr): return self.url_result(attr, available_IE, video_id, item[2])
return attr self.to_screen(f'Failed to find a suitable extractor for {item[2]}.')
self.write_debug('Failed to extract url!')
return None return None
def make_playlist(items, playlist_id):
entries = []
for item in items:
entry = item_url_getter(item, playlist_id)
if entry:
entries.append(entry)
return self.playlist_result(entries, playlist_id, title)
folder_id = self._match_id(url) folder_id = self._match_id(url)
headers = self.geo_verification_headers() headers = self.geo_verification_headers()
@ -361,5 +368,4 @@ class GoogleDriveFolderIE(InfoExtractor):
title = json_folder_info[1][2] title = json_folder_info[1][2]
items = json_items[-1] items = json_items[-1]
return self.playlist_from_matches((item for item in items), folder_id, title, return make_playlist(items, folder_id)
ie=GoogleDriveIE, getter=item_url_getter)