apply patch

This commit is contained in:
Lesmiscore 2022-07-14 09:11:54 +09:00
parent df63ae4477
commit 012993fa8d
No known key found for this signature in database
GPG key ID: 0EC2B52CF86236FF

View file

@ -9,7 +9,7 @@
from ..dependencies import websockets
class AsyncSinkFD(FileDownloader):
class _WebSocketFD(FileDownloader):
async def connect(self, stdin, info_dict):
try:
await self.real_connection(stdin, info_dict)
@ -21,11 +21,15 @@ async def connect(self, stdin, info_dict):
stdin.close()
async def real_connection(self, sink, info_dict):
""" Override this in subclasses """
raise NotImplementedError('This method must be implemented by subclasses')
async with websockets.connect(info_dict['url'], extra_headers=info_dict.get('http_headers', {})) as ws:
while True:
recv = await ws.recv()
if isinstance(recv, str):
recv = recv.encode('utf8')
sink.write(recv)
class FFmpegSinkFD(AsyncSinkFD):
class WebSocketFragmentFD(_WebSocketFD):
""" A sink to ffmpeg for downloading fragments in any form """
def real_download(self, filename, info_dict):
@ -45,7 +49,7 @@ def on_process_started(self, proc, stdin):
return FFmpegStdinFD(self.ydl, self.params or {}).download(filename, info_copy)
class FileSinkFD(AsyncSinkFD):
class WebSocketToFileFD(_WebSocketFD):
""" A sink to a file for downloading fragments in any form """
def real_download(self, filename, info_dict):
tempname = self.temp_name(filename)
@ -87,21 +91,3 @@ def real_download(self, filename, info_dict):
finally:
os.replace(tempname, filename)
return True
class _WebSocketFD(AsyncSinkFD):
async def real_connection(self, sink, info_dict):
async with websockets.connect(info_dict['url'], extra_headers=info_dict.get('http_headers', {})) as ws:
while True:
recv = await ws.recv()
if isinstance(recv, str):
recv = recv.encode('utf8')
sink.write(recv)
class WebSocketFragmentFD(_WebSocketFD, FFmpegSinkFD):
pass
class WebSocketToFileFD(_WebSocketFD, FileSinkFD):
pass