]>
jfr.im git - yt-dlp.git/blob - yt_dlp/downloader/websocket.py
10 has_websockets
= False
12 from .common
import FileDownloader
13 from .external
import FFmpegFD
16 class FFmpegSinkFD(FileDownloader
):
17 """ A sink to ffmpeg for downloading fragments in any form """
19 def real_download(self
, filename
, info_dict
):
20 info_copy
= info_dict
.copy()
21 info_copy
['url'] = '-'
23 async def call_conn(proc
, stdin
):
25 await self
.real_connection(stdin
, info_dict
)
26 except (BrokenPipeError
, OSError):
34 os
.kill(os
.getpid(), signal
.SIGINT
)
36 class FFmpegStdinFD(FFmpegFD
):
38 def get_basename(cls
):
39 return FFmpegFD
.get_basename()
41 def on_process_started(self
, proc
, stdin
):
42 thread
= threading
.Thread(target
=asyncio
.run
, daemon
=True, args
=(call_conn(proc
, stdin
), ))
45 return FFmpegStdinFD(self
.ydl
, self
.params
or {}).download(filename
, info_copy
)
47 async def real_connection(self
, sink
, info_dict
):
48 """ Override this in subclasses """
49 raise NotImplementedError('This method must be implemented by subclasses')
52 class WebSocketFragmentFD(FFmpegSinkFD
):
53 async def real_connection(self
, sink
, info_dict
):
54 async with websockets
.connect(info_dict
['url'], extra_headers
=info_dict
.get('http_headers', {})) as ws
:
56 recv
= await ws
.recv()
57 if isinstance(recv
, str):
58 recv
= recv
.encode('utf8')