]>
jfr.im git - yt-dlp.git/blob - yt_dlp/downloader/websocket.py
8 except (ImportError, SyntaxError):
9 # websockets 3.10 on python 3.6 causes SyntaxError
10 # See https://github.com/yt-dlp/yt-dlp/issues/2633
11 has_websockets
= False
15 from .common
import FileDownloader
16 from .external
import FFmpegFD
17 from ..compat
import asyncio
20 class FFmpegSinkFD(FileDownloader
):
21 """ A sink to ffmpeg for downloading fragments in any form """
23 def real_download(self
, filename
, info_dict
):
24 info_copy
= info_dict
.copy()
25 info_copy
['url'] = '-'
27 async def call_conn(proc
, stdin
):
29 await self
.real_connection(stdin
, info_dict
)
30 except (BrokenPipeError
, OSError):
33 with contextlib
.suppress(OSError):
36 os
.kill(os
.getpid(), signal
.SIGINT
)
38 class FFmpegStdinFD(FFmpegFD
):
40 def get_basename(cls
):
41 return FFmpegFD
.get_basename()
43 def on_process_started(self
, proc
, stdin
):
44 thread
= threading
.Thread(target
=asyncio
.run
, daemon
=True, args
=(call_conn(proc
, stdin
), ))
47 return FFmpegStdinFD(self
.ydl
, self
.params
or {}).download(filename
, info_copy
)
49 async def real_connection(self
, sink
, info_dict
):
50 """ Override this in subclasses """
51 raise NotImplementedError('This method must be implemented by subclasses')
54 class WebSocketFragmentFD(FFmpegSinkFD
):
55 async def real_connection(self
, sink
, info_dict
):
56 async with websockets
.connect(info_dict
['url'], extra_headers
=info_dict
.get('http_headers', {})) as ws
:
58 recv
= await ws
.recv()
59 if isinstance(recv
, str):
60 recv
= recv
.encode('utf8')