From d3eb3aaadecc7c0d11104ea256af7ca8ff12ab1b Mon Sep 17 00:00:00 2001 From: insaneracist Date: Sat, 31 Oct 2020 15:19:57 -0700 Subject: [PATCH] [niconico] fix: download video while sending heartbeat (#72) --- youtube_dlc/extractor/niconico.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/youtube_dlc/extractor/niconico.py b/youtube_dlc/extractor/niconico.py index eb07ca776..6b4726bae 100644 --- a/youtube_dlc/extractor/niconico.py +++ b/youtube_dlc/extractor/niconico.py @@ -254,6 +254,19 @@ def yesno(boolean): } }).encode()) + heartbeat_url = '{}/{}?_format=json&_method=PUT'.format(session_api_endpoint['url'], session_response['data']['session']['id']) + heartbeat_headers = { + 'Accept': 'application/json', + 'Content-Type': 'application/json', + } + heartbeat = { + 'data': json.dumps(session_response['data']), + 'headers': heartbeat_headers, + 'interval': session_api_data['heartbeat_lifetime'] / 2000, + 'method': 'POST', + 'url': heartbeat_url, + } + resolution = video_quality.get('resolution', {}) return { @@ -264,6 +277,7 @@ def yesno(boolean): 'vbr': float_or_none(video_quality.get('bitrate'), 1000), 'height': resolution.get('height'), 'width': resolution.get('width'), + 'heartbeat': heartbeat, } def _real_extract(self, url):