From 83f45661471e56a83a59af8c467094f34e744b5f 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) default interval --- youtube_dlc/extractor/niconico.py | 14 ++++++++++++++ youtube_dlc/heartbeat.py | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) 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 @@ class NiconicoIE(InfoExtractor): } }).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 @@ class NiconicoIE(InfoExtractor): 'vbr': float_or_none(video_quality.get('bitrate'), 1000), 'height': resolution.get('height'), 'width': resolution.get('width'), + 'heartbeat': heartbeat, } def _real_extract(self, url): diff --git a/youtube_dlc/heartbeat.py b/youtube_dlc/heartbeat.py index a7d3229a3..7c6a234de 100644 --- a/youtube_dlc/heartbeat.py +++ b/youtube_dlc/heartbeat.py @@ -21,7 +21,7 @@ class Heartbeat(object): method=params.get('method') ) - self.interval = params.get('interval') + self.interval = params.get('interval', 30) self.stopped = False self.thread = threading.Thread(target=self.__heartbeat, daemon=True)