From 41c6125907f59ee84b392d832299a6927b99a9c9 Mon Sep 17 00:00:00 2001 From: Mozi <29089388+pzhlkj6612@users.noreply.github.com> Date: Mon, 11 Mar 2024 15:22:07 +0000 Subject: [PATCH] [ie/niconico] Move WebSocket headers to info_dict Thanks for coletdjnz's suggestion! --- yt_dlp/downloader/niconico.py | 3 +-- yt_dlp/extractor/niconico.py | 7 +++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/yt_dlp/downloader/niconico.py b/yt_dlp/downloader/niconico.py index 4c51bb166..7011d83e2 100644 --- a/yt_dlp/downloader/niconico.py +++ b/yt_dlp/downloader/niconico.py @@ -84,8 +84,7 @@ def _ws_context(self, info_dict): def communicate_ws(reconnect): if reconnect: - self.ws = self.ydl.urlopen(Request( - self.ws.url, headers={'Origin': self.ws.wsw.request.headers['Origin']})) + self.ws = self.ydl.urlopen(Request(self.ws.url, headers=info_dict.get('http_headers'))) if self.ydl.params.get('verbose', False): self.to_screen('[debug] Sending startWatching request') self.ws.send(json.dumps({ diff --git a/yt_dlp/extractor/niconico.py b/yt_dlp/extractor/niconico.py index 5fa84a34b..805b40193 100644 --- a/yt_dlp/extractor/niconico.py +++ b/yt_dlp/extractor/niconico.py @@ -1009,6 +1009,7 @@ def _yield_formats(self, ws, video_id, latency, is_live): def _real_extract(self, url): video_id = self._match_id(url) webpage, urlh = self._download_webpage_handle(f'https://live.nicovideo.jp/watch/{video_id}', video_id) + headers = {'Origin': 'https://' + remove_start(urlparse(urlh.url).hostname, 'sp.')} embedded_data = self._parse_json(unescapeHTML(self._search_regex( r'