A feature-rich command-line audio/video downloader
[fd/external] Fix ffmpeg input from stdin (#7655)
bashonlye57eb98222d2
diff --git a/test/test_downloader_external.py b/test/test_downloader_external.pyindex d3d74df043..62f7d45d49 100644--- a/test/test_downloader_external.py+++ b/test/test_downloader_external.py@@ -129,6 +129,11 @@ class TestFFmpegFD(unittest.TestCase):'ffmpeg', '-y', '-hide_banner', '-cookies', 'test=ytdlp; path=/; domain=.example.com;\r\n','-i', 'http://www.example.com/', '-c', 'copy', '-f', 'mp4', 'file:test'])+ # Test with non-url input (ffmpeg reads from stdin '-' for websockets)+ downloader._call_downloader('test', {'url': 'x', 'ext': 'mp4'})+ self.assertEqual(self._args, [+ 'ffmpeg', '-y', '-hide_banner', '-i', 'x', '-c', 'copy', '-f', 'mp4', 'file:test'])+if __name__ == '__main__':unittest.main()diff --git a/yt_dlp/downloader/external.py b/yt_dlp/downloader/external.pyindex 4f52f6e8df..d3c3eba888 100644--- a/yt_dlp/downloader/external.py+++ b/yt_dlp/downloader/external.py@@ -559,12 +559,13 @@ class FFmpegFD(ExternalFD):selected_formats = info_dict.get('requested_formats') or [info_dict]for i, fmt in enumerate(selected_formats):- cookies = self.ydl.cookiejar.get_cookies_for_url(fmt['url'])+ is_http = re.match(r'^https?://', fmt['url'])+ cookies = self.ydl.cookiejar.get_cookies_for_url(fmt['url']) if is_http else []if cookies:args.extend(['-cookies', ''.join(f'{cookie.name}={cookie.value}; path={cookie.path}; domain={cookie.domain};\r\n'for cookie in cookies)])- if fmt.get('http_headers') and re.match(r'^https?://', fmt['url']):+ if fmt.get('http_headers') and is_http:# Trailing \r\n after each HTTP header is important to prevent warning from ffmpeg/avconv:# [http @ 00000000003d2fa0] No trailing CRLF found in HTTP header.args.extend(['-headers', ''.join(f'{key}: {val}\r\n' for key, val in fmt['http_headers'].items())])