From 918f4f374a6e97acc9d0d3d556a9fd3c0544f154 Mon Sep 17 00:00:00 2001 From: Wong Yiu Hang Date: Thu, 4 Feb 2021 00:06:40 +0800 Subject: [PATCH] [Loom] Update: Move related member functions into LoomIE --- youtube_dl/extractor/loom.py | 48 ++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/youtube_dl/extractor/loom.py b/youtube_dl/extractor/loom.py index 1a22d7aeb..a386f6283 100644 --- a/youtube_dl/extractor/loom.py +++ b/youtube_dl/extractor/loom.py @@ -17,30 +17,6 @@ from ..utils import ( class LoomBaseInfoIE(InfoExtractor): _BASE_URL = 'https://www.loom.com/' - def _extract_video_info_json(self, webpage, video_id): - info = self._html_search_regex( - r'window.loomSSRVideo = (.+?);', - webpage, - 'info') - return self._parse_json(info, 'json', js_to_json) - - def _get_url_by_id_type(self, video_id, type): - request = compat_urllib_request.Request( - self._BASE_URL + 'api/campaigns/sessions/' + video_id + '/' + type, - {}) - (json, _) = self._download_json_handle(request, video_id) - return (url_or_none(json.get('url')), json.get('part_credentials')) - - def _get_m3u8_formats(self, url, video_id, credentials): - format_list = self._extract_m3u8_formats(url, video_id) - for item in format_list: - item['protocol'] = 'm3u8_native' - item['url'] += '?' + credentials - item['ext'] = 'mp4' - item['format_id'] = 'hls-' + str(item.get('height', 0)) - item['extra_param_to_segment_url'] = credentials - return format_list - class LoomIE(LoomBaseInfoIE): _VALID_URL = r'https?://(?:www\.)?loom\.com/share/(?P[a-zA-Z0-9]+)' @@ -83,6 +59,30 @@ class LoomIE(LoomBaseInfoIE): } ] + def _extract_video_info_json(self, webpage, video_id): + info = self._html_search_regex( + r'window.loomSSRVideo = (.+?);', + webpage, + 'info') + return self._parse_json(info, 'json', js_to_json) + + def _get_url_by_id_type(self, video_id, type): + request = compat_urllib_request.Request( + self._BASE_URL + 'api/campaigns/sessions/' + video_id + '/' + type, + {}) + json = self._download_json(request, video_id) + return (url_or_none(json.get('url')), json.get('part_credentials')) + + def _get_m3u8_formats(self, url, video_id, credentials): + format_list = self._extract_m3u8_formats(url, video_id) + for item in format_list: + item['protocol'] = 'm3u8_native' + item['url'] += '?' + credentials + item['ext'] = 'mp4' + item['format_id'] = 'hls-' + str(item.get('height', 0)) + item['extra_param_to_segment_url'] = credentials + return format_list + def _real_extract(self, url): video_id = self._match_id(url) webpage = self._download_webpage(url, video_id)