]>
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
19 class FFmpegSinkFD(FileDownloader
):
20 """ A sink to ffmpeg for downloading fragments in any form """
22 def real_download(self
, filename
, info_dict
):
23 info_copy
= info_dict
.copy()
24 info_copy
['url'] = '-'
26 async def call_conn(proc
, stdin
):
28 await self
.real_connection(stdin
, info_dict
)
29 except (BrokenPipeError
, OSError):
37 os
.kill(os
.getpid(), signal
.SIGINT
)
39 class FFmpegStdinFD(FFmpegFD
):
41 def get_basename(cls
):
42 return FFmpegFD
.get_basename()
44 def on_process_started(self
, proc
, stdin
):
45 thread
= threading
.Thread(target
=asyncio
.run
, daemon
=True, args
=(call_conn(proc
, stdin
), ))
48 return FFmpegStdinFD(self
.ydl
, self
.params
or {}).download(filename
, info_copy
)
50 async def real_connection(self
, sink
, info_dict
):
51 """ Override this in subclasses """
52 raise NotImplementedError('This method must be implemented by subclasses')
55 class WebSocketFragmentFD(FFmpegSinkFD
):
56 async def real_connection(self
, sink
, info_dict
):
57 async with websockets
.connect(info_dict
['url'], extra_headers
=info_dict
.get('http_headers', {})) as ws
:
59 recv
= await ws
.recv()
60 if isinstance(recv
, str):
61 recv
= recv
.encode('utf8')