mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2025-12-13 19:55:25 +00:00
@@ -8,12 +8,10 @@ from ..utils import (
|
|||||||
ExtractorError,
|
ExtractorError,
|
||||||
determine_ext,
|
determine_ext,
|
||||||
filter_dict,
|
filter_dict,
|
||||||
get_first,
|
|
||||||
int_or_none,
|
int_or_none,
|
||||||
parse_iso8601,
|
parse_iso8601,
|
||||||
update_url,
|
update_url,
|
||||||
url_or_none,
|
url_or_none,
|
||||||
variadic,
|
|
||||||
)
|
)
|
||||||
from ..utils.traversal import traverse_obj
|
from ..utils.traversal import traverse_obj
|
||||||
|
|
||||||
@@ -51,7 +49,7 @@ class LoomIE(InfoExtractor):
|
|||||||
}, {
|
}, {
|
||||||
# m3u8 raw-url, mp4 transcoded-url, cdn url == raw-url, vtt sub and json subs
|
# m3u8 raw-url, mp4 transcoded-url, cdn url == raw-url, vtt sub and json subs
|
||||||
'url': 'https://www.loom.com/share/9458bcbf79784162aa62ffb8dd66201b',
|
'url': 'https://www.loom.com/share/9458bcbf79784162aa62ffb8dd66201b',
|
||||||
'md5': '51737ec002969dd28344db4d60b9cbbb',
|
'md5': '7b6bfdef8181c4ffc376e18919a4dcc2',
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': '9458bcbf79784162aa62ffb8dd66201b',
|
'id': '9458bcbf79784162aa62ffb8dd66201b',
|
||||||
'ext': 'mp4',
|
'ext': 'mp4',
|
||||||
@@ -71,12 +69,13 @@ class LoomIE(InfoExtractor):
|
|||||||
'ext': 'webm',
|
'ext': 'webm',
|
||||||
'title': 'OMFG clown',
|
'title': 'OMFG clown',
|
||||||
'description': 'md5:285c5ee9d62aa087b7e3271b08796815',
|
'description': 'md5:285c5ee9d62aa087b7e3271b08796815',
|
||||||
'uploader': 'MrPumkin B',
|
'uploader': 'Brailey Bragg',
|
||||||
'upload_date': '20210924',
|
'upload_date': '20210924',
|
||||||
'timestamp': 1632519618,
|
'timestamp': 1632519618,
|
||||||
'duration': 210,
|
'duration': 210,
|
||||||
},
|
},
|
||||||
'params': {'skip_download': 'dash'},
|
'params': {'skip_download': 'dash'},
|
||||||
|
'expected_warnings': ['Failed to parse JSON'], # transcoded-url no longer available
|
||||||
}, {
|
}, {
|
||||||
# password-protected
|
# password-protected
|
||||||
'url': 'https://www.loom.com/share/50e26e8aeb7940189dff5630f95ce1f4',
|
'url': 'https://www.loom.com/share/50e26e8aeb7940189dff5630f95ce1f4',
|
||||||
@@ -91,10 +90,11 @@ class LoomIE(InfoExtractor):
|
|||||||
'duration': 35,
|
'duration': 35,
|
||||||
},
|
},
|
||||||
'params': {'videopassword': 'seniorinfants2'},
|
'params': {'videopassword': 'seniorinfants2'},
|
||||||
|
'expected_warnings': ['Failed to parse JSON'], # transcoded-url no longer available
|
||||||
}, {
|
}, {
|
||||||
# embed, transcoded-url endpoint sends empty JSON response, split video and audio HLS formats
|
# embed, transcoded-url endpoint sends empty JSON response, split video and audio HLS formats
|
||||||
'url': 'https://www.loom.com/embed/ddcf1c1ad21f451ea7468b1e33917e4e',
|
'url': 'https://www.loom.com/embed/ddcf1c1ad21f451ea7468b1e33917e4e',
|
||||||
'md5': 'b321d261656848c184a94e3b93eae28d',
|
'md5': 'f983a0f02f24331738b2f43aecb05256',
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': 'ddcf1c1ad21f451ea7468b1e33917e4e',
|
'id': 'ddcf1c1ad21f451ea7468b1e33917e4e',
|
||||||
'ext': 'mp4',
|
'ext': 'mp4',
|
||||||
@@ -119,11 +119,12 @@ class LoomIE(InfoExtractor):
|
|||||||
'duration': 247,
|
'duration': 247,
|
||||||
'timestamp': 1676274030,
|
'timestamp': 1676274030,
|
||||||
},
|
},
|
||||||
|
'skip': '404 Not Found',
|
||||||
}]
|
}]
|
||||||
|
|
||||||
_GRAPHQL_VARIABLES = {
|
_GRAPHQL_VARIABLES = {
|
||||||
'GetVideoSource': {
|
'GetVideoSource': {
|
||||||
'acceptableMimes': ['DASH', 'M3U8', 'MP4'],
|
'acceptableMimes': ['DASH', 'M3U8', 'MP4', 'WEBM'],
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
_GRAPHQL_QUERIES = {
|
_GRAPHQL_QUERIES = {
|
||||||
@@ -192,6 +193,12 @@ class LoomIE(InfoExtractor):
|
|||||||
id
|
id
|
||||||
nullableRawCdnUrl(acceptableMimes: $acceptableMimes, password: $password) {
|
nullableRawCdnUrl(acceptableMimes: $acceptableMimes, password: $password) {
|
||||||
url
|
url
|
||||||
|
credentials {
|
||||||
|
Policy
|
||||||
|
Signature
|
||||||
|
KeyPairId
|
||||||
|
__typename
|
||||||
|
}
|
||||||
__typename
|
__typename
|
||||||
}
|
}
|
||||||
__typename
|
__typename
|
||||||
@@ -240,9 +247,9 @@ class LoomIE(InfoExtractor):
|
|||||||
}
|
}
|
||||||
}\n'''),
|
}\n'''),
|
||||||
}
|
}
|
||||||
_APOLLO_GRAPHQL_VERSION = '0a1856c'
|
_APOLLO_GRAPHQL_VERSION = '45a5bd4'
|
||||||
|
|
||||||
def _call_graphql_api(self, operations, video_id, note=None, errnote=None):
|
def _call_graphql_api(self, operation_name, video_id, note=None, errnote=None, fatal=True):
|
||||||
password = self.get_param('videopassword')
|
password = self.get_param('videopassword')
|
||||||
return self._download_json(
|
return self._download_json(
|
||||||
'https://www.loom.com/graphql', video_id, note or 'Downloading GraphQL JSON',
|
'https://www.loom.com/graphql', video_id, note or 'Downloading GraphQL JSON',
|
||||||
@@ -252,7 +259,9 @@ class LoomIE(InfoExtractor):
|
|||||||
'x-loom-request-source': f'loom_web_{self._APOLLO_GRAPHQL_VERSION}',
|
'x-loom-request-source': f'loom_web_{self._APOLLO_GRAPHQL_VERSION}',
|
||||||
'apollographql-client-name': 'web',
|
'apollographql-client-name': 'web',
|
||||||
'apollographql-client-version': self._APOLLO_GRAPHQL_VERSION,
|
'apollographql-client-version': self._APOLLO_GRAPHQL_VERSION,
|
||||||
}, data=json.dumps([{
|
'graphql-operation-name': operation_name,
|
||||||
|
'Origin': 'https://www.loom.com',
|
||||||
|
}, data=json.dumps({
|
||||||
'operationName': operation_name,
|
'operationName': operation_name,
|
||||||
'variables': {
|
'variables': {
|
||||||
'videoId': video_id,
|
'videoId': video_id,
|
||||||
@@ -260,7 +269,7 @@ class LoomIE(InfoExtractor):
|
|||||||
**self._GRAPHQL_VARIABLES.get(operation_name, {}),
|
**self._GRAPHQL_VARIABLES.get(operation_name, {}),
|
||||||
},
|
},
|
||||||
'query': self._GRAPHQL_QUERIES[operation_name],
|
'query': self._GRAPHQL_QUERIES[operation_name],
|
||||||
} for operation_name in variadic(operations)], separators=(',', ':')).encode())
|
}, separators=(',', ':')).encode(), fatal=fatal)
|
||||||
|
|
||||||
def _call_url_api(self, endpoint, video_id):
|
def _call_url_api(self, endpoint, video_id):
|
||||||
response = self._download_json(
|
response = self._download_json(
|
||||||
@@ -275,7 +284,7 @@ class LoomIE(InfoExtractor):
|
|||||||
}, separators=(',', ':')).encode())
|
}, separators=(',', ':')).encode())
|
||||||
return traverse_obj(response, ('url', {url_or_none}))
|
return traverse_obj(response, ('url', {url_or_none}))
|
||||||
|
|
||||||
def _extract_formats(self, video_id, metadata, gql_data):
|
def _extract_formats(self, video_id, metadata, video_data):
|
||||||
formats = []
|
formats = []
|
||||||
video_properties = traverse_obj(metadata, ('video_properties', {
|
video_properties = traverse_obj(metadata, ('video_properties', {
|
||||||
'width': ('width', {int_or_none}),
|
'width': ('width', {int_or_none}),
|
||||||
@@ -330,7 +339,7 @@ class LoomIE(InfoExtractor):
|
|||||||
transcoded_url = self._call_url_api('transcoded-url', video_id)
|
transcoded_url = self._call_url_api('transcoded-url', video_id)
|
||||||
formats.extend(get_formats(transcoded_url, 'transcoded', quality=-1)) # transcoded quality
|
formats.extend(get_formats(transcoded_url, 'transcoded', quality=-1)) # transcoded quality
|
||||||
|
|
||||||
cdn_url = get_first(gql_data, ('data', 'getVideo', 'nullableRawCdnUrl', 'url', {url_or_none}))
|
cdn_url = traverse_obj(video_data, ('data', 'getVideo', 'nullableRawCdnUrl', 'url', {url_or_none}))
|
||||||
# cdn_url is usually a dupe, but the raw-url/transcoded-url endpoints could return errors
|
# cdn_url is usually a dupe, but the raw-url/transcoded-url endpoints could return errors
|
||||||
valid_urls = [update_url(url, query=None) for url in (raw_url, transcoded_url) if url]
|
valid_urls = [update_url(url, query=None) for url in (raw_url, transcoded_url) if url]
|
||||||
if cdn_url and update_url(cdn_url, query=None) not in valid_urls:
|
if cdn_url and update_url(cdn_url, query=None) not in valid_urls:
|
||||||
@@ -338,10 +347,21 @@ class LoomIE(InfoExtractor):
|
|||||||
|
|
||||||
return formats
|
return formats
|
||||||
|
|
||||||
|
def _get_subtitles(self, video_id):
|
||||||
|
subs_data = self._call_graphql_api(
|
||||||
|
'FetchVideoTranscript', video_id, 'Downloading GraphQL subtitles JSON', fatal=False)
|
||||||
|
return filter_dict({
|
||||||
|
'en': traverse_obj(subs_data, (
|
||||||
|
'data', 'fetchVideoTranscript',
|
||||||
|
('source_url', 'captions_source_url'), {
|
||||||
|
'url': {url_or_none},
|
||||||
|
})) or None,
|
||||||
|
})
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
video_id = self._match_id(url)
|
video_id = self._match_id(url)
|
||||||
metadata = get_first(
|
metadata = traverse_obj(
|
||||||
self._call_graphql_api('GetVideoSSR', video_id, 'Downloading GraphQL metadata JSON'),
|
self._call_graphql_api('GetVideoSSR', video_id, 'Downloading GraphQL metadata JSON', fatal=False),
|
||||||
('data', 'getVideo', {dict})) or {}
|
('data', 'getVideo', {dict})) or {}
|
||||||
|
|
||||||
if metadata.get('__typename') == 'VideoPasswordMissingOrIncorrect':
|
if metadata.get('__typename') == 'VideoPasswordMissingOrIncorrect':
|
||||||
@@ -350,22 +370,19 @@ class LoomIE(InfoExtractor):
|
|||||||
'This video is password-protected, use the --video-password option', expected=True)
|
'This video is password-protected, use the --video-password option', expected=True)
|
||||||
raise ExtractorError('Invalid video password', expected=True)
|
raise ExtractorError('Invalid video password', expected=True)
|
||||||
|
|
||||||
gql_data = self._call_graphql_api(['FetchChapters', 'FetchVideoTranscript', 'GetVideoSource'], video_id)
|
video_data = self._call_graphql_api(
|
||||||
|
'GetVideoSource', video_id, 'Downloading GraphQL video JSON')
|
||||||
|
chapter_data = self._call_graphql_api(
|
||||||
|
'FetchChapters', video_id, 'Downloading GraphQL chapters JSON', fatal=False)
|
||||||
duration = traverse_obj(metadata, ('video_properties', 'duration', {int_or_none}))
|
duration = traverse_obj(metadata, ('video_properties', 'duration', {int_or_none}))
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'id': video_id,
|
'id': video_id,
|
||||||
'duration': duration,
|
'duration': duration,
|
||||||
'chapters': self._extract_chapters_from_description(
|
'chapters': self._extract_chapters_from_description(
|
||||||
get_first(gql_data, ('data', 'fetchVideoChapters', 'content', {str})), duration) or None,
|
traverse_obj(chapter_data, ('data', 'fetchVideoChapters', 'content', {str})), duration) or None,
|
||||||
'formats': self._extract_formats(video_id, metadata, gql_data),
|
'formats': self._extract_formats(video_id, metadata, video_data),
|
||||||
'subtitles': filter_dict({
|
'subtitles': self.extract_subtitles(video_id),
|
||||||
'en': traverse_obj(gql_data, (
|
|
||||||
..., 'data', 'fetchVideoTranscript',
|
|
||||||
('source_url', 'captions_source_url'), {
|
|
||||||
'url': {url_or_none},
|
|
||||||
})) or None,
|
|
||||||
}),
|
|
||||||
**traverse_obj(metadata, {
|
**traverse_obj(metadata, {
|
||||||
'title': ('name', {str}),
|
'title': ('name', {str}),
|
||||||
'description': ('description', {str}),
|
'description': ('description', {str}),
|
||||||
@@ -376,6 +393,7 @@ class LoomIE(InfoExtractor):
|
|||||||
|
|
||||||
|
|
||||||
class LoomFolderIE(InfoExtractor):
|
class LoomFolderIE(InfoExtractor):
|
||||||
|
_WORKING = False
|
||||||
IE_NAME = 'loom:folder'
|
IE_NAME = 'loom:folder'
|
||||||
_VALID_URL = r'https?://(?:www\.)?loom\.com/share/folder/(?P<id>[\da-f]{32})'
|
_VALID_URL = r'https?://(?:www\.)?loom\.com/share/folder/(?P<id>[\da-f]{32})'
|
||||||
_TESTS = [{
|
_TESTS = [{
|
||||||
|
|||||||
Reference in New Issue
Block a user