From 6d805a6a1a2db5ce3223a1c8c7031a69a0cedb94 Mon Sep 17 00:00:00 2001 From: Lam Date: Mon, 3 Aug 2020 19:07:32 +0200 Subject: [PATCH] New v3 API for Floatplane. Saves us downloading urls for each quality separately. --- youtube_dl/extractor/floatplane.py | 39 ++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/youtube_dl/extractor/floatplane.py b/youtube_dl/extractor/floatplane.py index b9adb06d4..c7547a4ac 100644 --- a/youtube_dl/extractor/floatplane.py +++ b/youtube_dl/extractor/floatplane.py @@ -7,7 +7,7 @@ from ..compat import compat_str class FloatplaneIE(InfoExtractor): - _VALID_URL = r'https?://(?:www\.)?floatplane\.com/video/(?P[A-Za-z0-9]+)' + _VALID_URL = r'https?://(?:www\.)?floatplane\.com/post/(?P[A-Za-z0-9]+)' _NETRC_MACHINE = 'floatplane' def _real_extract(self, url): @@ -19,7 +19,7 @@ class FloatplaneIE(InfoExtractor): 'username': username, 'password': password }) - user_json = self._download_json('https://www.floatplane.com/api/auth/login', video_id, data=request_data, note='Logging in') + user_json = self._download_json('https://www.floatplane.com/api/v2/auth/login', video_id, data=request_data, note='Logging in') self.to_screen('Logged in as %s.' % user_json['user']['username']) # What if url_json['user']['needs2FA']? Can we ask for token from ytdl? # Post 'token' to https://www.floatplane.com/api/auth/checkFor2faLogin @@ -29,23 +29,42 @@ class FloatplaneIE(InfoExtractor): raise ExtractorError('Floatplane login error! Check your .netrc for correct login/password.', expected=True) try: - info_json = self._download_json('https://www.floatplane.com/api/video/info?videoGUID=%s' % video_id, video_id, note='Downloading video info') + info_json = self._download_json('https://www.floatplane.com/api/v3/content/post?id=%s' % video_id, video_id, note='Downloading video info') + except ExtractorError as e: + print(e) + raise ExtractorError('Floatplane download error! Please make sure you\'re logged in.', expected=True) + + attachments = info_json.get('attachmentOrder') + if not attachments or len(attachments) < 1: + raise ExtractorError('Can\'t get real video id!') + # I'm guessing this is for future addition of playlists, but currently + # a "post" always contains a single video + real_video_id = attachments[0] + if self._downloader.params.get('verbose', False): + self.to_screen('Real video id: %s.' % real_video_id) + + try: + cdn_json = self._download_json('https://www.floatplane.com/api/v2/cdn/delivery?type=vod&guid=%s' % real_video_id, video_id, note='Downloading delivery info') except ExtractorError as e: print(e) raise ExtractorError('Floatplane download error! Please make sure you\'re logged in.', expected=True) formats = [] - # unfortunately it needs to download video url for each quality - # so I have to download 4 pages each time - for level in info_json['levels']: - video_url = self._download_webpage('https://www.floatplane.com/api/video/url?guid=%s&quality=%s' % (video_id, level['name']), video_id, note='Downloading url for %s' % level['label']) - video_url = video_url.strip('"') + # new api has all the info in one request, no more downloading + # each url separately + for level in cdn_json['resource']['data']['qualityLevels']: + video_url = cdn_json['cdn'] + cdn_json['resource']['uri'] + video_url = video_url.replace('{qualityLevels}',level['name']) + video_url = video_url.replace('{qualityLevelParams.token}',cdn_json['resource']['data']['qualityLevelParams'][level['name']]['token']) formats.append({ 'format_id': level['name'], 'url': video_url, 'quality': level.get('label'), 'width': level.get('width'), - 'height': level.get('height') + 'height': level.get('height'), + 'ext': 'mp4' + # with delivery?type=download, extension is mp4, but we want + # to keep using the vod api (worked when downloads didn't) }) return { @@ -55,5 +74,5 @@ class FloatplaneIE(InfoExtractor): 'url': video_url, 'thumbnail': try_get(info_json, lambda x: x['thumbnail']['path'], compat_str), 'formats': formats, - 'duration': int_or_none(info_json.get('duration')) + 'duration': int_or_none(try_get(info_json, lambda x: x['metsadata']['videoDuration'])) }