Plugin cleanup and tweaks
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import re
|
||||
|
||||
from .common import InfoExtractor
|
||||
@@ -79,13 +77,13 @@ class GoogleDriveIE(InfoExtractor):
|
||||
_caption_formats_ext = []
|
||||
_captions_xml = None
|
||||
|
||||
@staticmethod
|
||||
def _extract_url(webpage):
|
||||
@classmethod
|
||||
def _extract_embed_urls(cls, url, webpage):
|
||||
mobj = re.search(
|
||||
r'<iframe[^>]+src="https?://(?:video\.google\.com/get_player\?.*?docid=|(?:docs|drive)\.google\.com/file/d/)(?P<id>[a-zA-Z0-9_-]{28,})',
|
||||
webpage)
|
||||
if mobj:
|
||||
return 'https://drive.google.com/file/d/%s' % mobj.group('id')
|
||||
yield 'https://drive.google.com/file/d/%s' % mobj.group('id')
|
||||
|
||||
def _download_subtitles_xml(self, video_id, subtitles_id, hl):
|
||||
if self._captions_xml:
|
||||
@@ -255,8 +253,6 @@ class GoogleDriveIE(InfoExtractor):
|
||||
if not formats and reason:
|
||||
self.raise_no_formats(reason, expected=True)
|
||||
|
||||
self._sort_formats(formats)
|
||||
|
||||
hl = get_value('hl')
|
||||
subtitles_id = None
|
||||
ttsurl = get_value('ttsurl')
|
||||
@@ -266,7 +262,7 @@ class GoogleDriveIE(InfoExtractor):
|
||||
subtitles_id = ttsurl.encode('utf-8').decode(
|
||||
'unicode_escape').split('=')[-1]
|
||||
|
||||
self._downloader.cookiejar.clear(domain='.google.com', path='/', name='NID')
|
||||
self.cookiejar.clear(domain='.google.com', path='/', name='NID')
|
||||
|
||||
return {
|
||||
'id': video_id,
|
||||
@@ -278,3 +274,59 @@ class GoogleDriveIE(InfoExtractor):
|
||||
'automatic_captions': self.extract_automatic_captions(
|
||||
video_id, subtitles_id, hl),
|
||||
}
|
||||
|
||||
|
||||
class GoogleDriveFolderIE(InfoExtractor):
|
||||
IE_NAME = 'GoogleDrive:Folder'
|
||||
_VALID_URL = r'https?://(?:docs|drive)\.google\.com/drive/folders/(?P<id>[\w-]{28,})'
|
||||
_TESTS = [{
|
||||
'url': 'https://drive.google.com/drive/folders/1dQ4sx0-__Nvg65rxTSgQrl7VyW_FZ9QI',
|
||||
'info_dict': {
|
||||
'id': '1dQ4sx0-__Nvg65rxTSgQrl7VyW_FZ9QI',
|
||||
'title': 'Forrest'
|
||||
},
|
||||
'playlist_count': 3,
|
||||
}]
|
||||
_BOUNDARY = '=====vc17a3rwnndj====='
|
||||
_REQUEST = "/drive/v2beta/files?openDrive=true&reason=102&syncType=0&errorRecovery=false&q=trashed%20%3D%20false%20and%20'{folder_id}'%20in%20parents&fields=kind%2CnextPageToken%2Citems(kind%2CmodifiedDate%2CmodifiedByMeDate%2ClastViewedByMeDate%2CfileSize%2Cowners(kind%2CpermissionId%2Cid)%2ClastModifyingUser(kind%2CpermissionId%2Cid)%2ChasThumbnail%2CthumbnailVersion%2Ctitle%2Cid%2CresourceKey%2Cshared%2CsharedWithMeDate%2CuserPermission(role)%2CexplicitlyTrashed%2CmimeType%2CquotaBytesUsed%2Ccopyable%2CfileExtension%2CsharingUser(kind%2CpermissionId%2Cid)%2Cspaces%2Cversion%2CteamDriveId%2ChasAugmentedPermissions%2CcreatedDate%2CtrashingUser(kind%2CpermissionId%2Cid)%2CtrashedDate%2Cparents(id)%2CshortcutDetails(targetId%2CtargetMimeType%2CtargetLookupStatus)%2Ccapabilities(canCopy%2CcanDownload%2CcanEdit%2CcanAddChildren%2CcanDelete%2CcanRemoveChildren%2CcanShare%2CcanTrash%2CcanRename%2CcanReadTeamDrive%2CcanMoveTeamDriveItem)%2Clabels(starred%2Ctrashed%2Crestricted%2Cviewed))%2CincompleteSearch&appDataFilter=NO_APP_DATA&spaces=drive&pageToken={page_token}&maxResults=50&supportsTeamDrives=true&includeItemsFromAllDrives=true&corpora=default&orderBy=folder%2Ctitle_natural%20asc&retryCount=0&key={key} HTTP/1.1"
|
||||
_DATA = f'''--{_BOUNDARY}
|
||||
content-type: application/http
|
||||
content-transfer-encoding: binary
|
||||
|
||||
GET %s
|
||||
|
||||
--{_BOUNDARY}
|
||||
'''
|
||||
|
||||
def _call_api(self, folder_id, key, data, **kwargs):
|
||||
response = self._download_webpage(
|
||||
'https://clients6.google.com/batch/drive/v2beta',
|
||||
folder_id, data=data.encode('utf-8'),
|
||||
headers={
|
||||
'Content-Type': 'text/plain;charset=UTF-8;',
|
||||
'Origin': 'https://drive.google.com',
|
||||
}, query={
|
||||
'$ct': f'multipart/mixed; boundary="{self._BOUNDARY}"',
|
||||
'key': key
|
||||
}, **kwargs)
|
||||
return self._search_json('', response, 'api response', folder_id, **kwargs) or {}
|
||||
|
||||
def _get_folder_items(self, folder_id, key):
|
||||
page_token = ''
|
||||
while page_token is not None:
|
||||
request = self._REQUEST.format(folder_id=folder_id, page_token=page_token, key=key)
|
||||
page = self._call_api(folder_id, key, self._DATA % request)
|
||||
yield from page['items']
|
||||
page_token = page.get('nextPageToken')
|
||||
|
||||
def _real_extract(self, url):
|
||||
folder_id = self._match_id(url)
|
||||
|
||||
webpage = self._download_webpage(url, folder_id)
|
||||
key = self._search_regex(r'"(\w{39})"', webpage, 'key')
|
||||
|
||||
folder_info = self._call_api(folder_id, key, self._DATA % f'/drive/v2beta/files/{folder_id} HTTP/1.1', fatal=False)
|
||||
|
||||
return self.playlist_from_matches(
|
||||
self._get_folder_items(folder_id, key), folder_id, folder_info.get('title'),
|
||||
ie=GoogleDriveIE, getter=lambda item: f'https://drive.google.com/file/d/{item["id"]}')
|
||||
|
Reference in New Issue
Block a user