mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-26 09:11:25 +01:00
Compare commits
25 Commits
431e1f5117
...
167573e763
Author | SHA1 | Date | |
---|---|---|---|
|
167573e763 | ||
|
f2a4983df7 | ||
|
bacc31b05a | ||
|
1ef35f1c00 | ||
|
3068d9897d | ||
|
b3534df159 | ||
|
3582a238a0 | ||
|
23ea25196d | ||
|
83e0860835 | ||
|
8d827d2460 | ||
|
beb76094fa | ||
|
d133c2c7f7 | ||
|
4a76306868 | ||
|
b81a41d5ff | ||
|
28ed64d87a | ||
|
8623ada293 | ||
|
6e98d99dd5 | ||
|
99d9105f33 | ||
|
017997068b | ||
|
9962859595 | ||
|
cbe698b4b0 | ||
|
64d4e93516 | ||
|
a917af960c | ||
|
05403ea5ad | ||
|
d65753ce05 |
|
@ -205,6 +205,26 @@ class ArchiveOrgIE(InfoExtractor):
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
}, {
|
||||||
|
# The reviewbody is None for one of the reviews; just need to extract data without crashing
|
||||||
|
'url': 'https://archive.org/details/gd95-04-02.sbd.11622.sbeok.shnf/gd95-04-02d1t04.shn',
|
||||||
|
'info_dict': {
|
||||||
|
'id': 'gd95-04-02.sbd.11622.sbeok.shnf/gd95-04-02d1t04.shn',
|
||||||
|
'ext': 'mp3',
|
||||||
|
'title': 'Stuck Inside of Mobile with the Memphis Blues Again',
|
||||||
|
'creators': ['Grateful Dead'],
|
||||||
|
'duration': 338.31,
|
||||||
|
'track': 'Stuck Inside of Mobile with the Memphis Blues Again',
|
||||||
|
'description': 'md5:764348a470b986f1217ffd38d6ac7b72',
|
||||||
|
'display_id': 'gd95-04-02d1t04.shn',
|
||||||
|
'location': 'Pyramid Arena',
|
||||||
|
'uploader': 'jon@archive.org',
|
||||||
|
'album': '1995-04-02 - Pyramid Arena',
|
||||||
|
'upload_date': '20040519',
|
||||||
|
'track_number': 4,
|
||||||
|
'release_date': '19950402',
|
||||||
|
'timestamp': 1084927901,
|
||||||
|
},
|
||||||
}]
|
}]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -335,7 +355,7 @@ class ArchiveOrgIE(InfoExtractor):
|
||||||
info['comments'].append({
|
info['comments'].append({
|
||||||
'id': review.get('review_id'),
|
'id': review.get('review_id'),
|
||||||
'author': review.get('reviewer'),
|
'author': review.get('reviewer'),
|
||||||
'text': str_or_none(review.get('reviewtitle'), '') + '\n\n' + review.get('reviewbody'),
|
'text': join_nonempty('reviewtitle', 'reviewbody', from_dict=review, delim='\n\n'),
|
||||||
'timestamp': unified_timestamp(review.get('createdate')),
|
'timestamp': unified_timestamp(review.get('createdate')),
|
||||||
'parent': 'root'})
|
'parent': 'root'})
|
||||||
|
|
||||||
|
|
|
@ -563,13 +563,13 @@ class FacebookIE(InfoExtractor):
|
||||||
return extract_video_data(try_get(
|
return extract_video_data(try_get(
|
||||||
js_data, lambda x: x['jsmods']['instances'], list) or [])
|
js_data, lambda x: x['jsmods']['instances'], list) or [])
|
||||||
|
|
||||||
def extract_dash_manifest(video, formats):
|
def extract_dash_manifest(vid_data, formats, mpd_url=None):
|
||||||
dash_manifest = traverse_obj(
|
dash_manifest = traverse_obj(
|
||||||
video, 'dash_manifest', 'playlist', 'dash_manifest_xml_string', expected_type=str)
|
vid_data, 'dash_manifest', 'playlist', 'dash_manifest_xml_string', 'manifest_xml', expected_type=str)
|
||||||
if dash_manifest:
|
if dash_manifest:
|
||||||
formats.extend(self._parse_mpd_formats(
|
formats.extend(self._parse_mpd_formats(
|
||||||
compat_etree_fromstring(urllib.parse.unquote_plus(dash_manifest)),
|
compat_etree_fromstring(urllib.parse.unquote_plus(dash_manifest)),
|
||||||
mpd_url=url_or_none(video.get('dash_manifest_url'))))
|
mpd_url=url_or_none(video.get('dash_manifest_url')) or mpd_url))
|
||||||
|
|
||||||
def process_formats(info):
|
def process_formats(info):
|
||||||
# Downloads with browser's User-Agent are rate limited. Working around
|
# Downloads with browser's User-Agent are rate limited. Working around
|
||||||
|
@ -619,9 +619,12 @@ class FacebookIE(InfoExtractor):
|
||||||
video = video['creation_story']
|
video = video['creation_story']
|
||||||
video['owner'] = traverse_obj(video, ('short_form_video_context', 'video_owner'))
|
video['owner'] = traverse_obj(video, ('short_form_video_context', 'video_owner'))
|
||||||
video.update(reel_info)
|
video.update(reel_info)
|
||||||
fmt_data = traverse_obj(video, ('videoDeliveryLegacyFields', {dict})) or video
|
|
||||||
formats = []
|
formats = []
|
||||||
q = qualities(['sd', 'hd'])
|
q = qualities(['sd', 'hd'])
|
||||||
|
|
||||||
|
# Legacy formats extraction
|
||||||
|
fmt_data = traverse_obj(video, ('videoDeliveryLegacyFields', {dict})) or video
|
||||||
for key, format_id in (('playable_url', 'sd'), ('playable_url_quality_hd', 'hd'),
|
for key, format_id in (('playable_url', 'sd'), ('playable_url_quality_hd', 'hd'),
|
||||||
('playable_url_dash', ''), ('browser_native_hd_url', 'hd'),
|
('playable_url_dash', ''), ('browser_native_hd_url', 'hd'),
|
||||||
('browser_native_sd_url', 'sd')):
|
('browser_native_sd_url', 'sd')):
|
||||||
|
@ -629,7 +632,7 @@ class FacebookIE(InfoExtractor):
|
||||||
if not playable_url:
|
if not playable_url:
|
||||||
continue
|
continue
|
||||||
if determine_ext(playable_url) == 'mpd':
|
if determine_ext(playable_url) == 'mpd':
|
||||||
formats.extend(self._extract_mpd_formats(playable_url, video_id))
|
formats.extend(self._extract_mpd_formats(playable_url, video_id, fatal=False))
|
||||||
else:
|
else:
|
||||||
formats.append({
|
formats.append({
|
||||||
'format_id': format_id,
|
'format_id': format_id,
|
||||||
|
@ -638,6 +641,28 @@ class FacebookIE(InfoExtractor):
|
||||||
'url': playable_url,
|
'url': playable_url,
|
||||||
})
|
})
|
||||||
extract_dash_manifest(fmt_data, formats)
|
extract_dash_manifest(fmt_data, formats)
|
||||||
|
|
||||||
|
# New videoDeliveryResponse formats extraction
|
||||||
|
fmt_data = traverse_obj(video, ('videoDeliveryResponseFragment', 'videoDeliveryResponseResult'))
|
||||||
|
mpd_urls = traverse_obj(fmt_data, ('dash_manifest_urls', ..., 'manifest_url', {url_or_none}))
|
||||||
|
dash_manifests = traverse_obj(fmt_data, ('dash_manifests', lambda _, v: v['manifest_xml']))
|
||||||
|
for idx, dash_manifest in enumerate(dash_manifests):
|
||||||
|
extract_dash_manifest(dash_manifest, formats, mpd_url=traverse_obj(mpd_urls, idx))
|
||||||
|
if not dash_manifests:
|
||||||
|
# Only extract from MPD URLs if the manifests are not already provided
|
||||||
|
for mpd_url in mpd_urls:
|
||||||
|
formats.extend(self._extract_mpd_formats(mpd_url, video_id, fatal=False))
|
||||||
|
for prog_fmt in traverse_obj(fmt_data, ('progressive_urls', lambda _, v: v['progressive_url'])):
|
||||||
|
format_id = traverse_obj(prog_fmt, ('metadata', 'quality', {str.lower}))
|
||||||
|
formats.append({
|
||||||
|
'format_id': format_id,
|
||||||
|
# sd, hd formats w/o resolution info should be deprioritized below DASH
|
||||||
|
'quality': q(format_id) - 3,
|
||||||
|
'url': prog_fmt['progressive_url'],
|
||||||
|
})
|
||||||
|
for m3u8_url in traverse_obj(fmt_data, ('hls_playlist_urls', ..., 'hls_playlist_url', {url_or_none})):
|
||||||
|
formats.extend(self._extract_m3u8_formats(m3u8_url, video_id, 'mp4', fatal=False, m3u8_id='hls'))
|
||||||
|
|
||||||
if not formats:
|
if not formats:
|
||||||
# Do not append false positive entry w/o any formats
|
# Do not append false positive entry w/o any formats
|
||||||
return
|
return
|
||||||
|
|
|
@ -3,6 +3,7 @@ import urllib.parse
|
||||||
|
|
||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
from .youtube import YoutubeIE
|
from .youtube import YoutubeIE
|
||||||
|
from ..networking.exceptions import HTTPError
|
||||||
from ..utils import (
|
from ..utils import (
|
||||||
ExtractorError,
|
ExtractorError,
|
||||||
bug_reports_message,
|
bug_reports_message,
|
||||||
|
@ -12,6 +13,7 @@ from ..utils import (
|
||||||
get_element_html_by_id,
|
get_element_html_by_id,
|
||||||
int_or_none,
|
int_or_none,
|
||||||
lowercase_escape,
|
lowercase_escape,
|
||||||
|
traverse_obj,
|
||||||
try_get,
|
try_get,
|
||||||
update_url_query,
|
update_url_query,
|
||||||
)
|
)
|
||||||
|
@ -51,6 +53,17 @@ class GoogleDriveIE(InfoExtractor):
|
||||||
'duration': 184,
|
'duration': 184,
|
||||||
'thumbnail': 'https://drive.google.com/thumbnail?id=1IP0o8dHcQrIHGgVyp0Ofvx2cGfLzyO1x',
|
'thumbnail': 'https://drive.google.com/thumbnail?id=1IP0o8dHcQrIHGgVyp0Ofvx2cGfLzyO1x',
|
||||||
},
|
},
|
||||||
|
}, {
|
||||||
|
# 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',
|
||||||
|
},
|
||||||
}, {
|
}, {
|
||||||
# video can't be watched anonymously due to view count limit reached,
|
# video can't be watched anonymously due to view count limit reached,
|
||||||
# but can be downloaded (see https://github.com/ytdl-org/youtube-dl/issues/14046)
|
# but can be downloaded (see https://github.com/ytdl-org/youtube-dl/issues/14046)
|
||||||
|
@ -166,6 +179,17 @@ class GoogleDriveIE(InfoExtractor):
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
video_id = self._match_id(url)
|
video_id = self._match_id(url)
|
||||||
|
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
|
||||||
|
if webpage_urlh.url != url:
|
||||||
|
url = webpage_urlh.url
|
||||||
|
video_id = self._match_id(url)
|
||||||
|
|
||||||
video_info = urllib.parse.parse_qs(self._download_webpage(
|
video_info = urllib.parse.parse_qs(self._download_webpage(
|
||||||
'https://drive.google.com/get_video_info',
|
'https://drive.google.com/get_video_info',
|
||||||
video_id, 'Downloading video webpage', query={'docid': video_id}))
|
video_id, 'Downloading video webpage', query={'docid': video_id}))
|
||||||
|
@ -289,7 +313,7 @@ class GoogleDriveIE(InfoExtractor):
|
||||||
|
|
||||||
class GoogleDriveFolderIE(InfoExtractor):
|
class GoogleDriveFolderIE(InfoExtractor):
|
||||||
IE_NAME = 'GoogleDrive:Folder'
|
IE_NAME = 'GoogleDrive:Folder'
|
||||||
_VALID_URL = r'https?://(?:docs|drive)\.google\.com/drive/folders/(?P<id>[\w-]{28,})'
|
_VALID_URL = r'https?://(?:docs|drive)\.google\.com/drive/(?:folders/(?P<id>[\w-]{19,})|my-drive)'
|
||||||
_TESTS = [{
|
_TESTS = [{
|
||||||
'url': 'https://drive.google.com/drive/folders/1dQ4sx0-__Nvg65rxTSgQrl7VyW_FZ9QI',
|
'url': 'https://drive.google.com/drive/folders/1dQ4sx0-__Nvg65rxTSgQrl7VyW_FZ9QI',
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
|
@ -297,47 +321,83 @@ class GoogleDriveFolderIE(InfoExtractor):
|
||||||
'title': 'Forrest',
|
'title': 'Forrest',
|
||||||
},
|
},
|
||||||
'playlist_count': 3,
|
'playlist_count': 3,
|
||||||
|
}, {
|
||||||
|
'note': 'Contains various formats and a subfolder, folder name was formerly mismatched.'
|
||||||
|
'also contains loop shortcut, shortcut to non-downloadable files, etc.',
|
||||||
|
'url': 'https://docs.google.com/drive/folders/1jjrhqi94d8TSHSVMSdBjD49MOiHYpHfF',
|
||||||
|
'info_dict': {
|
||||||
|
'id': '1jjrhqi94d8TSHSVMSdBjD49MOiHYpHfF',
|
||||||
|
'title': '], sideChannel: {}});',
|
||||||
|
},
|
||||||
|
'playlist_count': 8,
|
||||||
}]
|
}]
|
||||||
_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
|
def _extract_json_meta(self, webpage, video_id, dsval=None, hashval=None, name=None, **kwargs):
|
||||||
|
"""
|
||||||
--{_BOUNDARY}
|
Uses regex to search for json metadata with 'ds' value(0-5) or 'hash' value(1-6)
|
||||||
'''
|
from the webpage.
|
||||||
|
logged out folder info:ds0hash1; items:ds4hash6
|
||||||
def _call_api(self, folder_id, key, data, **kwargs):
|
logged in folder info:ds0hash1; items:ds5hash6
|
||||||
response = self._download_webpage(
|
my-drive folder info:ds0hash1/ds0hash4; items:ds5hash6
|
||||||
'https://clients6.google.com/batch/drive/v2beta',
|
For example, if the webpage contains the line below, the empty data array
|
||||||
folder_id, data=data.encode(),
|
can be got by passing dsval=3 or hashval=2 to this method.
|
||||||
headers={
|
AF_initDataCallback({key: 'ds:3', hash: '2', data:[], sideChannel: {}});
|
||||||
'Content-Type': 'text/plain;charset=UTF-8;',
|
"""
|
||||||
'Origin': 'https://drive.google.com',
|
_ARRAY_RE = r'\[(?s:.+)\]'
|
||||||
}, query={
|
_META_END_RE = r', sideChannel: \{\}\}\);' # greedy match to deal with the 2nd test case
|
||||||
'$ct': f'multipart/mixed; boundary="{self._BOUNDARY}"',
|
if dsval is not None:
|
||||||
'key': key,
|
if not name:
|
||||||
}, **kwargs)
|
name = f'webpage JSON metadata ds:{dsval}'
|
||||||
return self._search_json('', response, 'api response', folder_id, **kwargs) or {}
|
return self._search_json(
|
||||||
|
rf'''key\s*?:\s*?(['"])ds:\s*?{dsval}\1,[^\[]*?data:''', webpage, name, video_id,
|
||||||
def _get_folder_items(self, folder_id, key):
|
end_pattern=_META_END_RE, contains_pattern=_ARRAY_RE, **kwargs)
|
||||||
page_token = ''
|
elif hashval is not None:
|
||||||
while page_token is not None:
|
if not name:
|
||||||
request = self._REQUEST.format(folder_id=folder_id, page_token=page_token, key=key)
|
name = f'webpage JSON metadata hash:{hashval}'
|
||||||
page = self._call_api(folder_id, key, self._DATA % request)
|
return self._search_json(
|
||||||
yield from page['items']
|
rf'''hash\s*?:\s*?(['"]){hashval}\1,[^\[]*?data:''', webpage, name, video_id,
|
||||||
page_token = page.get('nextPageToken')
|
end_pattern=_META_END_RE, contains_pattern=_ARRAY_RE, **kwargs)
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
folder_id = self._match_id(url)
|
def item_url_getter(item, video_id):
|
||||||
|
if not isinstance(item, list):
|
||||||
|
return None
|
||||||
|
available_IEs = (GoogleDriveFolderIE, GoogleDriveIE) # subfolder or item
|
||||||
|
if 'application/vnd.google-apps.shortcut' in item: # extract real link
|
||||||
|
entry_url = traverse_obj(
|
||||||
|
item,
|
||||||
|
(..., ..., lambda _, v: any(ie.suitable(v) for ie in available_IEs), any))
|
||||||
|
else:
|
||||||
|
entry_url = traverse_obj(
|
||||||
|
item,
|
||||||
|
(lambda _, v: any(ie.suitable(v) for ie in available_IEs), any))
|
||||||
|
if not entry_url:
|
||||||
|
return None
|
||||||
|
return self.url_result(entry_url, video_id=video_id, video_title=item[2])
|
||||||
|
|
||||||
webpage = self._download_webpage(url, folder_id)
|
folder_id = self._match_id(url) or 'my-drive'
|
||||||
key = self._search_regex(r'"(\w{39})"', webpage, 'key')
|
headers = self.geo_verification_headers()
|
||||||
|
|
||||||
folder_info = self._call_api(folder_id, key, self._DATA % f'/drive/v2beta/files/{folder_id} HTTP/1.1', fatal=False)
|
try:
|
||||||
|
webpage, urlh = self._download_webpage_handle(url, folder_id, headers=headers)
|
||||||
|
except ExtractorError as e:
|
||||||
|
if isinstance(e.cause, HTTPError):
|
||||||
|
if e.cause.status == 404:
|
||||||
|
self.raise_no_formats(e.cause.msg, expected=True)
|
||||||
|
elif e.cause.status == 403:
|
||||||
|
# logged in with an account without access
|
||||||
|
self.raise_login_required('Access Denied')
|
||||||
|
raise
|
||||||
|
if urllib.parse.urlparse(urlh.url).netloc == 'accounts.google.com':
|
||||||
|
# not logged in when visiting a private folder
|
||||||
|
self.raise_login_required('Access Denied')
|
||||||
|
|
||||||
return self.playlist_from_matches(
|
title = self._extract_json_meta(webpage, folder_id, dsval=0, name='folder info')[1][2]
|
||||||
self._get_folder_items(folder_id, key), folder_id, folder_info.get('title'),
|
items = self._extract_json_meta(webpage, folder_id, hashval=6, name='folder items')[-1]
|
||||||
ie=GoogleDriveIE, getter=lambda item: f'https://drive.google.com/file/d/{item["id"]}')
|
|
||||||
|
if items is False: # empty folder
|
||||||
|
return self.playlist_result([], folder_id, title)
|
||||||
|
|
||||||
|
return self.playlist_result(
|
||||||
|
(entry for item in items if (entry := item_url_getter(item, folder_id))),
|
||||||
|
folder_id, title)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user